dialog.vue
15.9 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
<template>
<div>
<el-dialog :title="title" :visible.sync="open" width="25%" :close-on-click-modal="false" :show-close="false"
append-to-body center>
<el-form ref="add" :model="newDictionary" label-width="auto" label-position="left" size="small"
:rules="rules" @submit.native.prevent>
<!-- 新增虚拟航班 -->
<div v-if="dictName == '虚拟航班'">
<el-form-item label="所属口岸" prop="portName">
<el-select v-model="newDictionary.portName" placeholder="选择口岸" disabled>
<el-option v-for="item in $store.state.user.portNames" :label="item" :value="item"
:key="item">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="航班名称" v-if="status == 'allAdd'" prop="flightNo">
<el-input type="textarea" v-model="flightNo" :rows="7" maxlength="255" show-word-limit
placeholder="用;分隔,单条航班名长度25">
</el-input>
</el-form-item>
<el-form-item label="航班名称" prop="flightNo" v-else>
<el-input type="text" v-model="flightNo" placeholder="请输入数据名称" maxlength="25"></el-input>
</el-form-item>
</div>
<!-- 新增航线 -->
<div v-else-if="dictName == '航线'">
<div v-if="status == 'add'">
<el-form-item label="航班号" prop="fltNo">
<el-input type="text" v-model="newDictionary.fltNo" placeholder="请输入航班号" maxlength="20">
</el-input>
</el-form-item>
<el-form-item label="航线" prop="route">
<el-input type="text" v-model="newDictionary.route" placeholder="请输入航线" maxlength="40">
</el-input>
</el-form-item>
</div>
<div v-else-if="status == 'sort'">
<el-form-item label="航班号" prop="fltNo">
<el-input type="text" v-model="newDictionary.fltNo" disabled></el-input>
</el-form-item>
<el-form-item label="航线">
<Drag :routes="routeList" @drag="drag"></Drag>
</el-form-item>
</div>
<el-form-item>
<div style="color:#ff4949;line-height: 30px;">注意:此处不能添加虚拟航班!</div>
</el-form-item>
</div>
<!-- 新增数据字典 -->
<div v-else>
<el-form-item label="所属父级" v-if="newDictionary.serviceCodeKey">
<el-input type="text" v-model="newDictionary.serviceCodeKey" placeholder="用回车分隔" disabled>
</el-input>
</el-form-item>
<!-- 批量新增 -->
<el-form-item label="数据名称" v-if="status == 'allAdd' || status == 'childrenAdd'" prop="chineseName">
<el-input type="textarea" v-model="newDictionary.chineseName" :rows="7" maxlength="255"
show-word-limit placeholder="用回车分隔">
</el-input>
</el-form-item>
<div v-else>
<!-- 单条新增 -->
<el-form-item label="数据名称" prop="chineseName">
<el-input type="text" v-model.trim="newDictionary.chineseName" placeholder="请输入数据名称"
maxlength="50"></el-input>
</el-form-item>
<!-- <el-form-item label="字典CODE" prop="code" v-show="addDictionary.chineseName">
<el-input type="text" v-model.trim="newDictionary.code" placeholder="请输入字典CODE" disabled>
</el-input>
</el-form-item> -->
<el-form-item label="描述" prop="description">
<el-input type="textarea" v-model="newDictionary.description" :row="3" maxlength="125"
show-word-limit></el-input>
</el-form-item>
</div>
</div>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" :loading="loading" @click="submit">确 定</el-button>
<el-button @click="close">取 消</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { addDict, addDictBatch, addServiceCodeBatch, addFlight, addRoute, queryRoute, orderRoute } from '@/api/system/dictionary.js'
export default {
props: {
open: {
type: Boolean,
default: false,
},
dictName: {
type: String,
default: ''
},
addDictionary: {
type: Object,
default: null
},
status: {
type: String,
default: null
}
},
data() {
return {
newDictionary: { flightNo: undefined, chineseName: undefined, route: undefined },
rules: {
chineseName: [
{
required: true,
message: "数据名称不能为空",
trigger: "blur",
}
],
flightNo: [
{
required: true,
message: "航班名称不能为空",
trigger: "blur",
},
],
fltNo: [
{
required: true,
message: "航班号不能为空",
trigger: "blur",
}
],
route: [
{
required: true,
message: "航线不能为空",
trigger: "blur",
}
],
},
routeList: [],
title: '',
loading: false,
}
},
watch: {
open(val, oldVal) {
if (val) {
this.newDictionary = { flightNo: undefined, chineseName: undefined }
if (this.status == 'add') {
this.title = '新增'
} else if (this.status == 'allAdd') {
this.title = '批量新增'
} else if (this.status == 'childrenAdd') {
this.newDictionary = this.addDictionary
this.title = '新增子集'
} else if (this.status == 'sort') {
this.newDictionary = this.addDictionary.serviceCodeKey
this.title = '航线排序'
queryRoute({ fltNo: this.newDictionary.fltNo }).then(res => {
if (res.code === 200) {
this.routeList = res.data.list
} else {
this.msgWarning(res.msg)
}
}).catch(err => {
console.log(err)
})
}
// else if (this.status == 'update') {
// if (this.addDictionary.serviceCodeValue) {
// this.newDictionary = {
// chineseName: this.addDictionary.serviceCodeValue,
// fname: this.addDictionary.serviceCodeKey,
// code: this.addDictionary.serviceCodeValue,
// }
// } else {
// this.newDictionary = this.addDictionary
// }
// this.title = '修改'
// }
if (this.dictName == '虚拟航班') {
this.newDictionary.portName = this.$store.state.user.activePortName
}
}
},
},
methods: {
//确定
submit() {
this.$refs['add'].validate((val) => {
if (val) {
this.loading = true
this.newDictionary.dictCode = this.dictName
//新增字典
if (this.status == 'add') {
if (this.dictName === '虚拟航班') {
this.flightAdd()
} else if (this.dictName === '航线') {
let obj = {
fltNo: this.upCase(this.newDictionary.fltNo),
route: this.upCase(this.newDictionary.route)
}
addRoute(obj).then(res => {
this.loading = false
if (res.code === 200) {
this.msgSuccess(res.msg)
this.close()
} else {
this.msgWarning(res.msg)
}
}).catch(err => {
this.loading = false
console.log(err)
})
} else {
addDict(this.newDictionary).then(res => {
this.loading = false
if (res.code === 200) {
this.msgSuccess(res.msg)
this.close()
} else {
this.msgWarning(res.msg)
}
}).catch(err => {
this.loading = false
console.log(err)
})
}
}
//批量新增
else if (this.status == 'allAdd') {
if (this.dictName === '虚拟航班') {
this.flightAdd()
} else {
let obj = {
nameList: [],
dictCode: this.dictName
}
this.newDictionary.chineseName.split("\n").forEach(item => {
if (item != null && item != undefined && item != '') {
obj.nameList.push(item)
}
})
addDictBatch(obj).then(res => {
this.loading = false
if (res.code === 200) {
this.msgSuccess(res.msg)
this.close()
} else {
this.msgWarning(res.msg)
}
}).catch(err => {
this.loading = false
console.log(err)
})
}
}
//新增子集
else if (this.status == 'childrenAdd') {
let arr = []
this.newDictionary.chineseName.split("\n").forEach(item => {
arr.push({
serviceCodeKey: this.newDictionary.serviceCodeKey,
serviceCodeValue: item
})
})
addServiceCodeBatch(arr).then(res => {
this.loading = false
if (res.code === 200) {
this.msgSuccess(res.msg)
this.close()
} else {
this.msgWarning(res.msg)
}
}).catch(err => {
this.loading = false
console.log(err)
})
}
//航线排序
else if (this.status == 'sort') {
let arr = []
this.routeList.forEach(item => {
arr.push(item.id)
})
orderRoute(arr).then(res => {
this.loading = false
if (res.code === 200) {
this.msgSuccess(res.msg)
this.close()
} else {
this.msgWarning(res.msg)
}
}).catch(err => {
this.loading = false
console.log(err)
})
}
}
})
},
//新增虚拟航班
flightAdd() {
let flightNo = []
flightNo = this.newDictionary.flightNo.toUpperCase().split(';')
addFlight(flightNo).then(res => {
this.loading = false
if (res.code === 200) {
this.msgSuccess(res.msg)
this.close()
} else {
this.msgWarning(res.msg)
}
}).catch(err => {
this.loading = false
console.log(err)
})
},
//航线排序
drag(val) {
this.routeList = val
},
//关闭
close() {
this.newDictionary = { chineseName: null, code: null, remark: null }
this.routeList = []
this.clearValidate('add')
this.$emit('close', false)
},
//清除表单验证
clearValidate(formName) {
this.$refs[formName].clearValidate();
},
},
computed: {
chineseName: {
get: function () {
return this.newDictionary.chineseName
},
set: function (val) {
const reg = /^([a-zA-Z0-9]{0,25}(\n[a-zA-Z0-9]{0,25})*)$/
if (reg.test(val)) {
this.newDictionary.chineseName = val
}
},
},
flightNo: {
get: function () {
return this.newDictionary.flightNo
},
set: function (val) {
const reg = /^([a-zA-Z0-9]{0,25}(\;[a-zA-Z0-9]{0,25})*)$/
if (reg.test(val)) {
this.newDictionary.flightNo = val
}
},
},
fltNo: {
get: function () {
return this.newDictionary.fltNo
},
set: function (val) {
this.newDictionary.fltNo = this.upCase(val)
},
},
route: {
get: function () {
return this.newDictionary.route
},
set: function (val) {
const reg = /^([0-9a-zA-Z!@#$%^&*()`]{0,100})$/
if (reg.test(val)) {
this.newDictionary.route = val
}
},
}
}
}
</script>
<style>
</style>