addAndEditor.js 8.5 KB

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