addAndEditor.js 11 KB

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