怎么做垂直門(mén)戶(hù)網(wǎng)站百度廣告位價(jià)格
需求:驗(yàn)證表格同一行的最低限價(jià)不能超過(guò)銷(xiāo)售定價(jià)
思路:先獲取當(dāng)前行table的index,然后在做大小比較
1.局部html
<el-table-column label="銷(xiāo)售定價(jià)(元)" min-width="200px"><template slot="header"><span class="star">*</span><span class="star-name">銷(xiāo)售定價(jià)(元)</span></template><template slot-scope="scope"><el-form-item:prop="'skuList.' + scope.$index + '.price'":rules="tableRules.price"><el-inputsize="small"v-model.trim="scope.row.price"@input="userInput"placeholder="請(qǐng)輸入銷(xiāo)售定價(jià)"/></el-form-item></template>
</el-table-column><el-table-column label="最低限價(jià)(元)" min-width="200px"><template slot="header"><span class="star">*</span><span class="star-name">最低限價(jià)(元)</span></template><template slot-scope="scope"><el-form-item:prop="'skuList.' + scope.$index + '.floorPrice'":rules="tableRules.floorPrice"><el-inputsize="small"v-model.trim="scope.row.floorPrice"@input="userInput"placeholder="請(qǐng)輸入最低限價(jià)"/></el-form-item></template>
</el-table-column>
2.驗(yàn)證規(guī)則
const checkFloorPrice = (rule, value, callback) => {let index = rule.field.split(".")[1];//獲取當(dāng)前行角標(biāo)if (!value) {callback(new Error("請(qǐng)輸入最低限價(jià)"));} else if (value == Infinity || value > Math.pow(2, 31) - 1) {callback(new Error("您填寫(xiě)的數(shù)字過(guò)長(zhǎng)"));} else if (!/^\d+(\.\d{1,2})?$/.test(value)) {callback(new Error("請(qǐng)輸入小數(shù)不超過(guò)兩位的自然數(shù)"));} else if (value >= this.tableForm.skuList[index].price) {//重點(diǎn)看這里callback(new Error("最低限價(jià)不能超過(guò)銷(xiāo)售定價(jià)"));} else {callback();}
};