commonProcess.js 15.3 KB
Newer Older
fukai committed
1 2
import commonDeclare from "./commonDeclare"
import commonApi from "./commonApi"
3
import SettleEvent from "~/components/business/setmod/event"
4
import LiaccvEvent from "~/components/business/ccvpan/event"
5 6
import LiaallEvent from "~/components/business/engp/event"
import GletnryEvent from "~/components/business/glentry/event"
7
import DocpanEvent from "~/components/business/docpan/event"
8
import commonGlobalSearch from "./commonGlobalSearch";
9
import Utils from "~/utils"
zhengxiaokui committed
10
import _ from "~/utils/Lodash.js";
11

Wuyuqiu committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
const tabNameToRulePathMapping = {
  "setpan": "setmod.setpan",
  "glepan": "setmod.glemod.glepan",
  "docpan": "trnmod.trndoc.docpan",
  "doctre": "trnmod.trndoc.doctre",
  "cips": "trnmod.cipmod.cips",
  "cips2": "trnmod.cipmod.cips",
  "engp": "liaall.engp",
  "limitbody": "liaall.limmod.limitbody",
  "ccvpan": "liaall.liaccv.ccvpan",
  "detp1": "setmod.setpan",
  "actinf": "recpan.actinf",
  "libp": "cnybop.libp",
  "basp": "bopmod.dbap.basp",
  "basp1": "bopmod.dbdp.basp",
  "basp2": "bopmod.dbdp.basp",
  "basp3": "bopmod.dbap.basp",
  "incp": "cnybop.incp",
  "outp": "cnybop.Outp",
  "dbb": "bopmod.dbbp.basp",
LiRui committed
32
  "dbe": "bopmod.dbep.basp",
潘际乾 committed
33
  "dclpp":"recp.dclp(1).dclpp",
34 35 36
  "conp":"cfabpt.recp.conp",
  "cfactlp":"cfactlp",//资本项目标签页切换触发点击切换标签页事件
  "cnyp1":"cnybop.cnyp1"//跨境人民申报标签页切换触发点击切换标签页事件
Wuyuqiu committed
37 38
}

