mitao
2024-07-08 022a7ff7abf82cd2546e18071ade5228b4e2339f
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
@layout("/common/_container.html"){
<div class="ibox float-e-margins">
    <div class="ibox-content">
        <div class="form-horizontal">
            <input type="hidden" id="id" value="${id}">
            <div class="row">
                <div class="col-sm-12">
                    <button class="btn btn-primary" onclick="DialogInfo._add('')">添加一级分类</button>
                </div>
                <div class="col-sm-12">
                    <ul class="ztree" id="classify_tree"></ul>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
 
    var DialogInfo = {
        $parent: window.parent.MemMerchant,
        validFields: {
 
        }
    }
    DialogInfo.get = function( key) {
        return $( "#" + key).val();
    }
    DialogInfo.close = function () {
        this.$parent.search();
        window.parent.layer.close( this.$parent.layerIndex);
    }
    // 获取提交数据
    DialogInfo.get_submit_data = function() {
        return {
            id: this.get( "id"),
        }
    }
    // 提交
    DialogInfo.addSubmit = function () {
 
 
    }
 
    /* 添加/移除 节点 */
    var is_exist = function( id) { return $( "#" + id).length > 0; }
    DialogInfo.removeHoverDom = function( treeId, node) {
        $("#add_btn_"+node.tId+",#remove_btn_"+node.tId).remove()
    }
    DialogInfo.addHoverDom = function( treeId, node) {
        var $node_span = $("#" + node.tId + "_span");
 
        var btn_list = [];
        var re_str = $("<span id='remove_btn_" + node.tId
            + "' title='删除此分类' onfocus='this.blur()' style='color: red;margin-left: 3em'>删除此分类</span>");
        if ( !is_exist("remove_btn_" + node.tId)) {
            btn_list.push( re_str);
            re_str.on( "click", function () {
                return DialogInfo._remove( node);
            })
        }
 
        if ( !node['pId']) {
            var add_str = $("<span id='add_btn_" + node.tId
                + "' title='添加二级分类' onfocus='this.blur()' style='color: blue;margin-left: 3em'>添加二级分类</span>");
            if ( !is_exist("add_btn_" + node.tId)) {
                btn_list.push( add_str);
                add_str.on( "click", function () {
                    return DialogInfo._add( node.id);
                })
            }
        }
        $node_span.after( btn_list);
    }
 
    /**
     * 删除节点
     */
    DialogInfo._remove = function( item) {
        Feng.confirm( "是否确定".concat("删除").concat("所选中的数据?"), function () {
            Feng.base_ajax_data( "/memMerchant/deleteMallClassifyMerchant", { id: item.id, merchantId: DialogInfo.get( "id") }, function ( data) {
                Feng.success( "删除成功");
                DialogInfo.refresh_tree( data);
            });
        });
    }
 
    /**
     * 新增节点
     */
    DialogInfo._add = function( id) {
        this.layerIndex = layer.open({
            type: 2,
            title: '新增分类',
            area: ['60%', '60%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/memMerchant/add-classify/' + this.get( "id") + "?classifyOneId=" + id
        });
    }
 
    /* 刷新树 */
    DialogInfo.refresh_tree = function (nodes) {
        this.zTreeObj = $.fn.zTree.init($("#classify_tree"), {
            callback: {
                beforeDrag: function() { return false; }
            },
            view: {
                selectedMulti: false,
                addHoverDom: DialogInfo.addHoverDom,
                removeHoverDom: DialogInfo.removeHoverDom
            },
            data: { simpleData: { enable:true } }
        }, nodes);
 
        this.zTreeObj.expandAll( true);
    }
 
    $(function () {
        DialogInfo.refresh_tree( JSON.parse( `${classifyList!}`));
    })
</script>
@}