element的table获取当前表格行

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

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

1.局部html

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.验证规则

javascript 复制代码
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();
  }
};
相关推荐
子兮曰15 小时前
OpenClaw入门:从零开始搭建你的私有化AI助手
前端·架构·github
吴仰晖15 小时前
使用github copliot chat的源码学习之Chromium Compositor
前端
1024小神15 小时前
github发布pages的几种状态记录
前端
不像程序员的程序媛17 小时前
Nginx日志切分
服务器·前端·nginx
Daniel李华17 小时前
echarts使用案例
android·javascript·echarts
北原_春希17 小时前
如何在Vue3项目中引入并使用Echarts图表
前端·javascript·echarts
JY-HPS17 小时前
echarts天气折线图
javascript·vue.js·echarts
尽意啊17 小时前
echarts树图动态添加子节点
前端·javascript·echarts
吃面必吃蒜17 小时前
echarts 极坐标柱状图 如何定义柱子颜色
前端·javascript·echarts
O_oStayPositive17 小时前
Vue3使用ECharts
前端·javascript·echarts