addAndEditor.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. let _Http = getApp().globalData.http,
  2. count = null;
  3. Page({
  4. data: {
  5. showAll: false,
  6. repetitionShow: false,
  7. repetitionList: [],
  8. isSubmit: false,
  9. form: [{
  10. label: "客户(企业)",
  11. error: false,
  12. errMsg: "",
  13. type: "textarea",
  14. value: "",
  15. placeholder: "客户(企业)名称",
  16. valueName: "enterprisename",
  17. checking: "base",
  18. slot: "info",
  19. required: true
  20. }, {
  21. label: "企业简称",
  22. error: false,
  23. errMsg: "",
  24. type: "textarea",
  25. value: "",
  26. placeholder: "企业简称",
  27. valueName: "abbreviation",
  28. checking: "base",
  29. required: false
  30. }, {
  31. label: "客户类型",
  32. error: false,
  33. errMsg: "",
  34. type: "option",
  35. optionNmae: "customertypemx",
  36. optionType: "radio", //复选 radio 单选
  37. value: "",
  38. placeholder: "客户类型",
  39. valueName: "type",
  40. checking: "base",
  41. required: true
  42. }, {
  43. label: "企业等级",
  44. error: false,
  45. errMsg: "",
  46. type: "option",
  47. optionNmae: "agentgrade",
  48. optionType: "radio", //复选 radio 单选
  49. value: "",
  50. placeholder: "企业等级",
  51. valueName: "grade",
  52. checking: "base",
  53. required: false
  54. }, {
  55. label: "客户分类",
  56. error: false,
  57. errMsg: "",
  58. type: "option",
  59. optionNmae: "customergrade",
  60. optionType: "radio", //复选 radio 单选
  61. value: "",
  62. placeholder: "客户分类",
  63. valueName: "customergrade",
  64. checking: "base",
  65. required: false
  66. }, {
  67. label: "客户行业",
  68. error: false,
  69. errMsg: "",
  70. type: "option", //自定义选择 配合预定接口
  71. optionNmae: "industry", //选择类型
  72. optionType: "checkbox", //复选 radio 单选
  73. value: "",
  74. placeholder: "客户所属行业",
  75. valueName: "industry",
  76. checking: "base",
  77. required: false
  78. }, {
  79. label: "税号",
  80. error: false,
  81. errMsg: "",
  82. type: "textarea",
  83. value: "",
  84. placeholder: "企业税号",
  85. valueName: "taxno",
  86. checking: "base",
  87. required: false
  88. }, {
  89. label: "法人",
  90. error: false,
  91. errMsg: "",
  92. type: "text",
  93. value: "",
  94. placeholder: "企业法人",
  95. valueName: "contact",
  96. checking: "base",
  97. required: false
  98. }, {
  99. label: "电话",
  100. error: false,
  101. errMsg: "",
  102. type: "number",
  103. value: "",
  104. placeholder: "联系电话",
  105. valueName: "telephone",
  106. checking: "base",
  107. required: false
  108. }, {
  109. label: "省市县",
  110. error: false,
  111. errMsg: "",
  112. type: "region",
  113. value: [],
  114. placeholder: "所在地区",
  115. valueName: "region",
  116. required: false
  117. }, {
  118. label: "详细地址",
  119. error: false,
  120. errMsg: "",
  121. type: "textarea",
  122. value: "",
  123. placeholder: "详细地址",
  124. valueName: "address",
  125. checking: "base",
  126. required: false
  127. }, {
  128. label: "上级企业",
  129. error: false,
  130. errMsg: "",
  131. type: "route",
  132. url: "/packageA/select/setclient/select",
  133. value: "",
  134. params: {
  135. id: 20221012164402,
  136. content: {
  137. nocache: true,
  138. "type": 1,
  139. "isExport": 0,
  140. isend: 0,
  141. "where": {
  142. "condition": "",
  143. "status": "", //状态
  144. "startdate": "",
  145. "enddate": ""
  146. },
  147. "sort": [{
  148. sortname: "默认",
  149. sorted: 1,
  150. sortid: 67,
  151. reversed: 0
  152. }]
  153. },
  154. },
  155. query: "&radio=true&idname=sa_customersid",
  156. placeholder: "选择上级企业",
  157. valueName: "parentid",
  158. checking: "base",
  159. required: false
  160. }, {
  161. label: "客户来源",
  162. error: false,
  163. errMsg: "",
  164. type: "textarea",
  165. value: "",
  166. placeholder: "客户来源",
  167. valueName: "source",
  168. checking: "base",
  169. required: false
  170. }, {
  171. label: "归属经销商",
  172. error: false,
  173. errMsg: "",
  174. type: "route",
  175. url: "/packageA/select/setclient/select",
  176. value: "",
  177. params: {
  178. "id": 20230214162602,
  179. "content": {
  180. "hrid": wx.getStorageSync('userMsg').hrid,
  181. "where": {
  182. "condition": ""
  183. }
  184. },
  185. },
  186. query: "&radio=true&idname=sa_agentsid",
  187. placeholder: "归属经销商",
  188. valueName: "sa_agentsid",
  189. checking: "base",
  190. required: false
  191. }],
  192. content: {
  193. "sa_customersid": 0, //新增是传0
  194. "sys_enterpriseid": 0, //合作企业档案ID,新增是传0,更新
  195. "sa_customerpoolid": 0, //客户池(公海池)ID,默认或没有的时候传0
  196. ispublic: 0, //是否为公海客户
  197. },
  198. disabled: true,
  199. countDown: "", //查重倒计时
  200. },
  201. queryClient() {
  202. let data = this.selectComponent("#Form").query();
  203. if (data.enterprisename == '') {
  204. wx.showToast({
  205. title: `您还未填写企业名称`,
  206. icon: "none"
  207. });
  208. } else {
  209. this.setData({
  210. form: this.selectComponent("#Form").data.form,
  211. })
  212. this.selectComponent("#Info").queryClient(data.enterprisename)
  213. }
  214. },
  215. /* 工商查询 */
  216. introduce({
  217. detail
  218. }) {
  219. let item = detail;
  220. let data = {
  221. enterprisename: item.companyName, //企业名称
  222. taxno: item.taxNum, //税号
  223. contact: item.legalPerson, //法人
  224. region: [item.regProvince, item.regCity, item.regArea], //地区
  225. address: item.address, //地区
  226. }
  227. this.setData({
  228. form: this.data.form.map(v => {
  229. if (data[v.valueName]) v.value = data[v.valueName];
  230. return v
  231. })
  232. })
  233. },
  234. setOption(item) {
  235. let i = this.data.form.findIndex(v => v.valueName == item.valueName);
  236. this.setData({
  237. [`form[${i}]`]: item
  238. })
  239. },
  240. onLoad(options) {
  241. if (options.data) {
  242. let data = JSON.parse(options.data);
  243. this.setData({
  244. disabled: false,
  245. content: {
  246. sa_customersid: data.sa_customersid,
  247. sys_enterpriseid: data.sys_enterpriseid,
  248. sa_customerpoolid: data.sa_customerpoolid,
  249. },
  250. form: this.data.form.map(v => {
  251. if (v.valueName != 'region') {
  252. v.value = data[v.valueName] || "";
  253. if (v.valueName == "grade") v.value = data[v.valueName] + "";
  254. } else {
  255. v.value = data.province ? [data.province, data.city, data.county] : []
  256. }
  257. return v
  258. })
  259. })
  260. }
  261. },
  262. repClose() {
  263. if (this.data.isSubmit) {
  264. let that = this;
  265. wx.showModal({
  266. title: '提示',
  267. content: `是否继续创建客户`,
  268. complete: (res) => {
  269. if (res.confirm) that.handleSubmit(true);
  270. }
  271. })
  272. }
  273. this.setData({
  274. repetitionShow: false,
  275. isSubmit: false
  276. })
  277. },
  278. /* 表单必填项是否完成 */
  279. onConfirm({
  280. detail
  281. }) {
  282. this.setData({
  283. disabled: detail
  284. })
  285. },
  286. // 是否显示全部
  287. onChange({
  288. detail
  289. }) {
  290. this.setData({
  291. showAll: detail
  292. })
  293. },
  294. /* 查询是否重复 */
  295. async queryRepetition(e) {
  296. let {
  297. enterprisename,
  298. taxno,
  299. address
  300. } = this.selectComponent("#Form").query();
  301. if (enterprisename == '') return wx.showToast({
  302. title: `您还未填写企业名称`,
  303. icon: "none"
  304. });
  305. let res = await this.handleQueryRepetition({
  306. sa_customersid: this.data.content.sa_customersid,
  307. enterprisename,
  308. taxno,
  309. address
  310. });
  311. console.log("查询重复", res)
  312. if (res.msg != '成功') return wx.showToast({
  313. title: res.msg,
  314. icon: "none"
  315. });
  316. this.setData({
  317. countDown: 6
  318. });
  319. count = setInterval(() => {
  320. let countDown = this.data.countDown;
  321. if (countDown == 0) {
  322. clearInterval(count);
  323. this.setData({
  324. countDown: ""
  325. })
  326. } else {
  327. countDown--;
  328. this.setData({
  329. countDown
  330. })
  331. }
  332. }, 1000)
  333. if (res.total == 0) {
  334. wx.showToast({
  335. title: '未查询到疑似重复的客户信息',
  336. icon: "none"
  337. })
  338. } else {
  339. wx.showToast({
  340. title: `查询到${res.total}条疑似重复客户信息`,
  341. icon: "none"
  342. })
  343. this.setData({
  344. repetitionShow: true,
  345. repetitionList: res.data
  346. })
  347. }
  348. },
  349. /* 处理查重 */
  350. handleQueryRepetition(content) {
  351. return _Http.basic({
  352. "id": 20221208172002,
  353. content
  354. })
  355. },
  356. async submit() {
  357. let data = this.selectComponent("#Form").submit();
  358. let query = await this.handleQueryRepetition({
  359. sa_customersid: this.data.content.sa_customersid,
  360. enterprisename: data.enterprisename,
  361. taxno: data.taxno,
  362. address: data.address
  363. });
  364. if (query.total != 0) {
  365. wx.showToast({
  366. title: `查询到${query.total}条疑似重复客户信息`,
  367. icon: "none"
  368. })
  369. this.setData({
  370. repetitionShow: true,
  371. repetitionList: query.data,
  372. isSubmit: true
  373. })
  374. } else {
  375. this.handleSubmit();
  376. }
  377. },
  378. handleSubmit(tag = false) {
  379. let data = this.selectComponent("#Form").submit();
  380. data.province = data.region[0] || "";
  381. data.city = data.region[1] || "";
  382. data.county = data.region[2] || "";
  383. data.parentid = data.parentid[1] ? data.parentid[1][0] : 0;
  384. data.sa_agentsid = data.sa_agentsid[1] ? data.sa_agentsid[1][0] : 0;
  385. delete(data.region);
  386. _Http.basic({
  387. "id": 20221012163902,
  388. "content": {
  389. ...this.data.content,
  390. ...data,
  391. }
  392. }).then(res => {
  393. console.log("新建客户", res)
  394. if (res.msg != '成功') return wx.showToast({
  395. title: res.data,
  396. icon: "none"
  397. })
  398. wx.showToast({
  399. title: '保存成功',
  400. icon: "none"
  401. })
  402. //绑定疑似重复标签
  403. if (tag) _Http.basic({
  404. "id": 20220929090901,
  405. "content": {
  406. "ownertable": "sa_customers",
  407. "ownerid": res.data.sa_customersid,
  408. "datatag": ["疑似重复"]
  409. }
  410. })
  411. setTimeout(() => {
  412. getCurrentPages().forEach(v => {
  413. switch (v.__route__) {
  414. case 'packageA/setclient/index':
  415. v.getList(true);
  416. break;
  417. case 'packageA/setclient/detail':
  418. v.getDetail();
  419. wx.navigateBack()
  420. break;
  421. }
  422. })
  423. let pages = getCurrentPages();
  424. if (pages[pages.length - 2].__route__ == 'packageA/setclient/index') wx.redirectTo({
  425. url: '/packageA/setclient/detail?id=' + res.data.sa_customersid,
  426. })
  427. }, tag ? 500 : 300)
  428. })
  429. },
  430. })