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();
  }
};
相关推荐
前端小巷子11 小时前
JS实现丝滑文字滚动
前端·javascript·面试
oil欧哟11 小时前
🧐 我用 Vibe Coding 从 0 到 1 打造 AI 产品,上线一个月效果如何?有什么心得?
前端·产品·vibecoding
霍克itxt点top11 小时前
NestJS 入门到实战 前端必学服务端新趋势无密分享
前端
xiguolangzi11 小时前
1panel web服务部署
前端
写不出来就跑路12 小时前
基于 HTML+CSS+JavaScript 的薪资实时计算器(含本地存储和炫酷动画)
javascript·css·html
摘星编程12 小时前
Cursor Pair Programming:在前端项目里用 AI 快速迭代 UI 组件
前端·人工智能·ui·typescript·前端开发·cursorai
醉方休12 小时前
React Fiber 风格任务调度库
前端·javascript·react.js
北辰alk12 小时前
React Intl 全方位解析:为你的 React 应用注入国际化灵魂
前端
李白白i单身版12 小时前
前端VUE项目实现静默打印,无需用户手动确认
前端
bysking12 小时前
【29 - git bisect】git bisect 命令进行二分定位,排查异常commit bysking
前端