el-input 限制数字
{
pattern: /^[0-9\-]+$/,
message: '请输入7位数字',
},
{
pattern: /^[\u4E00-\u9FA5a-z0-9\-]+$/,
message: '仅限中文、数字,小写字母,-',
},
{
pattern: /^[\u4E00-\u9FA5\-]+$/,
message: '仅限中文',
},
第一:数组校验
:prop="'recordList.' + index + '.problem'"
:rules="{
required:problemRequired==1?true:false,
message: '咨询问题不能为空',
trigger: 'change',
}"
<div v-for="(recordList, index) in inquiry.recordList"
:key="index">
<el-form-item
label="咨询问题"
:prop="'recordList.' + index + '.problem'"
:rules="{
required:problemRequired==1?true:false,
message: '咨询问题不能为空',
trigger: 'change',
}"
>
<el-select
v-model="recordList.problem"
placeholder="疾病知识"
:disabled="startStatus.problemTypestartStatus == '2' ? true : false "
>
<el-option
v-for="item in problemType"
:key="item"
:label="item"
:value="item">
</el-option>
</el-select>
</el-form-item>
</div>
根据数组放回得字段进行是否必选得判断
data(){
problemRequired:''
}
async stateChange() {
const parms = {
projectId: this.projectId,
type: ""
};
const res = await this.$cm.requestPost(101266, parms);
if (res.sucess) {
let list = res.paramBody.list;
let list_demo = list.map(data => {
switch (data.names) {
case "问询类型":
this.startStatus.followType = data.startStatus;
this.inquiry_rules.followType[0].required = data.required===1;
break;
case "问询对象":
this.startStatus.target = data.startStatus;
this.inquiry_rules.target[0].required=data.required===1;
break;
case "患者问题":
this.startStatus.problemTypestartStatus = data.startStatus;
this.problemRequired=data.required===1
this.problemType = data.problemType.split(',');
console.log("str",this.problemType)
break;
}
return;
});
}
},
第二:
prop="target"
target: [
{ required: false, message: "问询对象不能为空", trigger: "change" }
],
<el-form
ref="inquiry-ref"
:model="inquiry"
:rules="inquiry_rules"
size="medium"
label-width="180px"
label-position="left"
>
<el-form-item
label="问询对象"
prop="target"
>
<el-radio-group v-model="inquiry.target" size="medium">
<el-radio
:disabled="startStatus.target == '2' ? true : false"
v-for="(item, index) in targetOptions"
:key="index"
:label="item.value"
style="padding-bottom:5px;"
>{{ item.label }}</el-radio
>
</el-radio-group>
</el-form-item>
第三中
prop="inquiryOne"
const inquiryOneFun = (rule, value, callback) => {
console.log("校验函数",rule, value, callback)
if (this.inquiry.target !== "") {
this.$refs["inquiry-ref"].clearValidate("inquiryOne");
callback();
}
}
inquiryOne: [{ validator: inquiryOneFun, trigger: "change" }]
网友评论