add.js 7.4 KB

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