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
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
/**
 * 角色管理的单例
 */
var SalesPromotion = {
    id: "SalesPromotionTable",    //表格id
    seItem: null,        //选中的条目
    table: null,
    layerIndex: -1
};
 
/**
 * 初始化表格的列
 */
SalesPromotion.initColumn = function () {
    var columns = [
        {field: 'select_item', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: 'ID', field: 'code', align: 'center', valign: 'middle', width: '150px'},
        {title: '活动名称', field: 'name', align: 'center', valign: 'middle', width: '150px',
            formatter: function (value, row) {
                return '<a href="#" onclick="SalesPromotion.openSalesPromotionInfo(\'' + row.id + '\')" title="' + value + '">' + value + '</a>';
            }
        },
        {title: '活动预览', field: 'name', align: 'center', valign: 'middle', width: '150px',
            formatter: function (value, row) {
                return '<a href="#" onclick="SalesPromotion.openSalesPromotionView(\'' + row.id + '\')" title="预览主页">预览主页</a>';
            }
        },
        {title: '活动时间周期', field: 'time', align: 'center', valign: 'middle', width: '300px'},
        {title: '投放频率', field: 'frequency', align: 'center', valign: 'middle', width: '200px',
            formatter: function (value,row) {
                if(value==1){
                    if(row.frequencyTime == "[]"){
                        return "每周";
                    }else {
                        return  "每周"+row.frequencyTime.replace("[","(").replace("]",")");
                    }
                }else if(value==2){
                    if(row.frequencyTime == "[]"){
                        return "每月";
                    }else {
                        return  "每月"+row.frequencyTime.replace("[","(").replace("]",")");
                    }
                }else if(value == 0){
                    return  "全部";
                }
            }
        },
        {title: '浏览人数', field: 'browseNum', align: 'center', valign: 'middle', width: '100px',
            formatter: function (value, row) {
                return '<a href="#" onclick="SalesPromotion.openClickUser(\'' + row.id + '\',1)">' + value + '</a>';
            }
        },
        {title: '导航人数', field: 'navigation', align: 'center', valign: 'middle', width: '100px',
            formatter: function (value, row) {
                return '<a href="#" onclick="SalesPromotion.openClickUser(\'' + row.id + '\',2)">' + value + '</a>';
            }
        },
        {title: '配置人', field: 'createUser', align: 'center', valign: 'middle', width: '80px'},
        {title: '配置时间', field: 'createTime', align: 'center', valign: 'middle', width: '150px'},
        {title: '加油站', field: 'id', align: 'center', valign: 'middle', width: '80px',
            formatter: function (value) {
                return '<a href="#" onclick="SalesPromotion.gasStationOilPrice(\'' + value + '\')">查看</a>'
            }
        },
        {title: '状态', field: 'state', align: 'center', valign: 'middle', width: '80px',
            formatter: function (value) {
                switch (value) {
                    case 1:
                        return '已上架';
                    case 2:
                        return '已下架';
                }
            }
        },
        {title: '操作', field: 'forwardShareState', align: 'center', valign: 'middle', width: '150px',
            formatter: function (value, row) {
                let str = '<a onclick="SalesPromotion.showQRCode(\'' + row.id + '\',\'' + row.name + '\')">查看链接/二维码</a><br><br><select onchange="SalesPromotion.updateForwardShareState(\'' + row.id + '\',this)">';
                if(value == 1){
                    str += '<option value="1" selected>开启转发</option><option value="0">关闭转发</option></select>';
                }
                if(value == 0){
                    str += '<option value="1">开启转发</option><option value="0" selected>关闭转发</option></select>';
                }
                return str;
            }
        }
    ]
    return columns;
};
 
 
/**
 * 检查是否选中
 */
SalesPromotion.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录!");
        return false;
    } else {
        SalesPromotion.seItem = selected[0];
        return true;
    }
};
 
/**
 * 点击添加
 */
