ruleMixin.js 2.33 KB
import { mapGetters } from 'vuex'
import ruleConfig from '@/api/ruleConfig'
let mixin = {
  computed: {
    ...mapGetters(['dicData', 'rules','Edit'])
  },
  data () {
    return {
      key: 0,
      typeNum: { type: 'number' },
      initRules: {},
      subRules: {}
    }
  },
  created () {
    this.featchData()
  },
  methods: {
    /**
     * @description: featchData
     * @author: renchao
     */
    featchData () {
    },
    /**
     * @description: verificationForm
     * @author: renchao
     */
    verificationForm () {
      return new Promise((resolve) => {
        this.$refs['formList'].validate((valid) => {
          if (valid) {
            resolve(true)
          } else {
            resolve(false)
          }
        })
      })
    },
    /**
     * @description: changeCertificate
     * @author: renchao
     */
    changeCertificate() {

    },
    /**
     * @description: featchRule
     * @author: renchao
     */
    async featchRule () {
      try {
        let { result: { sysywsjbfieldlist } } = await ruleConfig.getRuleList(this.bsmYwsjb)
        sysywsjbfieldlist.forEach((item) => {
          this.subRules[item.FIELD] = [
            {
              required: item.REQUIRED == '1' ? true : false,
              pattern: item.EXPRESSION? new RegExp(item.EXPRESSION): null,
              message: item.MESSAGE || '请输入内容',
              trigger: item.TRIGGERS || 'change'
            }
          ]
          this.initRules[item.FIELD] = [
            {
              required: item.REQUIRED == '1' ? true : false,
              message: item.MESSAGE || '请输入内容',
              trigger: item.TRIGGERS || 'change'
            }
          ]
        })
        if (this.Edit) {
          this.$store.dispatch('business/setRules', {})
        }else {
          this.$store.dispatch('business/setRules', this.initRules)
        }
        this.$store.dispatch('business/setInitRules', this.initRules)
        this.$store.dispatch('business/setSubRules', this.subRules)
        this.key++
        this.$nextTick(() => {
          this.$refs['formList'] && this.$refs['formList'].validate((valid) => {
            if (!valid) {
              return false
            }
          })
        })
      } catch (error) {
        if (this.$refs.msg) {
          this.$refs.msg.messageShow()
        }
      }
    }
  }
}
export default mixin