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 37 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 79 80 81 82 83 84 85 86 87 88 89 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 126 127 128 129 130 131 132 133 134
| <template> <el-dialog title="动态设置校验规则" :visible.sync="dialogVisible" size="small" :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false"> <el-form ref="form" :model="form" :rules="rules" label-width="80px"> <el-form-item label="证件信息" required> <el-row> <el-col :span="8"> <el-form-item prop="certificateType"> <el-select v-model="form.certificateType" clearable @change="changeHander" placeholder="请选择证件类型"> <el-option label="身份证" value="id"></el-option> <el-option label="护照" value="passPort"></el-option> </el-select> </el-form-item> </el-col> <el-col class="line" :span="1"> </el-col> <el-col :span="15"> <el-form-item label="" ref="certificateNum" :rules="certificateNumRule" prop="certificateNum"> <el-input placeholder="请输入证件号" v-model="form.certificateNum"></el-input> </el-form-item> </el-col> </el-row> </el-form-item> </el-form> <div slot="footer" class="dialog-footer"> <el-button @click="cancelDialog('form')" size="small">取 消</el-button> <el-button type="primary" @click="saveDialog('form')" size="small">确 定</el-button> </div> </el-dialog> </template>
<script> export default { props: { visible: { type: Boolean, default: true, }, }, computed: { dialogVisible: { set (newValue) { this.$emit('update:visible', newValue) }, get () { return this.visible }, }, }, data () { return { certificateNumRule: [], form: { certificateType: '', certificateNum: '', }, rules: { id: [{ required: true, min: 18, max: 18, message: '请输入长度18位的身份证号', trigger: 'blur', }, ], passPort: [{ required: true, min: 6, max: 6, message: '请输入长度6位的护照号', trigger: 'blur', }, ], certificateType: [{ required: true, message: '请选择证件类型', trigger: 'blur,change', }, ], }, } }, methods: { changeHander (val) { if (val === 'id') { this.certificateNumRule = this.rules.id } else if (val === 'passPort') { this.certificateNumRule = this.rules.passPort } else { this.certificateNumRule = [] } this.$nextTick(() => { this.$refs.certificateNum.resetField() this.$refs.certificateNum.resetField() }) }, cancelDialog (formName) { this.$refs[formName].resetFields() this.dialogVisible = false this.$emit('cancel') }, saveDialog (formName) { this.$refs[formName].validate(valid => { if (valid) { console.log('校验通过') } else { console.log('校验失败') } }) }, }, } </script>
|