gaoshp
2024-11-19 f29900986f01cf5d39b5755cec674825cef27961
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
<template>
    <el-dialog :title="titleMap[mode]" v-model="visible" :width="800" destroy-on-close @closed="$emit('closed')">
        <el-form :model="addFieldForm" :rules="addFieldRules" :disabled="mode=='show'" ref="dialogForm" label-width="100px" label-position="center">
            <el-row>
                <el-col :span="24">
                    <el-form-item label="字段名称" prop="fieldName">
                        <el-input v-model="addFieldForm.fieldName" placeholder="输入一个符合阅读习惯的简短名称,建议4个字符,最多不超过12字" clearable></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="提示文字">
                        <el-input v-model="addFieldForm.fieldDescription" placeholder="描述提示用户如何填写字段值(例如:请输入名字)" clearable></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="字段类型">
                        <el-select v-model="addFieldForm.fieldType" style="width: 100%" placeholder="选择符合业务的字段类型">
                            <el-option v-for="item in fieldTypeList" :disabled="item.disabled" :key="item.id" :label="item.title" :value="item.id"/>
                        </el-select>
                    </el-form-item>
                </el-col>
                <!-- 变量1 输入框 -->
                <el-col :span="24" v-if="addFieldForm.fieldType == '1'">
                    <el-form-item label="默认值">
                        <el-input v-model="addFieldForm.defaultValue" placeholder="系统默认提供的值,可不填,设置默认值会替换提示文字" clearable></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="addFieldForm.fieldType == '1'">
                    <el-form-item label="文字长度">
                        <el-input-number v-model="addFieldForm.maxlength" :min="0" :max="200" label="系统默认提供的值,可不填,设置默认值会替换提示文字"></el-input-number>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="addFieldForm.fieldType == '1'">
                    <el-form-item label="输入格式">
                        <el-select v-model="addFieldForm.formatName" style="width: 100%" placeholder="选择输入框不同的输入格式">
                            <el-option v-for="item in inputTypeList" :key="item.id" :label="item.title" :value="item.id"/>
                        </el-select>
                    </el-form-item>
                </el-col>
                <!-- 变量2 数字输入框-->
                <el-col :span="24" v-if="addFieldForm.fieldType == '2'">
                    <el-form-item label="默认值">
                        <el-input-number v-model="addFieldForm.defaultValue" :precision="addFieldForm.saveDecimalNum" @change="handleChange" :min="0" :max="999" label="系统默认提供的值,可不填,设置默认值会替换提示文字"></el-input-number>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="addFieldForm.fieldType == '2'">
                    <el-form-item label="格式">
                        <el-radio v-model="addFieldForm.format" label="0">数值</el-radio>
                        <el-radio v-model="addFieldForm.format" label="1">百分比</el-radio>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="addFieldForm.fieldType == '2'">
                    <el-form-item label="保留小数位">
                        <el-input-number v-model="addFieldForm.saveDecimalNum" @change="handleChange" :min="0" :max="10" label="最多不超过4位小数"></el-input-number>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="addFieldForm.fieldType == '2'" v-show="addFieldForm.format == '0'">
                    <el-form-item label="显示千分符">
                        <el-checkbox v-model="addFieldForm.isShowPercentage"></el-checkbox>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="addFieldForm.fieldType == '2'">
                    <el-form-item label="限定值范围">
                        <el-input-number v-model="addFieldForm.rangeMin" :min="0" :max="9999"></el-input-number>
                        <span>-</span>
                        <el-input-number v-model="addFieldForm.rangeMax" :min="0" :max="9999"></el-input-number>
                    </el-form-item>
                </el-col>
                <!-- 变量3 多行文本-->
                <el-col :span="24" v-if="addFieldForm.fieldType == '3'">
                    <el-form-item label="默认值">
                        <el-input v-model="addFieldForm.defaultValue" type="textarea" placeholder="系统默认提供的值,可不填,设置默认值会替换提示文字" clearable></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="addFieldForm.fieldType == '3'">
                    <el-form-item label="文字长度">
                        <el-input-number v-model="addFieldForm.maxlength" :min="0" :max="200" label="请输入文字最长限制字数"></el-input-number>
                    </el-form-item>
                </el-col>
                <!-- 变量4 日期选择器-->
                <el-col :span="24" v-if="addFieldForm.fieldType == '4'">
                    <el-form-item label="默认值">
                        <el-date-picker :editable="true" v-model="addFieldForm.defaultValue" style="width: 100%" :format="addFieldForm.dateFormat" :value-format="addFieldForm.dateFormat" :type="addFieldForm.dateType" placeholder="系统默认提供的值,可不填,设置默认值会替换提示文字" @change="dateChange"></el-date-picker>
                    </el-form-item>
                </el-col> 
                <el-col :span="24"  v-if="addFieldForm.fieldType == '4'">
                    <el-form-item label="日期格式">
                        <el-select v-model="addFieldForm.type" style="width: 100%" placeholder="请输入文字最长限制字数" @change="typeDateChange">
                            <el-option v-for="item in dateFormatList" :key="item.id" :label="item.title" :value="item.id"/>
                        </el-select>
                    </el-form-item>
                </el-col>
                <!-- 变量5 单选按钮-->
                <el-col :span="24" v-if="addFieldForm.fieldType == '5'">
                    <el-form-item label="选项" class="specialItem">
                        <el-radio-group v-model="addFieldForm.selectOption" class="specialRadio">
                            <el-radio :label="item.value" style="margin-right: 0px;" v-for="(item,index) in addFieldForm.radioList">
                                <el-input v-model="item.label" clearable></el-input>
                                <span class="remove-btn" @click="removeRadio(index)">删除</span>
                            </el-radio>
                        </el-radio-group>
                        <div class="add-btn" @click="addRadio">添加选项</div>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="addFieldForm.fieldType == '5'">
                    <el-form-item label="排序方式">
                        <el-radio v-model="addFieldForm.direction" label="0">横向排列</el-radio>
                        <el-radio v-model="addFieldForm.direction" label="1">纵向排列</el-radio>
                    </el-form-item>
                </el-col>
                <!-- 变量6 多选按钮-->
                <el-col :span="24" v-if="addFieldForm.fieldType == '6'">
                    <el-form-item label="选项" class="specialItem">
                        <el-checkbox-group v-model="addFieldForm.selectBoxOption" class="specialCheck">
                            <el-checkbox :label="item.value" :value="item.value" v-for="(item,index) in addFieldForm.checkboxList">
                                <el-input v-model="item.label" clearable></el-input>
                                <span class="remove-btn" @click="removeCheckbox(index)">删除</span>
                            </el-checkbox>
                        </el-checkbox-group>
                        <!-- <div v-for="(item,index) in addFieldForm.checkboxList" class="fieldContent">
                            <el-checkbox v-model="item.check" style="margin-right: 15px;"></el-checkbox>
                            <el-input v-model="item.input" clearable></el-input>
                            <span class="remove-btn" @click="removeCheckbox(index)">删除</span>
                        </div> -->
                        <div class="add-btn" @click="addCheckbox">添加选项</div>
                    </el-form-item>
                </el-col> 
                <el-col :span="24" v-if="addFieldForm.fieldType == '6'">
                    <el-form-item label="排序方式">
                        <el-radio v-model="addFieldForm.direction" label="0">横向排列</el-radio>
                        <el-radio v-model="addFieldForm.direction" label="1">纵向排列</el-radio>
                    </el-form-item>
                </el-col>
                <!-- 变量7 下拉选择器-->
                <el-col :span="24" v-if="addFieldForm.fieldType == '7'">
                    <el-form-item label="选项" class="specialItem">
                        <div v-for="(item,index) in addFieldForm.selectList" class="fieldContent">
                            <el-input v-model="item.label" clearable></el-input>
                            <span class="remove-btn" @click="removeSelect(index)">删除</span>
                        </div>
                        <div class="add-btn" @click="addSelect">添加选项</div>
                    </el-form-item>
                </el-col> 
                <!-- 变量8 业务字段-人员-没有-->
                <!-- 变量9 默认-没有 -->
                <el-col :span="24">
                    <el-form-item label="编辑页显示">
                        <el-checkbox v-model="addFieldForm.updateShow"></el-checkbox>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="addFieldForm.updateShow">
                    <el-form-item label="支持编辑">
                        <el-radio v-model="addFieldForm.supportUpdate" label="1">是</el-radio>
                        <el-radio v-model="addFieldForm.supportUpdate" label="0">否</el-radio>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="查看页显示">
                        <el-checkbox v-model="addFieldForm.viewShow"></el-checkbox>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <template #footer>
            <el-button @click="visible=false" >取 消</el-button>
            <el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="fieldSubmit">保存</el-button>
            <el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="saveSubmit">保存并继续添加</el-button>
        </template>
    </el-dialog>