SalesPromotion.openAddSalesPromotion = function () {
    var index = layer.open({
        type: 2,
        title: '添加促销活动',
        area: ['80%', '90%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/salesPromotion/openAddSalesPromotion'
    });
    this.layerIndex = index;
};
 
/**
 * 点击修改
 */
SalesPromotion.openChangeSalesPromotion = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '编辑促销活动',
            area: ['80%', '90%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/salesPromotion/openChangeSalesPromotion?id=' + this.seItem.id
        });
        this.layerIndex = index;
    }
};
 
/**
 * 删除
 */
SalesPromotion.delSalesPromotion = function () {
    if (this.check()) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/salesPromotion/delSalesPromotion", function (data) {
                if(data.code == 200 ){
                    Feng.success("删除成功!");
                    SalesPromotion.table.refresh();
                }else{
                    Feng.error(data.msg);
                }
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", SalesPromotion.seItem.id);
            ajax.start();
        };
 
        Feng.confirm("是否刪除该促销活动?", operation);
    }
};
 
/**
 * 上架
 */
SalesPromotion.putSalesPromotion = function () {
    if (this.check()) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/salesPromotion/putSalesPromotion", function (data) {
                if(data.code == 200 ){
                    Feng.success("上架成功!");
                    SalesPromotion.table.refresh();
                }else{
                    Feng.error(data.msg);
                }
            }, function (data) {
                Feng.error("上架失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", SalesPromotion.seItem.id);
            ajax.start();
        };
 
        Feng.confirm("是否确认上架?", operation);
    }
};
 
/**
 * 下架
 */
SalesPromotion.offSalesPromotion = function () {
    if (this.check()) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/salesPromotion/offSalesPromotion", function (data) {
                if(data.code == 200 ){
                    Feng.success("下架成功!");
                    SalesPromotion.table.refresh();
                }else{
                    Feng.error(data.msg);
                }
            }, function (data) {
                Feng.error("下架失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", SalesPromotion.seItem.id);
            ajax.start();
        };
 
        Feng.confirm("是否确认下架?", operation);
    }
};
/**
 * 查看活动详情
 * @param id
 */
SalesPromotion.openSalesPromotionInfo = function(id){
    var index = layer.open({
        type: 2,
        title: '促销活动详情',
        area: ['80%', '90%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/salesPromotion/openChangeSalesPromotionInfo?id=' +id
    });
    this.layerIndex = index;
}
/**
 * 预览
 * @param id
 */
SalesPromotion.openSalesPromotionView = function(id){
    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 + '/QrCode/getPreviewQrCode?id=' + id + '&type=2&v=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>'
        ,btnAlign: 'c' //按钮居中
        ,shade: 0.5 //不显示遮罩
    });
}
 
 
/**
 * 导出
 */
SalesPromotion.exportSalesPromotion = function(){
    if(this.check()){
        var ajax = new $ax(Feng.ctxPath + "/gasStation/queryList", function (data) {
            if (data.code == 200) {
                let gasStation = "";
                const d = data.data;
                for (var i in d) {
                    gasStation += '<option value="' + d[i].id + '">' + d[i].name + '</option>'
                }
                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 type="text" class="form-control" id="params" placeholder="参数值1;参数值2">\n' +
                    '                    </div>\n' +
                    '                </div>\n' +
                    '       </div>'
                layer.open({
                    type: 1
                    , title: ''
                    , area: ['500px', '250px']
                    , 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 () {
                        window.location.href = Feng.ctxPath + "/salesPromotion/downloadQRCodeZip?id=" + SalesPromotion.seItem.id + "&params=" + $('#params').val()
                        layer.closeAll();
                    },
                });
                $('#gasStation').selectpicker();
            } else {
                Feng.error(data.msg);
            }
        }, function (data) {
            Feng.error("获取失败!" + data.responseJSON.message + "!");
        });
        ajax.start();
 
    }
}
 
 
 
 
/**
 * 点击用户列表
 */
