commonProcess.js 7.96 KB
Newer Older
fukai committed
1 2
import commonDeclare from "./commonDeclare"
import commonApi from "./commonApi"
3
import commonGlobalSearch from "./commonGlobalSearch";
4
import Utils from "~/utils"
zhengxiaokui committed
5
import _ from "~/utils/Lodash.js";
6

liuxin committed
7
export default {
8
  mixins: [commonApi, commonDeclare,commonGlobalSearch],
liuxin committed
9 10
  data: function () {
    return {
潘际乾 committed
11 12 13 14 15 16 17
      // 弹框回填
      promptData: {
        title: '',
        columnStr: '',
        data: [],
        rulePath: ''
      }
liuxin committed
18 19
    }
  },
潘际乾 committed
20 21
  created() {
  },
潘际乾 committed
22
  mounted() {
潘际乾 committed
23
    if (!this.isInDisplay) {
fukai committed
24 25
      this.ruleCheck()
    }
liuxin committed
26 27
  },
  methods: {
28 29 30 31
    /**
     * 表单校验 rules 的赋值
     * @returns void
     */
32
    ruleCheck() {
潘际乾 committed
33
      if (!this.pattern)
fukai committed
34
        return
潘际乾 committed
35 36
      // 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)))
37
      const res = {};
潘际乾 committed
38
      const that = this;
39 40
      for (let key of keySet.keys()) {
        const rule = []
潘际乾 committed
41
        if (that.pattern[key]) {
潘际乾 committed
42 43 44
          rule.push(...that.pattern[key])
        }
        const triggerType = that.getTriggerType(key)
潘际乾 committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
        // 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
61 62 63 64 65 66
        if (that.defaultRules[key]) {
          rule.push({
            validator: that.defaultRules[key].bind(that),
            trigger: triggerType
          })
        }
潘际乾 committed
67
        if (rule.length > 0) {
68
          res[key] = rule;
liuxin committed
69 70
        }
      }
潘际乾 committed
71 72
      that.rules = res;
    },
73 74 75 76 77
    /**
     * 触发方式
     * @param {String} prop item属性
     * @returns 
     */
潘际乾 committed
78 79 80 81 82
    getTriggerType(prop) {
      const fields = this.$refs.modelForm.fields;
      for (let i = 0; i < fields.length; i++) {
        const field = fields[i];
        if (field.prop === prop) {
潘际乾 committed
83
          // select、checkbox使用change触发
潘际乾 committed
84
          if (field.$children[1].$children[0].$el.className.startsWith("el-select") || field.$children[1].$children[0].$el.className.startsWith("el-checkbox")) {
潘际乾 committed
85 86 87 88 89
            return "change";
          }
          return "blur";
        }
      }
潘际乾 committed
90
      return "blur";
91
    },
潘际乾 committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    /**
     * Tabs切换事件
     * @param {VM} tab 
     */
    tabClick(tab) {
      if (this.isInDisplay) {
        return
      }
      const name = tab.name
      let rulePath;
      if (name === "setpan") {
        rulePath = "setmod.setpan";
      }
      if (name === "glepan") {
        rulePath = "setmod.glemod.glepan";
      }
      if (name === "docpan") {
        rulePath = "trnmod.trndoc.docpan"
      }
      if (name === "doctre") {
        rulePath = "trnmod.trndoc.doctre"
      }
      if (name === "engp") {
        rulePath = "liaall.engp"
      }
      if (name === "limitbody") {
        rulePath = "liaall.limmod.limitbody"
      }
hulei committed
120 121 122
      if (name === "ccvpan") {
        rulePath = "liaall.liaccv.ccvpan"
      }
潘际乾 committed
123 124 125 126 127 128 129 130
      if (!!rulePath) {
        this.executeRule(rulePath).then(res => {
          if (res.respCode == SUCCESS) {
            this.updateModel(res.data)
          }
        })
      }
    },
131 132 133
    /**
     * 以函数形式获取model(请求参数),保证取到的是最新赋值的
     * @param {any} params 参数
134
     * @param {any} selfCb 允许延时组数 参数
135 136
     * @returns 
     */
137
    wrapper(params,delayCb) {
138 139
      params = params || {}
      const fn = async () => {
潘际乾 committed
140 141 142 143
        const that = this;
        const data = await new Promise(resolve => {
          // 保证前一次请求结果赋值VO完成
          setTimeout(() => {
144
            delayCb && delayCb()
潘际乾 committed
145 146 147 148 149
            const d = Utils.flatObject(that.model)
            resolve(d)
          }, 0)
        })
        return { ...data, params }
150 151 152
      }
      return fn;
    },
153 154 155 156 157
    /**
     * 用于手动的触发model里属性的 executeDefault 
     * @param {string} rule 执行的 rule path
     * @param {any} value   更改的值
     */
zhengxiaokui committed
158
    defaultFunction(rule, value) {
159 160
      Utils.defaultFunction.call(this, rule, value)
    },
161 162 163 164 165 166
    /**
     * 更新Model
     * @param {any} data model数据
     */
    updateModel(data) {
      Utils.copyValueFromVO(this.model, data);
潘际乾 committed
167
    },
潘际乾 committed
168 169
    /**
     * 弹出机构选择框
zhengxiaokui committed
170 171 172 173 174
     * @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='',默认全部覆盖
潘际乾 committed
175
     */
zhengxiaokui committed
176
    showGridPromptDialog(rulePath, columns, shadow, modelUrl, isCover = "T",Dialog='etyDialog') {
潘际乾 committed
177
      this.executeRule(rulePath).then((res) => {
潘际乾 committed
178
        if (res.respCode = SUCCESS) {
潘际乾 committed
179
          if (res.data.params) {
潘际乾 committed
180
            Utils.copyValueFromVO(this.model, res.data);
潘际乾 committed
181
          } else {
zhengxiaokui committed
182
            this.root.$refs[Dialog].show = true
潘际乾 committed
183 184
            this.root.promptData = {
              title: res.data.title,
zhengxiaokui committed
185
              columnStr: columns ? columns : res.data.columns,
zhengxiaokui committed
186
              shadow: shadow,
潘际乾 committed
187 188
              data: res.data.vals.rows,
              rulePath: rulePath,
zhengxiaokui committed
189 190
              modelUrl: modelUrl,
              isCover: isCover,
潘际乾 committed
191
            }
潘际乾 committed
192 193 194 195
          }
        }
      })
    },
潘际乾 committed
196 197 198 199 200
    /**
     * 机构回填
     * @param {String} val 选种行的值(一般是首列)
     * @param {String} rulePath 路径
     */
潘际乾 committed
201 202 203 204 205 206
    selectEty(val, rulePath) {
      const props = rulePath.replaceAll(".", "_")
      const obj = {}
      obj[props] = val;
      Utils.copyValueFromVO(this.model, obj);
      this.executeRule(rulePath).then((res) => {
潘际乾 committed
207
        if (res.respCode = SUCCESS) {
潘际乾 committed
208 209 210
          Utils.copyValueFromVO(this.model, res.data);
        }
      });
潘际乾 committed
211
    },
zhengxiaokui committed
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229

    /**
        * 货物条款等非机构栏位回填
        * @param {Object} val 选种行的值
        * @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);
      }
    },
潘际乾 committed
230 231 232 233 234 235 236
    /**
     * 改变表单项的是否必填属性
     * @param {String} property 属性
     * @param {Boolean} required 是否必填
     */
    changeFormItemRequired(property, required) {
      this.pattern[property][0].required = required
237 238 239 240 241 242 243 244 245 246 247 248 249 250
    },
    /**
     * 在 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
251
      this.$router.push({ name, params, query })
252 253 254
    },
    gotoUrl(url) {
      this.$router.push(url)
liuxin committed
255
    }
fukai committed
256
  },
潘际乾 committed
257 258
  computed: {
    isInDisplay() {
fukai committed
259 260
      return this.$store.state.Status.mode === 'display'
    }
liuxin committed
261 262
  }
}