mitao
2024-04-22 28a19584dca02f05fe0b8be9ab426b586efead6e
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
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
var Feng = {
    ctxPath: "",
    addCtx: function (ctx) {
        if (this.ctxPath == "") {
            this.ctxPath = ctx;
        }
    },
    confirm: function (tip, ensure) {//询问框
        parent.layer.confirm(tip, {
            btn: ['确定', '取消']
        }, function (index) {
            ensure();
            parent.layer.close(index);
        }, function (index) {
            parent.layer.close(index);
        });
    },
    log: function (info) {
        console.log(info);
    },
    alert: function (info, iconIndex) {
        parent.layer.msg(info, {
            icon: iconIndex
        });
    },
    info: function (info) {
        Feng.alert(info, 0);
    },
    success: function (info) {
        Feng.alert(info, 1);
    },
    error: function (info) {
        Feng.alert(info, 2);
    },
    infoDetail: function (title, info) {
        var display = "";
        if (typeof info == "string") {
            display = info;
        } else {
            if (info instanceof Array) {
                for (var x in info) {
                    display = display + info[x] + "<br/>";
                }
            } else {
                display = info;
            }
        }
        parent.layer.open({
            title: title,
            type: 1,
            skin: 'layui-layer-rim', //加上边框
            area: ['950px', '600px'], //宽高
            content: '<div style="padding: 20px;">' + display + '</div>'
        });
    },
    writeObj: function (obj) {
        var description = "";
        for (var i in obj) {
            var property = obj[i];
            description += i + " = " + property + ",";
        }
        layer.alert(description, {
            skin: 'layui-layer-molv',
            closeBtn: 0
        });
    },
    showInputTree: function (inputId, inputTreeContentId, leftOffset, rightOffset) {
        var onBodyDown = function (event) {
            if (!(event.target.id == "menuBtn" || event.target.id == inputTreeContentId || $(event.target).parents("#" + inputTreeContentId).length > 0)) {
                $("#" + inputTreeContentId).fadeOut("fast");
                $("body").unbind("mousedown", onBodyDown);// mousedown当鼠标按下就可以触发,不用弹起
            }
        };
 
        if (leftOffset == undefined && rightOffset == undefined) {
            var inputDiv = $("#" + inputId);
            var inputDivOffset = $("#" + inputId).offset();
            $("#" + inputTreeContentId).css({
                left: inputDivOffset.left + "px",
                top: inputDivOffset.top + inputDiv.outerHeight() + "px"
            }).slideDown("fast");
        } else {
            $("#" + inputTreeContentId).css({
                left: leftOffset + "px",
                top: rightOffset + "px"
            }).slideDown("fast");
        }
 
        $("body").bind("mousedown", onBodyDown);
    },
    baseAjax: function (url, tip) {
        var ajax = new $ax(Feng.ctxPath + url, function (data) {
            Feng.success(tip + "成功!");
        }, function (data) {
            Feng.error(tip + "失败!" + data.responseJSON.message + "!");
        });
        return ajax;
    },
    base_ajax: function (url, data, success, error) {
        // 加载动画层,0代表加载的风格,支持0-2
        var index = parent.layer.load(0, {shade: [ 0.1, "#2a2b3c"]}), close_layer = function() { parent.layer.close(index); };
        error = error || function( data) { Feng.error("操作失败!" + data.responseJSON.message + "!");}
        setTimeout(function () {
            new $ax(Feng.ctxPath + url,
                function ( data) {
                    close_layer();
                    if ( data.code != 200) { data.responseJSON = data; return error ? error( data) : Feng.error( "操作失败!" + data.message); }
                    success && success( data)
                },
                function ( data) { close_layer(); error( data) })
                .setData( data).start();
        }, 100);
    },
    base_ajax_data: function (url, data, success, error) {
        // 加载动画层,0代表加载的风格,支持0-2
        var index = parent.layer.load(0, {shade: [ 0.1, "#2a2b3c"]}), close_layer = function() { parent.layer.close(index); };
        error = error || function( data) { Feng.error("操作失败!" + data.responseJSON.message + "!");}
        setTimeout(function () {
            new $ax(Feng.ctxPath + url,
                function ( data) {
                    close_layer();
                    success && success( data)
                },
                function ( data) { close_layer(); error( data) })
                .setData( data).start();
        }, 100);
    },
    changeAjax: function (url) {
        return Feng.baseAjax(url, "修改");
    },
    zTreeCheckedNodes: function (zTreeId) {
        var zTree = $.fn.zTree.getZTreeObj(zTreeId);
        var nodes = zTree.getCheckedNodes();
        var ids = "";
        for (var i = 0, l = nodes.length; i < l; i++) {
            ids += "," + nodes[i].id;
        }
        return ids.substring(1);
    },
    eventParseObject: function (event) {//获取点击事件的源对象
        event = event ? event : window.event;
        var obj = event.srcElement ? event.srcElement : event.target;
        return $(obj);
    },
    sessionTimeoutRegistry: function () {
        $.ajaxSetup({
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            complete: function (XMLHttpRequest, textStatus) {
                //通过XMLHttpRequest取得响应头,sessionstatus,
                var sessionstatus = XMLHttpRequest.getResponseHeader("sessionstatus");
                if (sessionstatus == "timeout") {
                    //如果超时就处理 ,指定要跳转的页面
                    window.location = Feng.ctxPath + "/global/sessionError";
                }
            }
        });
    },
    initValidator: function (formId, fields) {
        $('#' + formId).bootstrapValidator({
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: fields,
            live: 'enabled',
            message: '该字段不能为空'
        });
    },
    underLineToCamel: function (str) {
        var strArr = str.split('_');
        for (var i = 1; i < strArr.length; i++) {
            strArr[i] = strArr[i].charAt(0).toUpperCase() + strArr[i].substring(1);
        }
        var result = strArr.join('');
        return result.charAt(0).toUpperCase() + result.substring(1);
    },
    randomNum: function (minNum, maxNum) {
        switch (arguments.length) {
            case 1:
                return parseInt(Math.random() * minNum + 1, 10);
                break;
            case 2:
                return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
                break;
            default:
                return 0;
                break;
        }
    },
    newCrontab: function (href, menuName) {
        var dataUrl = href;
        var needCreateCrontab = true;
 
        // 轮询已有的标签,判断是否已经存在标签
        parent.$('.J_menuTab').each(function () {
            if ($(this).data('id') == dataUrl) {
                if (!$(this).hasClass('active')) {
                    $(this).addClass('active').siblings('.J_menuTab').removeClass('active');
                    parent.MyCrontab.scrollToTab(this);
                    parent.MyCrontab.$('.J_mainContent .J_iframe').each(function () {
                        if ($(this).data('id') == dataUrl) {
                            $(this).show().siblings('.J_iframe').hide();
                            $(this).attr('src', $(this).attr('src'));
                            return false;
                        }
                    });
                }
                needCreateCrontab = false;
                return false;
            }
        });
 
        //创建标签
        if (needCreateCrontab) {
            var tabLink = '<a href="javascript:;" class="active J_menuTab" data-id="' + dataUrl + '">' + menuName + ' <i class="fa fa-times-circle"></i></a>';
            parent.$('.J_menuTab').removeClass('active');
            parent.$('.J_menuTabs .page-tabs-content').append(tabLink);
 
            var iframeContent = '<iframe class="J_iframe" name="iframe' + Feng.randomNum(100,999) + '" width="100%" height="100%" src="' + dataUrl + '" frameborder="0" data-id="' + dataUrl + '" seamless></iframe>';
            parent.$('.J_mainContent').find('iframe.J_iframe').hide().parents('.J_mainContent').append(iframeContent);
            parent.MyCrontab.scrollToTab($('.J_menuTab.active'));
        }
    },
    /**
     * 获取复选框选中值
     */
    checkBoxIds: function (tableId) {
        var selected = $("#" + tableId).bootstrapTable('getSelections');
        if (selected.length == 0) {
            Feng.info("请选择要操作的数据!!");
            return '';
        }
        var ids = '';
        if (selected.length > 0) {
            for (var i = 0; i < selected.length; i++) {
                ids += selected[i]['id'] + ",";
            }
            ids = ids.substring(0, ids.length - 1);
        }
        return ids;
    },
    /**
     * 设置操作按钮
     * @returns <a href="javascript:void(0);" onclick=update('1');>编辑</a>
     *
    Opts: function() {
        var opts = '';
        return {
            add: function (funcName, label) {
                if (opts != "") {
                    opts += " | ";
                }
                opts += '<a href="javascript:void(0);" onclick=' + funcName + '>' + label + '</a>';
            },
            getOpts: function() {
                return opts;
            }
        }
    },
     * @returns <button type="button" class="btn btn-outline btn-success btn-sm" style="margin-right: 3px;">编辑</button>
     */
    Opts: function() {
        var opts = '';
        return {
            add: function (funcName, label) {
                opts += '<button type="button" class="btn btn-outline btn-success btn-xs" style="margin-right: 3px;" ' +
                    'onclick=' + funcName + '>' + label + '</button>';
            },
            addDanger: function (funcName, label) {
                opts += '<button type="button" class="btn btn-outline btn-danger btn-xs" style="margin-right: 3px;" ' +
                    'onclick=' + funcName + '>' + label + '</button>';
            },
            addBtn: function (funcName, label, btn) {
                // 按钮样式:btn-default / btn-primary / btn-success / btn-info / btn-warning / btn-danger / btn-link
                opts += '<button type="button" class="btn btn-outline ' + btn + ' btn-xs" style="margin-right: 3px;" ' +
                    'onclick=' + funcName + '>' + label + '</button>';
            },
            getOpts: function() {
                return opts;
            }
        }
    },
    /**
     * 获取状态转换说明
     */
    getStateFormat: function(value) {
        return {0 : "待处理", 1 : "通过", 2 : "拒绝"}[value];
    },
    /**
     * 格式化处理图片路径
     */
    getImageUrlFormat: function(imgUrl) {
        if (imgUrl == null || imgUrl == '' || imgUrl == undefined) {
            return Feng.ctxPath + '/static/img/NoPIC.png';
        } else {
            if(imgUrl.indexOf("http") == -1) {
                // 不是全路径,拼接项目路径
                imgUrl = Feng.ctxPath + '/kaptcha/' + imgUrl;
            }
            return imgUrl;
        }
    },
    /**
     * 获取图片Dom对象
     */
    getImageDom: function(imgUrl) {
        return '<a class = "view"  href="javascript:void(0)"><img style="height:40px;" src="' + Feng.getImageUrlFormat(imgUrl) + '" onclick="Feng.openImageLayer(this);" /></a>';
    },
    /**
     * 点击图片,弹出层显示大图
     */
    openImageLayer: function(image) {
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: 'auto',
            skin: 'layui-layer-nobg', //没有背景色
            shadeClose: true,
            content: '<img src="' + $(image).attr("src") + '" height="100%" width="100%" />'
        });
    },
    lookBigImg: function (obj) {
        console.log("进入")
        console.log(obj)
        // 设置图片路径
        var imgUrl = obj;
        if (imgUrl != "") {
            imgUrl = imgUrl;// 设置图片路径
        } else {
            imgUrl = Feng.ctxPath + '/static/img/NoPIC.png';// 默认无图
        }
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: ['80%', '100%'],
            skin: 'layui-layer-nobg', //没有背景色
            shadeClose: true, //点击空白区域关闭弹出层
            content: '<div id="zoomableImageContainer" style="height: 100%; width: 100%; overflow: hidden; display: flex; justify-content: center; align-items: center; position: relative;"><img id="zoomableImage" src="'
                + imgUrl
                + '" style="max-width: none; max-height: none; position: absolute;"></div>',
            success: function (layero, index) {
                // 获取图片容器和图片元素
                var zoomableImageContainer = document.getElementById(
                    'zoomableImageContainer');
                var zoomableImage = document.getElementById('zoomableImage');
                var imageWidth = zoomableImage.naturalWidth;
                var imageHeight = zoomableImage.naturalHeight;
                var containerWidth = zoomableImageContainer.offsetWidth;
                var containerHeight = zoomableImageContainer.offsetHeight;
                var isDragging = false; // 标记是否正在拖动
                var startX, startY; // 记录拖动起始位置
                zoomableImageContainer.addEventListener('wheel',
                    function (event) {
                        event.preventDefault();
                        var delta = Math.sign(-event.deltaY); // 获取滚动方向,1表示向上滚动,-1表示向下滚动
                        var currentWidth = zoomableImage.offsetWidth;
                        var currentHeight = zoomableImage.offsetHeight;
                        var step = 0.1; // 缩放步长
                        var newWidth = currentWidth + delta * step
                            * currentWidth;
                        var aspectRatio = zoomableImage.naturalWidth
                            / zoomableImage.naturalHeight;
                        var newHeight = newWidth / aspectRatio;
                        zoomableImage.style.width = newWidth + 'px';
                        zoomableImage.style.height = newHeight + 'px';
                    });
                zoomableImageContainer.addEventListener('mousedown',
                    function (event) {
                        if (event.button === 0) { // 判断是否为鼠标左键点击
                            event.preventDefault();
                            isDragging = true;
                            startX = event.clientX - zoomableImage.offsetLeft;
                            startY = event.clientY - zoomableImage.offsetTop;
                        }
                    });
                zoomableImageContainer.addEventListener('mousemove',
                    function (event) {
                        if (isDragging) {
                            event.preventDefault();
                            var offsetX = event.clientX - startX;
                            var offsetY = event.clientY - startY;
                            var maxX = zoomableImage.offsetWidth
                                - containerWidth;
                            var maxY = zoomableImage.offsetHeight
                                - containerHeight;
                            offsetX = Math.min(Math.max(offsetX, -maxX), 0);
                            offsetY = Math.min(Math.max(offsetY, -maxY), 0);
                            zoomableImage.style.left = offsetX + 'px';
                            zoomableImage.style.top = offsetY + 'px';
                        }
                    });
                zoomableImageContainer.addEventListener('mousemove',
                    function (event) {
                        if (isDragging) {
                            var mouseX = event.clientX;
                            var mouseY = event.clientY;
                            var newLeft = mouseX - startX;
                            var newTop = mouseY - startY;
                            // 确保图片不会移出容器范围
                            if (newLeft >= 0 && newLeft
                                + zoomableImage.offsetWidth <= containerWidth) {
                                zoomableImage.style.left = newLeft + 'px';
                            }
                            if (newTop >= 0 && newTop
                                + zoomableImage.offsetHeight
                                <= containerHeight) {
                                zoomableImage.style.top = newTop + 'px';
                            }
                        }
                    });
                zoomableImageContainer.addEventListener('mouseup',
                    function (event) {
                        if (event.button === 0) {
                            isDragging = false;
                        }
                    });
            }
        });
    },
    /**
     * 单选框-取值
     */
    getRadioVal: function(key) {
        return $("input:radio[name='" + key + "']:checked").val();
    },
    /**
     * 复选框-取值
     */
    getCheckboxVal: function(key) {
        var checkIds = [];
        $("input:checkbox[name='" + key + "']:checked").each(function(i){
            checkIds[i] = $(this).val();
        });
        return checkIds.join();
    },
    /**
     * 复选框-填充赋值
     */
    fillCheckboxVal: function(key, fillVal) {
        // 遍历复选框
        $("input:checkbox[name='" + key + "']").each(function(i, item) {
            var itemVal = $(item).val();
            // 判断是否被选中
            $(fillVal.split(",")).each(function(ii, iItem) {
                if(itemVal == iItem) {
                    $(item).attr('checked', 'checked');
                }
            });
        });
    },
    /**
     * 多选下拉框-取值
     */
    getMultipleSelectVal: function(key) {
        var selected = [];
        $("#" + key).find("option:selected").each(function() {
            selected.push(this.value);
        });
        return selected.join(",");
    },
    /**
     * 下拉搜索框-取值
     */
    getSelectPickerVal: function(key) {
        if(document.getElementById(key) != null && $("#" + key).selectpicker('val') != null) {
            return $("#" + key).selectpicker('val').join();
        }
        return '';
    },
    /**
     * 富文本编辑器-取值
     */
    getEditorContent: function(obj) {
        if(obj != null && obj != undefined){
            return obj.getContent();
        }
        return '';
    },
    /**
     * 时间格式化
     */
    getDateFormat: function (value) {
        if (value != "" && value != undefined) {
            return new Date(value).format("Y-m-d"); // Y-m-d H:i:s
        }
        return "";
    },
    /**
     * 文本缩略格式化
     */
    getTextFormat: function (value, size) {
        if(value != undefined && value.length > size){
            return "<span title='"+value+"'>"+value.substring(0,size)+"...</span>";
        }
        return value;
    },
    /**
     * 是/否判断格式化
     */
    getIsObjFormat: function (value) {
        if(value != undefined && value == 1){
            return "是";
        }
        return "否";
    },
    /**
     * 格式化:小于10进行补0显示。1 -> 01
     */
    addPreZero: function (value) {
        var format = '';
        if (value <= 9) {
            format = "0";
        }
        return format + value;
    },
    selectCity1: function() {
        var code1 = $("#cityCode1").val();
        $.ajax({
            type: "GET",
            url: Feng.ctxPath + "/cityRegion/getListByParentId",
            data: {code1: code1},
            success: function(data) {
                var options = '<option value="-1">请选择</option>';
                $(data).each(function (i, item) {
                    options += "<option value='" + item.code + "'>" + item.name + "</option>"
                });
                $("#cityCode2").html(options);
                $("#cityCode").html('<option value="-1">请选择</option>');
            }
        });
    },
    selectCity2: function() {
        var code2 = $("#cityCode2").val();
        $.ajax({
            type: "GET",
            url: Feng.ctxPath + "/cityRegion/getListByParentId",
            data: {code2: code2},
            success: function(data) {
                var options = '<option value="-1">请选择</option>';
                $(data).each(function (i, item) {
                    options += "<option value='" + item.code + "'>" + item.name + "</option>"
                });
                $("#cityCode").html(options);
            }
        });
    },
    // 单选列表
    get_radio_checkbox: function ( $el) { return !!$el[0]['checked']; },
    i_checks_radio_init: function ( $elem, name, array, callback) {
        $elem.append( (array||[]).map(function (val) {
            var other = (val['others'] && val['others']())||"";
            var $div = $('<div class="radio i-checks '+ (other ? "" : "inline")  +'">' +
                '   <label>' +
                '       <input '+ (val.checked ? 'checked=""':'') +
                '       '+ (val.disabled ? 'disabled="disabled"':'') +' name="'+ name +'" type="radio" value="'+ val.value +'" />' +
                '       '+ val.name + '' +
                '   </label>' +
                '   <div style="display: inline; margin-left: 2em;">' + (other) + '</div>' +
                '</div>');
            $div.find( "input").on("ifChecked", function () { callback && callback( val); });
            return $div;
        }));
        return {
            getValue: function () {
                var select;
                $elem.find( "input[type='radio']").each(function () {
                    var checkbox = Feng.get_radio_checkbox( $( this));
                    if ( checkbox) { select = $( this).attr( "value"); }
                });
                return select;
            }
        }
    },
 
    /**
     * 简化 表单验证方法
     * @param isEmpty
     * @param regexp
     * @param regexp_msg
     * @param callback
     * @param map
     * @returns {{validators: {}}}
     */
    def_valid_info: function ( isEmpty, regexp, regexp_msg, callback, map) {
        var vail = {};
        if ( isEmpty) { vail.notEmpty = { message: "不能为空" } }
        if ( regexp ) { vail.regexp = { regexp: regexp,message: regexp_msg} }
        if ( callback) {  vail.callback = callback;}
        if ( map) {for (var key in map) {vail[ key] = map[ key];}}
        return { validators: vail };
    },
    def_valid_money: function() {
        return Feng.def_valid_info( true, /^((\d{1,10})|(0))(\.\d{1,2})?$/, "只能是数字,且最多保留两位小数")
    },
    def_valid_num: function() {
        return Feng.def_valid_info( true, /^((\d{1,10})|(0))$/, "只能是整数")
    },
    check_form: function ( form_id) {
        $('#' + form_id).data("bootstrapValidator").resetForm();
        $('#' + form_id).bootstrapValidator('validate');
        return $('#' + form_id).data('bootstrapValidator').isValid();
    },
 
 
 
    /**
     * 获取select option 值 : 一般用于 有码表转换 然后查询条件有码表 直接在页面上获取值 不用后台再转一次
     */
    getOptionItems: function( $id, isMap) {
        var result = [], resMap = {};
        $($id).find( "option").each(function (){
            result.push( { value: this.value, name: this.text});
            resMap[ this.value] = this.text;
        });
        return isMap ? resMap : result;
    },
    getOptionFormatter: function( $id) {
        var optionItems = Feng.getOptionItems( $id, true);
        return function( value) { return optionItems[ value] || ""}
    },
    getOrderTypeFormatter: function( key) {
        //订单类型,0普通商品,1黄金套餐,2钻石套餐
        var value = "普通商品";
        if(key ==1){
            value = "黄金套餐";
        }else if(key ==2){
            value = "钻石套餐";
        }
        return value;
    },
    getWorkDate: function( key) {
        var value = "周一";
        if(key ==2){
            value = "周二";
        }else if(key ==3){
            value = "周三";
        }else if(key ==4){
            value = "周四";
        }else if(key ==5){
            value = "周五";
        }else if(key ==6){
            value = "周六";
        }else if(key ==7){
            value = "周日";
        }
        return value;
    },
    /**
     *  下载导出
     * @param url 请求URL
     * @param data 请求参数
     */
    down_export: function ( url, data) {
        var params = "";
        if ( data) {
            params = Object.keys( data).map(function( k) { return k + "=" + data[ k]}).join( "&");
        }
        window.open( Feng.ctxPath + Feng.url_params( url, data));
    },
    url_params: function ( url, data) {
        var params = "";
        if ( data) {
            params = Object.keys( data).map(function( k) { return k + "=" + data[ k]}).join( "&");
        }
        if ( url.indexOf("?") != -1) { return url + "&" + params; }
        return url + "?" + params;
    },
 
    tableUserInfo: function( v, row) {
        return [ "id:" + row['userId_showId'], "手机号:" + row[ 'userId_phone'], "昵称:" + row['userId_nickName']].join( "<br>")
    },
 
    get_select_option_values: function ( $id) {
        var res = [];
        $($id).find( "option").each(function () {
            res.push( $( this).attr( "value"));
        }); return res;
    },
    init_chosen: function( $id, options, onChange) {
        var $elem = $( $id);
        var default_setting = {no_results_text:"没有找到", search_contains:true, allow_single_deselect:true}
        $elem.on( "change", onChange);
        return $elem.chosen( $.extend( default_setting, options||{}));
    },
    get_chosen_selected: function( $id, callback) {
        var selected = [];
        $( $id).find("option:selected").each(function() {
            selected.push( this.value);
            callback && callback( this.value, this);
        }); return selected.join( ",");
    },
    chose_change: function( $id, value) {
        return $($id).val( value).trigger("chosen:updated");
    },
 
    to_br_formatter: function( sp, max) {
        max = max||4;
        return function (value) {
            var strings = (value||"").split( (sp||/\,/g));
            return strings.filter( function (val, index) {
                return index < max
            }).concat( strings.length > max ? ["..."]:[]).join( "<br>");
        }
    },
 
    /**
     *  商品 动态table 处理
     * @param $id table dom 或 table id
     */
    move_table: function( $id) {
        var $elem = $( $id);
        function get_sort_id ( array) {
            if ( !array) { return array; }
            if ( typeof array == "string") { array = array.split( ",") }
            return array.sort( function (a, b) { return a - b; }).join( ",")
        }
        var Node = function( id, name, tId, parent) {
            this.id = id;
            this.name = name;
            this.tId = tId;
            this.parent = parent;
            this.children = [];
            this.$map = {};
            parent && parent.add_child( this);
 
            return this.init_$map();
        }
        Node.prototype = {
            add_child:function( node) { this.children.push( node); },
            is_last:function() { return this.children.length <= 0; },
            get_name: function( tId) {
                if ( this.tId == tId) { return this.name; }
                return (this.$map[ tId]||{}).name;
            },
            init_$map: function () {
                this.$item = {ids: [ this.id], names: [ this.name], $pIds: [ this.$pId]};
                var parent = this.parent;
                while ( parent) {
                    this.$map[ parent.tId] = parent;
                    this.$item.ids.push( parent.id);
                    this.$item.$pIds.push( parent.$pId);
                    this.$item.names.push( parent.name);
                    parent = parent.parent;
                }
                this.$mId = get_sort_id( this.$item.ids);
                return this;
            }
        }
 
        var Operation = function() {
            this.$thead = this._read_$el( "thead");
            this.$tbody = this._read_$el( "tbody");
            this.items = [];
        }
 
        Operation.prototype = {
            _read_$el: function( key) {
                if ($elem.find(key).length <= 0) {
                    $elem.append( $( "<"+ key +">"));
                } return $elem.find( key);
            },
            init: function( $aThead, tr_fun) {
                this.$aThead = $aThead;
                this.tr_fun = tr_fun;
 
                return this._init_table();
            },
            append: function( item) {
                if ( !item) { return this; }
                var isFlag = this.items.filter( function( val) {
                    if ( val.id == item.id) {
                        val.values = item.values;
                        return true;
                    } return false;
                }).length > 0;
                isFlag || this.items.push( item);
 
                return this._init_table();
            },
 
 
            _init_table: function() {
                var self = this, values = this._get_values();
                this.$thead.empty().append( $('<tr>')
                    .append( self._item_map( function( val) {
                        return $('<th>').text( val.name); }).concat( self.$aThead)));
                this.$tbody.empty().append( values.map(function (node) {
                    return $( "<tr>").data( node).append(self._item_map(function( val) {
                        return $('<td>').data( val).text( node.get_name( val.id));
                    }).concat( self.tr_fun( node)));
                }));
                if ( values.length <= 0) {
                    this.$tbody.append( "<tr><td colspan='10000000'>暂无规格数据</td></tr>")
                }
 
                $elem.find( "td,th").addClass( "text-center");
                return this;
            },
            _item_map: function( callback) {
                return this.items.map(function (item) { return callback( item);});
            },
            _get_values: function() {
                var result = [];
                this._item_map(function( val) {
                    var is_move = result.length <= 0,
                        c_result = [].concat( result);
                    (val.values||[]).forEach(function( v) {
                        if ( is_move) {
                            result.push( new Node( v.id, v.name, val.id, null))
                        } else {
                            c_result.forEach( function( node) {
                                result.push( new Node( v.id, v.name, val.id, node));
                            });
                        }
                    });
                })
                return result.filter( function( node){ return node.is_last() });
            },
 
            clear: function() {
                this.items = [];
                return this._init_table();
            },
 
            get_trs: function() {
                return this.$tbody.find( 'tr');
            }
        }
 
        return new Operation();
    },
};