addAndEditor.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. let _Http = getApp().globalData.http,
  2. count = null;
  3. Page({
  4. data: {
  5. queryShow: false,
  6. repetitionShow: false,
  7. repetitionList: [],
  8. isSubmit: false,
  9. showAll: false,
  10. form: [{
  11. label: "企业名称",
  12. error: false,
  13. errMsg: "",
  14. type: "textarea",
  15. value: "",
  16. placeholder: "企业全称",
  17. valueName: "enterprisename",
  18. checking: "base",
  19. slot: "info",
  20. required: true
  21. }, {
  22. label: "选择公海池",
  23. error: false,
  24. errMsg: "",
  25. type: "route",
  26. url: "/packageA/publicCustomer/pond/index",
  27. radio: true,
  28. value: "",
  29. params: {
  30. "id": 20221206195102,
  31. "content": {
  32. "pageNumber": 1,
  33. "pageSize": 20,
  34. "where": {
  35. "condition": ""
  36. }
  37. }
  38. },
  39. placeholder: "选择所属公海池",
  40. valueName: "sa_customerpoolid",
  41. checking: "base",
  42. required: true
  43. }, {
  44. label: "企业简称",
  45. error: false,
  46. errMsg: "",
  47. type: "textarea",
  48. value: "",
  49. placeholder: "企业简称",
  50. valueName: "abbreviation",
  51. checking: "base",
  52. required: false
  53. }, {
  54. label: "统一社会信用代码",
  55. error: false,
  56. errMsg: "",
  57. type: "textarea",
  58. value: "",
  59. placeholder: "企业税号/注册号/营业执照号码",
  60. valueName: "taxno",
  61. checking: "base",
  62. required: false
  63. }, {
  64. label: "法定代表人",
  65. error: false,
  66. errMsg: "",
  67. type: "text",
  68. value: "",
  69. placeholder: "企业法人",
  70. valueName: "contact",
  71. checking: "base",
  72. required: false
  73. }, {
  74. label: "法人电话号码",
  75. error: false,
  76. errMsg: "",
  77. type: "number",
  78. value: "",
  79. placeholder: "法人联系手机号",
  80. valueName: "phonenumber",
  81. checking: "phone",
  82. required: false
  83. }, {
  84. label: "所属行业",
  85. error: false,
  86. errMsg: "",
  87. type: "option", //自定义选择 配合预定接口
  88. optionNmae: "industry", //选择类型
  89. optionType: "radio", //复选 radio 单选
  90. value: "",
  91. placeholder: "企业所属行业",
  92. valueName: "industry",
  93. checking: "base",
  94. required: false
  95. }, {
  96. label: "地区",
  97. error: false,
  98. errMsg: "",
  99. type: "region",
  100. value: [],
  101. placeholder: "所属地区 省/市/区",
  102. valueName: "region",
  103. required: false
  104. }, {
  105. label: "注册地址",
  106. error: false,
  107. errMsg: "",
  108. type: "textarea",
  109. value: "",
  110. placeholder: "企业注册地址",
  111. valueName: "address",
  112. checking: "base",
  113. required: false
  114. }, {
  115. label: "客户类型",
  116. error: false,
  117. errMsg: "",
  118. type: "option",
  119. optionNmae: "customertypemx",
  120. optionType: "radio", //复选 radio 单选
  121. value: "",
  122. placeholder: "客户类型",
  123. valueName: "type",
  124. checking: "base",
  125. required: true
  126. }, {
  127. label: "客户级别",
  128. error: false,
  129. errMsg: "",
  130. type: "option",
  131. optionNmae: "agentgrade",
  132. optionType: "radio", //复选 radio 单选
  133. value: "",
  134. placeholder: "客户数字级别",
  135. valueName: "grade",
  136. checking: "base",
  137. required: false
  138. }],
  139. content: {
  140. "sa_customersid": 0, //新增是传0
  141. "parentid": 0, //上级客户ID,默认或没有上级的时候传0
  142. "sys_enterpriseid": 0, //合作企业档案ID,新增是传0,更新
  143. "source": "", //客户来源
  144. ispublic: 1, //是否为公海客户
  145. },
  146. disabled: true,
  147. countDown: "", //查重倒计时
  148. },
  149. setOption(item) {
  150. let i = this.data.form.findIndex(v => v.valueName == item.valueName);
  151. this.setData({
  152. [`form[${i}]`]: item
  153. })
  154. },
  155. onLoad(options) {
  156. if (options.data) {
  157. let data = JSON.parse(options.data);
  158. this.setData({
  159. disabled: false,
  160. content: {
  161. sa_customersid: data.sa_customersid,
  162. parentid: data.parentid,
  163. sys_enterpriseid: data.sys_enterpriseid,
  164. sa_customerpoolid: data.sa_customerpoolid,
  165. source: data.source,
  166. },
  167. form: this.data.form.map(v => {
  168. if (v.valueName != 'region') {
  169. v.value = data[v.valueName];
  170. } else {
  171. v.value = data.province ? [data.province, data.city, data.county] : []
  172. }
  173. return v
  174. })
  175. })
  176. }
  177. },
  178. /* 引入 */
  179. introduce(e) {
  180. let {
  181. item
  182. } = e.currentTarget.dataset,
  183. that = this;
  184. wx.showModal({
  185. title: '提示',
  186. content: `是否确定引入“${item.companyName}”信息`,
  187. complete: (res) => {
  188. if (res.confirm) {
  189. let data = {
  190. enterprisename: item.companyName, //企业名称
  191. taxno: item.taxNum, //税号
  192. contact: item.legalPerson, //法人
  193. region: [item.regProvince, item.regCity, item.regArea], //地区
  194. address: item.address, //地区
  195. }
  196. that.setData({
  197. form: that.data.form.map(v => {
  198. if (data[v.valueName]) v.value = data[v.valueName];
  199. return v
  200. }),
  201. queryShow: false,
  202. queryList: null
  203. })
  204. }
  205. }
  206. })
  207. },
  208. /* 工商查询 */
  209. queryClient(e) {
  210. let data = this.selectComponent("#Form").query();
  211. this.setData({
  212. form: this.data.form.map(v => {
  213. v.value = data[v.valueName];
  214. return v
  215. }),
  216. })
  217. console.log(this.data.form)
  218. if (data.enterprisename == '') return wx.showToast({
  219. title: `您还未填写企业名称`,
  220. icon: "none"
  221. });
  222. _Http.basic({
  223. id: 20221208103601,
  224. content: {
  225. pageNumber: 1,
  226. pageTotal: 1,
  227. pageSize: 5,
  228. keyword: data.enterprisename,
  229. }
  230. }).then(res => {
  231. console.log("工商查询", res)
  232. if (!res.data[0]) return wx.showToast({
  233. title: '未查询到相关企业!',
  234. icon: "none"
  235. });
  236. this.setData({
  237. queryList: res.data,
  238. queryShow: true
  239. })
  240. })
  241. },
  242. onClose() {
  243. this.setData({
  244. queryShow: false
  245. })
  246. },
  247. repClose() {
  248. if (this.data.isSubmit) {
  249. let that = this;
  250. wx.showModal({
  251. title: '提示',
  252. content: `是否继续创建客户`,
  253. complete: (res) => {
  254. if (res.confirm) that.handleSubmit(true);
  255. }
  256. })
  257. }
  258. this.setData({
  259. repetitionShow: false,
  260. isSubmit: false
  261. })
  262. },
  263. /* 表单必填项是否完成 */
  264. onConfirm({
  265. detail
  266. }) {
  267. this.setData({
  268. disabled: detail
  269. })
  270. },
  271. // 是否显示全部
  272. onChange({
  273. detail
  274. }) {
  275. this.setData({
  276. showAll: detail
  277. })
  278. },
  279. /* 查询是否重复 */
  280. async queryRepetition(e) {
  281. let {
  282. enterprisename,
  283. taxno,
  284. address
  285. } = this.selectComponent("#Form").query();
  286. if (enterprisename == '') return wx.showToast({
  287. title: `您还未填写企业名称`,
  288. icon: "none"
  289. });
  290. let res = await this.handleQueryRepetition({
  291. sa_customersid: this.data.content.sa_customersid,
  292. enterprisename,
  293. taxno,
  294. address
  295. });
  296. console.log("查询重复", res)
  297. if (res.msg != '成功') return wx.showToast({
  298. title: res.msg,
  299. icon: "none"
  300. });
  301. this.setData({
  302. countDown: 6
  303. });
  304. count = setInterval(() => {
  305. let countDown = this.data.countDown;
  306. if (countDown == 0) {
  307. clearInterval(count);
  308. this.setData({
  309. countDown: ""
  310. })
  311. } else {
  312. countDown--;
  313. this.setData({
  314. countDown
  315. })
  316. }
  317. }, 1000)
  318. if (res.total == 0) {
  319. wx.showToast({
  320. title: '未查询到疑似重复的客户信息',
  321. icon: "none"
  322. })
  323. } else {
  324. wx.showToast({
  325. title: `查询到${res.total}条疑似重复客户信息`,
  326. icon: "none"
  327. })
  328. this.setData({
  329. repetitionShow: true,
  330. repetitionList: res.data
  331. })
  332. }
  333. },
  334. /* 处理查重 */
  335. handleQueryRepetition(content) {
  336. return _Http.basic({
  337. "id": 20221208172002,
  338. content
  339. })
  340. },
  341. async submit() {
  342. let data = this.selectComponent("#Form").submit();
  343. let query = await this.handleQueryRepetition({
  344. sa_customersid: this.data.content.sa_customersid,
  345. enterprisename: data.enterprisename,
  346. taxno: data.taxno,
  347. address: data.address
  348. });
  349. if (query.total != 0) {
  350. wx.showToast({
  351. title: `查询到${query.total}条疑似重复客户信息`,
  352. icon: "none"
  353. })
  354. this.setData({
  355. repetitionShow: true,
  356. repetitionList: query.data,
  357. isSubmit: true
  358. })
  359. } else {
  360. this.handleSubmit();
  361. }
  362. },
  363. handleSubmit(tag = false) {
  364. let data = this.selectComponent("#Form").submit();
  365. if (data.region.length != 0) {
  366. data.province = data.region[0]
  367. data.city = data.region[1]
  368. data.county = data.region[2]
  369. };
  370. data.sa_customerpoolid = data.sa_customerpoolid[1][0]
  371. delete(data.region);
  372. _Http.basic({
  373. "id": 20221010164302,
  374. "content": {
  375. ...this.data.content,
  376. ...data,
  377. }
  378. }).then(res => {
  379. console.log("新建客户", res)
  380. if (res.msg != '成功') return wx.showToast({
  381. title: res.data,
  382. icon: "none"
  383. })
  384. wx.showToast({
  385. title: '保存成功',
  386. icon: "none"
  387. });
  388. //绑定疑似重复标签
  389. if (tag) _Http.basic({
  390. "id": 20220929090901,
  391. "content": {
  392. "ownertable": "sa_customers",
  393. "ownerid": res.data.sa_customersid,
  394. "datatag": ["疑似重复"]
  395. }
  396. })
  397. setTimeout(() => {
  398. getCurrentPages().forEach(v => {
  399. switch (v.__route__) {
  400. case 'packageA/publicCustomer/index':
  401. v.getList(true);
  402. break;
  403. case 'packageA/publicCustomer/detail':
  404. wx.navigateBack()
  405. v.getDetail();
  406. break;
  407. }
  408. })
  409. let pages = getCurrentPages();
  410. if (pages[pages.length - 2].__route__ == 'packageA/publicCustomer/index') wx.redirectTo({
  411. url: '/packageA/publicCustomer/detail?id=' + res.data.sa_customersid,
  412. })
  413. }, tag ? 500 : 300);
  414. })
  415. },
  416. })