💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
![](https://img.kancloud.cn/16/2c/162cfb3737f7d9965e2ffd7cb3e5f3f4_1797x210.png) 需求:在输入值后,拿当前值和当前行中某些数据比较,根据特定规则动态去改变样式 功能:大于上差+标准值:箭头向上,颜色变红,小于下差+标准值:箭头向下,颜色变红 ``` <el-table ref="multipleTable" :data="formTableData" tooltip-effect="dark" border style="width: 100%;0verflow-x:auto" :header-cell-style="{ 'text-align': 'center', background: '#f3f3f3', 'font-size': '12px', 'font-weight': 'normal', color: '#606266', }" > <el-table-column v-for="(item,key) in detailListHeader" :label="item.title" :prop="item.field" :key="key" width="100px" > </el-table-column> <el-table-column v-for="(val,i) in tableHead" :label="val.name" :prop="val.field" width="150px" :key="val.field" > <template slot-scope="scope"> <el-input :class="scope.row[`meter_${val.field}`] && scope.row[`meter_${val.field}`].isBad ?'isBad' : ''" v-model="scope.row[val.field]" type="number" @change="sampleChange($event, scope.$index, scope.row,val.field)" :disabled="false" :min="0" :max="999999999" :precision="2" > <template v-if="scope.row[`meter_${val.field}`] && scope.row[`meter_${val.field}`].isBad" slot="prepend" > {{ scope.row[`meter_${val.field}`].isHigh ? '↑' : '↓' }}</template> </el-input> </template> </el-table-column> </el-table> ``` ``` // 输入值改变 sampleChange(val, i, row, fieldName) { let low = row.standardvalue + row.under; //下限 let high = row.standardvalue + row.top; //上限 let obj = {}; let field = "meter_" + fieldName; if (val) { if (val > high) { obj.isBad = true; obj.isHigh = true; this.$set(this.formTableData[i], field, obj); //是否是不良 } else if (val < low) { // this.$message.error("小于下限值"); obj.isBad = true; obj.isHigh = false; this.$set(this.formTableData[i], field, obj); //是否是不良 } else { obj.isBad = false; obj.isHigh = false; this.$set(this.formTableData[i], field, obj); //是否是不良 } } }, //查询时,增加标识 query(){ recordQuery2({ id: row.id }).then(res => { if (res.code == 200) { this.formTableData = res.data.insMpList; let arr = ["sample1", "sample2", "sample3", "sample4", "sample5"]; if (this.formTableData.length > 0) { this.formTableData.forEach((val, i) => { let low = val.standardvalue + val.under; //下限 let high = val.standardvalue + val.top; //上限 let filedArr = Object.keys(val); //字段名存储 filedArr.forEach((item, i) => { // 判断是否是需要填写的样品字段 if (arr.indexOf(item) != -1) { let field = "meter_" + item; //增加前缀做唯一标识 let obj = {}; if (val[item]) { // 样品值比较 if (val[item] > high) { obj.isBad = true; //是否是坏的 obj.isHigh = true; //是否偏高 this.$set(val, field, obj); } else if (val[item] < low) { obj.isBad = true; obj.isHigh = false; this.$set(val, field, obj); } else { obj.isBad = false; obj.isHigh = false; this.$set(val, field, obj); } } } }); }); } } else { this.$message.error(res.message); } }); } ``` ``` <style scoped> /deep/ .el-input-group__prepend { color: red !important; padding: 0 10px; } .isBad >>> .el-input__inner { color: red !important; } </style> ```