TemplateCtrlFieldDialog.vue
22.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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
<template>
<el-dialog
title="控件设置"
:visible.sync="dialogVisible"
width="60%"
appendToBody
:close-on-click-modal="false"
:before-close="handleClose"
>
<el-form v-model="ctrlFiled" data-vv-scope="ctrlFieldForm">
<table class="form-table" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<th width="15%">字段描述:</th>
<td width="35%">
<span>{{ ctrlFiled.name }}</span>
</td>
<th width="15%">字段名称:</th>
<td width="35%">
<span>{{ ctrlFiled.cm }}</span>
</td>
</tr>
<tr>
<th width="15%">字段类型:</th>
<td width="35%">
<span>{{ ctrlFiled.ty }}</span>
</td>
<th width="15%">控件类型:</th>
<td width="35%">
<span v-if="ctrlFiled.ct == 'select'">下拉选项</span>
<span v-if="ctrlFiled.ct == 'radio'"
>单选按钮
<el-tooltip
class="item"
effect="dark"
content="超过两个选项建议使用下拉框或自定义对话框控件"
placement="top"
>
<i class="el-icon-info"></i> </el-tooltip
></span>
<span v-if="ctrlFiled.ct == 'customDialog'">自定义对话框</span>
</td>
</tr>
<tr v-if="ctrlFiled.ct != 'customDialog'">
<th width="15%">
<div v-if="ctrlFiled.ct == 'select'">下拉选项</div>
<div v-if="ctrlFiled.ct == 'radio'">单选按钮选项</div>
</th>
<td width="100%" colspan="3">
<ht-form-item
customColon
label="选项配置"
label-width="100px"
style="margin-bottom: 0px; margin-right: 0px"
>
<el-radio-group
@change="dynamicClick"
v-model="ctrlFiled.option.choiceType"
size="mini"
class="btn-radio"
style="float: right"
>
<el-radio-button label="static">固定选项</el-radio-button>
<el-radio-button
label="dynamic"
v-if="ctrlFiled.ct != 'radio'"
>动态选项</el-radio-button
>
</el-radio-group>
</ht-form-item>
<div v-if="ctrlFiled.option.choiceType == 'static'">
<table class="table-list custom_condition_tab table">
<tbody>
<tr>
<th colspan="3">
<el-button
@click="addControlContent"
type="primary"
size="mini"
style="float: left"
icon="el-icon-plus"
>添加</el-button
>
</th>
</tr>
<tr
class="trSet"
v-for="(item, index) in controlContentArray"
:key="index"
>
<td>
值:
<ht-input
v-model="item.key"
:validate="{required: true}"
:maxlength="50"
:showWordLimit="true"
></ht-input>
</td>
<td>
选项:
<ht-input
v-model="item.value"
:validate="{required: true}"
:maxlength="50"
:showWordLimit="true"
></ht-input>
</td>
<td>
<el-button
@click="sort(index, 'down')"
size="small"
icon="el-icon-arrow-down"
plain
></el-button>
<el-button
@click="sort(index, 'up')"
size="small"
icon="el-icon-arrow-up"
plain
></el-button>
<el-button
@click="remove(index)"
size="small"
icon="el-icon-delete"
plain
></el-button>
</td>
</tr>
</tbody>
</table>
</div>
<div
v-if="ctrlFiled.option.choiceType == 'dynamic'"
class="customQuery-inputs"
>
<ht-load-data
:url="customQueryUrl"
requestMethod="post"
context="form"
@after-load-data="afterCustomQueryLoadData"
></ht-load-data>
<ht-select
clearable
filterable
@change="setCurrentCustomQuery()"
v-model="ctrlFiled.option.customQuery.alias"
:options="customQuerys"
:props="{key: 'alias', value: 'name'}"
style="margin-bottom: 14px;"
/>
<ht-form-item
label
label-width
v-if="
ctrlFiled.option.bind && ctrlFiled.option.bind.length > 0
"
class="choiceType-bottom"
>
<template slot="label">
<el-tooltip content="自定义查询需要的参数传入">
<i class="property-tip icon-question" />
</el-tooltip>
<span>参数绑定</span>
</template>
<div class="customQuery-box">
<ht-form-item
:label="bind.comment"
label-width="100px"
class="customQuery-select"
v-for="(bind, index) in ctrlFiled.option.bind"
:key="index"
>
<el-select
clearable
style="width: 100%"
v-model="bind.fieldPath"
placeholder="请选择"
>
<el-option
v-for="item in conditionFields.filter(
field => field.na != ctrlFiled.name
)"
:key="item.value"
:label="item.cm"
:value="item.value"
>
</el-option>
</el-select>
</ht-form-item>
</div>
</ht-form-item>
<ht-form-item label label-width class="choiceType-bottom">
<template slot="label">
<el-tooltip content="返回值作为选项时的绑定">
<i class="property-tip icon-question" />
</el-tooltip>
<span>选项绑定</span>
</template>
<div class="customQuery-inputs-box">
<ht-form-item
label="值"
label-width="100px"
class="customQuery-inputs"
>
<ht-select
clearable
style="width: 100%"
v-model="ctrlFiled.option.customQuery.valueBind"
:options="ctrlFiled.option.customQuery.resultfield"
:props="{key: 'field', value: 'comment'}"
/>
</ht-form-item>
<ht-form-item
label="标签"
label-width="100px"
class="customQuery-inputs"
>
<ht-select
clearable
style="width: 100%"
v-model="ctrlFiled.option.customQuery.labelBind"
:options="ctrlFiled.option.customQuery.resultfield"
:props="{key: 'field', value: 'comment'}"
/>
</ht-form-item>
</div>
</ht-form-item>
</div>
</td>
</tr>
<tr v-if="ctrlFiled.ct == 'customDialog'">
<th width="15%">自定义对话框:</th>
<td width="35%">
<ht-select
@change="changeDialog"
v-model="controlContentObject.alias"
:options="customDialogs"
:validate="{required: true}"
/>
<el-button
size="small"
style="margin-left: 5px;"
icon="el-icon-refresh"
@click="changeDialog('refresh')"
></el-button>
</td>
<th width="15%">显示字段:</th>
<td width="35%">
<ht-select
v-model="controlContentObject.resultField"
@change="changeResultField"
:validate="{required: true}"
:options="custDialogFields"
/>
</td>
</tr>
<tr
v-if="ctrlFiled.ct == 'customDialog' && custDialogFields.length > 0"
>
<th width="15%">返回字段:</th>
<td colspan="3">
<table
class="form-table"
cellspacing="0"
cellpadding="0"
border="0"
>
<tbody>
<tr class="linkageTable-tr">
<td width="40.9%;">返回结果字段</td>
<td>绑定显示的属性</td>
</tr>
<tr
class="linkageTable-tr"
v-for="(field, index) in custDialogFields"
:key="index"
>
<td>{{ field.value }}</td>
<td>
<el-select
clearable
v-model="custDialogprop[field.value]"
placeholder="请选择"
>
<el-option
v-for="item in conditionFields.filter(
field => field.na != ctrlFiled.name
)"
:key="item.value"
:label="item.cm"
:value="item.value"
>
</el-option>
</el-select>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr
v-if="
ctrlFiled.ct == 'customDialog' &&
conditionfield &&
conditionfield.length > 0
"
>
<th width="15%">列表参数绑定:</th>
<td colspan="3">
<table
class="form-table custDialog-table"
cellspacing="0"
cellpadding="0"
border="0"
>
<tbody>
<tr class="linkageTable-tr">
<td width="40.9%;">参数名</td>
<td>取值对象</td>
</tr>
<tr
class="linkageTable-tr"
v-for="(condition, indexCondition) in conditionfield"
:key="indexCondition"
>
<td>{{ condition.comment }}</td>
<td>
<el-select
clearable
v-model="condition.bind"
placeholder="请选择"
>
<el-option
v-for="item in conditionFields.filter(
field => field.na != ctrlFiled.name
)"
:key="item.value"
:label="item.cm"
:value="`data.searchForm.${item.value}`"
>
</el-option>
</el-select>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取 消</el-button>
<el-button type="primary" @click="onConfirm">确 定</el-button>
</span>
</el-dialog>
</template>
<script>
import form from '@/api/form.js'
import cloneDeep from '@/utils/cloneDeep'
import utils from 'hotent-ui/src/utils.js'
export default {
name: 'template-ctrl-field-dialog',
components: {},
props: {},
data() {
return {
ctrlFiled: {},
controlContentObject: {},
controlContentArray: [],
customDialogs: [],
custDialogFields: [],
dialogVisible: false,
conditionFields: [],
conditionfield: [],
customQuerys: [],
customQueryUrl: '/form/customQuery/v1/list',
custDialogprop: {}
}
},
created() {
if (!this.ctrlFiled.option) {
this.ctrlFiled.option = {
choiceType: 'static',
customQuery: {}
}
}
},
methods: {
initData() {
if (this.ctrlFiled.ct == 'customDialog') {
if (this.ctrlFiled.controlContent) {
this.controlContentObject = this.ctrlFiled.controlContent
} else {
this.controlContentObject = {}
}
if (
this.ctrlFiled.custDialogprop &&
Object.keys(this.ctrlFiled.custDialogprop).length != 0
) {
this.custDialogprop = this.ctrlFiled.custDialogprop
} else {
this.custDialogprop = {}
}
this.changeDialog()
form.getCustomDialogs().then(response => {
this.customDialogs = []
if (response && response.length > 0) {
response.forEach(d => {
this.customDialogs.push({key: d.alias, value: d.name})
})
}
})
} else {
if (
this.ctrlFiled.controlContent &&
this.ctrlFiled.controlContent.length > 0
) {
this.controlContentArray = this.ctrlFiled.controlContent
} else {
this.controlContentArray = []
}
}
},
handleClose() {
this.$set(this, 'controlContentObject', {})
this.dialogVisible = false
},
showDialog(row, conditionFields) {
this.ctrlFiled = cloneDeep(row)
if (conditionFields) {
conditionFields.forEach(item => {
item.value = item.colPrefix + item.na
})
}
this.conditionFields = conditionFields
this.dialogVisible = true
this.initData()
},
addControlContent() {
this.controlContentArray.push({key: '', value: ''})
},
changeDialog(type) {
if (this.controlContentObject.alias) {
const this_ = this
form
.getCustomDialogByAlias(this.controlContentObject.alias)
.then(response => {
let custDialogFields = []
let conditionfield = []
if (response && response.resultfield) {
let fields = JSON.parse(response.resultfield)
fields.forEach(f => {
custDialogFields.push({key: f.comment, value: f.comment})
})
}
if (response && response.conditionfield) {
conditionfield = JSON.parse(response.conditionfield)
if (this_.ctrlFiled.bind) {
conditionfield.forEach(conf => {
this_.ctrlFiled.bind.forEach(fbind => {
if (
!conf.bind &&
conf.field.toLowerCase() == fbind.field.toLowerCase()
) {
conf.bind = fbind.bind
}
})
})
}
}
// 刷新对话框配置
if (type == 'refresh') {
conditionfield.forEach((item, index) => {
let oldItem = this.conditionfield.find(sub => {
return (
sub.field === item.field &&
sub.defaultType === item.defaultType
)
})
if (oldItem) {
conditionfield[index] = oldItem
}
})
this.$message.info('对话框更新配置成功!点击保存后生效')
}
if (type && type !== 'refresh') {
this.controlContentObject.resultField = ''
}
this.custDialogFields = custDialogFields
this.conditionfield = conditionfield
})
} else {
this.custDialogFields = []
this.conditionfield = []
}
},
//弹窗提交确定
onConfirm(selection) {
utils
.validateForm(this, 'ctrlFieldForm')
.then(r => {
if (this.ctrlFiled.ct == 'customDialog') {
this.ctrlFiled.controlContent = this.controlContentObject
if (this.conditionfield && this.conditionfield.length > 0) {
this.ctrlFiled.bind = this.conditionfield
}
if (Object.keys(this.custDialogprop).length != 0) {
this.ctrlFiled.custDialogprop = this.custDialogprop
}
} else {
this.ctrlFiled.controlContent = this.controlContentArray
if (this.ctrlFiled.option && this.ctrlFiled.option.bind) {
this.ctrlFiled.option.bind.forEach(item => {
item.json = {
path: 'searchForm',
name: item.fieldPath
}
})
}
let goNext = true
//单选框校验
if (this.ctrlFiled.ct == 'radio') {
this.ctrlFiled.controlContent.forEach(item => {
if (item.key == '' || item.value == '') {
goNext = false
}
})
}
if (!goNext) {
this.$message.error('固定选项值不可为空')
return false
}
}
this.dialogVisible = false
this.$emit('onConfirm', this.ctrlFiled)
})
.catch(items => {
this.$message.error(
`有${items.length}个字段未通过校验,请正确填写表单内容。`
)
})
},
//显示字段排序
sort(index, type) {
if ('up' == type) {
if (index === 0) {
this.$message({
message: '已经是列表中第一位',
type: 'warning'
})
} else {
let temp = this.controlContentArray[index - 1]
this.$set(
this.controlContentArray,
index - 1,
this.controlContentArray[index]
)
this.$set(this.controlContentArray, index, temp)
}
} else {
if (index === this.controlContentArray.length - 1) {
this.$message({
message: '已经是列表中最后一位',
type: 'warning'
})
} else {
let i = this.controlContentArray[index + 1]
this.$set(
this.controlContentArray,
index + 1,
this.controlContentArray[index]
)
this.$set(this.controlContentArray, index, i)
}
}
},
//删除显示字段
remove(index) {
this.controlContentArray.splice(index, 1)
},
changeResultField() {
this.$forceUpdate()
},
//切换固定选项和动态选项时
dynamicClick() {
this.controlContentArray = []
this.customQueryUrl = '/form/customQuery/v1/list'
this.ctrlFiled.option.customQuery = {
valueBind: '',
labelBind: '',
conditionfield: [],
custQueryJson: []
}
this.ctrlFiled.option.bind = []
this.ctrlFiled.option.options = []
if (this.ctrlFiled.option.choiceType == 'dynamic') {
this.ctrlFiled.option.linkage = []
}
},
afterCustomQueryLoadData(data) {
this.customQuerys = data.rows
},
//选择动态选项
setCurrentCustomQuery() {
const _this = this
_this.ctrlFiled.option.customQuery.custQueryJson = []
_this.customQuerys.forEach(item => {
if (_this.ctrlFiled.option.customQuery.alias == item.alias) {
if (typeof item.conditionfield == 'string') {
item.conditionfield = JSON.parse(item.conditionfield) //parseToJson(item.customQuery.conditionfield);
item.resultfield = JSON.parse(item.resultfield) // parseToJson(item.customQuery.resultfield);
}
//把当前对象克隆一份到控件属性配置
Object.assign(_this.ctrlFiled.option.customQuery, item)
// _this.slimCustomQuery(_this.ctrlFiled.option.customQuery);
}
})
//删除掉无效的参数
var bind = []
this.ctrlFiled.option.customQuery.conditionfield.forEach(item => {
if (item.defaultType == 1) {
bind.push(item)
}
})
this.ctrlFiled.option.bind = bind
//切换关联数据设置项或下拉框动态值 同时清空绑定返回值、参数绑定、选项绑定
this.custDialogprop = {}
this.ctrlFiled.option.gangedBind = {}
this.ctrlFiled.option.customQuery.valueBind = ''
this.ctrlFiled.option.customQuery.labelBind = ''
if (this.ctrlFiled.option.customQuery.conditionfield) {
this.ctrlFiled.option.customQuery.conditionfield.forEach(element => {
this.$set(element, 'fieldPath', '')
})
}
}
}
}
</script>
<style lang="scss" scoped>
div >>> .el-dialog__body {
padding: 10px;
}
.customQuery-inputs-box {
display: flex;
flex-wrap: wrap;
.customQuery-inputs {
/deep/.el-form-item__label {
text-align: right;
}
}
}
.customQuery-select {
/deep/.el-form-item__label {
text-align: right;
}
}
.customQuery-inputs >>> .inputs,
.customQuery-inputs >>> .inputs .el-select {
width: 100%;
}
.customQuery-box {
display: flex;
flex-wrap: wrap;
}
.trSet td {
padding-bottom: 10px;
}
>>> .el-form-item__label {
text-align: left;
}
.choiceType-bottom {
margin-bottom: 0px;
}
.choiceType-bottom >>> .el-form-item {
margin-bottom: 5px;
}
</style>