element的table获取当前表格行

需求:验证表格同一行的最低限价不能超过销售定价

思路:先获取当前行table的index,然后在做大小比较

1.局部html

<el-table-column label="销售定价(元)" min-width="200px">
  <template slot="header">
    <span class="star">*</span>
    <span class="star-name">销售定价(元)</span>
  </template>
  <template slot-scope="scope">
    <el-form-item
      :prop="'skuList.' + scope.$index + '.price'"
      :rules="tableRules.price"
    >
      <el-input
        size="small"
        v-model.trim="scope.row.price"
        @input="userInput"
        placeholder="请输入销售定价"
      />
    </el-form-item>
  </template>
</el-table-column>

<el-table-column label="最低限价(元)" min-width="200px">
  <template slot="header">
    <span class="star">*</span>
    <span class="star-name">最低限价(元)</span>
  </template>
  <template slot-scope="scope">
    <el-form-item
      :prop="'skuList.' + scope.$index + '.floorPrice'"
      :rules="tableRules.floorPrice"
    >
      <el-input
        size="small"
        v-model.trim="scope.row.floorPrice"
        @input="userInput"
        placeholder="请输入最低限价"
      />
    </el-form-item>
  </template>
</el-table-column>

2.验证规则

const checkFloorPrice = (rule, value, callback) => {
  let index = rule.field.split(".")[1];//获取当前行角标
  if (!value) {
    callback(new Error("请输入最低限价"));
  } else if (value == Infinity || value > Math.pow(2, 31) - 1) {
    callback(new Error("您填写的数字过长"));
  } else if (!/^\d+(\.\d{1,2})?$/.test(value)) {
    callback(new Error("请输入小数不超过两位的自然数"));
  } else if (value >= this.tableForm.skuList[index].price) {//重点看这里
    callback(new Error("最低限价不能超过销售定价"));
  } else {
    callback();
  }
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值