Skip to content

Commit 3022814

Browse files
committed
Table:修改搜索逻辑
1 parent f7fb309 commit 3022814

File tree

1 file changed

+20
-40
lines changed

1 file changed

+20
-40
lines changed

src/components/page/BaseTable.vue

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
class="handle-del mr10"
1616
@click="delAllSelection"
1717
>批量删除</el-button>
18-
<el-select v-model="selectCate" placeholder="筛选省份" class="handle-select mr10">
18+
<el-select v-model="query.address" placeholder="地址" class="handle-select mr10">
1919
<el-option key="1" label="广东省" value="广东省"></el-option>
2020
<el-option key="2" label="湖南省" value="湖南省"></el-option>
2121
</el-select>
22-
<el-input v-model="selectWord" placeholder="筛选关键词" class="handle-input mr10"></el-input>
22+
<el-input v-model="query.name" placeholder="用户名" class="handle-input mr10"></el-input>
2323
<el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
2424
</div>
2525
<el-table
26-
:data="data"
26+
:data="tableData"
2727
border
2828
class="table"
2929
ref="multipleTable"
@@ -75,9 +75,9 @@
7575
<el-pagination
7676
background
7777
layout="total, prev, pager, next"
78-
:current-page="page.index"
79-
:page-size="page.size"
80-
:total="page.total"
78+
:current-page="query.pageIndex"
79+
:page-size="query.pageSize"
80+
:total="pageTotal"
8181
@current-change="handlePageChange"
8282
></el-pagination>
8383
</div>
@@ -107,17 +107,17 @@ export default {
107107
name: 'basetable',
108108
data() {
109109
return {
110+
query: {
111+
address: '',
112+
name: '',
113+
pageIndex: 1,
114+
pageSize: 10
115+
},
110116
tableData: [],
111117
multipleSelection: [],
112118
delList: [],
113-
selectCate: '',
114-
selectWord: '',
115119
editVisible: false,
116-
page: {
117-
index: 1,
118-
size: 10,
119-
total: 50
120-
},
120+
pageTotal: 0,
121121
form: {},
122122
idx: -1,
123123
id: -1
@@ -126,38 +126,19 @@ export default {
126126
created() {
127127
this.getData();
128128
},
129-
computed: {
130-
data() {
131-
return this.tableData.filter(d => {
132-
let is_del = false;
133-
for (let i = 0; i < this.delList.length; i++) {
134-
if (d.name === this.delList[i].name) {
135-
is_del = true;
136-
break;
137-
}
138-
}
139-
if (!is_del) {
140-
if (
141-
d.address.indexOf(this.selectCate) > -1 &&
142-
(d.name.indexOf(this.selectWord) > -1 || d.address.indexOf(this.selectWord) > -1)
143-
) {
144-
return d;
145-
}
146-
}
147-
});
148-
}
149-
},
150129
methods: {
151130
// 获取 easy-mock 的模拟数据
152131
getData() {
153-
fetchData({
154-
page: this.page.index
155-
}).then(res => {
132+
fetchData(this.query).then(res => {
156133
this.tableData = res.list;
134+
this.pageTotal = res.pageTotal || 50;
157135
});
158136
},
159137
// 触发搜索按钮
160-
handleSearch() {},
138+
handleSearch() {
139+
this.$set(this.query, 'pageIndex', 1);
140+
this.getData();
141+
},
161142
// 删除操作
162143
handleDelete(index, row) {
163144
// 二次确认删除
@@ -187,7 +168,6 @@ export default {
187168
// 编辑操作
188169
handleEdit(index, row) {
189170
this.idx = index;
190-
this.id = row.id;
191171
this.form = row;
192172
this.editVisible = true;
193173
},
@@ -199,7 +179,7 @@ export default {
199179
},
200180
// 分页导航
201181
handlePageChange(val) {
202-
this.page.index = val;
182+
this.$set(this.query, 'pageIndex', val);
203183
this.getData();
204184
}
205185
}

0 commit comments

Comments
 (0)