let _Http = getApp().globalData.http, count = null; Page({ data: { loading: false, showAll: false, repetitionShow: false, repetitionList: [], isSubmit: false, form: [{ label: "企业名称", error: false, errMsg: "", type: "textarea", value: "", placeholder: "企业全称", valueName: "enterprisename", checking: "base", slot: "info", required: true }, { label: "品牌名称", error: false, errMsg: "", type: "textarea", value: "", placeholder: "品牌名称", valueName: "brandname", checking: "base", required: true }, { label: "优势信息", error: false, errMsg: "", type: "textarea", value: "", placeholder: "优势信息", valueName: "advantage", checking: "base", required: false }, { label: "劣势信息", error: false, errMsg: "", type: "textarea", value: "", placeholder: "劣势信息", valueName: "inferiority", checking: "base", required: false }, { label: "备注", error: false, errMsg: "", type: "textarea", value: "", placeholder: "", valueName: "remarks", checking: "base", required: false }], content: { "sa_competitorid": 0, "sys_enterpriseid": 0, }, disabled: true }, onLoad(options) { if (options.data) { let data = JSON.parse(options.data); let form = this.data.form.filter(v => !["advantage", "inferiority"].includes(v.valueName)) this.setData({ disabled: false, form: form.map(v => { v.value = data[v.valueName] || '' return v }), "content.sa_competitorid": data.sa_competitorid, "content.sys_enterpriseid": data.sys_enterpriseid, }) } getApp().globalData.Language.getLanguagePackage(this, '设置对手'); }, introduce({ detail }) { let item = detail; this.setData({ [`form[0].value`]: item.companyName }) }, queryClient() { let data = this.selectComponent("#Form").query(); if (data.enterprisename == '') { getApp().globalData.Language.showToast('您还未填写企业名称') } else { this.setData({ form: this.selectComponent("#Form").data.form, }) this.selectComponent("#Info").queryClient(data.enterprisename) } }, repClose() { if (this.data.isSubmit) { let that = this; wx.showModal({ title: getApp().globalData.Language.getMapText('提示'), content: getApp().globalData.Language.getMapText('是否继续创建'), cancelText: getApp().globalData.Language.getMapText('取消'), confirmText: getApp().globalData.Language.getMapText('确定'), complete: (res) => { if (res.confirm) that.handleSubmit(true); } }) } this.setData({ repetitionShow: false, isSubmit: false }) }, /* 表单必填项是否完成 */ onConfirm({ detail }) { this.setData({ disabled: detail }) }, // 是否显示全部 onChange({ detail }) { this.setData({ showAll: detail }) }, /* 查询是否重复 */ async queryRepetition(e) { let data = this.selectComponent("#Form").query(); /* if (data.enterprisename == '') return wx.showToast({ title: `您还未填写企业名称`, icon: "none" }); */ let res = await this.handleQueryRepetition({ ...data, sa_competitorid: this.data.sa_competitorid || '0' }); console.log("查询重复", res) if (res.code != '1') return wx.showToast({ title: res.msg, icon: "none" }); this.setData({ countDown: 6 }); count = setInterval(() => { let countDown = this.data.countDown; if (countDown == 0) { clearInterval(count); this.setData({ countDown: "" }) } else { countDown--; this.setData({ countDown }) } }, 1000) if (res.total == 0) { wx.showToast({ title: getApp().globalData.Language.getMapText('未查询到疑似重复的客户信息'), icon: "none" }) } else { getApp().globalData.Language.showToast([{ t: 1, v: '查询到', r: " " }, { v: res.total, r: " " }, { t: 1, v: '条疑似重复客户信息', }]) this.setData({ repetitionShow: true, repetitionList: res.data.map(v => { v.chars = v.chars.reduce((acc, item) => ({ ...acc, ...item }), {}); return v }), }) } }, /* 处理查重 */ handleQueryRepetition(content) { return _Http.basic({ "id": 20230324132602, content }) }, async submit() { let data = this.selectComponent("#Form").submit(); let query = await this.handleQueryRepetition({ ...data, sa_competitorid: this.data.sa_competitorid || '0' }); if (query.total != 0) { getApp().globalData.Language.showToast([{ t: 1, v: '查询到', r: " " }, { v: query.total, r: " " }, { t: 1, v: '条疑似重复客户信息', }]) this.setData({ repetitionShow: true, repetitionList: query.data.map(v => { v.chars = v.chars.reduce((acc, item) => ({ ...acc, ...item }), {}); return v }), isSubmit: true }) } else { this.handleSubmit(); } }, handleSubmit(tag = false) { this.setData({ loading: true }) let content = { ...this.data.content, ...this.selectComponent("#Form").submit() }; _Http.basic({ "id": 20221018164102, content }).then(res => { this.setData({ loading: false }) console.log("新建对手", res) if (res.code != '1') return wx.showToast({ title: res.data, icon: "none" }) getApp().globalData.Language.showToast('保存成功') //绑定疑似重复标签 if (tag) _Http.basic({ "id": 20220929090901, "content": { "ownertable": "sa_competitor", "ownerid": res.data.sa_competitorid, "datatag": ["疑似重复"] } }) setTimeout(() => { let pages = getCurrentPages(), page = pages[pages.length - 2]; if (page.__route__ == 'packageA/opponent/index') { page.getList(true); wx.redirectTo({ url: './detail?id=' + res.data.sa_competitorid, }) } else if (page.__route__ == 'packageA/opponent/detail') { wx.navigateBack(); page.getDetail(); } }, tag ? 500 : 300) }) }, })