转载自:https://www.jianshu.com/p/361ebeab3a97

一、效果图

在这里插入图片描述

二、vue格式文件代码

<el-row>
  <el-col :span="6">
    <el-form-item label="收款金额" prop="amount" :rules="[
        { required: true, message: '请输入', trigger: 'blur' },
        { validator: this.numberRule, trigger: 'blur'}
      ]">
      <el-input type="number" v-model="voucherForm.amount" placeholder="收款金额"></el-input>
    </el-form-item>
  </el-col>
  <el-col :span="6">
    <el-form-item label="核销金额">
      <el-input v-model="voucherForm.writeoffAmount" disabled placeholder="核销金额"></el-input>
    </el-form-item>
  </el-col>
</el-row>

三、data部分代码

data() {
    const numberRule = (rule, value, callback) => {
      if (Number(value) >= this.voucherForm.writeoffAmount) {
        if (Number.isInteger(Number(value)) && Number(value) > 0) {
          callback()
        } else {
          callback(new Error('请输入大于零的正整数'))
        }
      } else {
        callback(new Error('收款金额不能小于核销金额'))
      }
    }
    return {
      numberRule: numberRule,
      voucherForm: {
        voucher: 'R',
        custName: null,
        currCode: null,
        writeoffAmount: null
      },
    }
Logo

前往低代码交流专区

更多推荐