add.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*******************************************************************************
  2. * Copyright(c) 2022 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:
  5. * 编辑履历:
  6. * 作者 日期 版本 修改内容
  7. * 于继渤 2024-1-23 1.00 客户档案新增
  8. *******************************************************************************/
  9. const Constants = require('@/utils/Constants.js');
  10. const util = require('@/utils/util.js')
  11. const mixins = require('@/mixins/index.js')
  12. const app = getApp()
  13. Page({
  14. mixins: [mixins],
  15. /**
  16. * 页面的初始数据
  17. */
  18. data: {
  19. routeObjName: 'customer',
  20. gradeCode: app.globalData.company.gradeCode,
  21. saleChannelService: app.globalData['saleChannelService'],
  22. cardList: ['main', 'center', 'remarks'],
  23. buttonSaveList: [{ code: 'add', title: mixins.$t('save'), width: '120rpx' }],
  24. contentObj: {
  25. main: [
  26. { code: 'cusName', type: 'str', required: true, title: mixins.$t('customerName') },
  27. { code: 'cusPhone', type: 'phone', title: mixins.$t('cusPhone'), required: true },
  28. { code: 'addressFull', type: 'address', title: mixins.$t('addressFull'), required: true },
  29. { code: 'addressNo', type: 'str', required: true, title: mixins.$t('addressNo') },
  30. { code: 'cusFrom', name: 'cusFromName', required: true, title: mixins.$t('customerSource'), type: 'choose', urlKey: 'choosecusFrom' },
  31. { code: 'contactName', type: 'str', required: false, title: mixins.$t('contactName') },
  32. { code: 'contactPhone', type: 'str', title: mixins.$t('cpPhone'), required: false },
  33. ],
  34. center: [
  35. { code: 'channelId', name: 'channelName', required: true, title: mixins.$t('saleChannel'), type: 'choose', urlKey: 'chooseChannel' },
  36. { code: 'staffId', name: 'staffName', type: 'choose', required: true, title: mixins.$t('saleStaff'), urlKey: 'chooseStaff' },
  37. { code: 'orgId', name: 'orgName', type: 'choose', required: true, title: mixins.$t('saleOrg'), urlKey: 'chooseOrg' },
  38. { code: 'initialPaymentId', name: 'initialPayment', type: 'choose', title: mixins.$t('initialPayment'), urlKey: 'chooseInitialPaymentType' },
  39. ],
  40. remarks: [
  41. { code: 'remarks', type: 'textarea', title: mixins.$t('remarks') }
  42. ]
  43. },
  44. },
  45. /**
  46. * @desc : 选择数据源
  47. * @date : 2024/2/1 15:49
  48. * @author : 于继渤
  49. */
  50. chooseData(e) {
  51. let formData = JSON.parse(this.data.formData)
  52. let code = e.detail.code
  53. let data = e.detail.data.data
  54. console.log(code, data);
  55. if (code == "staffId") { //员工
  56. formData.staffId = data.id
  57. formData.staffName = data.name
  58. }
  59. if (code == "orgId") { //部门
  60. formData.orgId = data.id
  61. formData.orgName = data.name
  62. }
  63. //销售渠道
  64. if (code == 'channelId') {
  65. formData.channelId = data.id
  66. formData.channelCode = data.code
  67. formData.channelName = data.name
  68. }
  69. //客户来源
  70. if (code == 'cusFrom') {
  71. formData.cusFrom = data.id
  72. formData.cusFromCode = data.code
  73. formData.cusFromName = data.name
  74. }
  75. //客户来源
  76. if (code == 'macId') {
  77. formData.macId = data.id
  78. formData.macCode = data.code
  79. formData.macName = data.name
  80. }
  81. //初始款项
  82. if (code == "initialPaymentId") {
  83. formData.initialPaymentId = data.id
  84. formData.initialPayment = data.name
  85. let contentObj = this.data.contentObj;
  86. // 初始款项-欠款
  87. if (data.id == Constants.initialPayType.debt) {
  88. contentObj.center = [
  89. { code: 'channelId', name: 'channelName', required: true, title: mixins.$t('saleChannel'), type: 'choose', urlKey: 'chooseChannel' },
  90. { code: 'staffId', name: 'staffName', type: 'choose', required: true, title: mixins.$t('saleStaff'), urlKey: 'chooseStaff' },
  91. { code: 'orgId', name: 'orgName', type: 'choose', required: true, title: mixins.$t('saleOrg'), urlKey: 'chooseOrg' },
  92. { code: 'initialPaymentId', name: 'initialPayment', type: 'choose', title: mixins.$t('initialPayment'), urlKey: 'chooseInitialPaymentType' },
  93. { code: 'startAmount', type: 'number', required: true, title: mixins.$t('initialDebtOwed') },
  94. ]
  95. } else if (data.id == Constants.initialPayType.payment) {
  96. // 初始款项-预收
  97. contentObj.center = [
  98. { code: 'channelId', name: 'channelName', required: true, title: mixins.$t('saleChannel'), type: 'choose', urlKey: 'chooseChannel' },
  99. { code: 'staffId', name: 'staffName', type: 'choose', required: true, title: mixins.$t('saleStaff'), urlKey: 'chooseStaff' },
  100. { code: 'orgId', name: 'orgName', type: 'choose', required: true, title: mixins.$t('saleOrg'), urlKey: 'chooseOrg' },
  101. { code: 'initialPaymentId', name: 'initialPayment', type: 'choose', title: mixins.$t('initialPayment'), urlKey: 'chooseInitialPaymentType' },
  102. { code: 'startAmount', type: 'number', required: true, title: mixins.$t('initialDebtOwed') },
  103. { code: 'macId', name: 'macName', type: 'choose', required: true, title: mixins.$t('moneyAccount'), urlKey: 'chooseMoneyAccount' },
  104. ]
  105. } else {
  106. // 初始款项-无
  107. contentObj.center = [
  108. { code: 'channelId', name: 'channelName', required: true, title: mixins.$t('saleChannel'), type: 'choose', urlKey: 'chooseChannel' },
  109. { code: 'staffId', name: 'staffName', type: 'choose', required: true, title: mixins.$t('saleStaff'), urlKey: 'chooseStaff' },
  110. { code: 'orgId', name: 'orgName', type: 'choose', required: true, title: mixins.$t('saleOrg'), urlKey: 'chooseOrg' },
  111. { code: 'initialPaymentId', name: 'initialPayment', type: 'choose', title: mixins.$t('initialPayment'), urlKey: 'chooseInitialPaymentType' },
  112. ]
  113. }
  114. this.setData({
  115. contentObj: contentObj
  116. })
  117. }
  118. this.setData({
  119. formData: JSON.stringify(formData)
  120. })
  121. },
  122. /**
  123. * @desc : 保存数据服务
  124. * @date : 2024/2/1 15:49
  125. * @author : 于继渤
  126. */
  127. saveData() {
  128. if (this.data.formMode == Constants.formMode.edit) {
  129. return this.excute(this.data.service, this.data.service.update, this.data.params);
  130. } else {
  131. return this.excute(this.data.service, this.data.service.insert, this.data.params);
  132. }
  133. },
  134. /**
  135. * @desc : 给表单赋值
  136. * @date : 2024/2/1 15:49
  137. * @author : 于继渤
  138. */
  139. setValuesByEdit(data) {
  140. //处理地址
  141. data.address = {
  142. address: data.addressFull,
  143. addressFull: data.addressFull,
  144. addressArea: data.addressArea,
  145. addressGcj02: data.addressGcj02,
  146. addressName: data.addressName,
  147. }
  148. this.setData({
  149. formData: JSON.stringify(data)
  150. })
  151. // 控制初始欠款不允许编辑
  152. let contentObj = this.data.contentObj;
  153. let filters = contentObj.center.filter(it => it.code == 'initialPaymentId')
  154. if (filters && filters.length > 0) {
  155. filters[0].readonly = true;
  156. }
  157. this.setData({
  158. contentObj: contentObj
  159. })
  160. },
  161. /**
  162. * @desc : 设置销售渠道/人员/业务部门
  163. * @date : 2024/2/1 15:49
  164. * @author : 于继渤
  165. */
  166. getDefChannel() {
  167. this.excute(this.data.saleChannelService, this.data.saleChannelService.selectByCond, {
  168. flgDefault: true
  169. }).then(res => {
  170. if (res.data.code == 200) {
  171. let formData = JSON.parse(this.data.formData)
  172. if (res.data.data.list && res.data.data.list.length > 0) {
  173. formData.channelId = res.data.data.list[0].channelId
  174. formData.channelName = res.data.data.list[0].channelName
  175. formData.channelCode = res.data.data.list[0].channelCode
  176. }
  177. formData.staffId = app.globalData.user.staffId
  178. formData.staffName = app.globalData.user.staffName
  179. formData.orgId = app.globalData.user.orgId
  180. formData.orgName = app.globalData.user.orgName
  181. //设置默认值
  182. this.setData({
  183. formData: JSON.stringify(formData)
  184. })
  185. }
  186. })
  187. },
  188. /**
  189. * 生命周期函数--监听页面加载
  190. */
  191. loadInit(options) {
  192. //TODO 销售渠道默认 零售 ,销售部门销售员工默认当前登录人的
  193. let contentObj = this.data.contentObj
  194. if (this.data.gradeCode == Constants.gradeCode.STD) {
  195. contentObj.main = [
  196. { code: 'cusName', type: 'str', required: true, title: mixins.$t('customerName') },
  197. { code: 'cusPhone', type: 'phone', title: mixins.$t('cusPhone'), required: true },
  198. { code: 'addressFull', type: 'address', title: mixins.$t('addressFull'), required: true },
  199. { code: 'addressNo', type: 'str', required: true, title: mixins.$t('addressNo') },
  200. // { code: 'cusFrom', name: 'cusFromName', required: true, title: mixins.$t('customerSource'), type: 'choose', urlKey: 'choosecusFrom' },
  201. { code: 'contactName', type: 'str', required: false, title: mixins.$t('contactName') },
  202. { code: 'contactPhone', type: 'str', title: mixins.$t('cpPhone'), required: false },
  203. ]
  204. } else if (this.data.gradeCode == Constants.gradeCode.PRO) {
  205. contentObj.main = [
  206. { code: 'cusName', type: 'str', required: true, title: mixins.$t('customerName') },
  207. { code: 'cusPhone', type: 'phone', title: mixins.$t('cusPhone'), required: true },
  208. { code: 'addressFull', type: 'address', title: mixins.$t('addressFull'), required: true },
  209. { code: 'addressNo', type: 'str', required: true, title: mixins.$t('addressNo') },
  210. { code: 'cusFrom', name: 'cusFromName', required: false, title: mixins.$t('customerSource'), type: 'choose', urlKey: 'choosecusFrom' },
  211. { code: 'contactName', type: 'str', required: false, title: mixins.$t('contactName') },
  212. { code: 'contactPhone', type: 'str', title: mixins.$t('cpPhone'), required: false },
  213. ]
  214. }
  215. this.setData({
  216. contentObj: contentObj
  217. })
  218. if (this.data.formMode == Constants.formMode.edit) {
  219. wx.setNavigationBarTitle({
  220. title: mixins.$t('editCus'),
  221. })
  222. } else {
  223. //设置默认值
  224. this.getDefChannel()
  225. }
  226. },
  227. })