index.vue
11.3 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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
<template>
<div class="system-container">
<div class="orginiza-container">
<search-form
class="searchTop border-shadow"
:formModel="searchForm"
:formList="orginizaFormList"
>
<span
class="inline-b"
slot="form-slot"
>
<el-button
type="primary"
:size="btn_size"
icon="el-icon-search"
@click="search"
>搜索</el-button>
<el-button
type="primary"
:size="btn_size"
icon="el-icon-refresh"
@click="refresh"
>重置</el-button>
</span>
</search-form>
<h3>组织管理
<div class="pull-right">
<el-button
type="primary"
:size="btn_size"
icon="el-icon-plus"
@click="btnClick('root')"
>新增根组织</el-button>
</div>
</h3>
<el-table
ref="table"
:data="orginTableData"
style="width: 100%"
row-key="id"
highlight-current-row
lazy
stripe
:load="load"
:row-style="tableRowClassName"
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
>
<el-table-column
v-for="(item,index) in listHeadData"
:key="index"
:prop="item.prop"
:sortable="item.sortable"
:ref="item.ref"
:width="item.width"
:label="item.label"
show-overflow-tooltip
>
<template slot-scope="scope">
<template v-if="item.prop === 'enableStatus'">
<span
class="dot"
:class="scope.row.enableStatus ? ORGINIZASTATUS[scope.row.enableStatus].split(',')[1] : ''"
></span>
<span class="statusText">{{ scope.row.enableStatus ? ORGINIZASTATUS[scope.row.enableStatus].split(',')[0] : '--'}}</span>
</template>
<template v-else>
{{scope.row[item.prop]?scope.row[item.prop]:'--'}}
</template>
</template>
</el-table-column>
<el-table-column
align="center"
width="250"
fixed="right"
prop="btn"
label="操作"
>
<template slot-scope="scope">
<el-button
v-for="(j, idx) in tableParams.tableOption.btnList"
:key="idx"
:type="j.type || 'text'"
:size="btn_size"
@click="btnClick(j.pType, scope.row)"
>{{j.name}}</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="page.pageNum"
:page-sizes="[10,20,30,40]"
:page-size="page.pageSize"
:total="total"
layout="sizes,total,->,prev,pager,next,jumper"
>
</el-pagination>
<basic-dialog
:title="orginizaDialogTitle"
:isVisible="orginizaVisible"
@confirmDialog="handleConfirm"
@closeDialog="handleClose"
>
<slot>
<rule-form
:ruleForm="orginizaForm"
:rules="orginizaRules"
:ruleData="orginizaData"
ref='orginizaForm'
></rule-form>
</slot>
</basic-dialog>
</div>
</div>
</template>
<script>
import _ from 'lodash'
import { getTableList, getChildren, addOrganiza, editOrganiza, deleteOrganiza, organizaInfo } from 'services/orginizaManage'
export default {
data() {
return {
ORGINIZASTATUS: this.$Constants.ORGINIZA_STATUS,
searchForm: {},
orginizaFormList: [
{
type: 'input',
inputType: 'text',
prop: 'orgName',
placeholder: '请输入组织名称'
},
{
type: 'select',
prop: 'enableStatus',
placeholder: '请选择组织状态',
options: [{
value: '1',
label: '正常'
}, {
value: '2',
label: '停用'
}]
}
],
orginTableData: [],
listHeadData: [ // 列表 头部设置 数据
{ prop: 'departmentName', label: '组织名称', width: 300 },
{ prop: 'orderNum', label: '排序' },
{ prop: 'enableStatus', label: '状态' },
{ prop: 'createdDate', label: '创建时间' }
],
page: {
pageSize: 10,
pageNumber: 1
},
total: 10,
tableParams: {
tableOption: {
btnList: [
{
name: '新增',
pType: 'create'
},
{
name: '编辑',
pType: 'edit'
},
{
name: '删除',
pType: 'delete'
}
]
}
},
// 弹窗数据
orginizaDialogTitle: '新增组织',
orginizaVisible: false,
orginizaForm: {
superiorName: '',
enableStatus: true
},
form: {
enableStatus: true
},
orginizaData: [
{ label: '上级组织:', prop: 'superiorName', type: 'input', hidden: false, readonly: true },
{ label: '组织名称:', prop: 'departmentName', type: 'input', maxlength: 20 },
{ label: '显示排序:', prop: 'orderNum', type: 'input', maxlength: 5 },
{ label: '组织状态:', prop: 'enableStatus', type: 'switch' }
],
orginizaRules: {
departmentName: [{ required: true, message: '请输入组织名称', trigger: 'blur' }],
orderNum: [{ required: true, message: '请输入显示排序', trigger: 'blur' },
{ validator: this.$Common.checkRegExpNumber, trigger: 'blur' }],
enableStatus: [{ required: true }]
},
// 部门弹窗
isRoot: false
}
},
watch: {
filterText(val) {
this.$refs.tree.filter(val)
}
},
mounted() {
this.search()
},
methods: {
search() {
let params = Object.assign({}, this.searchForm, this.page)
this.getList(params)
},
// 重置搜索条件
refresh() {
this.searchForm = {}
this.search()
},
emptyData(params) {
let arr = params
for (let key in arr) {
if (params[key] == null || params[key] == '' || params[key] == []) {
delete params[key]
}
}
return arr
},
// 确定,新增组织、编辑组织
handleConfirm() {
this.$refs.orginizaForm.$children[0].validate((valid) => {
if (valid) {
let params = {
departmentName: this.orginizaForm.departmentName,
enableStatus: this.orginizaForm.enableStatus ? 1 : 2,
orderNum: this.orginizaForm.orderNum
}
if (this.orginizaForm.superiorId) params.superiorId = this.orginizaForm.superiorId
let api = addOrganiza
if (this.orginizaForm.id) {
api = editOrganiza
params.id = this.orginizaForm.id
}
api(params).then(res => {
if (res.code = 200) {
this.$message({
type: 'success',
message: '操作成功'
})
if (this.isRoot) {
this.search()
} else {
getChildren({ rootId: params.superiorId }).then(res => {
const nodes = res.data
this.$set(this.$refs.table.store.states.lazyTreeNodeMap, params.superiorId, nodes)
})
}
this.handleClose()
} else {
this.$message({
type: 'error',
message: res.message
})
}
})
}
})
},
// 取消
handleClose() {
if (!this.orginizaVisible && this.$refs.orginizaForm) {
this.$refs.orginizaForm.$children[0].resetFields()
}
this.orginizaVisible = !this.orginizaVisible
},
// 按钮事件
btnClick(pType, scope) {
switch (pType) {
case 'root':
this.isRoot = true
this.orginizaData[0].hidden = true
this.orginizaForm = {
enableStatus: true
}
this.orginizaDialogTitle = '新增根组织'
this.handleClose()
break
case 'create':
this.isRoot = false
this.orginizaData[0].hidden = false
const obj = {
superiorId: scope.id,
superiorName: scope.departmentName,
enableStatus: true
}
this.orginizaForm = obj
this.orginizaDialogTitle = '新增组织'
this.handleClose()
break
case 'edit':
this.orginizaDialogTitle = '编辑组织'
this.editEvent(scope)
break
case 'delete':
organizaInfo({ id: scope.id }).then(res => {
this.deleteEvent(res.data)
})
break
}
},
// 编辑触发事件
editEvent(row) {
organizaInfo({ id: row.id }).then(res => {
this.orginizaForm = _.cloneDeep(res.data)
this.orginizaForm.enableStatus = row.enableStatus == 1 ? true : false
if (!this.orginizaForm.superiorId) {
this.orginizaData[0].hidden = true
this.isRoot = true
} else {
this.isRoot = false
}
this.handleClose()
})
},
// 删除触发事件
deleteEvent(row) {
const that = this
const tipData = {
that: that,
tipText: '是否删除当前记录',
tipTitle: '提示',
type: 'error',
callBack: () => {
deleteOrganiza({ id: row.id }).then(res => {
if (res.code == 200) {
this.$message({
type: 'success',
message: '删除成功!'
})
if (!row.superiorId) {
this.search()
} else {
getChildren({ rootId: row.superiorId }).then(res => {
const nodes = res.data
this.$set(this.$refs.table.store.states.lazyTreeNodeMap, row.superiorId, nodes)
})
}
} else {
this.$message({
type: 'error',
message: res.message
})
}
})
}
}
this.$Common.confirmDialog(tipData)
},
// 树形table懒加载
load(tree, treeNode, resolve) {
console.log(tree, treeNode, resolve)
getChildren({ rootId: tree.id }).then(res => {
let nodes = res.data
resolve(nodes)
})
},
// 获取根节点列表
getList(params) {
getTableList(params).then((res) => {
if (res.code == 200) {
this.total = res.data.totalElements
this.orginTableData = res.data.list
} else {
this.orginTableData = []
}
})
},
// 子节点列表
getChildren(id) {
getChildren({ rootId: id }).then(res => {
return res.data
})
},
// 页码
handleSizeChange(value) {
this.page.pageSize = value
this.search()
},
handleCurrentChange(value) {
this.page.pageNumber = value
this.search()
},
tableRowClassName() {
return 'padding-left: 16px;'
}
}
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
</style>