commonProcess.js 5.4 KB
Newer Older
fukai committed
1 2
import commonDeclare from "./commonDeclare"
import commonApi from "./commonApi"
3 4
import Utils from "~/utils"

liuxin committed
5
export default {
潘际乾 committed
6
  mixins: [commonApi, commonDeclare],
liuxin committed
7 8
  data: function () {
    return {
潘际乾 committed
9 10 11 12 13 14 15
      // 弹框回填
      promptData: {
        title: '',
        columnStr: '',
        data: [],
        rulePath: ''
      }
liuxin committed
16 17
    }
  },
潘际乾 committed
18 19
  created() {
  },
潘际乾 committed
20
  mounted() {
潘际乾 committed
21
    if (!this.isInDisplay) {
fukai committed
22 23
      this.ruleCheck()
    }
liuxin committed
24 25
  },
  methods: {
26 27 28 29
    /**
     * 表单校验 rules 的赋值
     * @returns void
     */
30
    ruleCheck() {
潘际乾 committed
31
      if (!this.pattern)
fukai committed
32
        return
潘际乾 committed
33 34
      // 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)))
35
      const res = {};
潘际乾 committed
36
      const that = this;
37 38
      for (let key of keySet.keys()) {
        const rule = []
潘际乾 committed
39
        if (that.pattern[key]) {
潘际乾 committed
40 41 42
          rule.push(...that.pattern[key])
        }
        const triggerType = that.getTriggerType(key)
潘际乾 committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
        // 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
59 60 61 62 63 64
        if (that.defaultRules[key]) {
          rule.push({
            validator: that.defaultRules[key].bind(that),
            trigger: triggerType
          })
        }
潘际乾 committed
65
        if (rule.length > 0) {
66
          res[key] = rule;
liuxin committed
67 68
        }
      }
潘际乾 committed
69 70
      that.rules = res;
    },
71 72 73 74 75
    /**
     * 触发方式
     * @param {String} prop item属性
     * @returns 
     */
潘际乾 committed
76 77 78 79 80
    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
81
          // select、checkbox使用change触发
潘际乾 committed
82
          if (field.$children[1].$children[0].$el.className.startsWith("el-select") || field.$children[1].$children[0].$el.className.startsWith("el-checkbox")) {
潘际乾 committed
83 84 85 86 87
            return "change";
          }
          return "blur";
        }
      }
潘际乾 committed
88
      return "blur";
89
    },
潘际乾 committed
90 91 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 120 121 122 123 124 125
    /**
     * 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"
      }
      if (!!rulePath) {
        this.executeRule(rulePath).then(res => {
          if (res.respCode == SUCCESS) {
            this.updateModel(res.data)
          }
        })
      }
    },
126 127 128 129 130 131 132 133
    /**
     * 以函数形式获取model(请求参数),保证取到的是最新赋值的
     * @param {any} params 参数
     * @returns 
     */
    wrapper(params) {
      params = params || {}
      const fn = async () => {
潘际乾 committed
134 135 136 137 138 139 140 141 142
        const that = this;
        const data = await new Promise(resolve => {
          // 保证前一次请求结果赋值VO完成
          setTimeout(() => {
            const d = Utils.flatObject(that.model)
            resolve(d)
          }, 0)
        })
        return { ...data, params }
143 144 145
      }
      return fn;
    },
146 147 148 149 150 151
    /**
     * 更新Model
     * @param {any} data model数据
     */
    updateModel(data) {
      Utils.copyValueFromVO(this.model, data);
潘际乾 committed
152
    },
潘际乾 committed
153 154 155 156
    /**
     * 弹出机构选择框
     * @param {String} rulePath 路径
     */
潘际乾 committed
157 158
    showGridPromptDialog(rulePath) {
      this.executeRule(rulePath).then((res) => {
潘际乾 committed
159
        if (res.respCode = SUCCESS) {
潘际乾 committed
160
          if (res.data.params) {
潘际乾 committed
161
            Utils.copyValueFromVO(this.model, res.data);
潘际乾 committed
162
          } else {
潘际乾 committed
163 164 165 166 167 168 169
            this.root.$refs.etyDialog.show = true
            this.root.promptData = {
              title: res.data.title,
              columnStr: res.data.columns,
              data: res.data.vals.rows,
              rulePath: rulePath,
            }
潘际乾 committed
170 171 172 173
          }
        }
      })
    },
潘际乾 committed
174 175 176 177 178
    /**
     * 机构回填
     * @param {String} val 选种行的值(一般是首列)
     * @param {String} rulePath 路径
     */
潘际乾 committed
179 180 181 182 183 184
    selectEty(val, rulePath) {
      const props = rulePath.replaceAll(".", "_")
      const obj = {}
      obj[props] = val;
      Utils.copyValueFromVO(this.model, obj);
      this.executeRule(rulePath).then((res) => {
潘际乾 committed
185
        if (res.respCode = SUCCESS) {
潘际乾 committed
186 187 188
          Utils.copyValueFromVO(this.model, res.data);
        }
      });
潘际乾 committed
189 190 191 192 193 194 195 196
    },
    /**
     * 改变表单项的是否必填属性
     * @param {String} property 属性
     * @param {Boolean} required 是否必填
     */
    changeFormItemRequired(property, required) {
      this.pattern[property][0].required = required
liuxin committed
197
    }
fukai committed
198
  },
潘际乾 committed
199 200
  computed: {
    isInDisplay() {
fukai committed
201 202
      return this.$store.state.Status.mode === 'display'
    }
liuxin committed
203 204
  }
}