addAndEditor.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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. if (v.valueName == "grade") v.value = data[v.valueName] + "";
  217. } else {
  218. v.value = data.province ? [data.province, data.city, data.county] : []
  219. }
  220. return v
  221. })
  222. })
  223. }
  224. },
  225. repClose() {
  226. if (this.data.isSubmit) {
  227. let that = this;
  228. wx.showModal({
  229. title: '提示',
  230. content: `是否继续创建客户`,
  231. complete: (res) => {
  232. if (res.confirm) that.handleSubmit(true);
  233. }
  234. })
  235. }
  236. this.setData({
  237. repetitionShow: false,
  238. isSubmit: false
  239. })
  240. },
  241. /* 表单必填项是否完成 */
  242. onConfirm({
  243. detail
  244. }) {
  245. this.setData({
  246. disabled: detail
  247. })
  248. },
  249. // 是否显示全部
  250. onChange({
  251. detail
  252. }) {
  253. this.setData({
  254. showAll: detail
  255. })
  256. },
  257. /* 查询是否重复 */
  258. async queryRepetition(e) {
  259. let {
  260. enterprisename,
  261. taxno,
  262. address
  263. } = this.selectComponent("#Form").query();
  264. if (enterprisename == '') return wx.showToast({
  265. title: `您还未填写企业名称`,
  266. icon: "none"
  267. });
  268. let res = await this.handleQueryRepetition({
  269. sa_customersid: this.data.content.sa_customersid,
  270. enterprisename,
  271. taxno,
  272. address
  273. });
  274. console.log("查询重复", res)
  275. if (res.msg != '成功') return wx.showToast({
  276. title: res.msg,
  277. icon: "none"
  278. });
  279. this.setData({
  280. countDown: 6
  281. });
  282. count = setInterval(() => {
  283. let countDown = this.data.countDown;
  284. if (countDown == 0) {
  285. clearInterval(count);
  286. this.setData({
  287. countDown: ""
  288. })
  289. } else {
  290. countDown--;
  291. this.setData({
  292. countDown
  293. })
  294. }
  295. }, 1000)
  296. if (res.total == 0) {
  297. wx.showToast({
  298. title: '未查询到疑似重复的客户信息',
  299. icon: "none"
  300. })
  301. } else {
  302. wx.showToast({
  303. title: `查询到${res.total}条疑似重复客户信息`,
  304. icon: "none"
  305. })
  306. this.setData({
  307. repetitionShow: true,
  308. repetitionList: res.data
  309. })
  310. }
  311. },
  312. /* 处理查重 */
  313. handleQueryRepetition(content) {
  314. return _Http.basic({
  315. "id": 20221208172002,
  316. content
  317. })
  318. },
  319. async submit() {
  320. let data = this.selectComponent("#Form").submit();
  321. let query = await this.handleQueryRepetition({
  322. sa_customersid: this.data.content.sa_customersid,
  323. enterprisename: data.enterprisename,
  324. taxno: data.taxno,
  325. address: data.address
  326. });
  327. if (query.total != 0) {
  328. wx.showToast({
  329. title: `查询到${query.total}条疑似重复客户信息`,
  330. icon: "none"
  331. })
  332. this.setData({
  333. repetitionShow: true,
  334. repetitionList: query.data,
  335. isSubmit: true
  336. })
  337. } else {
  338. this.handleSubmit();
  339. }
  340. },
  341. handleSubmit(tag = false) {
  342. let data = this.selectComponent("#Form").submit();
  343. if (data.region.length != 0) {
  344. data.province = data.region[0]
  345. data.city = data.region[1]
  346. data.county = data.region[2]
  347. };
  348. if (data.parentid) data.parentid = data.parentid[1][0]
  349. delete(data.region);
  350. _Http.basic({
  351. "id": 20221012163902,
  352. "content": {
  353. ...this.data.content,
  354. ...data,
  355. }
  356. }).then(res => {
  357. console.log("新建客户", res)
  358. if (res.msg != '成功') return wx.showToast({
  359. title: res.data,
  360. icon: "none"
  361. })
  362. wx.showToast({
  363. title: '保存成功',
  364. icon: "none"
  365. })
  366. //绑定疑似重复标签
  367. if (tag) _Http.basic({
  368. "id": 20220929090901,
  369. "content": {
  370. "ownertable": "sa_customers",
  371. "ownerid": res.data.sa_customersid,
  372. "datatag": ["疑似重复"]
  373. }
  374. })
  375. setTimeout(() => {
  376. getCurrentPages().forEach(v => {
  377. switch (v.__route__) {
  378. case 'packageA/setclient/index':
  379. v.getList(true);
  380. break;
  381. case 'packageA/setclient/detail':
  382. v.getDetail();
  383. wx.navigateBack()
  384. break;
  385. }
  386. })
  387. let pages = getCurrentPages();
  388. if (pages[pages.length - 2].__route__ == 'packageA/setclient/index') wx.redirectTo({
  389. url: '/packageA/setclient/detail?id=' + res.data.sa_customersid,
  390. })
  391. }, tag ? 500 : 300)
  392. })
  393. },
  394. })