MessageManagement.vue
17.2 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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<template>
<el-container>
<el-main>
<el-card style="background-color: #F5F7FA">
<!-- 搜素区域 -->
<el-row>
<el-col :span="6">
<el-input placeholder="请输入内容" v-model="queryInfo.name" size="medium">
<template slot="prepend"><i class="el-icon-notebook-2"></i>消息标签</template>
</el-input>
</el-col>
<el-col :span="6" align="center" style="margin-left: 10px">
<el-input placeholder="请输入内容" v-model="queryInfo.des" size="medium">
<template slot="prepend"><i class="el-icon-notebook-2"></i>描述</template>
</el-input>
</el-col>
<el-col :span="6" align="center">
<el-button type="warning" size="medium" icon="el-icon-search" @click="getList">
查询标签
</el-button>
<el-button type="primary" size="medium" icon="el-icon-plus" @click="handleAdd">
添加标签
</el-button>
</el-col>
</el-row>
<!-- 列表区域 -->
<el-row style="margin-top: 20px;">
<el-row>
<el-col :span="24">
<el-table
:data="page.tableData"
border size="small" row-key="id" default-expand-all
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
:header-cell-style="{background:'#6F8294',color:'#FFFFFF'}"
style="border-radius: 10px 10px 0px 0px;line-height: 25px;"
@selection-change="selsChange" >
<el-table-column type="selection" width="55" align="center"></el-table-column>
<el-table-column type="index" prop="id" label="ID" align="center" width="55"></el-table-column>
<el-table-column label="消息标签" prop="name" align="center" width="220"></el-table-column>
<el-table-column label="消息类型" prop="type" :formatter="formatType" align="center" width="220"></el-table-column>
<el-table-column label="相关描述" prop="des" align="center" width="220"></el-table-column>
<el-table-column label="创建时间" prop="creattime" align="center" width="220"></el-table-column>
<el-table-column label="操作" width="300px" align="center" fixed="right">
<template slot-scope="scope">
<!-- 新增下级-->
<el-tooltip effect="dark" content="新增" placement="top-start" :enterable="false">
<el-button type="success" icon="el-icon-plus" size="mini"@click="handleAdd(scope.$index, scope.row)">新增下级
</el-button>
</el-tooltip>
<!-- 编辑按钮-->
<el-tooltip effect="dark" content="编辑" placement="top-start" :enterable="false">
<el-button type="primary" icon="el-icon-edit" size="mini" @click="handleEdit(scope.$index, scope.row)">编辑
</el-button>
</el-tooltip>
<!-- 删除按钮-->
<el-tooltip effect="dark" content="删除" placement="top-start" :enterable="false">
<el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDel(scope.$index, scope.row)">删除
</el-button>
</el-tooltip>
</template>
</el-table-column>
</el-table>
</el-col>
</el-row>
</el-row>
<el-row style="margin-top: 10px">
<el-col :span="5">
<el-button type="danger" icon="el-icon-delete" :disabled="this.selectList.length === 0" @click="batchRemove"
>批量删除
</el-button>
</el-col>
<el-col :span="10" style="margin-top: 5px">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="queryInfo.pageNum"
:page-sizes="[10,50,200,500]"
:page-size="queryInfo.pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="page.total">
</el-pagination>
</el-col>
</el-row>
<!-- 新增界面,对话框区域 -->
<el-row>
<el-dialog :title="dialogMap[dialogStatus]" :visible.sync="dialogFormVisible" style="margin-top: -50px" width="45%" >
<el-form :model="addForm" :rules="addFormRules" ref="addForm" label-width="120px" >
<el-form-item v-if="this.demoName == true" label="上级标签" style="width:300px" prop="parentId">
<span>{{addForm.parentName}}</span>
</el-form-item>
<el-form-item v-else style="display: none" label="上级标签" prop="parentId">
<span>{{addForm.parentName}}</span>
</el-form-item>
<el-form-item label="" prop="name">
<el-input placeholder="请输入内容" v-model="addForm.name" style="width:300px" size="medium">
<template slot="prepend" >消息标签</template>
</el-input>
</el-form-item>
<el-form-item label="" prop="type" >
<el-select v-model="addForm.type" placeholder="请选择消息分类"
:disabled="selectDisabled" name='test' id='test' style="width:300px">
<el-option
v-for="item in options"
:key="item.value"
:disabled="item.value == 1"
:label="item.label"
:value="item.value">
<span style="float: left">{{ item.label }}</span>
<span style="float: right; color: #8492a6; font-size: 13px">{{ item.value }}</span>
</el-option>
</el-select>
</el-form-item>
<el-form-item label="" prop="des">
<el-input placeholder="请输入内容" v-model="addForm.des" size="medium" style="width:300px">
<template slot="prepend" >描述</template>
</el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer" align="center">
<el-button type="info" @click="dialogFormVisible = false" size="medium"
style="width: 100px;background-color: #6F8294;color: #ffffff">取 消</el-button>
<el-button type="primary" size="medium" style="width: 100px" @click="dialogStatus==='create'?addList():editList()">提 交</el-button>
</div>
</el-dialog>
</el-row>
</el-card>
</el-main>
</el-container>
</template>
<script>
import {getTypesPage, addType,updateMessage,deleteMessage,batchDelete} from "../../api/message_bus";
import util from "../../common/js/util";
export default {
name: 'MessageManagement',
data() {
return {
queryInfo: {
// 消息标签
name: '',
// 当前页数
pageNum: 1,
// 每页条数
pageSize: 10,
},
page: {
total: 0,
tableData: [],
},
//选中的行
selectList: [],
dialogFormVisible: false,
addForm: {
name: '',
des: '',
type:'',
parentId:''
},
selectDisabled: false,
dialogMap: {
update: '编辑',
create: '新增',
},
dialogStatus: 'create',
demoName: false,
options: [{
label: "消息分类",
value: 1
},{
label: "消息大类",
value: 2
},{
label: "消息子类",
value: 3
}],
addFormRules: {
name: [
{ required: true, message: '请输入消息标签', trigger: 'blur' }
],
type: [
{ required: true, message: '请选择上级标签', trigger: 'blur' }
]
},
}
},
methods: {
// 类型转换
formatType: function (row, column) {
return row.type == 1 ? '消息分类' : row.type == 2 ? '消息大类' : '消息子类';
},
handleSizeChange(newSize) {
this.queryInfo.pageSize = newSize;
this.getList();
},
handleCurrentChange(newPage) {
this.queryInfo.pageNum = newPage;
this.getList();
},
searchSubmit:function () {
this.queryInfo.pageNum = 1;
this.queryInfo.pageSize = 10;
this.getList();
} ,
// 获取消息标签列表
getList() {
let _this = this;
getTypesPage(this.queryInfo).then((response) => {
let res = response.data;
if (res.code !== '200') {
return _this.$message.error('获取消息收发记录,失败!');
}
// 获取列表数据
_this.page.tableData = res.data.list;
// 获取列表的总记录数
_this.page.total = res.data.total;
_this.$message.success('获取消息收发记录,成功!');
}).catch(error => {
// 关闭加载
_this.$message.error(error.toString());
});
},
//显示添加标签界面
handleAdd: function (index,row) {
this.dialogFormVisible = true;
this.dialogStatus= 'create';
this.addForm.type = 1;
//消息分类禁选
this.selectDisabled = true;
//上级标签隐藏
if (this.$refs.addForm != undefined){
if (row != undefined){
this.demoName = true;
}else {
this.demoName = false;
}
this.$refs.addForm.resetFields();
}
//新增下级
if(util.checkNull(row)){
//传递上级ID
let parentId = Object.assign({}, row);
this.addForm.parentId = parentId.id;
this.addForm.parentName = parentId.name;
this.selectDisabled = false;
this.addForm.type = 2;
if(this.$refs.parent[type] = 2){
this.addForm.child[type] = 3;
}
}
//数据初始化
// this.addForm = {
// name: '',
// des: '',
// type:'' };
},
//提交添加的消息标签
addList: function () {
this.$refs.addForm.validate((valid) => {
if (valid) {
this.$confirm('确认提交吗?', '提示', {}).then(() => {
let para = Object.assign({}, this.addForm);
addType(para).then((res) => {
this.$message({
message: res.data.msg,
type: 'success'
});
//数据初始化
this.$refs['addForm'].resetFields();
this.dialogFormVisible = false;
this.getList();
}).catch(error => alert(error));
});
}
});
},
//删除
handleDel: function (index, row) {
this.$confirm('确认删除该记录吗?', '提示', {
type: 'warning'
}).then(() => {
//let para = { id: row.id };
//console.log(row);
deleteMessage(row).then((res) => {
this.$message({
message: '删除成功',
type: 'success'
});
this.getList();
}).catch((error) => {
alert(error);
});
}).catch();
},
//批量选中
selsChange: function (selected) {
let _this= this;
selected.forEach(
function (row,index) {
_this.selectList.push(row.id);
}
);
},
//批量删除
batchRemove: function () {
//取 选中 多条信息 的id 赋给ids
this.$confirm('确认删除选中记录吗?', '提示', {
type: 'warning'
}).then(() => {
batchDelete(this.selectList).then((res) => {
this.$message({
message: '删除成功',
type: 'success'
});
this.getList();
});
}).catch(() => {
});
},
//显示编辑界面
handleEdit: function (index, row) {
this.dialogFormVisible = true;
this.demoName = false;
this.dialogStatus= 'update',
this.addForm = Object.assign({}, row);
//消息分类禁选
this.selectDisabled = true;
if (this.$refs.addForm != undefined){
if (row != undefined){
this.demoName = true;
}else {
this.demoName = false;
}
this.$refs.addForm.resetFields();
}
},
//编辑
editList: function () {
this.$refs.addForm.validate((valid) => {
if (valid) {
this.$confirm('确认提交吗?', '提示', {}).then(() => {
let para = Object.assign({}, this.addForm);
updateMessage(para).then((res) => {
this.$message({
message: '提交成功',
type: 'success'
});
this.$refs['addForm'].resetFields();
this.dialogFormVisible = false;
this.getList();
}).catch(error => alert(error));
});
}
});
},
}
}
</script>
<style>
</style>