add.js 10.0 KB

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