addAndEditor.js 12 KB

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