index.vue
9.17 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<template>
<div class="simple-page">
<el-card shadow="never">
<el-tabs v-model="activeType" @tab-click="handleTypeChange">
<el-tab-pane label="产品合同" name="product" />
<el-tab-pane label="商品合同" name="goods" />
<el-tab-pane label="套餐合同" name="package" />
</el-tabs>
<el-form size="small"
:inline="true"
:model="query">
<el-form-item label="合同名称">
<el-input v-model.trim="query.templateName" clearable />
</el-form-item>
<el-form-item label="商品/套餐编码">
<el-input v-model.trim="query.packageCode" clearable />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="handleSearch">
查询
</el-button>
<el-button @click="handleReset">
重置
</el-button>
</el-form-item>
</el-form>
<div class="toolbar">
<el-button size="small"
type="primary"
:disabled="!selection.length"
@click="batchInitialize">
批量初始化
</el-button>
<el-button size="small"
:disabled="!selection.length"
@click="openReplaceDialog()">
批量更换模板
</el-button>
<el-button size="small"
:loading="exporting"
@click="handleExport">
导出
</el-button>
</div>
<el-table v-loading="loading"
empty-text="暂无合同"
border
:data="rows"
@selection-change="selection = $event">
<el-table-column type="selection" width="45" />
<el-table-column label="商品/套餐编码"
min-width="150"
prop="packageCode" />
<el-table-column label="商品/套餐名称"
min-width="180"
prop="packageName"
show-overflow-tooltip />
<el-table-column label="合同模板"
min-width="180"
prop="templateName"
show-overflow-tooltip />
<el-table-column label="更新时间"
min-width="160"
prop="updateTime" />
<el-table-column label="操作" width="240">
<template #default="scope">
<el-button type="text" @click="openEditor(scope.row)">
编辑
</el-button>
<el-button type="text" @click="openEditor(scope.row, true)">
详情
</el-button>
<el-button type="text" @click="preview(scope.row)">
预览/打印
</el-button>
<el-button type="text" @click="openReplaceDialog(scope.row)">
更换
</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination class="pagination"
layout="total, sizes, prev, pager, next, jumper"
:current-page="pageNum"
:page-size="pageSize"
:total="total"
@current-change="handlePageChange"
@size-change="handleSizeChange" />
</el-card>
<el-dialog title="更换合同模板"
width="520px"
:visible.sync="replaceVisible">
<el-form label-width="100px">
<el-form-item label="基础模板">
<el-select v-model="replaceTemplateId" filterable>
<el-option v-for="item in baseTemplates"
:key="item.id"
:label="item.templateName || item.name"
:value="item.id" />
</el-select>
</el-form-item>
</el-form>
<span slot="footer">
<el-button @click="replaceVisible = false">取消</el-button><el-button type="primary"
:loading="replacing"
@click="confirmReplace">
确认更换
</el-button>
</span>
</el-dialog>
<el-dialog title="合同预览"
top="4vh"
width="900px"
:visible.sync="previewVisible">
<iframe v-if="previewUrl"
class="preview-frame"
title="合同预览"
:src="previewUrl" />
<el-empty v-else description="暂无预览内容" />
</el-dialog>
</div>
</template>
<script>
import {
batchInitializeTemplates,
batchReplaceTemplates,
exportContractTemplates,
exportPackageContracts,
exportProductContracts,
getBaseTemplateList,
getContractTemplateList,
getPackageContractList,
getProductContractPage,
initializePackageTemplate,
printContractTemplate,
replaceContractTemplate,
} from "@/api/contractManager";
import { normalizePage, openDownload, unwrapData } from "../migrationSupport";
export default {
name: "ContractManager",
data() {
return {
activeType: "product",
query: { templateName: "", packageCode: "" },
rows: [],
selection: [],
baseTemplates: [],
pageNum: 1,
pageSize: 20,
total: 0,
loading: false,
exporting: false,
replacing: false,
replaceVisible: false,
replaceTemplateId: "",
replaceRow: null,
previewVisible: false,
previewUrl: "",
};
},
created() {
this.loadList();
},
methods: {
getListApi() {
if (this.activeType === "package") {
return getPackageContractList;
}
if (this.activeType === "goods") {
return getContractTemplateList;
}
return getProductContractPage;
},
async loadList() {
this.loading = true;
try {
const result = normalizePage(await this.getListApi()({ ...this.query, pageNum: this.pageNum, pageSize: this.pageSize }));
this.rows = result.rows;
this.total = result.total;
} catch (error) {
this.rows = [];
this.total = 0;
this.$message.error("合同列表加载失败,请稍后重试");
} finally {
this.loading = false;
}
},
handleTypeChange() {
this.pageNum = 1;
this.selection = [];
return this.loadList();
},
handleSearch() {
this.pageNum = 1;
return this.loadList();
},
handleReset() {
this.query = { templateName: "", packageCode: "" };
return this.handleSearch();
},
handlePageChange(pageNum) {
this.pageNum = pageNum;
this.loadList();
},
handleSizeChange(pageSize) {
this.pageSize = pageSize;
this.handleSearch();
},
openEditor(row, readonly = false) {
this.$router.push({
name: "contractTemplateEdit",
query: { id: row.id, type: this.activeType, readonly: readonly ? "1" : "0" },
});
},
async batchInitialize() {
try {
await this.$confirm("确认初始化选中的合同模板吗?", "初始化确认", { type: "warning" });
const ids = this.selection.map(item => item.id);
const requestApi = this.activeType === "package" ? initializePackageTemplate : batchInitializeTemplates;
await requestApi({ ids });
this.$message.success("合同模板初始化成功");
await this.loadList();
} catch (error) {
if (error !== "cancel" && error !== "close") {
this.$message.error("合同模板初始化失败");
}
}
},
async openReplaceDialog(row = null) {
this.replaceRow = row;
this.replaceTemplateId = "";
try {
const result = unwrapData(await getBaseTemplateList({ contractType: this.activeType }));
this.baseTemplates = result.list || result || [];
this.replaceVisible = true;
} catch (error) {
this.$message.error("基础合同模板加载失败");
}
},
async confirmReplace() {
if (!this.replaceTemplateId) {
return this.$message.error("请选择基础模板");
}
this.replacing = true;
try {
const rows = this.replaceRow ? [this.replaceRow] : this.selection;
const params = { templateId: this.replaceTemplateId, ids: rows.map(item => item.id) };
const requestApi = this.replaceRow ? replaceContractTemplate : batchReplaceTemplates;
await requestApi(params);
this.$message.success("合同模板更换成功");
this.replaceVisible = false;
await this.loadList();
} catch (error) {
this.$message.error("合同模板更换失败");
} finally {
this.replacing = false;
}
},
async preview(row) {
try {
this.previewUrl = openDownload(await printContractTemplate({ id: row.id, packageCode: row.packageCode }));
this.previewVisible = true;
} catch (error) {
this.$message.error("合同预览失败");
}
},
async handleExport() {
this.exporting = true;
try {
const requestApi = this.activeType === "package"
? exportPackageContracts
: this.activeType === "goods" ? exportContractTemplates : exportProductContracts;
openDownload(await requestApi({ ...this.query }));
} catch (error) {
this.$message.error("合同导出失败");
} finally {
this.exporting = false;
}
},
},
};
</script>
<style scoped>
.simple-page {
padding: 16px;
}
.toolbar {
margin-bottom: 16px;
}
.pagination {
margin-top: 16px;
text-align: right;
}
.preview-frame {
width: 100%;
height: 72vh;
border: 0;
}
</style>