add.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. saleChannelService: app.globalData['saleChannelService'],
  21. cardList: ['main', 'center', 'remarks'],
  22. buttonSaveList: [{ code: 'add', title: mixins.$t('save'), width: '120rpx' }],
  23. contentObj: {
  24. main: [
  25. { code: 'cusName', type: 'str', required: true, title: mixins.$t('customerName') },
  26. { code: 'cusPhone', type: 'phone', title: mixins.$t('cusPhone'), required: true },
  27. { code: 'addressFull', type: 'address', title: mixins.$t('addressFull'), required: true },
  28. { code: 'addressNo', type: 'str', required: true, title: mixins.$t('addressNo') },
  29. { code: 'cusFrom', name: 'cusFromName', required: true, title: mixins.$t('customerSource'), type: 'choose', urlKey: 'choosecusFrom' },
  30. { code: 'contactName', type: 'str', required: false, title: mixins.$t('contactName') },
  31. { code: 'contactPhone', type: 'str', title: mixins.$t('cpPhone'), required: false },
  32. ],
  33. center: [
  34. { code: 'channelId', name: 'channelName', required: true, title: mixins.$t('saleChannel'), type: 'choose', urlKey: 'chooseChannel' },
  35. { code: 'staffId', name: 'staffName', type: 'choose', required: true, title: mixins.$t('saleStaff'), urlKey: 'chooseStaff' },
  36. { code: 'orgId', name: 'orgName', type: 'choose', required: true, title: mixins.$t('saleOrg'), urlKey: 'chooseOrg' },
  37. { code: 'initialDebt', type: 'number', required: false, title: '初始欠款' },
  38. ],
  39. remarks: [
  40. { code: 'remarks', type: 'textarea', title: mixins.$t('remarks') }
  41. ]
  42. },
  43. },
  44. /**
  45. * @desc : 选择数据源
  46. * @date : 2024/2/1 15:49
  47. * @author : 于继渤
  48. */
  49. chooseData(e) {
  50. let formData = JSON.parse(this.data.formData)
  51. let code = e.detail.code
  52. let data = e.detail.data.data
  53. if (code == "staffId") { //员工
  54. formData.staffId = data.id
  55. formData.staffName = data.name
  56. }
  57. if (code == "orgId") { //部门
  58. formData.orgId = data.id
  59. formData.orgName = data.name
  60. }
  61. //销售渠道
  62. if (code == 'channelId') {
  63. formData.channelId = data.id
  64. formData.channelCode = data.code
  65. formData.channelName = data.name
  66. }
  67. //客户来源
  68. if (code == 'cusFrom') {
  69. formData.cusFrom = data.id
  70. formData.cusFromCode = data.code
  71. formData.cusFromName = data.name
  72. }
  73. this.setData({
  74. formData: JSON.stringify(formData)
  75. })
  76. },
  77. /**
  78. * @desc : 保存数据服务
  79. * @date : 2024/2/1 15:49
  80. * @author : 于继渤
  81. */
  82. saveData() {
  83. if (this.data.formMode == Constants.formMode.edit) {
  84. return this.excute(this.data.service, this.data.service.update, this.data.params);
  85. } else {
  86. return this.excute(this.data.service, this.data.service.insert, this.data.params);
  87. }
  88. },
  89. /**
  90. * @desc : 给表单赋值
  91. * @date : 2024/2/1 15:49
  92. * @author : 于继渤
  93. */
  94. setValuesByEdit(data) {
  95. //处理地址
  96. data.address = {
  97. address: data.addressFull,
  98. addressFull: data.addressFull,
  99. addressArea: data.addressArea,
  100. addressGcj02: data.addressGcj02,
  101. addressName: data.addressName,
  102. }
  103. this.setData({
  104. formData: JSON.stringify(data)
  105. })
  106. },
  107. /**
  108. * @desc : 设置销售渠道/人员/业务部门
  109. * @date : 2024/2/1 15:49
  110. * @author : 于继渤
  111. */
  112. getDefChannel() {
  113. this.excute(this.data.saleChannelService, this.data.saleChannelService.selectByCond, {
  114. flgDefault: true
  115. }).then(res => {
  116. if (res.data.code == 200) {
  117. let formData = JSON.parse(this.data.formData)
  118. if (res.data.data.list && res.data.data.list.length > 0) {
  119. formData.channelId = res.data.data.list[0].channelId
  120. formData.channelName = res.data.data.list[0].channelName
  121. formData.channelCode = res.data.data.list[0].channelCode
  122. }
  123. formData.staffId = app.globalData.user.staffId
  124. formData.staffName = app.globalData.user.staffName
  125. formData.orgId = app.globalData.user.orgId
  126. formData.orgName = app.globalData.user.orgName
  127. //设置默认值
  128. this.setData({
  129. formData: JSON.stringify(formData)
  130. })
  131. }
  132. })
  133. },
  134. /**
  135. * 生命周期函数--监听页面加载
  136. */
  137. loadInit(options) {
  138. //TODO 销售渠道默认 零售 ,销售部门销售员工默认当前登录人的
  139. if (this.data.formMode == Constants.formMode.edit) {
  140. wx.setNavigationBarTitle({
  141. title: mixins.$t('editCus'),
  142. })
  143. } else {
  144. //设置默认值
  145. this.getDefChannel()
  146. }
  147. },
  148. })