add.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*******************************************************************************
  2. * Copyright(c) 2022 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:
  5. * 2.客户资料列表
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * yjb 2022-0-12 1.00
  9. *******************************************************************************/
  10. const Constants = require('@/utils/Constants.js');
  11. const util = require('@/utils/util.js')
  12. const mixins = require('@/mixins/index.js')
  13. const app = getApp()
  14. Page({
  15. mixins: [mixins],
  16. /**
  17. * 页面的初始数据
  18. */
  19. data: {
  20. radioFollowUp: '1',
  21. routeObjName: 'cusFollow',
  22. cardList: ['main'],
  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: false },
  29. { code: 'addressNo', type: 'str', required: false, title: mixins.$t('addressNo') },
  30. { code: 'intention', name: 'intentionName', type: 'drop', required: true, dropType: 'customerIntention', title: mixins.$t('intention') },
  31. { code: 'remarks', type: 'textarea', rows: '5', required: true, showWordLimit: true, title: mixins.$t('followData') },
  32. { code: 'nextFollowTime', type: 'dateTime', required: true, title: mixins.$t('nextFollowTime') },
  33. { code: 'stayTimeLen', name: 'stayTimeLenName', required: true, title: mixins.$t('stayTimeLen'), dropType: 'storeRetentionTime', type: 'drop', },
  34. { code: 'file', type: 'uploader', title: mixins.$t("uploader") }
  35. ]
  36. },
  37. table: Constants.tables.cusFollow,
  38. customerService: app.globalData['customerService'],
  39. followStatus: mixins.$t('followStatusReporting')
  40. },
  41. /**
  42. * @desc : 设置保存参数
  43. * @date : 2024/2/1 15:49
  44. * @author : 于继渤
  45. */
  46. setParams(params) {
  47. params.followStatus = this.data.followStatus
  48. params.followType = '跟进方式-进店'
  49. params.followOrg = app.globalData.user.orgId
  50. return params
  51. },
  52. /**
  53. * @desc : 保存数据服务
  54. * @date : 2024/2/1 15:49
  55. * @author : 于继渤
  56. */
  57. saveData() {
  58. if (this.data.formMode == Constants.formMode.edit) {
  59. return this.excute(this.data.service, this.data.service.update, this.data.params);
  60. } else {
  61. return this.excute(this.data.service, this.data.service.insert, this.data.params);
  62. }
  63. },
  64. /**
  65. * @desc : 消息订阅方法
  66. * @author : 刘尧
  67. * @date : 2024/7/19
  68. */
  69. subscribeMessage(e) {
  70. const that = this
  71. const tmplIds = ['z3REuwft6NLPxVW8s5HN1UgWjFstWjD0QfCXNLTa0LA']
  72. wx.getSetting({
  73. withSubscriptions: true,
  74. success (res){
  75. if(res.subscriptionsSetting && res.subscriptionsSetting.mainSwitch){
  76. if(!(res.subscriptionsSetting['z3REuwft6NLPxVW8s5HN1UgWjFstWjD0QfCXNLTa0LA'] && res.subscriptionsSetting['z3REuwft6NLPxVW8s5HN1UgWjFstWjD0QfCXNLTa0LA'] !== "accept")){
  77. wx.requestSubscribeMessage({
  78. tmplIds: tmplIds,
  79. success (res) {
  80. // console.log('消息订阅成功', res);
  81. that.save(e)
  82. },
  83. fail(res) {
  84. // console.log('消息订阅取消', res);
  85. that.save(e)
  86. }
  87. })
  88. }else {
  89. that.save(e)
  90. }
  91. }
  92. },
  93. fail(res){
  94. that.save(e)
  95. }
  96. })
  97. },
  98. /**
  99. * @desc : 编辑
  100. * @date : 2024/2/1 15:49
  101. * @author : 于继渤
  102. */
  103. toEdit(){
  104. let item = JSON.parse(this.data.formData)
  105. let url = null
  106. if (item.followStatus == '跟进状态-报备' || item.followStatus == '跟进状态-接待') {
  107. url = this.data.route.toFollowStatus1.url
  108. }
  109. let _this = this;
  110. wx.navigateTo({
  111. url: url,
  112. events: {
  113. // 保存成功后刷新页面
  114. refresh: function (data) {
  115. // 刷新一览界面
  116. _this.searchData();
  117. }
  118. },
  119. success: function (res) {
  120. let data = {}
  121. data.id = item.followId
  122. data.formMode = Constants.formMode.edit
  123. res.eventChannel.emit('params', data);
  124. }
  125. })
  126. },
  127. /**
  128. * @desc : 保存处理
  129. * @date : 2024/2/1 15:49
  130. * @author : 于继渤
  131. */
  132. handleData() {
  133. let pages = getCurrentPages();
  134. let prevPage = pages[pages.length - 3]; //上二页
  135. prevPage.setData({
  136. refreshByAdd: true
  137. })
  138. wx.navigateBack({
  139. data: 2
  140. })
  141. },
  142. /**
  143. * @desc : 手机号离开焦点事件
  144. * @date : 2024/4/8 15:49
  145. * @author : 于继渤
  146. */
  147. changePhoneblur(e) {
  148. let phone = e.detail.detail.detail.value
  149. if (phone) {
  150. //查询客户信息
  151. this.getCustomerData({ cusPhone: phone })
  152. }
  153. },
  154. /**
  155. * @desc : 查询客户信息
  156. * @author : 于继渤
  157. * @date : 2024/1/23 9:16
  158. */
  159. getCustomerData(params) {
  160. return this.excute(this.data.customerService, this.data.customerService.selectByCondNoPage, params).then(res => {
  161. if (res.data.code == 200) {
  162. if (res.data.data.length > 0) {
  163. let formData = JSON.parse(this.data.formData)
  164. let item = res.data.data[0]
  165. formData.cusCode = item.cusCode
  166. formData.cusId = item.cusId
  167. formData.cusName = item.cusName
  168. formData.cusFromName = item.cusFromName
  169. //处理地址
  170. formData.address = {
  171. address: item.addressFull,
  172. addressFull: item.addressFull,
  173. addressArea: item.addressArea,
  174. addressGcj02: item.addressGcj02,
  175. addressName: item.addressName,
  176. }
  177. formData.addressArea = item.addressArea
  178. formData.addressFull = item.addressFull
  179. formData.addressGcj02 = item.addressGcj02
  180. formData.addressName = item.addressName
  181. formData.addressNo = item.addressNo
  182. this.setData({
  183. formData: JSON.stringify(formData)
  184. })
  185. }
  186. }
  187. });
  188. },
  189. /**
  190. * @desc : 顶部切换
  191. * @date : 2024/4/8 15:49
  192. * @author : 于继渤
  193. */
  194. onRadioFollowUp(e) {
  195. if (this.data.formMode == Constants.formMode.edit) {
  196. return
  197. }
  198. let detail = e.detail
  199. this.setFormContent(detail)
  200. this.setData({
  201. radioFollowUp: detail,
  202. formData: null
  203. })
  204. },
  205. /**
  206. * @desc : 跳转购物车
  207. * @date : 2024/2/1 15:49
  208. * @author : 于继渤
  209. */
  210. toShopping() {
  211. //跳转购物车开单
  212. let that = this
  213. wx.navigateTo({
  214. url: this.data.route.toSelectGoods.url,
  215. success: function (res) {
  216. res.eventChannel.emit('params', { choose: true, item: 'inventory', formItem: that.data.formData, formType: 'customer-reception', route: '/package-sales/pages/order-billing/add/add' })
  217. }
  218. })
  219. },
  220. /**
  221. * @desc : 给表单赋值
  222. * @date : 2024/2/1 15:49
  223. * @author : 于继渤
  224. */
  225. setValuesByEdit(data) {
  226. if (data.followStatus == '跟进状态-接待') {
  227. this.setData({
  228. radioFollowUp: '2'
  229. })
  230. this.setFormContent('2')
  231. }
  232. //处理地址
  233. data.address = {
  234. address: data.addressFull,
  235. addressFull: data.addressFull,
  236. addressArea: data.addressArea,
  237. addressGcj02: data.addressGcj02,
  238. addressName: data.addressName,
  239. }
  240. this.setData({
  241. formData: JSON.stringify(data)
  242. })
  243. },
  244. /**
  245. * @desc : 设置跟进form 字段
  246. * @date : 2024/2/1 15:49
  247. * @author : 于继渤
  248. */
  249. setFormContent(radioFollowUp) {
  250. let radioFollowUpOnelist = [
  251. { code: 'cusName', type: 'str', required: true, title: mixins.$t('customerName') },
  252. { code: 'cusPhone', type: 'phone', title: mixins.$t('cusPhone'), required: true },
  253. { code: 'addressFull', type: 'address', title: mixins.$t('addressFull'), required: false },
  254. { code: 'addressNo', type: 'str', required: false, title: mixins.$t('addressNo') },
  255. { code: 'intention', name: 'intentionName', type: 'drop', required: true, dropType: 'customerIntention', title: mixins.$t('intention') },
  256. { code: 'remarks', type: 'textarea', rows: '5', required: true, showWordLimit: true, title: mixins.$t('followData') },
  257. { code: 'nextFollowTime', type: 'dateTime', required: true, title: mixins.$t('nextFollowTime') },
  258. { code: 'stayTimeLen', name: 'stayTimeLenName', required: true, title: mixins.$t('stayTimeLen'), dropType: 'storeRetentionTime', type: 'drop', },
  259. { code: 'file', type: 'uploader', title: mixins.$t("uploader") }
  260. ]
  261. let radioFollowUpTwolist = [
  262. // { code: 'intention', name: 'intentionName', type: 'drop', required: true, dropType: 'customerIntention', title: mixins.$t('intention') },
  263. { code: 'remarks', type: 'textarea', rows: '5', required: true, showWordLimit: true, title: mixins.$t('followData') },
  264. { code: 'stayTimeLen', name: 'stayTimeLenName', required: true, title: mixins.$t('stayTimeLen'), dropType: 'storeRetentionTime', type: 'drop', },
  265. { code: 'file', type: 'uploader', title: mixins.$t("uploader") }
  266. ]
  267. let contentObj = this.data.contentObj
  268. let followStatus = this.data.followStatus
  269. if (radioFollowUp == '1') {
  270. followStatus = mixins.$t('followStatusReporting')
  271. contentObj.main = radioFollowUpOnelist
  272. }
  273. if (radioFollowUp == '2') {
  274. followStatus = mixins.$t('followStatusReception')
  275. contentObj.main = radioFollowUpTwolist
  276. }
  277. this.setData({
  278. followStatus, followStatus,
  279. contentObj: contentObj
  280. })
  281. }
  282. })