puzhibing
2023-11-28 7b726d5ff439e7b8bb66369ecc5881e370286bc8
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
/**
 * 角色管理的单例
 */
var ViewSubCodes = {
    id: "VipChannelTable",    //表格id
    seItem: null,        //选中的条目
    table: null,
    layerIndex: -1
};
 
/**
 * 初始化表格的列
 */
ViewSubCodes.initColumn = function () {
    var columns = [
        {field: 'select_item', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '子渠道码名称', field: 'name', align: 'center', valign: 'middle', width: '200px'},
        {title: '生成时间', field: 'createTime', align: 'center', valign: 'middle', width: '150px'},
        {title: '二维码', field: 'id', align: 'center', valign: 'middle', width: '100px',
            formatter: function (value, row) {
                return '<a style="color: #337ab7;" onclick="ViewSubCodes.showQRCode(\'' + row.id + '\',\'' + row.name + '\')">查看链接/二维码</a>';
            }
        },
        {title: '操作', field: 'id', align: 'center', valign: 'middle', width: '100px',
            formatter: function (value, row) {
                return '<a style="color: #337ab7;" onclick="ViewSubCodes.downloadQRCode(\'' + row.id + '\')">下载</a>';
            }
        }
    ]
    return columns;
};
 
 
/**
 * 检查是否选中
 */
ViewSubCodes.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录!");
        return false;
    } else {
        ViewSubCodes.seItem = selected[0];
        return true;
    }
};
 
 
/**
 * 添加
 */
ViewSubCodes.addViewSubCodes = function(){
    const str = '<div class="row">\n' +
        '                <div class="form-group" style="height: 50px;">\n' +
        '                    <label class="col-sm-3 control-label">子渠道名称</label>\n' +
        '                    <div class="col-sm-8">\n' +
        '                        <input id="name1" class="form-control"/>\n' +
        '                    </div>\n' +
        '                </div>\n' +
        '       </div>'
    layer.open({
        type: 1
        ,title: '添加子渠道'
        ,area: ['500px', '300px']
        ,offset: 'auto' //具体配置参考:http://www.layui.com/doc/modules/layer.html#offset
        ,id: 'layerDemo' //防止重复弹出
        ,content: '<div style="padding: 20px">' + str + '</div>'
        ,btn: ['确定', '取消']
        ,btnAlign: 'c' //按钮居中
        ,shade: 0.5 //不显示遮罩
        ,yes: function(){
            var name = $('#name1').val();
            if(null == name || '' == name){
                Feng.error("请填写子渠道名称");
                return;
            }
            var ajax = new $ax(Feng.ctxPath + "/vipChannel/addSubVipChannel", function (data) {
                if(data.code == 200 ){
                    Feng.success("添加成功!");
                    ViewSubCodes.table.refresh();
                    layer.closeAll();
                }else{
                    Feng.error(data.msg);
                }
            }, function (data) {
                Feng.error("添加失败!" + data.responseJSON.message + "!");
            });
            ajax.set("vipChannelId", $('#vipChannelId').val());
            ajax.set("name", $('#name1').val());
            ajax.start();
        },
    });
}
 
 
ViewSubCodes.importViewSubCodes = function () {
    $('#file').click();
};
 
 
 
 
/**
 * 删除
 */
ViewSubCodes.delViewSubCodes = function () {
    if (this.check()) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/vipChannel/delViewSubCodes", function (data) {
                if(data.code == 200 ){
                    Feng.success("删除成功!");
                    ViewSubCodes.table.refresh();
                }else{
                    Feng.error(data.msg);
                }
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", ViewSubCodes.seItem.id);
            ajax.start();
        };
 
        Feng.confirm("是否刪除该子渠道?", operation);
    }
};
 
 
 
 
 
 
/**
 * 查看二维码
 */
ViewSubCodes.showQRCode = function (id, name) {
    const str = '<div class="row">\n' +
        '                <div class="form-group" style="height: 50px;">\n' +
        '                    <label class="col-sm-3 control-label">分享链接二维码</label>\n' +
        '                    <div class="col-sm-8">\n' +
        '                        <img id="qr" style="width: 250px;height: 250px;" src="' + Feng.ctxPath + '/vipChannel/getVipChannelQRCode?id=' + id + '&vipChannelType=2"/>\n' +
        '                    </div>\n' +
        '                </div>\n' +
        '       </div>'
    layer.open({
        type: 1
        ,title: '分享二维码'
        ,area: ['500px', '400px']
        ,offset: 'auto' //具体配置参考:http://www.layui.com/doc/modules/layer.html#offset
        ,id: 'layerDemo' //防止重复弹出
        ,content: '<div style="padding: 20px">' + str + '</div>'
        ,btn: ['下载', '取消']
        ,btnAlign: 'c' //按钮居中
        ,shade: 0.5 //不显示遮罩
        ,yes: function(){
            html2canvas(document.querySelector("#qr")).then(canvas => {
                var a = document.createElement("a");
                a.href= canvas.toDataURL("image/jpg");
                a.download = name + ".jpg";
                a.click();
                layer.closeAll();
            });
        },
    });
};
 
 
ViewSubCodes.downloadQRCode = function(id){
    window.location.href = Feng.ctxPath + "/vipChannel/downloadQRCodeZip?id=" + id + "&vipChannelType=2";
}
 
 
/**
 * 搜索
 */
ViewSubCodes.search = function () {
    var queryData = {};
    queryData['name'] = $("#name").val();
    queryData['vipChannelId'] = $("#vipChannelId").val();
    ViewSubCodes.table.setQueryParams({});
    ViewSubCodes.table.refresh({query: queryData});
}
 
ViewSubCodes.resetSearch = function () {
    var queryData = {};
    $("#name").val('');
    ViewSubCodes.table.setQueryParams({});
    ViewSubCodes.table.refresh({query: queryData});
}
 
 
$(function () {
    var defaultColunms = ViewSubCodes.initColumn();
    var table = new BSTable(ViewSubCodes.id, "/vipChannel/queryViewSubCodesList", defaultColunms);
    table.setQueryParams({"vipChannelId": $('#vipChannelId').val()});
    table.setPaginationType("server");
    ViewSubCodes.table = table.init();
 
    $('#file').change(function () {
        var formData = new FormData()  //创建一个forData
        formData.append('file', $('#file')[0].files[0]) //把file添加进去  name命名为img
        formData.append("vipChannelId", $('#vipChannelId').val());
        layer.load(); //上传loading
        $.ajax({
            url: Feng.ctxPath + "/vipChannel/importViewSubCodes",
            data: formData,
            type: "POST",
            async: true,
            cache: false,
            contentType: false,
            processData: false,
            success: function(res) {
                layer.closeAll('loading'); //关闭loading
                $('#file').val('');
                if(res.code == 200){
                    Feng.success("添加成功");
                    ViewSubCodes.search();
                }else{
                    Feng.error(res.msg);
                }
            }
        })
    })
});