addAndEditor.js 14 KB

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