addAndEditor.js 9.0 KB

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