修复表格顺序改变后误删其他数据

pull/178/head
lin-xin 2019-06-13 16:57:05 +08:00
parent 8c33d1b5b3
commit ce21d13774
2 changed files with 73 additions and 42 deletions

View File

@ -1,43 +1,53 @@
{ {
"list": [{ "list": [{
"date": "1997-11-11", "id": 1,
"name": "林丽", "date": "2013-05-04",
"address": "吉林省 辽源市 龙山区" "name": "邱秀兰",
"address": "浙江省 金华市 兰溪市"
}, { }, {
"date": "1987-09-24", "id": 2,
"name": "文敏", "date": "1991-05-02",
"address": "江西省 萍乡市 芦溪县" "name": "蒋军",
"address": "广东省 东莞市 长安镇"
}, { }, {
"date": "1996-08-08", "id": 3,
"name": "杨秀兰", "date": "2009-12-01",
"address": "黑龙江省 黑河市 五大连池市" "name": "廖艳",
"address": "陕西省 渭南市 富平县"
}, { }, {
"date": "1978-06-18", "id": 4,
"date": "1999-07-15",
"name": "秦强",
"address": "内蒙古自治区 巴彦淖尔市 磴口县"
}, {
"id": 5,
"date": "1997-02-09",
"name": "唐洋",
"address": "湖南省 长沙市 "
}, {
"id": 6,
"date": "2018-05-23",
"name": "易勇",
"address": "重庆 重庆市 双桥区"
}, {
"id": 7,
"date": "2014-04-09",
"name": "袁丽",
"address": "陕西省 铜川市 耀州区"
}, {
"id": 8,
"date": "2013-08-05",
"name": "常刚",
"address": "海外 海外 -"
}, {
"id": 9,
"date": "1995-12-13",
"name": "龚勇",
"address": "黑龙江省 牡丹江市 西安区"
}, {
"id": 10,
"date": "2017-06-06",
"name": "魏强", "name": "魏强",
"address": "广东省 韶关市 始兴县" "address": "安徽省 六安市 裕安区"
}, {
"date": "1977-07-09",
"name": "石秀兰",
"address": "江苏省 宿迁市 宿豫区"
}, {
"date": "1994-09-20",
"name": "朱洋",
"address": "海外 海外 -"
}, {
"date": "1980-01-22",
"name": "傅敏",
"address": "海外 海外 -"
}, {
"date": "1985-10-10",
"name": "毛明",
"address": "内蒙古自治区 包头市 九原区"
}, {
"date": "1975-09-08",
"name": "何静",
"address": "西藏自治区 阿里地区 普兰县"
}, {
"date": "1970-06-07",
"name": "郭秀英",
"address": "四川省 巴中市 恩阳区"
}] }]
} }

View File

@ -87,7 +87,8 @@
date: '', date: '',
address: '' address: ''
}, },
idx: -1 idx: -1,
id: -1
} }
}, },
created() { created() {
@ -143,16 +144,18 @@
}, },
handleEdit(index, row) { handleEdit(index, row) {
this.idx = index; this.idx = index;
const item = this.tableData[index]; this.id = row.id;
this.form = { this.form = {
name: item.name, id: row.id,
date: item.date, name: row.name,
address: item.address date: row.date,
address: row.address
} }
this.editVisible = true; this.editVisible = true;
}, },
handleDelete(index, row) { handleDelete(index, row) {
this.idx = index; this.idx = index;
this.id = row.id;
this.delVisible = true; this.delVisible = true;
}, },
delAll() { delAll() {
@ -170,15 +173,33 @@
}, },
// //
saveEdit() { saveEdit() {
this.$set(this.tableData, this.idx, this.form);
this.editVisible = false; this.editVisible = false;
this.$message.success(`修改第 ${this.idx+1} 行成功`); this.$message.success(`修改第 ${this.idx+1} 行成功`);
if(this.tableData[this.idx].id === this.id){
this.$set(this.tableData, this.idx, this.form);
}else{
for(let i = 0; i < this.tableData.length; i++){
if(this.tableData[i].id === this.id){
this.$set(this.tableData, i, this.form);
return ;
}
}
}
}, },
// //
deleteRow(){ deleteRow(){
this.tableData.splice(this.idx, 1);
this.$message.success('删除成功'); this.$message.success('删除成功');
this.delVisible = false; this.delVisible = false;
if(this.tableData[this.idx].id === this.id){
this.tableData.splice(this.idx, 1);
}else{
for(let i = 0; i < this.tableData.length; i++){
if(this.tableData[i].id === this.id){
this.tableData.splice(i, 1);
return ;
}
}
}
} }
} }
} }