add.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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('initialRPayment'), 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. let center = contentObj.center
  87. center = center.filter(it=>it.code != 'startAmount' && it.code != 'macId')
  88. // 初始款项-欠款
  89. if (data.id == Constants.initialPayType.debt) {
  90. center.push({ code: 'startAmount', type: 'number', required: true, min:Constants.MIN_VALUE, title: mixins.$t('initialDebtOwed') })
  91. } else if (data.id == Constants.initialPayType.payment) {
  92. // 初始款项-预收
  93. center.push({ code: 'startAmount', type: 'number', required: true, title: mixins.$t('initialPayment') })
  94. center.push({ code: 'macId', name: 'macName', type: 'choose', required: true, title: mixins.$t('moneyAccount'), urlKey: 'chooseMoneyAccount' })
  95. }
  96. contentObj.center = center
  97. this.setData({
  98. contentObj: contentObj
  99. })
  100. }
  101. this.setData({
  102. formData: JSON.stringify(formData)
  103. })
  104. },
  105. /**
  106. * @desc : 保存数据服务
  107. * @date : 2024/2/1 15:49
  108. * @author : 于继渤
  109. */
  110. saveData() {
  111. if (this.data.formMode == Constants.formMode.edit) {
  112. return this.excute(this.data.service, this.data.service.update, this.data.params);
  113. } else {
  114. return this.excute(this.data.service, this.data.service.insert, this.data.params);
  115. }
  116. },
  117. /**
  118. * @desc : 处理保存后续事件
  119. * @date : 2024/2/1 15:49
  120. * @author : 姜永辉
  121. */
  122. handleSaveData() {
  123. //设置默认值
  124. let formData = {}
  125. if (this.data.channelDef) {
  126. formData.channelId = this.data.channelDef.channelId
  127. formData.channelName = this.data.channelDef.channelName
  128. formData.channelCode = this.data.channelDef.channelCode
  129. }
  130. formData.staffId = app.globalData.user.staffId
  131. formData.staffName = app.globalData.user.staffName
  132. formData.orgId = app.globalData.user.orgId
  133. formData.orgName = app.globalData.user.orgName
  134. //设置默认值
  135. this.setData({
  136. formData: JSON.stringify(formData),
  137. })
  138. },
  139. /**
  140. * @desc : 给表单赋值
  141. * @date : 2024/2/1 15:49
  142. * @author : 于继渤
  143. */
  144. setValuesByEdit(data) {
  145. //处理地址
  146. data.address = {
  147. address: data.addressFull,
  148. addressFull: data.addressFull,
  149. addressArea: data.addressArea,
  150. addressGcj02: data.addressGcj02,
  151. addressName: data.addressName,
  152. }
  153. this.setData({
  154. formData: JSON.stringify(data)
  155. })
  156. // 控制初始欠款不允许编辑
  157. let contentObj = this.data.contentObj;
  158. let filters = contentObj.center.filter(it => it.code == 'initialPaymentId')
  159. if (filters && filters.length > 0) {
  160. filters[0].readonly = true;
  161. }
  162. this.setData({
  163. contentObj: contentObj
  164. })
  165. },
  166. /**
  167. * @desc : 设置销售渠道/人员/业务部门
  168. * @date : 2024/2/1 15:49
  169. * @author : 于继渤
  170. */
  171. getDefChannel() {
  172. this.excute(this.data.saleChannelService, this.data.saleChannelService.selectByCond, {
  173. flgDefault: true
  174. }).then(res => {
  175. if (res.data.code == 200) {
  176. let formData = JSON.parse(this.data.formData)
  177. if (res.data.data.list && res.data.data.list.length > 0) {
  178. formData.channelId = res.data.data.list[0].channelId
  179. formData.channelName = res.data.data.list[0].channelName
  180. formData.channelCode = res.data.data.list[0].channelCode
  181. }
  182. formData.staffId = app.globalData.user.staffId
  183. formData.staffName = app.globalData.user.staffName
  184. formData.orgId = app.globalData.user.orgId
  185. formData.orgName = app.globalData.user.orgName
  186. //设置默认值
  187. this.setData({
  188. formData: JSON.stringify(formData),
  189. channelDef: res.data.data.list[0]
  190. })
  191. }
  192. })
  193. },
  194. /**
  195. * 生命周期函数--监听页面加载
  196. */
  197. loadInit(options) {
  198. //TODO 销售渠道默认 零售 ,销售部门销售员工默认当前登录人的
  199. let contentObj = this.data.contentObj
  200. if (this.data.gradeCode == Constants.gradeCode.STD) {
  201. contentObj.main = [
  202. { code: 'cusName', type: 'str', required: true, title: mixins.$t('customerName') },
  203. { code: 'cusPhone', type: 'phone', title: mixins.$t('cusPhone'), required: true },
  204. { code: 'addressFull', type: 'address', title: mixins.$t('addressFull'), required: true },
  205. { code: 'addressNo', type: 'str', required: true, title: mixins.$t('addressNo') },
  206. // { code: 'cusFrom', name: 'cusFromName', required: true, title: mixins.$t('customerSource'), type: 'choose', urlKey: 'choosecusFrom' },
  207. { code: 'contactName', type: 'str', required: false, title: mixins.$t('contactName') },
  208. { code: 'contactPhone', type: 'str', title: mixins.$t('cpPhone'), required: false },
  209. ]
  210. contentObj.center = [
  211. { code: 'initialPaymentId', name: 'initialPayment', type: 'drop', title: mixins.$t('initialRPayment'), urlKey: 'chooseInitialPaymentType', dropType: 'initialPayment' },
  212. ]
  213. } else if (this.data.gradeCode == Constants.gradeCode.PRO) {
  214. contentObj.main = [
  215. { code: 'cusName', type: 'str', required: true, title: mixins.$t('customerName') },
  216. { code: 'cusPhone', type: 'phone', title: mixins.$t('cusPhone'), required: true },
  217. { code: 'addressFull', type: 'address', title: mixins.$t('addressFull'), required: true },
  218. { code: 'addressNo', type: 'str', required: true, title: mixins.$t('addressNo') },
  219. { code: 'cusFrom', name: 'cusFromName', required: false, title: mixins.$t('customerSource'), type: 'choose', urlKey: 'choosecusFrom' },
  220. { code: 'contactName', type: 'str', required: false, title: mixins.$t('contactName') },
  221. { code: 'contactPhone', type: 'str', title: mixins.$t('cpPhone'), required: false },
  222. ]
  223. contentObj.center = [
  224. { code: 'staffId', name: 'staffName', type: 'choose', required: true, title: mixins.$t('reportStaff'), urlKey: 'chooseStaff' },
  225. { code: 'orgId', name: 'orgName', type: 'choose', required: true, title: mixins.$t('reportOrg'), urlKey: 'chooseOrg' },
  226. { code: 'initialPaymentId', name: 'initialPayment', type: 'choose', title: mixins.$t('initialRPayment'), urlKey: 'chooseInitialPaymentType' },
  227. ]
  228. }
  229. this.setData({
  230. contentObj: contentObj
  231. })
  232. if (this.data.formMode == Constants.formMode.edit) {
  233. wx.setNavigationBarTitle({
  234. title: mixins.$t('editCus'),
  235. })
  236. } else {
  237. //设置默认值
  238. this.getDefChannel()
  239. }
  240. },
  241. })