index.vue
3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<template>
<div class="app-container">
<el-form
:inline="true"
:model="listQuery"
size="small"
class="qg-search-form"
>
<el-form-item label="书本编号" >
<el-input v-model="listQuery.code" clearable />
</el-form-item>
<el-form-item label=" ">
<el-button type="primary" @click="handleSearch">查询</el-button>
</el-form-item>
</el-form>
<el-row class="opt-bar">
<el-button type="primary" @click="handleAdd">新增</el-button>
<el-button type="default">导入</el-button>
<el-button type="default" @click="handleExport">导出</el-button>
<el-button type="default" @click="handleBatchDel">批量删除</el-button>
</el-row>
<qg-table
ref="bookListTable"
:columns="tableColumns"
:param="listQuery"
:request="listRequest"
/>
</div>
</template>
<script>
import {bookBatchDelete, bookPage} from '@/api/moudles/xieyunhui/book';
import {bookSearchModel, tableColumns, componentsData} from './config.js';
import {deepClone, postExcelFile} from '@/utils';
import {getToken} from '@/utils/auth'
export default {
name: 'BookTable',
data() {
return {
tableColumns: tableColumns.bind(this)(),
listRequest: bookPage,
listQuery: deepClone(bookSearchModel),
componentsData
};
},
created() {
},
methods: {
handleSearch() {
this.$refs.bookListTable.load();
},
handleAdd() {
this.$router.push({name: `bookAdd`});
},
handleBatchDel: function () {
const {ids} = this.$refs.bookListTable.getSelections();
if(!ids && ids.length ===0){
this.$message.info('请先选择数据');
return;
}
this.$confirm('你确定要删除所选数据吗?').then(() => {
const request = bookBatchDelete(ids);
this.operate(request, true);
}).catch(() => {
});
},
handleExport: function () {
const url = process.env.VUE_APP_BASE_API + `/qgyun-xieyunhui/book/export?_token=` + getToken();
postExcelFile(Object.assign({}, this.listQuery), url);
},
handleOpt(type, params) {
let request = null;
switch (type) {
case 'VIEW':
this.$router.push({name: `bookDetail`, query: {id: params.id}});
return;
case 'DELETE':
this.$confirm('你确定要删除该数据吗?').then(() => {
request = bookBatchDelete([params.id]);
this.operate(request, true);
}).catch(() => {
});
return;
case 'EDIT':
this.$router.push({name: `bookEdit`, query: {id: params.id}});
return;
}
},
operate(request, isReloadList) {
if (!request) {
return;
}
request.then(res => {
if (res.success) {
this.$message.success(res.msg || '操作成功');
if (isReloadList) {
this.$refs.bookListTable.refresh();
}
}else{
this.$message.error(res.msg || '操作失败!');
}
});
}
}
};
</script>