let _Http = getApp().globalData.http, count = null; Page({ data: { queryShow: false, repetitionShow: false, repetitionList: [], isSubmit: false, showAll: false, form: [{ label: "企业名称", error: false, errMsg: "", type: "textarea", value: "", placeholder: "企业全称", valueName: "enterprisename", checking: "base", slot: "info", required: true }, { label: "选择公海池", error: false, errMsg: "", type: "route", url: "/packageA/publicCustomer/pond/index", radio: true, value: "", params: { "id": 20221206195102, "content": { "pageNumber": 1, "pageSize": 20, "where": { "condition": "" } } }, placeholder: "选择所属公海池", valueName: "sa_customerpoolid", checking: "base", required: true }, { label: "企业简称", error: false, errMsg: "", type: "textarea", value: "", placeholder: "企业简称", valueName: "abbreviation", checking: "base", required: false }, { label: "统一社会信用代码", error: false, errMsg: "", type: "textarea", value: "", placeholder: "企业税号/注册号/营业执照号码", valueName: "taxno", checking: "base", required: false }, { label: "法定代表人", error: false, errMsg: "", type: "text", value: "", placeholder: "企业法人", valueName: "contact", checking: "base", required: false }, { label: "法人电话号码", error: false, errMsg: "", type: "number", value: "", placeholder: "法人联系手机号", valueName: "phonenumber", checking: "phone", required: false }, { label: "所属行业", error: false, errMsg: "", type: "option", //自定义选择 配合预定接口 optionNmae: "industry", //选择类型 optionType: "radio", //复选 radio 单选 value: "", placeholder: "企业所属行业", valueName: "industry", checking: "base", required: false }, { label: "地区", error: false, errMsg: "", type: "region", value: [], placeholder: "所属地区 省/市/区", valueName: "region", required: false }, { label: "注册地址", error: false, errMsg: "", type: "textarea", value: "", placeholder: "企业注册地址", valueName: "address", checking: "base", required: false }, { label: "客户类型", error: false, errMsg: "", type: "option", optionNmae: "customertypemx", optionType: "radio", //复选 radio 单选 value: "", placeholder: "客户类型", valueName: "type", checking: "base", required: true }, { label: "客户级别", error: false, errMsg: "", type: "option", optionNmae: "agentgrade", optionType: "radio", //复选 radio 单选 value: "", placeholder: "客户数字级别", valueName: "grade", checking: "base", required: false }], content: { "sa_customersid": 0, //新增是传0 "parentid": 0, //上级客户ID,默认或没有上级的时候传0 "sys_enterpriseid": 0, //合作企业档案ID,新增是传0,更新 "source": "", //客户来源 ispublic: 1, //是否为公海客户 }, disabled: true, countDown: "", //查重倒计时 }, setOption(item) { let i = this.data.form.findIndex(v => v.valueName == item.valueName); this.setData({ [`form[${i}]`]: item }) }, onLoad(options) { if (options.data) { let data = JSON.parse(options.data); this.setData({ disabled: false, content: { sa_customersid: data.sa_customersid, parentid: data.parentid, sys_enterpriseid: data.sys_enterpriseid, sa_customerpoolid: data.sa_customerpoolid, source: data.source, }, form: this.data.form.map(v => { if (v.valueName != 'region') { v.value = data[v.valueName]; } else { v.value = data.province ? [data.province, data.city, data.county] : [] } return v }) }) } }, /* 引入 */ introduce(e) { let { item } = e.currentTarget.dataset, that = this; wx.showModal({ title: '提示', content: `是否确定引入“${item.companyName}”信息`, complete: (res) => { if (res.confirm) { let data = { enterprisename: item.companyName, //企业名称 taxno: item.taxNum, //税号 contact: item.legalPerson, //法人 region: [item.regProvince, item.regCity, item.regArea], //地区 address: item.address, //地区 } that.setData({ form: that.data.form.map(v => { if (data[v.valueName]) v.value = data[v.valueName]; return v }), queryShow: false, queryList: null }) } } }) }, /* 工商查询 */ queryClient(e) { let data = this.selectComponent("#Form").query(); this.setData({ form: this.data.form.map(v => { v.value = data[v.valueName]; return v }), }) console.log(this.data.form) if (data.enterprisename == '') return wx.showToast({ title: `您还未填写企业名称`, icon: "none" }); _Http.basic({ id: 20221208103601, content: { pageNumber: 1, pageTotal: 1, pageSize: 5, keyword: data.enterprisename, } }).then(res => { console.log("工商查询", res) if (!res.data[0]) return wx.showToast({ title: '未查询到相关企业!', icon: "none" }); this.setData({ queryList: res.data, queryShow: true }) }) }, onClose() { this.setData({ queryShow: false }) }, repClose() { if (this.data.isSubmit) { let that = this; wx.showModal({ title: '提示', content: `是否继续创建客户`, 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 { enterprisename, taxno, address } = this.selectComponent("#Form").query(); if (enterprisename == '') return wx.showToast({ title: `您还未填写企业名称`, icon: "none" }); let res = await this.handleQueryRepetition({ sa_customersid: this.data.content.sa_customersid, enterprisename, taxno, address }); console.log("查询重复", res) if (res.msg != '成功') 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: '未查询到疑似重复的客户信息', icon: "none" }) } else { wx.showToast({ title: `查询到${res.total}条疑似重复客户信息`, icon: "none" }) this.setData({ repetitionShow: true, repetitionList: res.data }) } }, /* 处理查重 */ handleQueryRepetition(content) { return _Http.basic({ "id": 20221208172002, content }) }, async submit() { let data = this.selectComponent("#Form").submit(); let query = await this.handleQueryRepetition({ sa_customersid: this.data.content.sa_customersid, enterprisename: data.enterprisename, taxno: data.taxno, address: data.address }); if (query.total != 0) { wx.showToast({ title: `查询到${query.total}条疑似重复客户信息`, icon: "none" }) this.setData({ repetitionShow: true, repetitionList: query.data, isSubmit: true }) } else { this.handleSubmit(); } }, handleSubmit(tag = false) { let data = this.selectComponent("#Form").submit(); if (data.region.length != 0) { data.province = data.region[0] data.city = data.region[1] data.county = data.region[2] }; data.sa_customerpoolid = data.sa_customerpoolid[1][0] delete(data.region); _Http.basic({ "id": 20221010164302, "content": { ...this.data.content, ...data, } }).then(res => { console.log("新建客户", res) if (res.msg != '成功') return wx.showToast({ title: res.data, icon: "none" }) wx.showToast({ title: '保存成功', icon: "none" }); //绑定疑似重复标签 if (tag) _Http.basic({ "id": 20220929090901, "content": { "ownertable": "sa_customers", "ownerid": res.data.sa_customersid, "datatag": ["疑似重复"] } }) setTimeout(() => { getCurrentPages().forEach(v => { switch (v.__route__) { case 'packageA/publicCustomer/index': v.getList(true); break; case 'packageA/publicCustomer/detail': wx.navigateBack() v.getDetail(); break; } }) let pages = getCurrentPages(); if (pages[pages.length - 2].__route__ == 'packageA/publicCustomer/index') wx.redirectTo({ url: '/packageA/publicCustomer/detail?id=' + res.data.sa_customersid, }) }, tag ? 500 : 300); }) }, })