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. form: [{
  26. label: "客户(企业)",
  27. error: false,
  28. errMsg: "",
  29. type: "textarea",
  30. value: "",
  31. placeholder: "客户(企业)名称",
  32. valueName: "enterprisename",
  33. checking: "base",
  34. slot: "info",
  35. required: true
  36. }, {
  37. label: "企业简称",
  38. error: false,
  39. errMsg: "",
  40. type: "textarea",
  41. value: "",
  42. placeholder: "企业简称",
  43. valueName: "abbreviation",
  44. checking: "base",
  45. required: false
  46. }, {
  47. label: "客户类型",
  48. error: false,
  49. errMsg: "",
  50. type: "option",
  51. optionNmae: "customertypemx",
  52. optionType: "radio", //复选 radio 单选
  53. value: "",
  54. placeholder: "客户类型",
  55. valueName: "type",
  56. checking: "base",
  57. required: true
  58. }, {
  59. label: "客户分类",
  60. error: false,
  61. errMsg: "",
  62. type: "option",
  63. optionNmae: "customergrade",
  64. optionType: "radio", //复选 radio 单选
  65. value: "",
  66. placeholder: "客户分类",
  67. valueName: "customergrade",
  68. checking: "base",
  69. required: false
  70. }, {
  71. label: "客户行业",
  72. error: false,
  73. errMsg: "",
  74. type: "option", //自定义选择 配合预定接口
  75. optionNmae: "industry", //选择类型
  76. optionType: "checkbox", //复选 radio 单选
  77. value: "",
  78. placeholder: "客户所属行业",
  79. valueName: "industry",
  80. checking: "base",
  81. required: false
  82. }, {
  83. label: "税号",
  84. error: false,
  85. errMsg: "",
  86. type: "textarea",
  87. value: "",
  88. placeholder: "企业税号",
  89. valueName: "taxno",
  90. checking: "base",
  91. required: false
  92. }, {
  93. label: "法人",
  94. error: false,
  95. errMsg: "",
  96. type: "text",
  97. value: "",
  98. placeholder: "企业法人",
  99. valueName: "contact",
  100. checking: "base",
  101. required: false
  102. }, {
  103. label: "联系电话",
  104. error: false,
  105. errMsg: "",
  106. type: "number",
  107. value: "",
  108. placeholder: "联系电话",
  109. valueName: "telephone",
  110. required: false
  111. }, {
  112. label: "省市县",
  113. error: false,
  114. errMsg: "",
  115. type: "region",
  116. value: [],
  117. placeholder: "所在地区",
  118. valueName: "region",
  119. required: true
  120. }, {
  121. label: "详细地址",
  122. error: false,
  123. errMsg: "",
  124. type: "textarea",
  125. value: "",
  126. placeholder: "详细地址",
  127. valueName: "address",
  128. checking: "base",
  129. required: false
  130. }, {
  131. label: "上级企业",
  132. error: false,
  133. errMsg: "",
  134. type: "route",
  135. url: "/packageA/select/setclient/select",
  136. value: "",
  137. params: {
  138. id: 20221012164402,
  139. content: {
  140. nocache: true,
  141. "type": 1,
  142. "isExport": 0,
  143. isend: 0,
  144. "where": {
  145. "condition": "",
  146. "status": "", //状态
  147. "startdate": "",
  148. "enddate": ""
  149. },
  150. "sort": [{
  151. sortname: "默认",
  152. sorted: 1,
  153. sortid: 67,
  154. reversed: 0
  155. }]
  156. },
  157. },
  158. query: "&radio=true&idname=sa_customersid",
  159. placeholder: "选择上级企业",
  160. valueName: "parentid",
  161. checking: "base",
  162. required: false
  163. }, {
  164. label: "客户来源",
  165. error: false,
  166. errMsg: "",
  167. type: "selector",
  168. range: [],
  169. rangeKey: "name",
  170. selectKey: "value",
  171. rangeIndex: "",
  172. value: "",
  173. placeholder: "来源",
  174. valueName: "source",
  175. checking: "base",
  176. required: true
  177. }, {
  178. label: "归属经销商",
  179. error: false,
  180. errMsg: "",
  181. type: "route",
  182. url: "/packageA/select/setclient/select",
  183. value: "",
  184. params: {
  185. "id": 20230214162602,
  186. "content": {
  187. "hrid": wx.getStorageSync('userMsg').hrid,
  188. "where": {
  189. "condition": ""
  190. }
  191. },
  192. },
  193. query: "&radio=true&idname=sa_agentsid",
  194. placeholder: "归属经销商",
  195. valueName: "sa_agentsid",
  196. checking: "base",
  197. required: false
  198. }],
  199. content: {
  200. "sa_customersid": 0, //新增是传0
  201. "sys_enterpriseid": 0, //合作企业档案ID,新增是传0,更新
  202. "sa_customerpoolid": 0, //客户池(公海池)ID,默认或没有的时候传0
  203. phonenumber: "",
  204. ispublic: 0, //是否为公海客户
  205. },
  206. disabled: true,
  207. countDown: "", //查重倒计时
  208. },
  209. queryClient() {
  210. let data = this.selectComponent("#Form").query();
  211. if (data.enterprisename == '') {
  212. wx.showToast({
  213. title: getApp().globalData.Language.getMapText('您还未填写企业名称'),
  214. icon: "none"
  215. });
  216. } else {
  217. this.setData({
  218. form: this.selectComponent("#Form").data.form,
  219. })
  220. this.selectComponent("#Info").queryClient(data.enterprisename)
  221. }
  222. },
  223. /* 工商查询 */
  224. introduce({
  225. detail
  226. }) {
  227. let item = detail;
  228. let data = {
  229. enterprisename: item.companyName, //企业名称
  230. taxno: item.taxNum, //税号
  231. contact: item.legalPerson, //法人
  232. region: [item.regProvince ? item.regProvince : item.regCity, item.regCity, item.regArea], //地区
  233. address: item.address,
  234. telephone: item.phone,
  235. }
  236. this.setData({
  237. form: this.data.form.map(v => {
  238. if (data[v.valueName]) v.value = data[v.valueName];
  239. return v
  240. })
  241. })
  242. },
  243. /* 打断 */
  244. interrupt({
  245. detail
  246. }) {
  247. let {
  248. data,
  249. form,
  250. temporary
  251. } = detail;
  252. if (data.label == '联系方式') {
  253. let index = temporary.index + 1
  254. if (data.value == 0) {
  255. data.telephone = form[index].value;
  256. if (data.telephone.join() == ',') data.telephone = "";
  257. form[index] = {
  258. label: "手机号",
  259. error: false,
  260. errMsg: "",
  261. type: "number",
  262. value: data.phonenumber,
  263. placeholder: "联系人手机号码",
  264. valueName: "phonenumber",
  265. required: true,
  266. checking: "phone"
  267. }
  268. } else {
  269. if (typeof (form[index].value) == 'object') form[index].value = "";
  270. data.phonenumber = form[index].value;
  271. form[index] = {
  272. label: "座机电话",
  273. error: false,
  274. errMsg: "",
  275. type: "telephone",
  276. value: data.telephone || ["", ""],
  277. valueName: "telephone1",
  278. required: true,
  279. checking: "telephone"
  280. }
  281. };
  282. this.setData({
  283. form
  284. })
  285. }
  286. },
  287. /* 打开通讯录 */
  288. openContacts() {
  289. let that = this;
  290. let page = that.selectComponent("#Form");
  291. let form = page.data.form,
  292. index = form.findIndex(v => v.label == '联系人');
  293. if (form[index].disabled) return;
  294. wx.navigateTo({
  295. url: '/packageA/setclient/contacts',
  296. })
  297. getApp().globalData.handleSelect = (item) => {
  298. wx.showModal({
  299. title: getApp().globalData.Language.getMapText('提示'),
  300. content: getApp().globalData.Language.getMapText('是否确定选择') + item.name,
  301. cancelText: getApp().globalData.Language.getMapText('取消'),
  302. confirmText: getApp().globalData.Language.getMapText('确定'),
  303. complete: ({
  304. confirm
  305. }) => {
  306. if (confirm) {
  307. form[index].value = item.name;
  308. that.data.oldcontactsid = item.contactsid;
  309. that.data.sys_phonebookid = item.sys_phonebookid;
  310. if (item.phonenumber.indexOf('-') !== -1) {
  311. form[index + 1].value = "1";
  312. form[index + 2] = {
  313. label: "座机电话",
  314. error: false,
  315. errMsg: "",
  316. type: "telephone",
  317. value: item.phonenumber.split("-"),
  318. valueName: "telephone1",
  319. required: true,
  320. checking: "telephone"
  321. }
  322. } else {
  323. form[index + 1].value = "0";
  324. form[index + 2] = {
  325. label: "手机号",
  326. error: false,
  327. errMsg: "",
  328. type: "number",
  329. value: item.phonenumber,
  330. placeholder: "联系人手机号码",
  331. valueName: "phonenumber",
  332. required: true,
  333. checking: "phone"
  334. }
  335. }
  336. that.setData({
  337. form
  338. })
  339. wx.navigateBack()
  340. getApp().globalData.handleSelect = null;
  341. page.confirm()
  342. }
  343. }
  344. })
  345. };
  346. },
  347. setOption(item) {
  348. let i = this.data.form.findIndex(v => v.valueName == item.valueName);
  349. this.setData({
  350. [`form[${i}]`]: item
  351. })
  352. },
  353. onLoad(options) {
  354. if (options.data) {
  355. let data = JSON.parse(options.data);
  356. let form = this.data.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. this.data.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. this.data.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. this.data.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: this.data.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. })