SalesPromotion.openClickUser = function(id, type){
    if(type == 1){
        var title = "浏览人数"
    }
    if(type == 2){
        var title = "导航人数"
    }
    var index = layer.open({
        type: 2,
        title: title,
        area: ['80%', '90%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/salesPromotion/openClickUser?id=' + id + "&type=" + type
    });
    this.layerIndex = index;
}
 
/**
 * 修改转发状态
 * @param id
 * @param s
 */
SalesPromotion.updateForwardShareState = function(id, s){
    var ajax = new $ax(Feng.ctxPath + "/salesPromotion/updateForwardShareState", function (data) {
        if(data.code == 200 ){
            Feng.success("修改成功!");
            SalesPromotion.table.refresh();
        }else{
            Feng.error(data.msg);
        }
    }, function (data) {
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set("id", id);
    ajax.set("forwardShareState", $(s).val());
    ajax.start();
}
 
 
/**
 * 查看二维码
 */
SalesPromotion.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 + '/QrCode/getPreviewQrCode?id=' + id + '&type=2&v=0"/>\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(function(canvas) {
                var a = document.createElement("a");
                a.href= canvas.toDataURL("image/jpg");
                a.download = name + ".jpg";
                a.click();
            });
            layer.closeAll();
        },
    });
};
 
/**
 * 导入加油站油价
 */
SalesPromotion.importOilPrice = function(){
    if(this.check()){
        $('#file').click();
    }
}
 
 
SalesPromotion.gasStationOilPrice = function (id) {
    var index = layer.open({
        type: 2,
        title: '加油站促销油价',
        area: ['100%', '100%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/salesPromotion/gasStationOilPrice?id=' + id
    });
    this.layerIndex = index;
};
 
 
/**
 * 克隆数据
 */
SalesPromotion.cloneTaskSalesPromotion = function () {
    if (this.check()) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/salesPromotion/cloneTaskSalesPromotion", function (data) {
                if(data.code == 200 ){
                    Feng.success("克隆成功!");
                    SalesPromotion.table.refresh();
                }else{
                    Feng.error(data.msg);
                }
            }, function (data) {
                Feng.error("克隆失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", SalesPromotion.seItem.id);
            ajax.start();
        };
 
        Feng.confirm("是否确认克隆?", operation);
    }
};
 
/**
 * 搜索
 */
SalesPromotion.search = function () {
    var queryData = {};
    queryData['code'] = $("#code").val();
    queryData['name'] = $("#name").val();
    queryData['state'] = $("#state").val();
    queryData['createUser'] = $("#createUser").val();
    SalesPromotion.table.setQueryParams({});
    SalesPromotion.table.refresh({query: queryData});
}
 
/**
 * 重置
 */
SalesPromotion.resetSearch = function(){
    var queryData = {};
    $("#code").val('');
    $("#name").val('');
    $("#state").val('');
    $("#createUser").val('');
    SalesPromotion.table.setQueryParams({});
    SalesPromotion.table.refresh({query: queryData});
}
 
 
 
$(function () {
    var defaultColunms = SalesPromotion.initColumn();
    var table = new BSTable(SalesPromotion.id, "/salesPromotion/querySalesPromotionList", defaultColunms);
    table.setPaginationType("server");
    SalesPromotion.table = table.init();
 
    $(document).click(function (e) {
        $(document).on("click","#qrcodeMask",function () {
            $("#qrcodeMask").hide();
            $("#qrcode").hide();
            $('#qrcodeCanvas').html('');
        })
    })
 
    $('#file').on('change', function () {
        var formData = new FormData()  //创建一个forData
        formData.append('file', $('#file')[0].files[0]) //把file添加进去  name命名为img
        formData.append('id', SalesPromotion.seItem.id)
        layer.load(); //上传loading
        $.ajax({
            url: Feng.ctxPath + '/salesPromotion/importOilPrice',
            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(res.msg);
                    SalesPromotion.search();
                }else{
                    Feng.error(res.msg);
                }
            }
        })
    })
 
});