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