add.js 11 KB

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