add.js 7.2 KB

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