liuxin committed
39
export default {
40
  mixins: [commonApi, commonDeclare, commonGlobalSearch],
liuxin committed
41 42
  data: function () {
    return {
潘际乾 committed
43 44 45 46 47 48
      // 弹框回填
      promptData: {
        title: '',
        columnStr: '',
        data: [],
        rulePath: ''
49 50
      },
      isChecking: false
liuxin committed
51 52
    }
  },
潘际乾 committed
53 54
  created() {
  },
潘际乾 committed
55
  mounted() {
56
    if (!this.isInDisplay && !['gitopn'].includes(this.trnName)) {
李少勇 committed
57
      // this.generateFormRules()
fukai committed
58
    }
liuxin committed
59 60
  },
  methods: {
61 62 63
    ...SettleEvent,
    ...LiaallEvent,
    ...GletnryEvent,
64
    ...DocpanEvent,
65
    ...LiaccvEvent,
66 67 68 69
    /**
     * 表单校验 rules 的赋值
     * @returns void
     */
70 71 72 73 74 75 76 77 78 79
    generateFormRules() {
      if (this.root) {
        if (!this.root.rules) {
          return;
        } else {
          // 新添加的表单项,需要重新确定下 validator 的触发 trigger
          this.updateRulesTrigger();
          return
        }
      }
潘际乾 committed
80
      if (!this.pattern)
fukai committed
81
        return
潘际乾 committed
82 83
      // const keySet = new Set(Object.keys(this.pattern).concat(Object.keys(this.checkRules).concat(Object.keys(this.defaultRules))))
      const keySet = new Set(Object.keys(this.pattern).concat(Object.keys(this.defaultRules)))
84
      const res = {};
潘际乾 committed
85
      const that = this;
86 87
      for (let key of keySet.keys()) {
        const rule = []
潘际乾 committed
88
        if (that.pattern[key]) {
潘际乾 committed
89 90 91
          rule.push(...that.pattern[key])
        }
        const triggerType = that.getTriggerType(key)
潘际乾 committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
        // if(that.checkRules[key]){
        //   if (Array.isArray(that.checkRules[key])) {
        //     for (let j = 0; j < that.checkRules[key].length; j++) {
        //       const check = that.checkRules[key][j];
        //       rule.push({
        //         validator: check.bind(that),
        //         trigger: triggerType
        //       })
        //     }
        //   } else {
        //     rule.push({
        //       validator: that.checkRules[key].bind(that),
        //       trigger: triggerType
        //     })
        //   }
        // }
潘际乾 committed
108 109 110 111 112 113
        if (that.defaultRules[key]) {
          rule.push({
            validator: that.defaultRules[key].bind(that),
            trigger: triggerType
          })
        }
潘际乾 committed
114
        if (rule.length > 0) {
115
          res[key] = rule;
liuxin committed
116 117
        }
      }
潘际乾 committed
118 119
      that.rules = res;
    },
120 121 122 123 124
    /**
     * 触发方式
     * @param {String} prop item属性
     * @returns 
     */
潘际乾 committed
125
    getTriggerType(prop) {
126 127
      const modelForm = this.root ? this.root.$refs.modelForm : this.$refs.modelForm
      const fields = modelForm.fields;
潘际乾 committed
128 129 130
      for (let i = 0; i < fields.length; i++) {
        const field = fields[i];
        if (field.prop === prop) {
潘际乾 committed
131
          // select、checkbox使用change触发
132 133
          const ele = field.$children[1] ? field.$children[1].$children[0] : field.$children[0].$children[0]
          if (ele.$el.className.startsWith("el-select") || ele.$el.className.startsWith("el-checkbox")) {
潘际乾 committed
134 135 136 137 138
            return "change";
          }
          return "blur";
        }
      }
潘际乾 committed
139
      return "blur";
140
    },
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
    /**
     * 表单有些 tab 是通过 v-if 控制的,这些表单项初始时的 trigger 均为 blur,需要手动更新
     */
    updateRulesTrigger() {
      const rules = this.root.rules
      for (const key in rules) {
        if (Object.hasOwnProperty.call(rules, key)) {
          const rule = rules[key];
          const triggerType = this.getTriggerType(key)
          for (let i = 0; i < rule.length; i++) {
            const r = rule[i];
            if (r.validator && r.trigger !== triggerType) {
              r.trigger = triggerType;
            }
          }
        }
      }
    },
潘际乾 committed
159 160
    /**
     * Tabs切换事件
161
     * @param {VM} tab  
潘际乾 committed
162
     */
163
    async tabClick(tab) {
潘际乾 committed
164 165 166
      if (this.isInDisplay) {
        return
      }
167
      let name = tab.name;
168 169 170 171
      if (name === "ccvpan") {
        this.processLiaccv();
        return;
     }
172 173 174 175 176 177 178 179
      if (name === "engp") {
         this.processLiaall();
         return;
      }
      if (name === "setpan") {
         this.processSetpan();
         return;
      }
180 181 182 183
      if (name === "docpan") {
        this.processTrndoc();
        return;
     }
184 185
      if (name === "glepan") {
        this.processGlentry();
186 187
        return;
      }
Wuyuqiu committed
188 189 190 191 192 193 194 195
      const nms = name.split(",")
      const arr = []
      for (let i = 0; i < nms.length; i++) {
        const n = nms[i];
        const path = tabNameToRulePathMapping[n]
        if (path) {
          arr.push(path)
        }
196
      }
Wuyuqiu committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254

      let rulePath = arr.join(",");
      // if (name.indexOf("setpan") > -1) {
      //   name = name.replace("setpan", "setmod.setpan");
      // }
      // if (name.indexOf("glepan") > -1) {
      //   name = name.replace("glepan", "setmod.glemod.glepan");
      // }
      // if (name === "docpan") {
      //   rulePath = "trnmod.trndoc.docpan"
      // }
      // if (name === "doctre") {
      //   rulePath = "trnmod.trndoc.doctre"
      // }
      // if (name === "cips" || name === "cips2") {
      //   rulePath = "trnmod.cipmod.cips"
      // }
      // if (name.indexOf("engp") > -1) {
      //   name = name.replace("engp", "liaall.engp")
      // }
      // if (name === "limitbody") {
      //   rulePath = "liaall.limmod.limitbody"
      // }
      // if (name === "ccvpan") {
      //   rulePath = "liaall.liaccv.ccvpan"
      // }
      // if (name === "detp1") {
      //   rulePath = "setmod.setpan"
      // }
      // if (name === "actinf") {
      //   rulePath = "recpan.actinf"
      // }
      // if (name === "libp") {
      //   rulePath = "cnybop.libp"
      // }
      // if (name === 'basp') {
      //   rulePath = "bopmod.dbap.basp"
      // }
      // if (name === 'basp1') {
      //   rulePath = "bopmod.dbdp.basp"
      // }
      // if (name === 'basp2') {
      //   rulePath = "bopmod.dbdp.basp"
      // }
      // if (name === 'basp3') {
      //   rulePath = "bopmod.dbap.basp"
      // }
      // if (name === 'incp') {
      //   rulePath = "cnybop.incp"
      // }
      // if (name === 'outp') {
      //   rulePath = "cnybop.Outp"
      // }
      // if (name === 'dbb') {
      //   rulePath = "bopmod.dbbp.basp"
      // } if (name === 'dbe') {
      //   rulePath = "bopmod.dbep.basp"
      // }
潘际乾 committed
255
      if (!!rulePath) {
liuxin committed
256 257 258 259 260 261 262
        // if(rulePath == "setmod.setpan"){
        //     this.executeCustomRule(rulePath).then(res => {
        //         if (res.respCode == SUCCESS) {
        //             this.updateModel(res.data)
        //         }
        //     })
        // }else{
Wuyuqiu committed
263 264
        this.executeRule(rulePath).then(res => {
          if (res.respCode == SUCCESS) {
265
            this.updateModel(res.data);
Wuyuqiu committed
266 267
          }
        })
liuxin committed
268
        // }
潘际乾 committed
269 270
      }
    },
271 272 273
    /**
     * 以函数形式获取model(请求参数),保证取到的是最新赋值的
     * @param {any} params 参数
274
     * @param {any} selfCb 允许延时组数 参数
275 276
     * @returns 
     */
Wuyuqiu committed
277
    wrapper(params, delayCb) {
278 279
      params = params || {}
      const fn = async () => {
潘际乾 committed
280 281 282 283
        const that = this;
        const data = await new Promise(resolve => {
          // 保证前一次请求结果赋值VO完成
          setTimeout(() => {
284
            delayCb && delayCb()
潘际乾 committed
285 286 287 288 289
            const d = Utils.flatObject(that.model)
            resolve(d)
          }, 0)
        })
        return { ...data, params }
290 291 292
      }
      return fn;
    },
Wuyuqiu committed
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
    wrapperCustom(params, delayCb) {
      params = params || {}
      params['isCustom'] = true
      const fn = async () => {
        const that = this;
        const data = await new Promise(resolve => {
          // 保证前一次请求结果赋值VO完成
          setTimeout(() => {
            delayCb && delayCb()
            const d = Utils.flatObject(that.customModel)
            resolve(d)
          }, 0)
        })
        params['keys'] = Object.keys(data)
        return { ...data, params }
      }
      return fn;
    },
311 312 313 314 315
    /**
     * 用于手动的触发model里属性的 executeDefault 
     * @param {string} rule 执行的 rule path
     * @param {any} value   更改的值
     */
zhengxiaokui committed
316
    defaultFunction(rule, value) {
317
      Utils.defaultFunction.call(this, rule, value)
318
    },
Wuyuqiu committed
319 320 321 322 323
    /**
 * 用于手动的触发model里属性的 event
 * @param {string} rule 执行的 rule path
 * @param {any} value   更改的值
 */
324 325 326
    eventFunction(rulePath) {
      this.executeRule(rulePath).then((res) => {
        if (res.respCode == SUCCESS) {
Wuyuqiu committed
327
          Utils.copyValueFromVO(this.model, res.data);
328 329
        }
      })
330
    },
331 332 333 334 335 336
    /**
     * 更新Model
     * @param {any} data model数据
     */
    updateModel(data) {
      Utils.copyValueFromVO(this.model, data);
潘际乾 committed
337
    },
潘际乾 committed
338 339
    /**
     * 弹出机构选择框
zhengxiaokui committed
340 341 342 343 344
     * @param {String} rulePath 
     * @param {String} columns 自定义需要展示列
     * @param {String} shadow 自定义列后需要保留的影藏字段
     * @param {String} modelUrl 非机构双击后需要回填的字段路劲,k:对应列,value:应用model路劲,如{TXT:'ledgrp.blk.lcrgod'}
     * @param {String} isCover 非机构双击后需要回填的字段值是覆盖还是叠加,部分覆盖值为对象,false为叠加,如{TXT:false},k值为modelUrl的k,如全部覆盖则isCover='T',如全部叠加则isCover='',默认全部覆盖
345
     * @param {String} defaultColumn 选中列,默认第0列
潘际乾 committed
346
     */
Wuyuqiu committed
347 348
    showGridPromptDialog(rulePath, columns, shadow, modelUrl, isCover = "T", Dialog = 'etyDialog', defaultColumn = 0) {
      this.executeRule(rulePath, { 'EventType': 4 }).then((res) => {
吴佳 committed
349
        if (res.respCode == SUCCESS) {
潘际乾 committed
350
          if (res.data.params) {
潘际乾 committed
351
            Utils.copyValueFromVO(this.model, res.data);
潘际乾 committed
352
          } else {
zhengxiaokui committed
353
            this.root.$refs[Dialog].show = true
潘际乾 committed
354 355
            this.root.promptData = {
              title: res.data.title,
zhengxiaokui committed
356
              columnStr: columns ? columns : res.data.columns,
zhengxiaokui committed
357
              shadow: shadow,
潘际乾 committed
358 359
              data: res.data.vals.rows,
              rulePath: rulePath,
zhengxiaokui committed
360 361
              modelUrl: modelUrl,
              isCover: isCover,
362
              defaultColumn: defaultColumn
潘际乾 committed
363
            }
潘际乾 committed
364 365
          }
        }
Wuyuqiu committed
366
        this.$el.querySelectorAll('input').forEach(input => input.blur())
潘际乾 committed
367 368
      })
    },
369 370 371 372
    /**
     * 下拉框/多选框 改变时执行rule
     * @param {String} rulePath 路径
     */
Wuyuqiu committed
373 374 375 376 377 378
    selectOrCheckboxRule(rulePath) {
      this.executeRule(rulePath).then((res) => {
        if (res.respCode == SUCCESS) {
          Utils.copyValueFromVO(this.model, res.data);
        }
      })
379
    },
潘际乾 committed
380 381 382 383 384
    /**
     * 机构回填
     * @param {String} val 选种行的值(一般是首列)
     * @param {String} rulePath 路径
     */
Wuyuqiu committed
385
    selectEty(val, rulePath) {
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
      // const props = rulePath.replaceAll(".", "_")
      // const obj = {}
      // obj[props] = val;
      // Utils.copyValueFromVO(this.model, obj);
      if (rulePath.indexOf("(") > 0) {//请求地址有"()"下标时,如setmod.setglg.setgll(2).setgrp.snd756.pts.extkey
        let tempRulePath = rulePath
        let rulePath = ""
        const reg = /\((\d+)\)/
        while (reg.test(tempRulePath)) {
          const match = tempRulePath.match(reg)
          rulePath += tempRulePath.substring(0, match.index) + "[" + (parseInt(match[1]) - 1) + "]"
          tempRulePath = tempRulePath.substring(match.index + match[0].length)
        }
        rulePath += tempRulePath
      }
      _.set(this.model, rulePath, val)
402
      this.executeRule(rulePath, { "selectStatus": 1,'EventType': 1}).then((res) => {
吴佳 committed
403
        if (res.respCode == SUCCESS) {
潘际乾 committed
404 405 406
          Utils.copyValueFromVO(this.model, res.data);
        }
      });
潘际乾 committed
407
    },
zhengxiaokui committed
408 409 410

    /**
        * 货物条款等非机构栏位回填
411
        * @param {Object} val 选种行的值,按钮的值
zhengxiaokui committed
412 413 414 415 416 417 418 419 420 421 422 423
        * @param {Object} url 字段路劲 需要回填的字段路劲
        *  @param {Object} url 对应字段值是否覆盖 ,需要为true,否则合并叠加
        * @param {String} rulePath 路径
        */
    selectMsg(val, modelUrl, isCover, rulePath) {
      for (let k in val) {
        let msg = val[k]
        if ((typeof isCover === 'string' && isCover === '') || !isCover[k]) {
          let ms = _.get(this.model, modelUrl[k], '')
          msg = (ms ? ms + '\r\n' : '') + msg
        }
        _.set(this.model, modelUrl[k], msg);
424
        this.defaultFunction();
zhengxiaokui committed
425 426
      }
    },
潘际乾 committed
427 428 429 430 431 432
    /**
     * 改变表单项的是否必填属性
     * @param {String} property 属性
     * @param {Boolean} required 是否必填
     */
    changeFormItemRequired(property, required) {
Wuyuqiu committed
433
      this.getRoot().pattern[property][0].required = required
434 435 436 437 438 439 440 441 442 443 444 445 446 447
    },
    /**
     * 在 A 交易中打开 B 交易视图(详情、开立...)。
     * 
     * 路由视图跳转,例:
     *    this.gotoView("Ditopn", {inr: "001021021"}, {name: "lisi"})   实际请求的 url 为 /business/ditopn/001021021?name=lisi
     *    params, query按需传入(得提前配置好 Router ),在对应的vue页面做好处理
     * @param {String} name 路由的name
     * @param {Object} params 路由的params
     * @param {Object} query 路由的query
     */
    gotoView(name, params, query) {
      params = params || {}
      query = query || {}
zhengxiaokui committed
448
      this.$router.push({ name, params, query })
449 450 451
    },
    gotoUrl(url) {
      this.$router.push(url)
潘际乾 committed
452 453 454 455 456 457 458 459 460 461 462 463
    },
    /**
     * 设置拖动组件的内容
     * @param {String} currentTool 
     * @param {String} toolTitle 
     */
    setDraggableContent(currentTool, toolTitle) {
      const layout = this.$root.$children[0].$children[0]
      layout.dragShow = true;
      layout.changeSize(1);
      layout.currentTool = currentTool;
      layout.toolTitle = toolTitle;
464 465 466 467 468 469
    },

    /**
     * 判断状态信息,包括visiable,modified,enabled等
     */
    judgeVisiableInfo(rulePath){
470 471 472 473 474 475 476 477 478 479 480 481 482 483
        // var model = this.model;
        // if(model == null){
        //     return false;
        // }
        // var info = this.model.statusInfo;
        // if(info == null || info.length == 0){
        //     return false;
        // }
        // var visiable = info["visiable"];
        // if(visiable[rulePath] == null){
        //     return false;
        // }
        // return visiable[rulePath];
        return true
liuxin committed
484
    }
fukai committed
485
  },
潘际乾 committed
486 487
  computed: {
    isInDisplay() {
fukai committed
488 489
      return this.$store.state.Status.mode === 'display'
    }
liuxin committed
490
  }
491
}