username@email.com
2023-02-28 67a0042c5f29e4bb0e0b82f6190f2bc51480b45c
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
(function ($, zou) {
    "use strict";
 
    //数据验证下拉
    var verifyDatalist = [
        { id: "", text: "==请选择==" },
        { id: "NotNull", text: "不能为空" },
        { id: "Num", text: "必须为数字" },
        { id: "NumOrNull", text: "数字或空" },
        { id: "Email", text: "必须为E-mail格式" },
        { id: "EmailOrNull", text: "E-mail格式或空" },
        { id: "EnglishStr", text: "必须为字符串" },
        { id: "EnglishStrOrNull", text: "字符串或空" },
        { id: "Phone", text: "必须电话格式" },
        { id: "PhoneOrNull", text: "电话格式或者空" },
        { id: "Fax", text: "必须为传真格式" },
        { id: "Mobile", text: "必须为手机格式" },
        { id: "MobileOrNull", text: "手机格式或者空" },
        { id: "MobileOrPhone", text: "电话格式或手机格式" },
        { id: "MobileOrPhoneOrNull", text: "电话格式或手机格式或空" },
        { id: "Uri", text: "必须为网址格式" },
        { id: "UriOrNull", text: "网址格式或空" }
    ];
 
    var verifyDatalist2 = [
        { id: "NotNull", text: "不能为空" }
    ];
 
    //行占比下拉
    var proportionList = [
        { id: "1", text: "1" },
        { id: "2", text: "1/2" },
        { id: "3", text: "1/3" }
    ];
 
    //数据来源下拉
    var dataSourceTypeList = [
        { id: "1", text: "数据字典" },
        { id: "2", text: "物理地址" }
    ];
 
    var dataformatList = [
        { id: "0", text: "仅日期" },
        { id: "1", text: "日期和时间" },
        { id: "2", text: "仅月份" }
    ];
 
    $.formComponents = {
        text: {//文本框
            init: function () {
                var $html = $('<div class="z-custmerform-component" data-type="text" ><i  class="fa fa-italic"></i>文本框</div>');
                return $html;
            },
 
            render: function ($component) {
                $component[0].dfop = $component[0].dfop || {
                    title: '文本框',
                    type: "text",
                    table: '',
                    field: "",
                    proportion: '1',
                    verify: ''
                };
                $component.html(getComponentRowHtml({ name: $component[0].dfop.title, text: "文本框" }));
            },
 
            property: function ($component) {
                var $html = initComponentPropertyHtml($component, verifyDatalist);
            }
        },
        textarea: {//文本区
            init: function () {
                var $html = $('<div class="z-custmerform-component" data-type="textarea" ><i class="fa fa-align-justify"></i>文本域</div>');
                return $html;
            },
 
            render: function ($component) {
                $component[0].dfop = $component[0].dfop || {
                    title: '文本域',
                    type: "textarea",
                    table: '',
                    field: "",
                    proportion: '1',
                    verify: '',
                    height: '90'
                };
                $component.html(getComponentRowHtml({ name: $component[0].dfop.title, text: "文本域" }));
            },
            property: function ($component) {
                var $html = initComponentPropertyHtml($component, verifyDatalist);
            }
        },
        radio: {//单选框
            init: function () {
                var $html = $('<div class="z-custmerform-component" data-type="radio" ><i class="fa fa-circle-thin"></i>单选框</div>');
                return $html;
            },
            render: function ($component) {
                $component[0].dfop = $component[0].dfop || {
                    title: '单选项',
                    type: "radio",
                    table: '',
                    field: "",
                    proportion: '1',
                    dataSourceType: '1',  // 1数据字典 2 物理地址
                    dataSource: '',
                    dataSourceUrl: ''
                };
                $component.html(getComponentRowHtml({ name: $component[0].dfop.title, text: "单选项" }));
            },
            property: function ($component) {
                var dfop = $component[0].dfop;
                var $html = initComponentPropertyHtml($component);
                var html = '';
                html += '<div class="z-component-title">数据来源</div>';
                html += '<div class="z-component-control"><select class="form-control" id="component_dataSourceType"></select></div>';
                html += '<div class="z-component-title dataItemCode">数据字典</div>';
                html += '<div class="z-component-control dataItemCode"><select class="form-control" id="component_dataSource"></select></div>';
                html += '<div class="z-component-title dataItemUrl">URL数据源</div>';
                html += '<div class="z-component-control dataItemUrl"><input id="component_dataSourceUrl" type="text" class="form-control" placeholder="URL数据源"/></div>';
                $html.append(html);
                createDatasource(dfop);
                // 数据源地址设置
                $html.find('#component_dataSourceUrl').val(dfop.dataSourceUrl);
                $html.find('#component_dataSourceUrl').keyup(function () {
                    var value = $(this).val();
                    dfop.dataSourceUrl = value;
                });
            }
        },
        checkbox: {//多选框
            init: function () {
                var $html = $('<div class="z-custmerform-component" data-type="checkbox" ><i class="fa fa-square-o"></i>多选框</div>');
                return $html;
            },
            render: function ($component) {
                $component[0].dfop = $component[0].dfop || {
                    title: '多选框',
                    type: "checkbox",
                    table: '',
                    field: "",
                    proportion: '1',
                    dataSourceType: '1',  // 1数据字典 2 物理地址
                    dataSource: '',
                    dataSourceUrl: ''
                };
                $component.html(getComponentRowHtml({ name: $component[0].dfop.title, text: "多选项" }));
            },
            property: function ($component) {
                var dfop = $component[0].dfop;
                var $html = initComponentPropertyHtml($component);
                var html = '';
                html += '<div class="z-component-title">数据来源</div>';
                html += '<div class="z-component-control"><select class="form-control" id="component_dataSourceType"></select></div>';
                html += '<div class="z-component-title dataItemCode">数据字典</div>';
                html += '<div class="z-component-control dataItemCode"><select class="form-control" id="component_dataSource"></select></div>';
                html += '<div class="z-component-title dataItemUrl">URL数据源</div>';
                html += '<div class="z-component-control dataItemUrl"><input id="component_dataSourceUrl" type="text" class="form-control" placeholder="URL数据源"/></div>';
                $html.append(html);
                createDatasource(dfop);
                // 数据源地址设置
                $html.find('#component_dataSourceUrl').val(dfop.dataSourceUrl);
                $html.find('#component_dataSourceUrl').keyup(function () {
                    var value = $(this).val();
                    dfop.dataSourceUrl = value;
                });
            }
        },
        combox: {//下拉框
            init: function () {
                var $html = $('<div class="z-custmerform-component" data-type="combox" ><i class="fa fa-caret-square-o-right"></i>下拉框</div>');
                return $html;
            },
            render: function ($component) {
                // console.log(JSON.stringify($component));
 
                $component[0].dfop = $component[0].dfop || {
                    title: '下拉框',
                    type: "combox",
                    table: '',
                    field: "",
                    proportion: '1',
                    dataSourceType: '1',  // 1数据字典 2 物理地址
                    dataSource: '',
                    dataSourceUrl: ''
                };
                $component.html(getComponentRowHtml({ name: $component[0].dfop.title, text: "下拉框" }));
            },
            property: function ($component) {
                var dfop = $component[0].dfop;
                var $html = initComponentPropertyHtml($component);
                var html = '';
                html += '<div class="z-component-title">数据来源</div>';
                html += '<div class="z-component-control"><select class="form-control" id="component_dataSourceType"></select></div>';
                html += '<div class="z-component-title dataItemCode">数据字典</div>';
                html += '<div class="z-component-control dataItemCode"><select class="form-control" id="component_dataSource"></select></div>';
                html += '<div class="z-component-title dataItemUrl">URL数据源</div>';
                html += '<div class="z-component-control dataItemUrl"><input id="component_dataSourceUrl" type="text" class="form-control" placeholder="URL数据源"/></div>';
                $html.append(html);
                createDatasource(dfop);
                // 数据源地址设置
                $html.find('#component_dataSourceUrl').val(dfop.dataSourceUrl);
                $html.find('#component_dataSourceUrl').keyup(function () {
                    var value = $(this).val();
                    dfop.dataSourceUrl = value;
                });
            }
        },
        datetime: {//日期框
            init: function () {
                var $html = $('<div class="z-custmerform-component" data-type="datetime" ><i class="fa fa-calendar"></i>日期框</div>');
                return $html;
            },
            render: function ($component) {
                $component[0].dfop = $component[0].dfop || {
                    title: '日期框',
                    type: "datetime",
                    table: '',
                    field: "",
                    proportion: '1',
                    verify: '',
                    dateformat: '0'
                };
                $component.html(getComponentRowHtml({ name: $component[0].dfop.title, text: '日期框' }));
            },
            property: function ($component) {
                var dfop = $component[0].dfop;
                var $html = initComponentPropertyHtml($component, verifyDatalist2);
                var html = '';
                html += '<div class="z-component-title">日期格式</div>';
                html += '<div class="z-component-control"><select class="form-control" id="component_dateformat"></select></div>';
                $html.append(html);
 
                // 日期格式
                var $dateformat = $(document).find("#component_dateformat");
                $.each(dataformatList, function (index, obj) {
                    if (dfop.dateformat === obj.id)//设置默认选项
                        $dateformat.append("<option value='" + obj.id + "' selected='selected'>" + obj.text + "</option>");
                    else
                        $dateformat.append("<option value='" + obj.id + "'>" + obj.text + "</option>");
                });
 
 
                // 日期格式选择
                $('#component_dateformat').on('change', function () {
                    var format = $('#component_dateformat').find("option:selected").val();
                    dfop.dateformat = format;
                });
            }
        },
        girdtable: {
            init: function () {
                var $html = $('<div class="z-custmerform-component" data-type="girdtable" ><i class="fa fa-table"></i>编辑表格</div>');
                return $html;
            },
            render: function ($component) {
                $component[0].dfop = $component[0].dfop || {
                    title: '编辑表格',
                    table: '',
                    type: "girdtable",
                    proportion: '1',
                    icon: "fa fa-table",
                    minheight: 400,  // 表格默认的行数
                    columns: []//设置的字段数据
                };
 
                $component.html(getComponentRowHtml({ name: '编辑表格', text: '编辑表格' }));
            },
            property: function ($component) {
                var $html = initGridTable($component);
 
            }
        }
    }
 
    // 获取组件行显示html
    function getComponentRowHtml(data) {
        var html = '<div class="z-compont-title"><span>' + data.name + '</span><div class="z-compont-remove"><i  title="移除组件" class="del fa fa-close"></i></div></div><div class="z-compont-value">' + data.text + '</div>';
        return html;
    };
    // 设置组件公共属性设置html
    function initComponentPropertyHtml($component) {
        var dfop = $component[0].dfop;
        var $html = $(".z-custmerform-designer-layout-right .mCSB_container");
        var html = '';
        html += '<div class="z-component-title">绑定表</div>';
        html += '<div class="z-component-control"><select class="form-control" id="component_table"></select></div>';
        html += '<div class="z-component-title">绑定字段</div>';
        html += '<div class="z-component-control"><select class="form-control" id="component_field"></select></div>';
        html += '<div class="z-component-title">组件标题</div>';
        html += '<div class="z-component-control"><input id="component_title" type="text" class="form-control" placeholder="必填项"/></div>';
        html += '<div class="z-component-title">字段验证</div>';
        html += '<div class="z-component-control"><select class="form-control" id="component_verify"></select></div>';
        html += '<div class="z-component-title">所占比例</div>';
        html += '<div class="z-component-control"><select class="form-control" id="component_proportion"></select></div>';
        $html.html(html);
 
        // 标题设置
        $html.find('#component_title').val(dfop.title);
        $html.find('#component_title').keyup(function () {
            var value = $(this).val();
            $component.find('.z-compont-title span').text(value);
            dfop.title = value;
        });
        //数据表设置
        var $table = $(document).find("#component_table");
        var url = "/FormDesigner/FindPrimaryTable?keyValue=" + window.keyValue;
        window.$.ajax({
            url: url,
            type: "get",
            dataType: "json",
            success: function (data) {
                $.each(data, function (index, obj) {
                    if (dfop.table === obj.Value)//设置默认选项
                        $table.append("<option value='" + obj.Value + "' selected='selected'>" + obj.Text + "</option>");
                    else
                        $table.append("<option value='" + obj.Value + "'>" + obj.Text + "</option>");
                });
            },
            complete: function () {
                var table = $('#component_table').find("option:selected").val();
                initColumn(table, dfop.field);
                dfop.table = table;
            }
        });
 
        // 验证初始化
        var $verify = $(document).find("#component_verify");
        $.each(verifyDatalist, function (index, obj) {
            if (dfop.verify === obj.id)//设置默认选项
                $verify.append("<option value='" + obj.id + "' selected='selected'>" + obj.text + "</option>");
            else
                $verify.append("<option value='" + obj.id + "'>" + obj.text + "</option>");
        });
 
        // 所占行比例初始化
        var $proportion = $(document).find("#component_proportion");
        $.each(proportionList, function (index, obj) {
            if (dfop.proportion === obj.id)//设置默认选项
                $proportion.append("<option value='" + obj.id + "' selected='selected'>" + obj.text + "</option>");
            else
                $proportion.append("<option value='" + obj.id + "'>" + obj.text + "</option>");
        });
 
        // 数据表选择
        $('#component_table').on('change', function () {
            var table = $('#component_table').find("option:selected").val();
            initColumn(table, dfop.field);
            dfop.table = table;
        });
 
        // 数据字段选择
        $('#component_field').on('change', function () {
            var field = $('#component_field').find("option:selected").val();
            dfop.field = field;
        });
 
        // 字段验证选择
        $('#component_verify').on('change', function () {
            var verify = $('#component_verify').find("option:selected").val();
            dfop.verify = verify;
        });
 
        // 所占比例选择
        $('#component_proportion').on('change', function () {
            var proportion = $('#component_proportion').find("option:selected").val();
            dfop.proportion = proportion;
            $component.css({ 'width': 100 / parseInt(dfop.proportion) + '%' });
        });
 
        return $html;
    };
 
    // 数据字典选择初始化、数据源选择初始化
    function createDatasource(dfop) {
 
        // 数据源类型
        var $sourceType = $(document).find("#component_dataSourceType");
        $.each(dataSourceTypeList, function (index, obj) {
            if (dfop.dataSourceType === obj.id)//设置默认选项
                $sourceType.append("<option value='" + obj.id + "' selected='selected'>" + obj.text + "</option>");
            else
                $sourceType.append("<option value='" + obj.id + "'>" + obj.text + "</option>");
        });
 
        //根据数据类型展示数据源选项或地址
        var sourceType = $("#component_dataSourceType").find("option:selected").val();
        if (sourceType === "1") {//数据字典
            initDataSource(dfop.dataSource);
            $(".dataItemCode").show();
            $(".dataItemUrl").hide();
        } else {
            $(".dataItemCode").hide();
            $(".dataItemUrl").show();
        }
        dfop.dataSourceType = sourceType;
 
        // 数据源选择
        $('#component_dataSourceType').on('change', function () {
            sourceType = $('#component_dataSourceType').find("option:selected").val();
            if (sourceType === "1") {//数据字典
                initDataSource(dfop.dataSource);
                $(".dataItemCode").show();
                $(".dataItemUrl").hide();
            } else {
                $(".dataItemCode").hide();
                $(".dataItemUrl").show();
            }
            dfop.dataSourceType = sourceType;
        });
 
        // 数据字典选择
        $("#component_dataSource").on('change', function () {
            var dataSource = $('#component_dataSource').find("option:selected").val();
            dfop.dataSource = dataSource;
        });
    }
 
    // 编辑表格初始化
    function initGridTable($component) {
        var dfop = $component[0].dfop;
        var $html = $(".z-custmerform-designer-layout-right .mCSB_container");
        var html = '<div class="z-component-title">绑定表</div>';
        html += '<div class="z-component-control"><select class="form-control" id="component_table"></select></div>';
        html += '<div class="z-component-title">组件标题</div>';
        html += '<div class="z-component-control"><input id="component_title" type="text" class="form-control" placeholder="必填项"/></div>';
        html += '<div class="z-component-title">组件图标</div>';
        html += '<div class="z-component-control"><input id="component_icon" type="text" class="form-control" placeholder="组件图标"/></div>';
        html += '<div class="z-component-title">最小高度</div>';
        html += '<div class="z-component-control"><input id="component_minheight" type="text" class="form-control" placeholder="必填项"/></div>';
        html += '<div class="z-component-control" style="text-align: center;padding-top: 10px;" ><a id="fieldsDataCreate" class="btn btn-primary btn-block">设置表格字段</a></div>';
        $html.html(html);
 
        // 标题设置
        $html.find('#component_title').val(dfop.title);
        $html.find('#component_title').keyup(function () {
            var value = $(this).val();
            $component.find('.z-compont-title span').text(value);
            dfop.title = value;
        });
 
        // 组件图标
        $html.find('#component_icon').val(dfop.icon);
        $html.find('#component_icon').keyup(function () {
            var value = $(this).val();
            dfop.icon = value;
        });
 
        // 最小高度设置
        $html.find('#component_minheight').val(dfop.minheight);
        $html.find('#component_minheight').keyup(function (e) {
            var value = $(this).val();
            dfop.minheight = value;
        });
 
        dfop.proportion = "1";
 
        //数据表设置
        var $table = $(document).find("#component_table");
        var url = "/FormDesigner/FindChildTable?keyValue=" + window.keyValue;
        window.$.ajax({
            url: url,
            type: "get",
            dataType: "json",
            success: function (data) {
                $.each(data, function (index, obj) {
                    if (dfop.table === obj.Value)//设置默认选项
                        $table.append("<option value='" + obj.Value + "' selected='selected'>" + obj.Text + "</option>");
                    else
                        $table.append("<option value='" + obj.Value + "'>" + obj.Text + "</option>");
                });
            },
            complete: function () {
                var table = $('#component_table').find("option:selected").val();
                initColumn(table, dfop.field);
                dfop.table = table;
            }
        });
 
        // 数据表选择
        $('#component_table').on('change', function () {
            var table = $('#component_table').find("option:selected").val();
            initColumn(table, dfop.field);
            dfop.table = table;
        });
 
        $('#fieldsDataCreate').on('click', function () {
            window.formGridSetting = {
                columns: dfop.columns,
                tableName: dfop.table
            };
            var gridUrl = "/FormDesigner/InitGridTableIndex?keyValue=formGridSetting";
            layer.open({
                type: 2,
                title: '从表数据设置',
                shadeClose: true,
                shade: 0.4,
                area: ['75%', '75%'],
                content: gridUrl
            });
        });
    }
 
    function initColumn(table, dfvalue) {
        var $field = $(document).find("#component_field");
        var url = "/FormDesigner/FindColumnList?table=" + table;
        window.$.ajax({
            url: url,
            type: "get",
            dataType: "json",
            success: function (data) {
                $.each(data, function (index, obj) {
                    if (dfvalue === obj.Value)
                        $field.append("<option value='" + obj.Value + "' selected='selected'>" + obj.Text + "</option>");
                    else
                        $field.append("<option value='" + obj.Value + "'>" + obj.Text + "</option>");
                });
            }
        });
    }
 
    // 初始化数据字典下拉
    function initDataSource(dfvalue) {
        //数据字典
        var $dataSource = $(document).find("#component_dataSource");
        var url = "/DropDown/DataSource";
        window.$.ajax({
            url: url,
            type: "get",
            dataType: "json",
            success: function (data) {
                $.each(data, function (index, obj) {
                    if (dfvalue === obj.Value)//设置默认选项
                        $dataSource.append("<option value='" + obj.Value + "' selected='selected'>" + obj.Text + "</option>");
                    else
                        $dataSource.append("<option value='" + obj.Value + "'>" + obj.Text + "</option>");
                });
            },
            complete: function () {
                $('#component_dataSource').chosen();
                //$('#component_dataSource').trigger("chosen:updated");
            }
        });
    }
 
})(jQuery, top.zou);