add.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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: "textarea",
  25. value: "",
  26. placeholder: "品牌名称",
  27. valueName: "brandname",
  28. checking: "base",
  29. required: true
  30. }, {
  31. label: "优势信息",
  32. error: false,
  33. errMsg: "",
  34. type: "textarea",
  35. value: "",
  36. placeholder: "优势信息",
  37. valueName: "advantage",
  38. checking: "base",
  39. required: false
  40. }, {
  41. label: "劣势信息",
  42. error: false,
  43. errMsg: "",
  44. type: "textarea",
  45. value: "",
  46. placeholder: "劣势信息",
  47. valueName: "inferiority",
  48. checking: "base",
  49. required: false
  50. }, {
  51. label: "备注",
  52. error: false,
  53. errMsg: "",
  54. type: "textarea",
  55. value: "",
  56. placeholder: "",
  57. valueName: "remarks",
  58. checking: "base",
  59. required: false
  60. }],
  61. content: {
  62. "sa_competitorid": 0,
  63. "sys_enterpriseid": 0,
  64. },
  65. disabled: true
  66. },
  67. onLoad(options) {
  68. if (options.data) {
  69. let data = JSON.parse(options.data);
  70. console.log(data)
  71. this.se
  72. this.setData({
  73. disabled: false,
  74. form: this.data.form.map(v => {
  75. if (v.valueName != 'region') {
  76. v.value = data[v.valueName];
  77. } else {
  78. v.value = data.province ? [data.province, data.city, data.county] : []
  79. }
  80. return v
  81. }),
  82. "content.sa_competitorid": data.sa_competitorid,
  83. "content.sys_enterpriseid": data.sys_enterpriseid,
  84. })
  85. }
  86. },
  87. introduce({
  88. detail
  89. }) {
  90. let item = detail;
  91. this.setData({
  92. [`form[0].value`]: item.companyName
  93. })
  94. },
  95. queryClient() {
  96. let data = this.selectComponent("#Form").query();
  97. if (data.enterprisename == '') {
  98. wx.showToast({
  99. title: `您还未填写企业名称`,
  100. icon: "none"
  101. });
  102. } else {
  103. this.setData({
  104. form: this.selectComponent("#Form").data.form,
  105. })
  106. this.selectComponent("#Info").queryClient(data.enterprisename)
  107. }
  108. },
  109. repClose() {
  110. if (this.data.isSubmit) {
  111. let that = this;
  112. wx.showModal({
  113. title: '提示',
  114. content: `是否继续创建`,
  115. complete: (res) => {
  116. if (res.confirm) that.handleSubmit(true);
  117. }
  118. })
  119. }
  120. this.setData({
  121. repetitionShow: false,
  122. isSubmit: false
  123. })
  124. },
  125. /* 表单必填项是否完成 */
  126. onConfirm({
  127. detail
  128. }) {
  129. this.setData({
  130. disabled: detail
  131. })
  132. },
  133. // 是否显示全部
  134. onChange({
  135. detail
  136. }) {
  137. this.setData({
  138. showAll: detail
  139. })
  140. },
  141. /* 查询是否重复 */
  142. async queryRepetition(e) {
  143. let {
  144. enterprisename
  145. } = this.selectComponent("#Form").query();
  146. if (enterprisename == '') return wx.showToast({
  147. title: `您还未填写企业名称`,
  148. icon: "none"
  149. });
  150. let res = await this.handleQueryRepetition({
  151. sa_customersid: 0,
  152. enterprisename,
  153. taxno: "",
  154. address: ""
  155. });
  156. console.log("查询重复", res)
  157. if (res.msg != '成功') return wx.showToast({
  158. title: res.msg,
  159. icon: "none"
  160. });
  161. this.setData({
  162. countDown: 6
  163. });
  164. count = setInterval(() => {
  165. let countDown = this.data.countDown;
  166. if (countDown == 0) {
  167. clearInterval(count);
  168. this.setData({
  169. countDown: ""
  170. })
  171. } else {
  172. countDown--;
  173. this.setData({
  174. countDown
  175. })
  176. }
  177. }, 1000)
  178. if (res.total == 0) {
  179. wx.showToast({
  180. title: '未查询到疑似重复的客户信息',
  181. icon: "none"
  182. })
  183. } else {
  184. wx.showToast({
  185. title: `查询到${res.total}条疑似重复客户信息`,
  186. icon: "none"
  187. })
  188. this.setData({
  189. repetitionShow: true,
  190. repetitionList: res.data
  191. })
  192. }
  193. },
  194. /* 处理查重 */
  195. handleQueryRepetition(content) {
  196. return _Http.basic({
  197. "id": 20221208172002,
  198. content
  199. })
  200. },
  201. async submit() {
  202. let data = this.selectComponent("#Form").submit();
  203. let query = await this.handleQueryRepetition({
  204. sa_customersid: 0,
  205. enterprisename: data.enterprisename,
  206. taxno: "",
  207. address: ""
  208. });
  209. if (query.total != 0) {
  210. wx.showToast({
  211. title: `查询到${query.total}条疑似重复信息`,
  212. icon: "none"
  213. })
  214. this.setData({
  215. repetitionShow: true,
  216. repetitionList: query.data,
  217. isSubmit: true
  218. })
  219. } else {
  220. this.handleSubmit();
  221. }
  222. },
  223. handleSubmit(tag = false) {
  224. let content = {
  225. ...this.data.content,
  226. ...this.selectComponent("#Form").submit()
  227. };
  228. _Http.basic({
  229. "id": 20221018164102,
  230. content
  231. }).then(res => {
  232. console.log("新建对手", res)
  233. if (res.msg != '成功') return wx.showToast({
  234. title: res.data,
  235. icon: "none"
  236. })
  237. wx.showToast({
  238. title: '保存成功',
  239. icon: "none"
  240. })
  241. //绑定疑似重复标签
  242. if (tag) _Http.basic({
  243. "id": 20220929090901,
  244. "content": {
  245. "ownertable": "sa_competitor",
  246. "ownerid": res.data.sa_competitorid,
  247. "datatag": ["疑似重复"]
  248. }
  249. })
  250. setTimeout(() => {
  251. let pages = getCurrentPages(),
  252. page = pages[pages.length - 2];
  253. if (page.__route__ == 'packageA/opponent/index') {
  254. page.getList(true);
  255. wx.redirectTo({
  256. url: './detail?id=' + res.data.sa_competitorid,
  257. })
  258. } else if (page.__route__ == 'packageA/opponent/detail') {
  259. wx.navigateBack();
  260. page.getDetail();
  261. }
  262. }, tag ? 500 : 300)
  263. })
  264. }
  265. })