addAndEditor.js 23 KB

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