addAndEditor.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  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. if (options.data) {
  181. let data = JSON.parse(options.data);
  182. let form = [{
  183. label: "客户(企业)",
  184. error: false,
  185. errMsg: "",
  186. type: "textarea",
  187. value: "",
  188. placeholder: "客户(企业)名称",
  189. valueName: "enterprisename",
  190. checking: "base",
  191. slot: "info",
  192. required: true
  193. }, {
  194. label: "企业简称",
  195. error: false,
  196. errMsg: "",
  197. type: "textarea",
  198. value: "",
  199. placeholder: "企业简称",
  200. valueName: "abbreviation",
  201. checking: "base",
  202. required: false
  203. }, {
  204. label: "客户类型",
  205. error: false,
  206. errMsg: "",
  207. type: "option",
  208. optionNmae: "customertypemx",
  209. optionType: "radio", //复选 radio 单选
  210. value: "",
  211. placeholder: "客户类型",
  212. valueName: "type",
  213. checking: "base",
  214. required: true
  215. }, {
  216. label: "客户分类",
  217. error: false,
  218. errMsg: "",
  219. type: "option",
  220. optionNmae: "customergrade",
  221. optionType: "radio", //复选 radio 单选
  222. value: "",
  223. placeholder: "客户分类",
  224. valueName: "customergrade",
  225. checking: "base",
  226. required: false
  227. }, {
  228. label: "客户行业",
  229. error: false,
  230. errMsg: "",
  231. type: "option", //自定义选择 配合预定接口
  232. optionNmae: "industry", //选择类型
  233. optionType: "checkbox", //复选 radio 单选
  234. value: "",
  235. placeholder: "客户所属行业",
  236. valueName: "industry",
  237. checking: "base",
  238. required: false
  239. }, {
  240. label: "税号",
  241. error: false,
  242. errMsg: "",
  243. type: "textarea",
  244. value: "",
  245. placeholder: "企业税号",
  246. valueName: "taxno",
  247. checking: "base",
  248. required: false
  249. }, {
  250. label: "法人",
  251. error: false,
  252. errMsg: "",
  253. type: "text",
  254. value: "",
  255. placeholder: "企业法人",
  256. valueName: "contact",
  257. checking: "base",
  258. required: false
  259. }, {
  260. label: "联系电话",
  261. error: false,
  262. errMsg: "",
  263. type: "number",
  264. value: "",
  265. placeholder: "联系电话",
  266. valueName: "telephone",
  267. required: false
  268. }, {
  269. label: "省市县",
  270. error: false,
  271. errMsg: "",
  272. type: "region",
  273. value: [],
  274. placeholder: "所在地区",
  275. valueName: "region",
  276. required: true
  277. }, {
  278. label: "详细地址",
  279. error: false,
  280. errMsg: "",
  281. type: "textarea",
  282. value: "",
  283. placeholder: "详细地址",
  284. valueName: "address",
  285. checking: "base",
  286. required: false
  287. }, {
  288. label: "上级企业",
  289. error: false,
  290. errMsg: "",
  291. type: "route",
  292. url: "/packageA/select/setclient/select",
  293. value: "",
  294. params: {
  295. id: 20221012164402,
  296. content: {
  297. nocache: true,
  298. "type": 1,
  299. "isExport": 0,
  300. isend: 0,
  301. "where": {
  302. "condition": "",
  303. "status": "", //状态
  304. "startdate": "",
  305. "enddate": ""
  306. },
  307. "sort": [{
  308. sortname: "默认",
  309. sorted: 1,
  310. sortid: 67,
  311. reversed: 0
  312. }]
  313. },
  314. },
  315. query: "&radio=true&idname=sa_customersid",
  316. placeholder: "选择上级企业",
  317. valueName: "parentid",
  318. checking: "base",
  319. required: false
  320. }, {
  321. label: "客户来源",
  322. error: false,
  323. errMsg: "",
  324. type: "selector",
  325. range: [],
  326. rangeKey: "name",
  327. selectKey: "value",
  328. rangeIndex: "",
  329. value: "",
  330. placeholder: "来源",
  331. valueName: "source",
  332. checking: "base",
  333. required: true
  334. }, {
  335. label: "归属经销商",
  336. error: false,
  337. errMsg: "",
  338. type: "route",
  339. url: "/packageA/select/setclient/select",
  340. value: "",
  341. params: {
  342. "id": 20230214162602,
  343. "content": {
  344. "hrid": wx.getStorageSync('userMsg').hrid,
  345. "where": {
  346. "condition": ""
  347. }
  348. },
  349. },
  350. query: "&radio=true&idname=sa_agentsid",
  351. placeholder: "归属经销商",
  352. valueName: "sa_agentsid",
  353. checking: "base",
  354. required: false
  355. }].map(v => {
  356. if (v.valueName != 'region') {
  357. v.value = data[v.valueName] || "";
  358. if (v.valueName == "grade") v.value = data[v.valueName] + "";
  359. } else {
  360. v.value = data.province ? [data.province, data.city, data.county] : []
  361. };
  362. // if (data.isagent && ['enterprisename', 'region', 'sa_agentsid', 'grade', 'address', 'contact', 'telephone'].includes(v.valueName)) v.disabled = true;
  363. return v
  364. })
  365. try {
  366. let contactsinfo = data.contactsinfo[0];
  367. let isTelephone = contactsinfo.telephone ? "1" : "0";
  368. form.splice(4, 0, isTelephone == 0 ? {
  369. label: "手机号",
  370. error: false,
  371. errMsg: "",
  372. type: "number",
  373. value: contactsinfo.phonenumber || '',
  374. placeholder: "联系人手机号码",
  375. valueName: "phonenumber",
  376. required: false,
  377. checking: "phone",
  378. disabled: true
  379. } : {
  380. label: "座机电话",
  381. error: false,
  382. errMsg: "",
  383. type: "telephone",
  384. value: contactsinfo.telephone.split("-"),
  385. valueName: "telephone1",
  386. required: false,
  387. checking: "telephone",
  388. disabled: true
  389. })
  390. form.splice(4, 0, {
  391. label: "联系方式",
  392. error: false,
  393. errMsg: "",
  394. hint: "",
  395. type: "radio",
  396. value: isTelephone,
  397. radioList: [{
  398. id: '0',
  399. name: '手机号'
  400. }, {
  401. id: '1',
  402. name: '座机电话'
  403. }],
  404. valueName: "isTelephone", //绑定的字段名称
  405. required: false, //必填
  406. interrupt: true,
  407. checking: `true`,
  408. phonenumber: "",
  409. telephone: ["", ""],
  410. disabled: true
  411. })
  412. form.splice(4, 0, {
  413. label: "联系人",
  414. error: false,
  415. errMsg: "",
  416. type: "textarea",
  417. value: contactsinfo.name || '',
  418. placeholder: "联系人名称",
  419. valueName: "name",
  420. checking: "base",
  421. slot: "TXL",
  422. required: false,
  423. disabled: true
  424. })
  425. } catch (error) {
  426. }
  427. this.setData({
  428. disabled: false,
  429. content: {
  430. sa_customersid: data.sa_customersid,
  431. sys_enterpriseid: data.sys_enterpriseid,
  432. sa_customerpoolid: data.sa_customerpoolid,
  433. },
  434. form
  435. })
  436. } else {
  437. this.data.form.splice(4, 0, {
  438. label: "手机号",
  439. error: false,
  440. errMsg: "",
  441. type: "number",
  442. value: "",
  443. placeholder: "联系人手机号码",
  444. valueName: "phonenumber",
  445. required: true,
  446. checking: "phone"
  447. })
  448. this.data.form.splice(4, 0, {
  449. label: "联系方式",
  450. error: false,
  451. errMsg: "",
  452. hint: "",
  453. type: "radio",
  454. value: "0",
  455. radioList: [{
  456. id: '0',
  457. name: '手机号'
  458. }, {
  459. id: '1',
  460. name: '座机电话'
  461. }],
  462. valueName: "isTelephone", //绑定的字段名称
  463. required: true, //必填
  464. interrupt: true,
  465. checking: `true`,
  466. phonenumber: "",
  467. telephone: ["", ""]
  468. })
  469. this.data.form.splice(4, 0, {
  470. label: "联系人",
  471. error: false,
  472. errMsg: "",
  473. type: "textarea",
  474. value: "",
  475. placeholder: "联系人名称",
  476. valueName: "name",
  477. checking: "base",
  478. slot: "TXL",
  479. required: true
  480. })
  481. this.setData({
  482. form: this.data.form
  483. })
  484. }
  485. getApp().globalData.Language.getLanguagePackage(this, options.data ? '编辑客户' : '新建客户');
  486. if (wx.getStorageSync('userMsg').siteid == 'HY') {
  487. this.setData({
  488. form: this.data.form.map(v => {
  489. if (["customergrade", "industry"].includes(v.valueName)) v.required = true;
  490. return v
  491. })
  492. })
  493. }
  494. /* 获取来源 */
  495. _Http.basic({
  496. "classname": "sysmanage.develop.optiontype.optiontype",
  497. "method": "optiontypeselect",
  498. "content": {
  499. "typename": "cluesource",
  500. pageSize: 9999
  501. }
  502. }).then(res => {
  503. console.log("获取线索来源", res)
  504. if (res.code == '1') {
  505. let form = this.data.form;
  506. let item = form.find(v => v.label == '客户来源');
  507. item.range = res.code == '1' ? res.data.map(v => {
  508. v.name = getApp().globalData.Language.getMapText(v.value)
  509. return v
  510. }) : [];
  511. this.setData({
  512. form
  513. })
  514. }
  515. })
  516. },
  517. repClose() {
  518. /* if (this.data.isSubmit) {
  519. let that = this;
  520. wx.showModal({
  521. title: getApp().globalData.Language.getMapText('提示'),
  522. content: `是否继续创建客户`,
  523. cancelText: getApp().globalData.Language.getMapText('取消'),
  524. confirmText: getApp().globalData.Language.getMapText('确定'),
  525. complete: (res) => {
  526. if (res.confirm) that.handleSubmit(true);
  527. }
  528. })
  529. } */
  530. this.setData({
  531. repetitionShow: false,
  532. isSubmit: false
  533. })
  534. },
  535. /* 表单必填项是否完成 */
  536. onConfirm({
  537. detail
  538. }) {
  539. this.setData({
  540. disabled: detail
  541. })
  542. },
  543. // 是否显示全部
  544. onChange({
  545. detail
  546. }) {
  547. this.setData({
  548. showAll: detail
  549. })
  550. },
  551. /* 查询是否重复 */
  552. async queryRepetition(e) {
  553. let data = this.selectComponent("#Form").query();
  554. data.province = data.region[0] || "";
  555. data.city = data.region[1] || "";
  556. data.county = data.region[2] || "";
  557. let res = await this.handleQueryRepetition({
  558. sa_customersid: this.data.content.sa_customersid,
  559. ...data
  560. });
  561. console.log("查询重复", res)
  562. if (res.code != '1') return wx.showToast({
  563. title: res.msg,
  564. icon: "none"
  565. });
  566. this.setData({
  567. countDown: 6
  568. });
  569. count = setInterval(() => {
  570. let countDown = this.data.countDown;
  571. if (countDown == 0) {
  572. clearInterval(count);
  573. this.setData({
  574. countDown: ""
  575. })
  576. } else {
  577. countDown--;
  578. this.setData({
  579. countDown
  580. })
  581. }
  582. }, 1000)
  583. if (res.total == 0) {
  584. getApp().globalData.Language.showToast('未查询到疑似重复的客户信息')
  585. } else {
  586. wx.showToast({
  587. title: getApp().globalData.Language.getMapText('查询到') + res.total + getApp().globalData.Language.getMapText('条疑似重复客户信息'),
  588. icon: "none"
  589. })
  590. this.setData({
  591. repetitionShow: true,
  592. repetitionList: res.data.map(v => {
  593. v.chars = v.chars.reduce((acc, item) => ({
  594. ...acc,
  595. ...item
  596. }), {});
  597. return v
  598. })
  599. })
  600. }
  601. },
  602. /* 处理查重 */
  603. handleQueryRepetition(content) {
  604. return _Http.basic({
  605. "id": 20221208172002,
  606. content
  607. })
  608. },
  609. async submit() {
  610. let data = this.selectComponent("#Form").submit(),
  611. that = this;
  612. data.province = data.region[0] || "";
  613. data.city = data.region[1] || "";
  614. data.county = data.region[2] || "";
  615. let query = await this.handleQueryRepetition({
  616. sa_customersid: this.data.content.sa_customersid,
  617. ...data
  618. });
  619. if (query.total != 0) {
  620. wx.showModal({
  621. content: getApp().globalData.Language.joint([{
  622. t: 1,
  623. v: '查询到',
  624. }, {
  625. v: query.total,
  626. f: "“",
  627. r: "”"
  628. }, {
  629. t: 1,
  630. v: '条疑似重复客户信息,不可',
  631. r: " "
  632. }, {
  633. t: 1,
  634. v: this.data.content.sa_customersid == 0 ? '创建' : '编辑',
  635. r: " "
  636. }, {
  637. t: 1,
  638. v: '客户',
  639. }]),
  640. confirmText: that.data.language['确定'] || '我知道了',
  641. showCancel: false
  642. })
  643. this.setData({
  644. repetitionShow: true,
  645. repetitionList: query.data.map(v => {
  646. v.chars = v.chars.reduce((acc, item) => ({
  647. ...acc,
  648. ...item
  649. }), {});
  650. return v
  651. }),
  652. isSubmit: true
  653. })
  654. } else {
  655. this.handleSubmit();
  656. }
  657. },
  658. handleSubmit(tag = false) {
  659. this.setData({
  660. loading: true
  661. })
  662. let data = this.selectComponent("#Form").submit();
  663. data.province = data.region[0] || "";
  664. data.city = data.region[1] || "";
  665. data.county = data.region[2] || "";
  666. data.parentid = data.parentid[1] ? data.parentid[1][0] : 0;
  667. data.sa_agentsid = data.sa_agentsid[1] ? data.sa_agentsid[1][0] : 0;
  668. delete(data.region);
  669. try {
  670. data.contactsinfo = {
  671. "name": data.name,
  672. "telephone": "",
  673. "phonenumber": data.isTelephone == 0 ? data.phonenumber || '' : data.telephone1.join("-") || '',
  674. oldcontactsid: this.data.oldcontactsid,
  675. sys_phonebookid: this.data.sys_phonebookid || 0,
  676. }
  677. } catch (error) {
  678. }
  679. _Http.basic({
  680. "id": 20221012163902,
  681. "content": {
  682. ...this.data.content,
  683. ...data,
  684. }
  685. }).then(res => {
  686. this.setData({
  687. loading: false
  688. })
  689. console.log("新建客户", res)
  690. if (res.code != '1') return wx.showToast({
  691. title: res.msg,
  692. icon: "none"
  693. })
  694. getApp().globalData.Language.showToast('保存成功')
  695. //绑定疑似重复标签
  696. if (tag) _Http.basic({
  697. "id": 20220929090901,
  698. "content": {
  699. "ownertable": "sa_customers",
  700. "ownerid": res.data.sa_customersid,
  701. "datatag": ["疑似重复"]
  702. }
  703. })
  704. setTimeout(() => {
  705. getCurrentPages().forEach(v => {
  706. switch (v.__route__) {
  707. case 'packageA/setclient/index':
  708. v.getList(true);
  709. break;
  710. case 'packageA/setclient/detail':
  711. v.getDetail();
  712. v.selectComponent("#Contacts").getList(this.data.content.sa_customersid, true)
  713. wx.navigateBack()
  714. break;
  715. }
  716. })
  717. let pages = getCurrentPages();
  718. if (pages[pages.length - 2].__route__ == 'packageA/setclient/index') wx.redirectTo({
  719. url: '/packageA/setclient/detail?id=' + res.data.sa_customersid,
  720. })
  721. }, tag ? 500 : 300)
  722. })
  723. },
  724. })