element的table获取当前表格行
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element
·
需求:验证表格同一行的最低限价不能超过销售定价
思路:先获取当前行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();
}
};
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:4 个月前 )
c345bb45
1 年前
a07f3a59
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update table.md
* Update transition.md
* Update popover.md 1 年前
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐


所有评论(0)