| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- 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)
- })
- },
- })
|