add.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. getApp().globalData.Language.getLanguagePackage(this, '设置对手');
  82. },
  83. introduce({
  84. detail
  85. }) {
  86. let item = detail;
  87. this.setData({
  88. [`form[0].value`]: item.companyName
  89. })
  90. },
  91. queryClient() {
  92. let data = this.selectComponent("#Form").query();
  93. if (data.enterprisename == '') {
  94. getApp().globalData.Language.showToast('您还未填写企业名称')
  95. } else {
  96. this.setData({
  97. form: this.selectComponent("#Form").data.form,
  98. })
  99. this.selectComponent("#Info").queryClient(data.enterprisename)
  100. }
  101. },
  102. repClose() {
  103. if (this.data.isSubmit) {
  104. let that = this;
  105. wx.showModal({
  106. title: getApp().globalData.Language.getMapText('提示'),
  107. content: getApp().globalData.Language.getMapText('是否继续创建'),
  108. cancelText: getApp().globalData.Language.getMapText('取消'),
  109. confirmText: getApp().globalData.Language.getMapText('确定'),
  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.code != '1') 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: getApp().globalData.Language.getMapText('未查询到疑似重复的客户信息'),
  172. icon: "none"
  173. })
  174. } else {
  175. getApp().globalData.Language.showToast([{
  176. t: 1,
  177. v: '查询到',
  178. r: " "
  179. }, {
  180. v: res.total,
  181. r: " "
  182. }, {
  183. t: 1,
  184. v: '条疑似重复客户信息',
  185. }])
  186. this.setData({
  187. repetitionShow: true,
  188. repetitionList: res.data
  189. })
  190. }
  191. },
  192. /* 处理查重 */
  193. handleQueryRepetition(content) {
  194. return _Http.basic({
  195. "id": 20230324132602,
  196. content
  197. })
  198. },
  199. async submit() {
  200. let data = this.selectComponent("#Form").submit();
  201. let query = await this.handleQueryRepetition({
  202. ...data,
  203. sa_competitorid: this.data.sa_competitorid || '0'
  204. });
  205. if (query.total != 0) {
  206. getApp().globalData.Language.showToast([{
  207. t: 1,
  208. v: '查询到',
  209. r: " "
  210. }, {
  211. v: query.total,
  212. r: " "
  213. }, {
  214. t: 1,
  215. v: '条疑似重复客户信息',
  216. }])
  217. this.setData({
  218. repetitionShow: true,
  219. repetitionList: query.data,
  220. isSubmit: true
  221. })
  222. } else {
  223. this.handleSubmit();
  224. }
  225. },
  226. handleSubmit(tag = false) {
  227. this.setData({
  228. loading: true
  229. })
  230. let content = {
  231. ...this.data.content,
  232. ...this.selectComponent("#Form").submit()
  233. };
  234. _Http.basic({
  235. "id": 20221018164102,
  236. content
  237. }).then(res => {
  238. this.setData({
  239. loading: false
  240. })
  241. console.log("新建对手", res)
  242. if (res.code != '1') return wx.showToast({
  243. title: res.data,
  244. icon: "none"
  245. })
  246. getApp().globalData.Language.showToast('保存成功')
  247. //绑定疑似重复标签
  248. if (tag) _Http.basic({
  249. "id": 20220929090901,
  250. "content": {
  251. "ownertable": "sa_competitor",
  252. "ownerid": res.data.sa_competitorid,
  253. "datatag": ["疑似重复"]
  254. }
  255. })
  256. setTimeout(() => {
  257. let pages = getCurrentPages(),
  258. page = pages[pages.length - 2];
  259. if (page.__route__ == 'packageA/opponent/index') {
  260. page.getList(true);
  261. wx.redirectTo({
  262. url: './detail?id=' + res.data.sa_competitorid,
  263. })
  264. } else if (page.__route__ == 'packageA/opponent/detail') {
  265. wx.navigateBack();
  266. page.getDetail();
  267. }
  268. }, tag ? 500 : 300)
  269. })
  270. },
  271. })