add.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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: 'initialDebt', type: 'number', required: false, title: '初始欠款' },
  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. if (code == "staffId") { //员工
  55. formData.staffId = data.id
  56. formData.staffName = data.name
  57. }
  58. if (code == "orgId") { //部门
  59. formData.orgId = data.id
  60. formData.orgName = data.name
  61. }
  62. //销售渠道
  63. if (code == 'channelId') {
  64. formData.channelId = data.id
  65. formData.channelCode = data.code
  66. formData.channelName = data.name
  67. }
  68. //客户来源
  69. if (code == 'cusFrom') {
  70. formData.cusFrom = data.id
  71. formData.cusFromCode = data.code
  72. formData.cusFromName = data.name
  73. }
  74. this.setData({
  75. formData: JSON.stringify(formData)
  76. })
  77. },
  78. /**
  79. * @desc : 保存数据服务
  80. * @date : 2024/2/1 15:49
  81. * @author : 于继渤
  82. */
  83. saveData() {
  84. if (this.data.formMode == Constants.formMode.edit) {
  85. return this.excute(this.data.service, this.data.service.update, this.data.params);
  86. } else {
  87. return this.excute(this.data.service, this.data.service.insert, this.data.params);
  88. }
  89. },
  90. /**
  91. * @desc : 给表单赋值
  92. * @date : 2024/2/1 15:49
  93. * @author : 于继渤
  94. */
  95. setValuesByEdit(data) {
  96. //处理地址
  97. data.address = {
  98. address: data.addressFull,
  99. addressFull: data.addressFull,
  100. addressArea: data.addressArea,
  101. addressGcj02: data.addressGcj02,
  102. addressName: data.addressName,
  103. }
  104. this.setData({
  105. formData: JSON.stringify(data)
  106. })
  107. },
  108. /**
  109. * @desc : 设置销售渠道/人员/业务部门
  110. * @date : 2024/2/1 15:49
  111. * @author : 于继渤
  112. */
  113. getDefChannel() {
  114. this.excute(this.data.saleChannelService, this.data.saleChannelService.selectByCond, {
  115. flgDefault: true
  116. }).then(res => {
  117. if (res.data.code == 200) {
  118. let formData = JSON.parse(this.data.formData)
  119. if (res.data.data.list && res.data.data.list.length > 0) {
  120. formData.channelId = res.data.data.list[0].channelId
  121. formData.channelName = res.data.data.list[0].channelName
  122. formData.channelCode = res.data.data.list[0].channelCode
  123. }
  124. formData.staffId = app.globalData.user.staffId
  125. formData.staffName = app.globalData.user.staffName
  126. formData.orgId = app.globalData.user.orgId
  127. formData.orgName = app.globalData.user.orgName
  128. //设置默认值
  129. this.setData({
  130. formData: JSON.stringify(formData)
  131. })
  132. }
  133. })
  134. },
  135. /**
  136. * 生命周期函数--监听页面加载
  137. */
  138. loadInit(options) {
  139. //TODO 销售渠道默认 零售 ,销售部门销售员工默认当前登录人的
  140. let contentObj = this.data.contentObj
  141. if (this.data.gradeCode == Constants.gradeCode.STD) {
  142. contentObj.main = [
  143. { code: 'cusName', type: 'str', required: true, title: mixins.$t('customerName') },
  144. { code: 'cusPhone', type: 'phone', title: mixins.$t('cusPhone'), required: true },
  145. { code: 'addressFull', type: 'address', title: mixins.$t('addressFull'), required: true },
  146. { code: 'addressNo', type: 'str', required: true, title: mixins.$t('addressNo') },
  147. // { code: 'cusFrom', name: 'cusFromName', required: true, title: mixins.$t('customerSource'), type: 'choose', urlKey: 'choosecusFrom' },
  148. { code: 'contactName', type: 'str', required: false, title: mixins.$t('contactName') },
  149. { code: 'contactPhone', type: 'str', title: mixins.$t('cpPhone'), required: false },
  150. ]
  151. } else if (this.data.gradeCode == Constants.gradeCode.PRO) {
  152. contentObj.main = [
  153. { code: 'cusName', type: 'str', required: true, title: mixins.$t('customerName') },
  154. { code: 'cusPhone', type: 'phone', title: mixins.$t('cusPhone'), required: true },
  155. { code: 'addressFull', type: 'address', title: mixins.$t('addressFull'), required: true },
  156. { code: 'addressNo', type: 'str', required: true, title: mixins.$t('addressNo') },
  157. { code: 'cusFrom', name: 'cusFromName', required: false, title: mixins.$t('customerSource'), type: 'choose', urlKey: 'choosecusFrom' },
  158. { code: 'contactName', type: 'str', required: false, title: mixins.$t('contactName') },
  159. { code: 'contactPhone', type: 'str', title: mixins.$t('cpPhone'), required: false },
  160. ]
  161. }
  162. this.setData({
  163. contentObj: contentObj
  164. })
  165. if (this.data.formMode == Constants.formMode.edit) {
  166. wx.setNavigationBarTitle({
  167. title: mixins.$t('editCus'),
  168. })
  169. } else {
  170. //设置默认值
  171. this.getDefChannel()
  172. }
  173. },
  174. })