1 <template>
2 <div id="Cold_all">
3 <div class="Cold_Left">
4 <el-row>
5 <div class="font_style"> 1.输入计算基本数据</div>
6 <el-col :span="24">
7
8 <el-table
9 size="mini"
10 :data="master_user.data"
11 border
12 style=" 100%;margin:auto"
13 highlight-current-row
14 >
15 <el-table-column type="index"></el-table-column>
16 <el-table-column
17 v-for="(item,index) in master_user.columns"
18 :label="item.label"
19 :prop="item.prop"
20 :width="item.width"
21 :key="index"
22 >
23 <template slot-scope="scope">
24 <span v-if="scope.row.isSet">
25 <el-input size="mini" placeholder="请输入内容" v-model="master_user.sel[item.prop]"></el-input>
26 </span>
27 <span v-else>{{scope.row[item.prop]}}</span>
28 </template>
29 </el-table-column>
30 <el-table-column label="操作">
31 <template slot-scope="scope">
32 <span
33 class="Insert_Cold"
34 style="cursor: pointer;"
35 @click.stop="saveRow(scope.row,scope.$index)"
36 >保存</span>
37 <span
38 class="Edit_Cold"
39 style="cursor: pointer;"
40 @click="editRow(scope.row,scope.$index)"
41 >编辑</span>
42 <span
43 class="Delete_Cold"
44 style="cursor: pointer;"
45 @click="deleteRow(scope.$index,master_user.data)"
46 >删除</span>
47 </template>
48 </el-table-column>
49 </el-table>
50 </el-col>
51 <el-col :span="24">
52 <div class="el-table-add-row" style=" 99.2%;" @click="add()">
53 <span>+ 添加</span>
54 </div>
55 </el-col>
56 </el-row>
57 </div>
58 </div>
59 </template>
<script>
export default {
name: "",
data() {
return {
master_user: {
sel: null, //选中行
columns: [
{
prop: "OutdoorTDB",
label: "室外计算温度(℃)",
},
{
prop: "IndoorTDB",
label: "室内计算温度(℃)"
},
{
prop: "TdbStartTime",
label: "运行开始时间"
},
{
prop: "TdbEndTime",
label: "运行结束时间"
}
],
data: []
}
}
<script>
methods: {
//基本输入列表
add() {
for (let i of this.master_user.data) {
if (i.isSet) return this.$message.error("请先保存当前编辑项");
}
let j = {
index: "",
OutdoorTDB: "",
IndoorTDB: "",
TdbStartTime: "",
TdbEndTime: "",
isSet: true
};
this.master_user.data.push(j);
this.master_user.sel = JSON.parse(JSON.stringify(j));
},
saveRow(row, index) {
//保存
let data = JSON.parse(JSON.stringify(this.master_user.sel));
for (let k in data) {
row[k] = data[k];
}
row.isSet = false;
},
editRow(row) {
//编辑
for (let i of this.master_user.data) {
if (i.isSet) return this.$message.error("请先保存当前编辑项");
}
this.master_user.sel = row;
row.isSet = true;
},
deleteRow(index, rows) {
//删除
rows.splice(index, 1);
},
components: {}
}