index.vue
8.44 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
<template>
<div class="system-container">
<div class="user-container">
<search-form
class="searchTop border-shadow"
:formModel="searchForm"
:formList="dictDataFormList"
>
<slot name="form-slot">
<el-button
type="primary"
:size="btn_size"
icon="el-icon-search"
:id="tableParams.btnId"
>搜索</el-button>
<el-button
type="primary"
:size="btn_size"
icon="el-icon-refresh"
@click="refresh"
>重置</el-button>
</slot>
</search-form>
<div class="table-btn">
<el-button
type="primary"
:size="btn_size"
icon="el-icon-plus"
@click="btnClick('create')"
>新增</el-button>
</div>
<basic-table
:tableParams="tableParams"
:getListApi="getListApi"
:beforeSearchFn="beforeSearchFn"
:searchForm="searchForm"
:hasNum="true"
ref="dictDataTable"
>
<span
slot="status"
slot-scope="scope"
>
<span
class="dot"
:class="scope.scope.enableStatus ? DICTSTATUS[scope.scope.enableStatus].split(',')[1] : ''"
></span><span class="statusText">{{ scope.scope.enableStatus ? DICTSTATUS[scope.scope.enableStatus].split(',')[0] : '--'}}</span>
</span>
<span
slot="table-button"
slot-scope="scope"
>
<el-button
v-for="(j, idx) in tableParams.tableOption.btnList"
:key="idx"
:type="j.type"
size="mini"
plain
@click="btnClick(j.pType, scope.scope)"
>{{j.name}}</el-button>
</span>
</basic-table>
<basic-dialog
:title="dictDataDialogTitle"
:isVisible="dictDataVisible"
@confirmDialog="handleConfirm"
@closeDialog="handleClose"
>
<slot>
<rule-form
:ruleForm="dictDataForm"
:rules="dictDataRules"
:ruleData="dictDataData"
ref='dictDataForm'
></rule-form>
</slot>
</basic-dialog>
</div>
</div>
</template>
<script>
import { getDictDataList, addDictData, editDictData, deleteDictData, exportDictData } from 'services/dictionary';
export default {
data() {
return {
DICTSTATUS: this.$Constants.DICT_STATUS,
searchForm: {
name: ''
},
dictDataFormList: [
{
type: 'input',
inputType: 'text',
prop: 'name',
readonly: true,
placeholder: '请输入字典名称'
},
{
type: 'input',
inputType: 'text',
prop: 'tag',
placeholder: '请输入字典标签'
},
{
type: 'select',
prop: 'status',
placeholder: '请选择字典状态',
options: [
{
label: '正常',
value: 1
}, {
label: '停用',
value: 2
}
]
}
],
tableParams: {
numName: '字典编码',
mutiSelectName: 'dictDataData',
mutiSelectUniqueKey: 'id',
btnId: new Date().getTime() + parseInt(Math.random() * 1000),
listName: 'list',
tableColumns: [
{
// label: '字典编码',
// prop: 'id'
// }, {
label: '字典标签',
prop: 'dictLabel'
}, {
label: '字典键值',
prop: 'dictValue'
}, {
label: '字典排序',
prop: 'dictSort'
}, {
label: '备注',
prop: 'remark'
}, {
label: '字典状态',
prop: 'enableStatus',
addHtml: 'status'
}, {
label: '创建时间',
prop: 'createdDate'
}
],
tableOption: {
width: 200,
btnList: [
{
type: 'primary',
name: '编辑',
pType: 'edit'
},
{
type: 'danger',
name: '删除',
pType: 'delete'
}
]
}
},
getListApi: getDictDataList,
// 弹窗
dictDataDialogTitle: '新增字典',
dictDataVisible: false,
dictDataForm: {
enableStatus: true
},
dictDataData: [
{ label: '字典类型:', prop: 'dictType', type: 'input', readonly: true },
{ label: '字典标签:', prop: 'dictLabel', type: 'input' },
// { label: '字典编码:', prop: 'id', type: 'input', readonly: true },
{ label: '字典键值:', prop: 'dictValue', type: 'input' },
{ label: '字典顺序:', prop: 'dictSort', type: 'input' },
{ label: '状态', prop: 'enableStatus', type: 'switch' },
{ label: '备注', prop: 'remark', type: 'input', inputText: 'textarea' }
],
dictDataRules: {
dictType: [{ required: true }],
dictLabel: [{ required: true, message: '请输入字典标签', trigger: 'blur' }],
// id: [{ required: true }],
dictValue: [{ required: true, message: '请输入字典键值', trigger: 'blur' }],
dictSort: [{ required: true, message: '请输入字典顺序', trigger: 'blur' }],
enableStatus: [{ required: true }]
}
}
},
mounted() {
console.log(this.$route.params)
this.searchForm.name = this.$route.params.row.dictName
this.dictDataForm.dictType = this.$route.params.row.dictType
},
methods: {
// 重置搜索条件
refresh() {
this.searchForm = {
name: this.$route.params.row.dictName
}
},
beforeSearchFn() {
return new Promise((resolve, reject) => {
this.searchForm.type = this.$route.params.row.dictType
console.log(this.searchForm)
resolve()
})
},
// 确定
handleConfirm() {
this.$refs.dictDataForm.$children[0].validate((valid) => {
if (valid) {
let params = JSON.parse(JSON.stringify(this.dictDataForm))
params.enableStatus = this.dictDataForm.enableStatus ? 1 : 2
console.log(params)
let api = addDictData
if (params.id) {
api = editDictData
}
api(params).then(res => {
console.log(res)
if (res.code = 200) {
this.$message({
type: 'success',
message: '操作成功!'
})
this.handleClose()
this.$refs.dictDataTable.refreshTable()
} else {
this.$message(res.message)
}
})
} else {
console.log('error')
}
})
},
// 取消
handleClose() {
if (!this.dictDataVisible && this.$refs.dictDataForm) {
this.$refs.dictDataForm.$children[0].resetFields()
}
this.dictDataVisible = !this.dictDataVisible
},
// 按钮事件
btnClick(pType, scope) {
console.log(pType, scope)
switch (pType) {
case 'create':
this.handleClose()
break
case 'edit':
this.editEvent(scope)
break
case 'delete':
this.deleteEvent(scope.id)
break
case 'list':
console.log('list')
break
}
},
// 编辑触发事件
editEvent(row) {
console.log(row, '------------')
this.dictDataForm = JSON.parse(JSON.stringify(row))
this.dictDataForm.enableStatus = row.enableStatus == 1 ? true : false
delete this.dictDataForm.createdDate
delete this.dictDataForm.isDefault
this.handleClose()
},
// 删除触发事件
deleteEvent(id) {
const that = this
const tipData = {
that: that,
tipText: '是否删除当前记录',
tipTitle: '提示',
type: 'error',
callBack: () => {
const params = {
dataId: id
}
deleteDictData(params).then(res => {
if (res.code == 200) {
this.$message({
type: 'success',
message: '删除成功!'
})
this.$refs.dictDataTable.refreshTable()
} else {
this.$message(res.message)
}
})
}
}
this.$Common.confirmDialog(tipData)
}
}
}
</script>