</template>
 
<script>
    export default {
        emits: ['success', 'closed'],
        data() {
            return {
                dialogData: {},
                inputTypeList: [  //输入格式
                    {title: "无",id: "1"},
                    {title: "手机号码",id: "mobile"},
                    {title: "电话号码",id: "telephone"},
                    {title: "邮箱",id: "email"}
                ],
                fieldTypeList: [  //字段类型
                    {title: "输入框",id: "1"},
                    {title: "数字输入框",id: "2"},
                    {title: "多行文本",id: "3"},
                    {title: "日期选择器",id: "4"},
                    {title: "单选按钮",id: "5"},
                    {title: "多选按钮",id: "6"},
                    {title: "下拉选择器",id: "7"},
                    {title: "业务字段-人员",id: "9"},
                    {title: "默认",id: "10",disabled: true}
                ],
                dateFormatList: [  //日期格式
                    {title: "年-月",id: "yyyy-MM"},
                    {title: "年-月-日",id: "yyyy-MM-dd"},
                    {title: "年-月-日 时:分",id: "yyyy-MM-dd HH:mm"},
                    {title: "年-月-日 时:分:秒",id: "yyyy-MM-dd HH:mm:ss"}
                ],
                mode: "add",
                titleMap: {
                    add: '添加自定义字段',
                    edit: '修改',
                    show: '查看'
                },
                visible: false,
                isSaveing: false,
                //表单数据
                addFieldForm: {
                    fieldName: "",
                    fieldDescription: "",
                    defaultValue: "",
                    maxlength: 20,
                    updateShow: false,
                    viewShow: true,
                    fieldType: "1",  //字段类型,默认输入框
                    formatName: "",
                    supportUpdate: "1",
                    saveDecimalNum: 0,
                    format: "0",
                    isShowPercentage: false,
                    rangeMin: 0,
                    rangeMax: 0,
                    type: "yyyy-MM",
                    dateType: "month",
                    dateFormat: "YYYY-MM",
                    val: {
                        label: "年-月",
                        value: "month",
                        format: "yyyy-MM"
                    },
                    direction: "0",
                    radioList: [],
                    selectOption: "",
                    selectBoxOption: [],
                    checkboxList: [],
                    selectList: []
                },
                //验证规则
                addFieldRules: {
                    fieldName:[{required: true, message: '请输入字段名称'}]
                }
            }
        },
        mounted() {
            
        },
        methods: {
            dateChange(val) {
                console.log(val)
                this.addFieldForm.defaultValue = val;
            },
            typeDateChange(val) {
                this.addFieldForm.defaultValue = "";
                if(val == "yyyy-MM") {
                    this.addFieldForm.dateType = "month";
                    this.addFieldForm.dateFormat = "YYYY-MM";
                    this.addFieldForm.val = {
                        label: "年-月",
                        value: "month",
                        format: val
                    };
                }else if(val == "yyyy-MM-dd") {
                    this.addFieldForm.dateType = "date";
                    this.addFieldForm.dateFormat = "YYYY-MM-DD";
                    this.addFieldForm.val = {
                        label: "年-月-日",
                        value: "date",
                        format: val
                    };
                }else if(val == "yyyy-MM-dd HH:mm") {
                    this.addFieldForm.dateType = "datetime";
                    this.addFieldForm.dateFormat = "YYYY-MM-DD HH-mm";
                    this.addFieldForm.val = {
                        label: "年-月-日 时:分",
                        value: "datetime",
                        format: val
                    };
                }else if(val == "yyyy-MM-dd HH:mm:ss") {
                    this.addFieldForm.dateType = "datetime";
                    this.addFieldForm.dateFormat = "YYYY-MM-DD HH-mm-ss";
                    this.addFieldForm.val = {
                        label: "年-月-日 时:分:秒",
                        value: "datetime",
                        format: val
                    };
                }
            },
            fieldSubmit() {  //保存
                this.saveSubmit('closeDialog');
            },
            saveSubmit(isClose) {  //保存并继续
                var obj = {
                    businessType: 1,
                    fieldDescription: this.addFieldForm.fieldDescription,
                    fieldName: this.addFieldForm.fieldName,
                    fieldType: this.addFieldForm.fieldType,
                    supportUpdate: this.addFieldForm.supportUpdate,
                    systemField: 0,
                    updateShow: this.addFieldForm.updateShow?"1":"0",
                    viewShow: this.addFieldForm.viewShow?"1":"0",
                }
                if(this.addFieldForm.fieldType == "1") {  //字段类型
                    obj.defaultValue = this.addFieldForm.defaultValue;  //默认值
                    var propertyJson = {  //长度、格式
                        maxlength: this.addFieldForm.maxlength,
                        formatName: this.addFieldForm.formatName == "1"?"":this.addFieldForm.formatName
                    }
                    obj.propertyJson = JSON.stringify(propertyJson);
                }
                if(this.addFieldForm.fieldType == "2") {  //字段类型
                    obj.defaultValue = this.addFieldForm.defaultValue;  //默认值
                    var propertyJson = {
                        format: this.addFieldForm.format,
                        saveDecimalNum: this.addFieldForm.saveDecimalNum,
                        isShowPercentage: this.addFieldForm.isShowPercentage,
                        rangeMin: this.addFieldForm.rangeMin,
                        rangeMax: this.addFieldForm.rangeMax
                    }
                    obj.propertyJson = JSON.stringify(propertyJson);
                }
                if(this.addFieldForm.fieldType == "3") {  //字段类型
                    obj.defaultValue = this.addFieldForm.defaultValue;  //默认值
                    var propertyJson = {
                        maxlength: this.addFieldForm.maxlength
                    }
                    obj.propertyJson = JSON.stringify(propertyJson);
                }
                if(this.addFieldForm.fieldType == "4") {  //字段类型
                    obj.defaultValue = this.addFieldForm.defaultValue;  //默认值
                    var propertyJson = {
                        type: this.addFieldForm.type,
                        val: this.addFieldForm.val
                    }
                    obj.propertyJson = JSON.stringify(propertyJson);
                }
                if(this.addFieldForm.fieldType == "5") {  //单选按钮
                    var propertyJson = {
                        selectOption: this.addFieldForm.selectOption,
                        options: this.addFieldForm.radioList,
                        direction: this.addFieldForm.direction
                    }
                    obj.propertyJson = JSON.stringify(propertyJson);
                }
                if(this.addFieldForm.fieldType == "6") {  //多选按钮
                    var propertyJson = {
                        selectOption: this.addFieldForm.selectBoxOption,
                        options: this.addFieldForm.checkboxList,
                        direction: this.addFieldForm.direction
                    }
                    obj.propertyJson = JSON.stringify(propertyJson);
                }
                if(this.addFieldForm.fieldType == "7") {  //下拉选择器
                    var propertyJson = {
                        options: this.addFieldForm.selectList
                    }
                    obj.propertyJson = JSON.stringify(propertyJson);
                }
                obj.businessType = this.$route.query.type;
                var that = this;
                if(this.mode == "edit") {
                    var url = "/api/blade-system/custom-template-field/update";
                    var method = "put";
                    obj.id  = this.dialogData.id;
                }else {
                    var url = "/api/blade-system/custom-template-field/insert";
                    var method = "post";
                }
                this.$HTTP[method](url,obj).then(res=> {
                    if(res.code == 200) {
                        that.$message.success("提交成功");
                        that.$emit("success",obj);
                        if(isClose == "closeDialog") {
                            that.visible = false;
                        }
                    }else {
                        that.$message.error(res.msg);
                    }
                })
            },
            removeRadio(index) {
                this.addFieldForm.radioList.splice(index,1);
            },
            addRadio() {
                var flag = false;
                if(this.addFieldForm.radioList.length > 0) {
                    this.addFieldForm.radioList.forEach(item=> {
                        if(item.label == "") {
                            flag = true;
                        }
                    })
                }
                if(flag) {
                    this.$message.error("请输入上一个自定义选项的内容");
                    return;
                }
                this.addFieldForm.radioList.push({label: "",value: "radiosSelect" + (this.addFieldForm.radioList.length + 1),parentId: 0});
            },
            removeCheckbox(index) {
                this.addFieldForm.checkboxList.splice(index,1);
            },
            addCheckbox() {
                var flag = false;
                if(this.addFieldForm.checkboxList.length > 0) {
                    this.addFieldForm.checkboxList.forEach(item=> {
                        if(item.label == "") {
                            flag = true;
                        }
                    })
                }
                if(flag) {
                    this.$message.error("请输入上一个自定义选项的内容");
                    return;
                }
                this.addFieldForm.checkboxList.push({label: "",value: "checkboxSelect" + (this.addFieldForm.checkboxList.length + 1),parentId: 0});
            },
            removeSelect(index) {
                this.addFieldForm.selectList.splice(index,1);
            },
            addSelect() {
                var flag = false;
                if(this.addFieldForm.selectList.length > 0) {
                    this.addFieldForm.selectList.forEach(item=> {
                        if(item.label == "") {
                            flag = true;
                        }
                    })
                }
                if(flag) {
                    this.$message.error("请输入上一个自定义选项的内容");
                    return;
                }
                this.addFieldForm.selectList.push({label: "",value: "select" + (this.addFieldForm.selectList.length + 1),parentId: 0});
            },
            //显示
            open(mode='add'){
                this.mode = mode;
                this.visible = true;
                return this
            },
            //表单注入数据
            setData(data){
                this.dialogData = data;
                this.$HTTP.get(`/api/blade-system/custom-template-field/get/${data.id}`).then(res=> {
                    if(res.code == 200) {
                        res.data.fieldType = String(res.data.fieldType);
                        res.data.format = res.data.format == "0"?"0":"1";
                        res.data.direction = String(res.data.direction);
                        res.data.updateShow = res.data.updateShow == "1"?true:false;
                        res.data.viewShow = res.data.viewShow == "1"?true:false;
                        res.data.supportUpdate = String(res.data.supportUpdate);
                        if(res.data.fieldType != "10") {
                            this.addFieldForm = Object.assign(res.data,JSON.parse(res.data.propertyJson));
                        }else {
                            this.addFieldForm = res.data;
                        }
                        this.addFieldForm.format = String(this.addFieldForm.format);
                        if(res.data.fieldType == "5") {
                            this.addFieldForm.radioList = this.addFieldForm.options;
                        }
                        if(res.data.fieldType == "6") {
                            this.addFieldForm.checkboxList = this.addFieldForm.options;
                            this.addFieldForm.selectBoxOption = this.addFieldForm.selectOption;
                        }
                        if(res.data.fieldType == "7") {
                            this.addFieldForm.selectList = this.addFieldForm.options;
                        }
                    }
                })
            }
        }
    }
</script>
 
<style scoped>
.add-btn {
    color: #409eff;
    cursor: pointer;
}
.specialItem /deep/ .el-form-item__content{
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}
.specialRadio,.specialCheck {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}
.specialRadio label,.specialCheck label{
    margin-bottom: 8px;
}
.fieldContent {
    display: flex;
    align-items: flex-start;
    margin-bottom: 8px;
}
.remove-btn {
    min-width: 60px;
    display: inline-block;
    margin-left: 12px;
    color: red;
    cursor: pointer;
}
</style>