addAndEditor.js 24 KB

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