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. required: false
  130. }, {
  131. label: "省市县",
  132. error: false,
  133. errMsg: "",
  134. type: "region",
  135. value: [],
  136. placeholder: "所在地区",
  137. valueName: "region",
  138. required: false
  139. }, {
  140. label: "详细地址",
  141. error: false,
  142. errMsg: "",
  143. type: "textarea",
  144. value: "",
  145. placeholder: "详细地址",
  146. valueName: "address",
  147. checking: "base",
  148. required: false
  149. }, {
  150. label: "上级企业",
  151. error: false,
  152. errMsg: "",
  153. type: "route",
  154. url: "/packageA/select/setclient/select",
  155. value: "",
  156. params: {
  157. id: 20221012164402,
  158. valueKey: "sa_customersid",
  159. content: {
  160. nocache: true,
  161. "type": 1,
  162. "isExport": 0,
  163. isend: 0,
  164. "where": {
  165. "condition": "",
  166. "status": "", //状态
  167. "startdate": "",
  168. "enddate": ""
  169. },
  170. "sort": [{
  171. sortname: "默认",
  172. sorted: 1,
  173. sortid: 67,
  174. reversed: 0
  175. }]
  176. },
  177. },
  178. query: "&radio=true",
  179. placeholder: "选择上级企业",
  180. valueName: "parentid",
  181. checking: "base",
  182. required: false
  183. }, {
  184. label: "客户来源",
  185. error: false,
  186. errMsg: "",
  187. type: "textarea",
  188. value: "",
  189. placeholder: "客户来源",
  190. valueName: "source",
  191. checking: "base",
  192. required: false
  193. }],
  194. content: {
  195. "sa_customersid": 0, //新增是传0
  196. "sys_enterpriseid": 0, //合作企业档案ID,新增是传0,更新
  197. phonenumber: "",
  198. },
  199. disabled: true,
  200. countDown: "", //查重倒计时
  201. },
  202. setOption(item) {
  203. let i = this.data.form.findIndex(v => v.valueName == item.valueName);
  204. this.setData({
  205. [`form[${i}]`]: item
  206. })
  207. },
  208. /* 打开通讯录 */
  209. openContacts() {
  210. let that = this;
  211. let page = that.selectComponent("#Form");
  212. let form = page.data.form,
  213. index = form.findIndex(v => v.label == '联系人');
  214. if (form[index].disabled) return;
  215. wx.navigateTo({
  216. url: '/packageA/setclient/contacts',
  217. })
  218. getApp().globalData.handleSelect = (item) => {
  219. wx.showModal({
  220. title: '提示',
  221. content: `是否确定选择${item.name}`,
  222. complete: ({
  223. confirm
  224. }) => {
  225. if (confirm) {
  226. form[index].value = item.name;
  227. that.data.oldcontactsid = item.contactsid
  228. if (item.phonenumber.indexOf('-') !== -1) {
  229. form[index + 1].value = "1";
  230. form[index + 2] = {
  231. label: "座机电话",
  232. error: false,
  233. errMsg: "",
  234. type: "telephone",
  235. value: item.phonenumber.split("-"),
  236. valueName: "telephone1",
  237. required: true,
  238. checking: "telephone"
  239. }
  240. } else {
  241. form[index + 1].value = "0";
  242. form[index + 2] = {
  243. label: "手机号",
  244. error: false,
  245. errMsg: "",
  246. type: "number",
  247. value: item.phonenumber,
  248. placeholder: "联系人手机号码",
  249. valueName: "phonenumber",
  250. required: true,
  251. checking: "phone"
  252. }
  253. }
  254. that.setData({
  255. form
  256. })
  257. wx.navigateBack()
  258. getApp().globalData.handleSelect = null;
  259. page.confirm()
  260. }
  261. }
  262. })
  263. };
  264. },
  265. /* 打断 */
  266. interrupt({
  267. detail
  268. }) {
  269. let {
  270. data,
  271. form,
  272. temporary
  273. } = detail;
  274. if (data.label == '联系方式') {
  275. let index = temporary.index + 1
  276. if (data.value == 0) {
  277. data.telephone = form[index].value;
  278. if (data.telephone.join() == ',') data.telephone = "";
  279. form[index] = {
  280. label: "手机号",
  281. error: false,
  282. errMsg: "",
  283. type: "number",
  284. value: data.phonenumber,
  285. placeholder: "联系人手机号码",
  286. valueName: "phonenumber",
  287. required: true,
  288. checking: "phone"
  289. }
  290. } else {
  291. if (typeof (form[index].value) == 'object') form[index].value = "";
  292. data.phonenumber = form[index].value;
  293. form[index] = {
  294. label: "座机电话",
  295. error: false,
  296. errMsg: "",
  297. type: "telephone",
  298. value: data.telephone || ["", ""],
  299. valueName: "telephone1",
  300. required: true,
  301. checking: "telephone"
  302. }
  303. };
  304. this.setData({
  305. form
  306. })
  307. }
  308. },
  309. onLoad(options) {
  310. if (options.data) {
  311. let data = JSON.parse(options.data);
  312. let form = this.data.form.map(v => {
  313. if (v.valueName != 'region') {
  314. v.value = data[v.valueName];
  315. if (v.valueName == "grade") v.value = data[v.valueName] + "";
  316. } else {
  317. v.value = data.province ? [data.province, data.city, data.county] : []
  318. }
  319. return v
  320. })
  321. let contactsinfo = data.contactsinfo[0];
  322. let isTelephone = contactsinfo.telephone ? "1" : "0";
  323. form.splice(5, 0, isTelephone == 0 ? {
  324. label: "手机号",
  325. error: false,
  326. errMsg: "",
  327. type: "number",
  328. value: contactsinfo.phonenumber || '',
  329. placeholder: "联系人手机号码",
  330. valueName: "phonenumber",
  331. required: false,
  332. checking: "phone",
  333. disabled: true
  334. } : {
  335. label: "座机电话",
  336. error: false,
  337. errMsg: "",
  338. type: "telephone",
  339. value: contactsinfo.telephone.split("-"),
  340. valueName: "telephone1",
  341. required: false,
  342. checking: "telephone",
  343. disabled: true
  344. })
  345. form.splice(5, 0, {
  346. label: "联系方式",
  347. error: false,
  348. errMsg: "",
  349. hint: "",
  350. type: "radio",
  351. value: isTelephone,
  352. radioList: [{
  353. id: '0',
  354. name: '手机号'
  355. }, {
  356. id: '1',
  357. name: '座机电话'
  358. }],
  359. valueName: "isTelephone", //绑定的字段名称
  360. required: false, //必填
  361. interrupt: true,
  362. checking: `true`,
  363. phonenumber: "",
  364. telephone: ["", ""],
  365. disabled: true
  366. })
  367. form.splice(5, 0, {
  368. label: "联系人",
  369. error: false,
  370. errMsg: "",
  371. type: "textarea",
  372. value: contactsinfo.name || '',
  373. placeholder: "联系人名称",
  374. valueName: "name",
  375. checking: "base",
  376. slot: "TXL",
  377. required: false,
  378. disabled: true
  379. })
  380. this.setData({
  381. disabled: false,
  382. content: {
  383. sa_customersid: data.sa_customersid,
  384. parentid: data.parentid,
  385. sys_enterpriseid: data.sys_enterpriseid,
  386. sa_customerpoolid: data.sa_customerpoolid,
  387. source: data.source,
  388. },
  389. form
  390. })
  391. } else {
  392. this.data.form.splice(5, 0, {
  393. label: "手机号",
  394. error: false,
  395. errMsg: "",
  396. type: "number",
  397. value: "",
  398. placeholder: "联系人手机号码",
  399. valueName: "phonenumber",
  400. required: true,
  401. checking: "phone"
  402. })
  403. this.data.form.splice(5, 0, {
  404. label: "联系方式",
  405. error: false,
  406. errMsg: "",
  407. hint: "",
  408. type: "radio",
  409. value: "0",
  410. radioList: [{
  411. id: '0',
  412. name: '手机号'
  413. }, {
  414. id: '1',
  415. name: '座机电话'
  416. }],
  417. valueName: "isTelephone", //绑定的字段名称
  418. required: true, //必填
  419. interrupt: true,
  420. checking: `true`,
  421. phonenumber: "",
  422. telephone: ["", ""]
  423. })
  424. this.data.form.splice(5, 0, {
  425. label: "联系人",
  426. error: false,
  427. errMsg: "",
  428. type: "textarea",
  429. value: "",
  430. placeholder: "联系人名称",
  431. valueName: "name",
  432. checking: "base",
  433. slot: "TXL",
  434. required: true
  435. })
  436. this.setData({
  437. form: this.data.form
  438. })
  439. }
  440. },
  441. /* 工商查询 */
  442. introduce({
  443. detail
  444. }) {
  445. let item = detail;
  446. let data = {
  447. enterprisename: item.companyName, //企业名称
  448. taxno: item.taxNum, //税号
  449. contact: item.legalPerson, //法人
  450. region: [item.regProvince ? item.regProvince : item.regCity, item.regCity, item.regArea], //地区
  451. address: item.address, //地区
  452. telephone: item.phone,
  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. delete(data.region);
  602. data.contactsinfo = {
  603. "name": data.name,
  604. "telephone": "",
  605. "phonenumber": data.isTelephone == 0 ? data.phonenumber || '' : data.telephone1.join("-") || '',
  606. oldcontactsid: this.data.oldcontactsid
  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. })