/**
|
* 角色管理的单例
|
*/
|
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 + "¶ms=" + $('#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);
|
}
|
}
|
})
|
})
|
|
});
|