html
<el-form-item label="编号范围">
<el-col :span="11">
<el-form-item prop="startNum">
<el-input
style="width: 160px"
type="number"
clearable
v-model="YXCXForm.startNum"
></el-input>
</el-form-item>
</el-col>
<el-col class="line" :span="2">-</el-col>
<el-col :span="11">
<el-form-item prop="endNum">
<el-input
style="width: 160px"
clearable
type="number"
v-model="YXCXForm.endNum"
></el-input>
</el-form-item>
</el-col>
</el-form-item>
js
data() {
const numberEndRule = (rule, value, callback) => {
if (this.YXCXForm.startNum != null) {
if (Number(value) >= this.YXCXForm.startNum) {
if (Number.isInteger(Number(value)) && Number(value) > 0) {
callback();
} else {
callback(new Error("请输入大于零的正整数"));
}
} else {
callback(new Error("结束编号必须大于开始编号"));
}
} else {
callback(new Error("请先输入开始编号"));
}
};
const numberStartRule = (rule, value, callback) => {
if (Number.isInteger(Number(value)) && Number(value) > 0) {
callback();
} else {
callback(new Error("请输入大于零的正整数"));
}
};
return {
YXCXForm: {
mainId: "",
datepicker: [],
startDate: "",
endDate: "",
checkType: 1,
nucleicNum: 1,
startNum: null,
endNum: null,
hType: 0,
},
YXCXRules: {
checkType: [
{ required: true, message: "请选择检查类型", trigger: "change" },
],
datepicker: [
{
type: "array",
required: true,
message: "请选择日期范围",
trigger: "change",
},
],
nucleicNum: [
{ required: true, message: "请选择核酸次数", trigger: "change" },
],
startNum: [{ validator: numberStartRule, trigger: "change" }],
endNum: [{ validator: numberEndRule, trigger: "change" }],
},
};
}