Blame view

src/mixins/ruleMixin.js 2.04 KB
任超 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
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: {
    featchData () {
    },
    verificationForm () {
      return new Promise((resolve) => {
        this.$refs['formList'].validate((valid) => {
          if (valid) {
            resolve(true)
          } else {
            resolve(false)
          }
        })
      })
    },
    changeCertificate() {
      
    },
    async featchRule () {
      try {
蔡俊立 committed
37
        let { result: { sysywsjbfieldlist } } = await ruleConfig.getRuleList(this.bsmYwsjb)
任超 committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
        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