addAndEditor.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. let _Http = getApp().globalData.http,
  2. count = null;
  3. Page({
  4. data: {
  5. loading: false,
  6. repetitionShow: false,
  7. repetitionList: [],
  8. isSubmit: false,
  9. showAll: false,
  10. oldcontactsid: 0,
  11. form: [{
  12. label: "客户(企业)",
  13. error: false,
  14. errMsg: "",
  15. type: "textarea",
  16. value: "",
  17. placeholder: "客户(企业)名称",
  18. valueName: "enterprisename",
  19. checking: "base",
  20. slot: "info",
  21. required: true
  22. }, {
  23. label: "企业简称",
  24. error: false,
  25. errMsg: "",
  26. type: "textarea",
  27. value: "",
  28. placeholder: "企业简称",
  29. valueName: "abbreviation",
  30. checking: "base",
  31. required: false
  32. }, {
  33. label: "选择公海池",
  34. error: false,
  35. errMsg: "",
  36. type: "route",
  37. url: "/packageA/publicCustomer/pond/index",
  38. value: "",
  39. params: {
  40. "id": 20221206195102,
  41. "content": {
  42. nocache: true,
  43. "where": {
  44. "condition": ""
  45. }
  46. }
  47. },
  48. query: "&radio=true",
  49. placeholder: "选择所属公海池",
  50. valueName: "sa_customerpoolid",
  51. checking: "base",
  52. required: true
  53. }, {
  54. label: "客户类型",
  55. error: false,
  56. errMsg: "",
  57. type: "option",
  58. optionNmae: "customertypemx",
  59. optionType: "radio", //复选 radio 单选
  60. value: "",
  61. placeholder: "客户类型",
  62. valueName: "type",
  63. checking: "base",
  64. required: true
  65. }, {
  66. label: "企业等级",
  67. error: false,
  68. errMsg: "",
  69. type: "option",
  70. optionNmae: "agentgrade",
  71. optionType: "radio", //复选 radio 单选
  72. value: "",
  73. placeholder: "企业等级",
  74. valueName: "grade",
  75. checking: "base",
  76. required: false
  77. }, {
  78. label: "客户分类",
  79. error: false,
  80. errMsg: "",
  81. type: "option",
  82. optionNmae: "customergrade",
  83. optionType: "radio", //复选 radio 单选
  84. value: "",
  85. placeholder: "客户分类",
  86. valueName: "customergrade",
  87. checking: "base",
  88. required: false
  89. }, {
  90. label: "客户行业",
  91. error: false,
  92. errMsg: "",
  93. type: "option", //自定义选择 配合预定接口
  94. optionNmae: "industry", //选择类型
  95. optionType: "checkbox", //复选 radio 单选
  96. value: "",
  97. placeholder: "客户所属行业",
  98. valueName: "industry",
  99. checking: "base",
  100. required: false
  101. }, {
  102. label: "税号",
  103. error: false,
  104. errMsg: "",
  105. type: "textarea",
  106. value: "",
  107. placeholder: "企业税号",
  108. valueName: "taxno",
  109. checking: "base",
  110. required: false
  111. }, {
  112. label: "法人",
  113. error: false,
  114. errMsg: "",
  115. type: "text",
  116. value: "",
  117. placeholder: "企业法人",
  118. valueName: "contact",
  119. checking: "base",
  120. required: false
  121. }, {
  122. label: "电话",
  123. error: false,
  124. errMsg: "",
  125. type: "number",
  126. value: "",
  127. placeholder: "联系电话",
  128. valueName: "telephone",
  129. checking: "phone",
  130. required: false
  131. }, {
  132. label: "省市县",
  133. error: false,
  134. errMsg: "",
  135. type: "region",
  136. value: [],
  137. placeholder: "所在地区",
  138. valueName: "region",
  139. required: false
  140. }, {
  141. label: "详细地址",
  142. error: false,
  143. errMsg: "",
  144. type: "textarea",
  145. value: "",
  146. placeholder: "详细地址",
  147. valueName: "address",
  148. checking: "base",
  149. required: false
  150. }, {
  151. label: "上级企业",
  152. error: false,
  153. errMsg: "",
  154. type: "route",
  155. url: "/packageA/select/setclient/select",
  156. value: "",
  157. params: {
  158. id: 20221012164402,
  159. valueKey: "sa_customersid",
  160. content: {
  161. nocache: true,
  162. "type": 1,
  163. "isExport": 0,
  164. isend: 0,
  165. "where": {
  166. "condition": "",
  167. "status": "", //状态
  168. "startdate": "",
  169. "enddate": ""
  170. },
  171. "sort": [{
  172. sortname: "默认",
  173. sorted: 1,
  174. sortid: 67,
  175. reversed: 0
  176. }]
  177. },
  178. },
  179. query: "&radio=true",
  180. placeholder: "选择上级企业",
  181. valueName: "parentid",
  182. checking: "base",
  183. required: false
  184. }, {
  185. label: "客户来源",
  186. error: false,
  187. errMsg: "",
  188. type: "textarea",
  189. value: "",
  190. placeholder: "客户来源",
  191. valueName: "source",
  192. checking: "base",
  193. required: false
  194. }],
  195. content: {
  196. "sa_customersid": 0, //新增是传0
  197. "sys_enterpriseid": 0, //合作企业档案ID,新增是传0,更新
  198. phonenumber: "",
  199. },
  200. disabled: true,
  201. countDown: "", //查重倒计时
  202. },
  203. setOption(item) {
  204. let i = this.data.form.findIndex(v => v.valueName == item.valueName);
  205. this.setData({
  206. [`form[${i}]`]: item
  207. })
  208. },
  209. /* 打开通讯录 */
  210. openContacts() {
  211. let that = this;
  212. let page = that.selectComponent("#Form");
  213. let form = page.data.form,
  214. index = form.findIndex(v => v.label == '联系人');
  215. if (form[index].disabled) return;
  216. wx.navigateTo({
  217. url: '/packageA/setclient/contacts',
  218. })
  219. getApp().globalData.handleSelect = (item) => {
  220. wx.showModal({
  221. title: '提示',
  222. content: `是否确定选择${item.name}`,
  223. complete: ({
  224. confirm
  225. }) => {
  226. if (confirm) {
  227. form[index].value = item.name;
  228. that.data.oldcontactsid = item.contactsid
  229. if (item.phonenumber.indexOf('-') !== -1) {
  230. form[index + 1].value = "1";
  231. form[index + 2] = {
  232. label: "座机电话",
  233. error: false,
  234. errMsg: "",
  235. type: "telephone",
  236. value: item.phonenumber.split("-"),
  237. valueName: "telephone1",
  238. required: true,
  239. checking: "telephone"
  240. }
  241. } else {
  242. form[index + 1].value = "0";
  243. form[index + 2] = {
  244. label: "手机号",
  245. error: false,
  246. errMsg: "",
  247. type: "number",
  248. value: item.phonenumber,
  249. placeholder: "联系人手机号码",
  250. valueName: "phonenumber",
  251. required: true,
  252. checking: "phone"
  253. }
  254. }
  255. that.setData({
  256. form
  257. })
  258. wx.navigateBack()
  259. getApp().globalData.handleSelect = null;
  260. page.confirm()
  261. }
  262. }
  263. })
  264. };
  265. },
  266. /* 打断 */
  267. interrupt({
  268. detail
  269. }) {
  270. let {
  271. data,
  272. form,
  273. temporary
  274. } = detail;
  275. if (data.label == '联系方式') {
  276. let index = temporary.index + 1
  277. if (data.value == 0) {
  278. data.telephone = form[index].value;
  279. if (data.telephone.join() == ',') data.telephone = "";
  280. form[index] = {
  281. label: "手机号",
  282. error: false,
  283. errMsg: "",
  284. type: "number",
  285. value: data.phonenumber,
  286. placeholder: "联系人手机号码",
  287. valueName: "phonenumber",
  288. required: true,
  289. checking: "phone"
  290. }
  291. } else {
  292. if (typeof (form[index].value) == 'object') form[index].value = "";
  293. data.phonenumber = form[index].value;
  294. form[index] = {
  295. label: "座机电话",
  296. error: false,
  297. errMsg: "",
  298. type: "telephone",
  299. value: data.telephone || ["", ""],
  300. valueName: "telephone1",
  301. required: true,
  302. checking: "telephone"
  303. }
  304. };
  305. this.setData({
  306. form
  307. })
  308. }
  309. },
  310. onLoad(options) {
  311. if (options.data) {
  312. let data = JSON.parse(options.data);
  313. let form = this.data.form.map(v => {
  314. if (v.valueName != 'region') {
  315. v.value = data[v.valueName];
  316. if (v.valueName == "grade") v.value = data[v.valueName] + "";
  317. } else {
  318. v.value = data.province ? [data.province, data.city, data.county] : []
  319. }
  320. return v
  321. })
  322. let contactsinfo = data.contactsinfo[0];
  323. let isTelephone = contactsinfo.telephone ? "1" : "0";
  324. form.splice(5, 0, isTelephone == 0 ? {
  325. label: "手机号",
  326. error: false,
  327. errMsg: "",
  328. type: "number",
  329. value: contactsinfo.phonenumber || '',
  330. placeholder: "联系人手机号码",
  331. valueName: "phonenumber",
  332. required: false,
  333. checking: "phone",
  334. disabled: true
  335. } : {
  336. label: "座机电话",
  337. error: false,
  338. errMsg: "",
  339. type: "telephone",
  340. value: contactsinfo.telephone.split("-"),
  341. valueName: "telephone1",
  342. required: false,
  343. checking: "telephone",
  344. disabled: true
  345. })
  346. form.splice(5, 0, {
  347. label: "联系方式",
  348. error: false,
  349. errMsg: "",
  350. hint: "",
  351. type: "radio",
  352. value: isTelephone,
  353. radioList: [{
  354. id: '0',
  355. name: '手机号'
  356. }, {
  357. id: '1',
  358. name: '座机电话'
  359. }],
  360. valueName: "isTelephone", //绑定的字段名称
  361. required: false, //必填
  362. interrupt: true,
  363. checking: `true`,
  364. phonenumber: "",
  365. telephone: ["", ""],
  366. disabled: true
  367. })
  368. form.splice(5, 0, {
  369. label: "联系人",
  370. error: false,
  371. errMsg: "",
  372. type: "textarea",
  373. value: contactsinfo.name || '',
  374. placeholder: "联系人名称",
  375. valueName: "name",
  376. checking: "base",
  377. slot: "TXL",
  378. required: false,
  379. disabled: true
  380. })
  381. this.setData({
  382. disabled: false,
  383. content: {
  384. sa_customersid: data.sa_customersid,
  385. parentid: data.parentid,
  386. sys_enterpriseid: data.sys_enterpriseid,
  387. sa_customerpoolid: data.sa_customerpoolid,
  388. source: data.source,
  389. },
  390. form
  391. })
  392. } else {
  393. this.data.form.splice(5, 0, {
  394. label: "手机号",
  395. error: false,
  396. errMsg: "",
  397. type: "number",
  398. value: "",
  399. placeholder: "联系人手机号码",
  400. valueName: "phonenumber",
  401. required: true,
  402. checking: "phone"
  403. })
  404. this.data.form.splice(5, 0, {
  405. label: "联系方式",
  406. error: false,
  407. errMsg: "",
  408. hint: "",
  409. type: "radio",
  410. value: "0",
  411. radioList: [{
  412. id: '0',
  413. name: '手机号'
  414. }, {
  415. id: '1',
  416. name: '座机电话'
  417. }],
  418. valueName: "isTelephone", //绑定的字段名称
  419. required: true, //必填
  420. interrupt: true,
  421. checking: `true`,
  422. phonenumber: "",
  423. telephone: ["", ""]
  424. })
  425. this.data.form.splice(5, 0, {
  426. label: "联系人",
  427. error: false,
  428. errMsg: "",
  429. type: "textarea",
  430. value: "",
  431. placeholder: "联系人名称",
  432. valueName: "name",
  433. checking: "base",
  434. slot: "TXL",
  435. required: true
  436. })
  437. this.setData({
  438. form: this.data.form
  439. })
  440. }
  441. },
  442. /* 工商查询 */
  443. introduce({
  444. detail
  445. }) {
  446. let item = detail;
  447. let data = {
  448. enterprisename: item.companyName, //企业名称
  449. taxno: item.taxNum, //税号
  450. contact: item.legalPerson, //法人
  451. region: [item.regProvince, item.regCity, item.regArea], //地区
  452. address: item.address, //地区
  453. }
  454. this.setData({
  455. form: this.data.form.map(v => {
  456. if (data[v.valueName]) v.value = data[v.valueName];
  457. return v
  458. }),
  459. })
  460. },
  461. /* 工商查询 */
  462. queryClient() {
  463. let data = this.selectComponent("#Form").query();
  464. if (data.enterprisename == '') {
  465. wx.showToast({
  466. title: `您还未填写企业名称`,
  467. icon: "none"
  468. });
  469. } else {
  470. this.setData({
  471. form: this.selectComponent("#Form").data.form,
  472. })
  473. this.selectComponent("#Info").queryClient(data.enterprisename)
  474. }
  475. },
  476. repClose() {
  477. /* if (this.data.isSubmit) {
  478. let that = this;
  479. wx.showModal({
  480. title: '提示',
  481. content: `是否继续${this.data.content.sys_enterpriseid==0?'创建':'编辑'}客户`,
  482. complete: (res) => {
  483. if (res.confirm) that.handleSubmit(true);
  484. }
  485. })
  486. } */
  487. this.setData({
  488. repetitionShow: false,
  489. isSubmit: false
  490. })
  491. },
  492. /* 表单必填项是否完成 */
  493. onConfirm({
  494. detail
  495. }) {
  496. this.setData({
  497. disabled: detail
  498. })
  499. },
  500. // 是否显示全部
  501. onChange({
  502. detail
  503. }) {
  504. this.setData({
  505. showAll: detail
  506. })
  507. },
  508. /* 查询是否重复 */
  509. async queryRepetition(e) {
  510. let data = this.selectComponent("#Form").query();
  511. /* if (data.enterprisename == '') return wx.showToast({
  512. title: `您还未填写企业名称`,
  513. icon: "none"
  514. }); */
  515. data.province = data.region[0] || "";
  516. data.city = data.region[1] || "";
  517. data.county = data.region[2] || "";
  518. let res = await this.handleQueryRepetition({
  519. sa_customersid: this.data.content.sa_customersid,
  520. ...data
  521. });
  522. console.log("查询重复", res)
  523. if (res.msg != '成功') return wx.showToast({
  524. title: res.msg,
  525. icon: "none"
  526. });
  527. this.setData({
  528. countDown: 6
  529. });
  530. count = setInterval(() => {
  531. let countDown = this.data.countDown;
  532. if (countDown == 0) {
  533. clearInterval(count);
  534. this.setData({
  535. countDown: ""
  536. })
  537. } else {
  538. countDown--;
  539. this.setData({
  540. countDown
  541. })
  542. }
  543. }, 1000)
  544. if (res.total == 0) {
  545. wx.showToast({
  546. title: '未查询到疑似重复的客户信息',
  547. icon: "none"
  548. })
  549. } else {
  550. wx.showToast({
  551. title: `查询到${res.total}条疑似重复客户信息`,
  552. icon: "none"
  553. })
  554. this.setData({
  555. repetitionShow: true,
  556. repetitionList: res.data
  557. })
  558. }
  559. },
  560. /* 处理查重 */
  561. handleQueryRepetition(content) {
  562. return _Http.basic({
  563. "id": 20221208172002,
  564. content
  565. })
  566. },
  567. async submit() {
  568. let data = this.selectComponent("#Form").submit();
  569. data.province = data.region[0] || "";
  570. data.city = data.region[1] || "";
  571. data.county = data.region[2] || "";
  572. let query = await this.handleQueryRepetition({
  573. sa_customersid: this.data.content.sa_customersid,
  574. ...data
  575. });
  576. if (query.total != 0) {
  577. wx.showToast({
  578. title: `查询到${query.total}条疑似重复客户信息,不允许保存`,
  579. icon: "none"
  580. })
  581. this.setData({
  582. repetitionShow: true,
  583. repetitionList: query.data,
  584. isSubmit: true
  585. })
  586. } else {
  587. this.handleSubmit();
  588. }
  589. },
  590. handleSubmit(tag = false) {
  591. this.setData({
  592. loading: true
  593. })
  594. let data = this.selectComponent("#Form").submit();
  595. data.province = data.region[0] || "";
  596. data.city = data.region[1] || "";
  597. data.county = data.region[2] || "";
  598. data.sa_customerpoolid = data.sa_customerpoolid[0] ? data.sa_customerpoolid[1][0] : 0;
  599. data.parentid = data.parentid[0] ? data.parentid[1][0] : 0;
  600. data.ispublic = 1; //是否为公海客户
  601. data.oldcontactsid = this.data.oldcontactsid;
  602. delete(data.region);
  603. data.contactsinfo = {
  604. "name": data.name,
  605. "telephone": "",
  606. "phonenumber": data.isTelephone == 0 ? data.phonenumber || '' : data.telephone1.join("-") || ''
  607. }
  608. _Http.basic({
  609. "id": 20221010164302,
  610. "content": {
  611. ...this.data.content,
  612. ...data,
  613. }
  614. }).then(res => {
  615. this.setData({
  616. loading: false
  617. })
  618. console.log("新建客户", res)
  619. if (res.msg != '成功') return wx.showToast({
  620. title: res.data,
  621. icon: "none"
  622. })
  623. wx.showToast({
  624. title: '保存成功',
  625. icon: "none"
  626. });
  627. //绑定疑似重复标签
  628. if (tag) _Http.basic({
  629. "id": 20220929090901,
  630. "content": {
  631. "ownertable": "sa_customers",
  632. "ownerid": res.data.sa_customersid,
  633. "datatag": ["疑似重复"]
  634. }
  635. })
  636. setTimeout(() => {
  637. getCurrentPages().forEach(v => {
  638. switch (v.__route__) {
  639. case 'packageA/publicCustomer/index':
  640. v.getList(true);
  641. break;
  642. case 'packageA/publicCustomer/detail':
  643. wx.navigateBack()
  644. v.getDetail();
  645. v.selectComponent("#Contacts").getList(this.data.content.sa_customersid, true)
  646. break;
  647. }
  648. })
  649. let pages = getCurrentPages();
  650. if (pages[pages.length - 2].__route__ == 'packageA/publicCustomer/index') wx.redirectTo({
  651. url: '/packageA/publicCustomer/detail?id=' + res.data.sa_customersid,
  652. })
  653. }, tag ? 500 : 300);
  654. })
  655. },
  656. })