export default {
  props: {
    label: {
      type: String,
      default: '未指定'
    },
    value: {
      required: true
    },
    required: {
      type: Boolean,
      default: false
    },
    disabled: {
      type: Boolean,
      default: false
    },
    clearable: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    requireRule(required, label, type) {
      const rules =  [{
        required: required,
        message: `${label}不能为空`,
        trigger: 'onBlur'
      }]

      const regRule = {message: `${label}格式不正确`, trigger: 'onBlur'}
      if (type === 'phone') {
        regRule.pattern = /^[1][3,4,5,7,8][0-9]{9}$/
        rules.push(regRule)
      } else if (type === 'idCard') {
        regRule.pattern = /^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$/
        rules.push(regRule)
      }
      return rules
    }
  }
}