add.js 8.4 KB

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