26
26
</el-table-column >
27
27
<el-table-column label =" 操作" width =" 180" >
28
28
<template slot-scope="scope">
29
- <el-button size =" small"
30
- @click =" handleEdit(scope.$index, scope.row)" >编辑</el-button >
31
- <el-button size =" small" type =" danger"
32
- @click =" handleDelete(scope.$index, scope.row)" >删除</el-button >
29
+ <el-button size =" small" @click =" handleEdit(scope.$index, scope.row)" >编辑</el-button >
30
+ <el-button size =" small" type =" danger" @click =" handleDelete(scope.$index, scope.row)" >删除</el-button >
33
31
</template >
34
32
</el-table-column >
35
33
</el-table >
36
34
<div class =" pagination" >
37
- <el-pagination
38
- @current-change =" handleCurrentChange"
39
- layout =" prev, pager, next"
40
- :total =" 1000" >
35
+ <el-pagination @current-change =" handleCurrentChange" layout =" prev, pager, next" :total =" 1000" >
41
36
</el-pagination >
42
37
</div >
43
38
</div >
39
+
40
+ <!-- 编辑弹出框 -->
41
+ <el-dialog title =" 编辑" :visible.sync =" editVisible" width =" 30%" >
42
+ <el-form ref =" form" :model =" form" label-width =" 50px" >
43
+ <el-form-item label =" 日期" >
44
+ <el-date-picker type =" date" placeholder =" 选择日期" v-model =" form.date" value-format =" yyyy-MM-dd" style =" width : 100% ;" ></el-date-picker >
45
+ </el-form-item >
46
+ <el-form-item label =" 姓名" >
47
+ <el-input v-model =" form.name" ></el-input >
48
+ </el-form-item >
49
+ <el-form-item label =" 地址" >
50
+ <el-input v-model =" form.address" ></el-input >
51
+ </el-form-item >
52
+
53
+ </el-form >
54
+ <span slot =" footer" class =" dialog-footer" >
55
+ <el-button @click =" editVisible = false" >取 消</el-button >
56
+ <el-button type =" primary" @click =" saveEdit" >确 定</el-button >
57
+ </span >
58
+ </el-dialog >
59
+
60
+ <!-- 删除提示框 -->
61
+ <el-dialog title =" 提示" :visible.sync =" delVisible" width =" 300px" center >
62
+ <div class =" del-dialog-cnt" >删除不可恢复,是否确定删除?</div >
63
+ <span slot =" footer" class =" dialog-footer" >
64
+ <el-button @click =" delVisible = false" >取 消</el-button >
65
+ <el-button type =" primary" @click =" deleteRow" >确 定</el-button >
66
+ </span >
67
+ </el-dialog >
44
68
</div >
45
69
</template >
46
70
55
79
select_cate: ' ' ,
56
80
select_word: ' ' ,
57
81
del_list: [],
58
- is_search: false
82
+ is_search: false ,
83
+ editVisible: false ,
84
+ delVisible: false ,
85
+ form: {
86
+ name: ' ' ,
87
+ date: ' ' ,
88
+ address: ' '
89
+ },
90
+ idx: - 1
59
91
}
60
92
},
61
- created (){
93
+ created () {
62
94
this .getData ();
63
95
},
64
96
computed: {
65
- data (){
97
+ data () {
66
98
return this .tableData .filter ((d ) => {
67
99
let is_del = false ;
68
100
for (let i = 0 ; i < this .del_list .length ; i++ ) {
69
- if (d .name === this .del_list [i].name ){
101
+ if (d .name === this .del_list [i].name ) {
70
102
is_del = true ;
71
103
break ;
72
104
}
73
105
}
74
- if (! is_del){
75
- if (d .address .indexOf (this .select_cate ) > - 1 &&
106
+ if (! is_del) {
107
+ if (d .address .indexOf (this .select_cate ) > - 1 &&
76
108
(d .name .indexOf (this .select_word ) > - 1 ||
77
- d .address .indexOf (this .select_word ) > - 1 )
78
- ){
109
+ d .address .indexOf (this .select_word ) > - 1 )
110
+ ) {
79
111
return d;
80
112
}
81
113
}
84
116
},
85
117
methods: {
86
118
// 分页导航
87
- handleCurrentChange (val ){
119
+ handleCurrentChange (val ) {
88
120
this .cur_page = val;
89
121
this .getData ();
90
122
},
91
123
// 获取 easy-mock 的模拟数据
92
- getData (){
124
+ getData () {
93
125
// 开发环境使用 easy-mock 数据,正式环境使用 json 文件
94
- if (process .env .NODE_ENV === ' development' ){
126
+ if (process .env .NODE_ENV === ' development' ) {
95
127
this .url = ' /ms/table/list' ;
96
128
};
97
- this .$axios .post (this .url , {page: this .cur_page }).then ((res ) => {
129
+ this .$axios .post (this .url , {
130
+ page: this .cur_page
131
+ }).then ((res ) => {
98
132
this .tableData = res .data .list ;
99
133
})
100
134
},
101
- search (){
135
+ search () {
102
136
this .is_search = true ;
103
137
},
104
138
formatter (row , column ) {
108
142
return row .tag === value;
109
143
},
110
144
handleEdit (index , row ) {
111
- this .$message (' 编辑第' + (index+ 1 )+ ' 行' );
145
+ this .idx = index;
146
+ const item = this .tableData [index];
147
+ this .form = {
148
+ name: item .name ,
149
+ date: item .date ,
150
+ address: item .address
151
+ }
152
+ this .editVisible = true ;
112
153
},
113
154
handleDelete (index , row ) {
114
- this .$message .error (' 删除第' + (index+ 1 )+ ' 行' );
155
+ this .idx = index;
156
+ this .delVisible = true ;
115
157
},
116
- delAll (){
158
+ delAll () {
117
159
const length = this .multipleSelection .length ;
118
160
let str = ' ' ;
119
161
this .del_list = this .del_list .concat (this .multipleSelection );
120
162
for (let i = 0 ; i < length; i++ ) {
121
163
str += this .multipleSelection [i].name + ' ' ;
122
164
}
123
- this .$message .error (' 删除了' + str);
165
+ this .$message .error (' 删除了' + str);
124
166
this .multipleSelection = [];
125
167
},
126
168
handleSelectionChange (val ) {
127
169
this .multipleSelection = val;
170
+ },
171
+ // 保存编辑
172
+ saveEdit () {
173
+ this .$set (this .tableData , this .idx , this .form );
174
+ this .editVisible = false ;
175
+ this .$message .success (` 修改第 ${ this .idx + 1 } 行成功` );
176
+ },
177
+ // 确定删除
178
+ deleteRow (){
179
+ this .tableData .splice (this .idx , 1 );
180
+ this .$message .success (' 删除成功' );
181
+ this .delVisible = false ;
128
182
}
129
183
}
130
184
}
185
+
131
186
</script >
132
187
133
188
<style scoped>
134
- .handle-box {
135
- margin-bottom : 20px ;
136
- }
137
- .handle-select {
138
- width : 120px ;
139
- }
140
- .handle-input {
141
- width : 300px ;
142
- display : inline-block ;
143
- }
144
- </style >
189
+ .handle-box {
190
+ margin-bottom : 20px ;
191
+ }
192
+
193
+ .handle-select {
194
+ width : 120px ;
195
+ }
196
+
197
+ .handle-input {
198
+ width : 300px ;
199
+ display : inline-block ;
200
+ }
201
+ .del-dialog-cnt {
202
+ font-size : 16px ;
203
+ text-align : center
204
+ }
205
+ </style >
0 commit comments