无关风月
2025-03-20 2ad97245d64b65132507cab36ad89d968edb7705
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
/**
 * 角色管理的单例
 */
var VipChannel = {
    id: "VipChannelTable",    //表格id
    seItem: null,        //选中的条目
    table: null,
    layerIndex: -1
};
 
/**
 * 初始化表格的列
 */
VipChannel.initColumn = function () {
    var columns = [
        {field: 'select_item', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '序号', field: 'id', align: 'center', valign: 'middle', width: '80px',
            formatter: function (value, item, i) {
                return (i+1);
            }
        },
        {title: '渠道码类型', field: 'type', align: 'center', valign: 'middle', width: '200px',
            formatter: function (value, row) {
                return value == 1 ? '加油站渠道' : '其他渠道';
            }
        },
        {title: '入会渠道', field: 'name', align: 'center', valign: 'middle', width: '100px'},
        {title: '渠道点位', field: 'position', align: 'center', valign: 'middle', width: '200px',
            formatter: function (value, row) {
                value = typeof value == "undefined" ? "" : value;
                return '<div title="' + value + '" style="width: 100%;white-space: normal;">' + value + '</div>';
            }
        },
        {title: '入会油站', field: 'gasStation', align: 'center', valign: 'middle', width: '200px',
            formatter: function (value, row) {
                value = typeof value == "undefined" ? "" : value;
                return '<div title="' + value + '" style="width: 100%;white-space: normal;">' + value + '</div>';
            }
        },
        {title: '距离', field: 'distance', align: 'center', valign: 'middle', width: '100px',
            formatter: function (value, row) {
                return row.type == 1 ? (typeof value == "undefined" ? '' : value + 'KM') : '';
            }
        },
        {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="VipChannel.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="VipChannel.downloadQRCode(\'' + row.id + '\')">下载</a>';
            }
        }
    ]
    return columns;
};
 
 
/**
 * 检查是否选中
 */
VipChannel.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录!");
        return false;
    } else {
        VipChannel.seItem = selected[0];
        return true;
    }
};
 
 
/**
 * 添加
 */
VipChannel.addVipChannel = function(){
    var index = layer.open({
        type: 2,
        title: '添加入会渠道',
        area: ['100%', '100%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/vipChannel/addVipChannel'
    });
    this.layerIndex = index;
}
 
 
VipChannel.editVipChannel = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '编辑入会渠道',
            area: ['100%', '100%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/vipChannel/editVipChannel?id=' + this.seItem.id
        });
        this.layerIndex = index;
    }
};
 
 
VipChannel.viewSubCodes = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '查看子码',
            area: ['100%', '100%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/vipChannel/viewSubCodes?id=' + this.seItem.id
        });
        this.layerIndex = index;
    }
};
 
 
/**
 * 删除
 */
VipChannel.delVipChannel = function () {
    if (this.check()) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/vipChannel/delVipChannel", function (data) {
                if(data.code == 200 ){
                    Feng.success("删除成功!");
                    VipChannel.table.refresh();
                }else{
                    Feng.error(data.msg);
                }
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", VipChannel.seItem.id);
            ajax.start();
        };
 
        Feng.confirm("是否刪除该入会渠道?", operation);
    }
};
 
 
 
 
 
 
/**
 * 查看二维码
 */
VipChannel.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=1"/>\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();
            });
        },
    });
};
 
 
VipChannel.downloadQRCode = function(id){
    window.location.href = Feng.ctxPath + "/vipChannel/downloadQRCodeZip?id=" + id + "&vipChannelType=1";
}
 
 
/**
 * 搜索
 */
VipChannel.search = function () {
    var queryData = {};
    queryData['name'] = $("#name").val();
    queryData['gasStation'] = $("#gasStation").val();
    queryData['position'] = $('#position').val();
    queryData['type'] = $('#type').val();
    VipChannel.table.setQueryParams({});
    VipChannel.table.refresh({query: queryData});
}
 
VipChannel.resetSearch = function () {
    var queryData = {};
    $("#name").val('');
    $("#gasStation").val('');
    $('#position').val('');
    $('#type').val('');
    VipChannel.table.setQueryParams({});
    VipChannel.table.refresh({query: queryData});
}
 
 
$(function () {
    var defaultColunms = VipChannel.initColumn();
    var table = new BSTable(VipChannel.id, "/vipChannel/queryVipChannelList", defaultColunms);
    table.setPaginationType("server");
    VipChannel.table = table.init();
});