/**
|
* 角色管理的单例
|
*/
|
var CouponActivity = {
|
id: "CouponActivityTable", //表格id
|
seItem: null, //选中的条目
|
table: null,
|
layerIndex: -1
|
};
|
|
/**
|
* 初始化表格的列
|
*/
|
CouponActivity.initColumn = function () {
|
var columns = [
|
{field: 'select_item', radio: true},
|
{title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle', width: '80px'},
|
{title: 'ID', field: 'code', align: 'center', valign: 'middle', width: '150px'},
|
{title: '名称', field: 'name', align: 'center', valign: 'middle', width: '200px',
|
formatter: function (value, row) {
|
return '<a href="#" onclick="CouponActivity.openCouponActivityInfo(' + row.id + ')">' + value + '</a>';
|
}
|
},
|
{title: '商品编号', field: 'couponCode', align: 'center', valign: 'middle', width: '100px'},
|
{title: '购买方式', field: 'payType', align: 'center', valign: 'middle', width: '150px',
|
formatter: function (value, row) {
|
return row.type == 1 ? '-' : value;
|
}
|
},
|
{title: '价值', field: 'price', align: 'center', valign: 'middle', width: '150px',
|
formatter: function (value, row) {
|
return row.type == 1 ? '-' : value;
|
}
|
},
|
{title: '活动时间周期', field: 'startEndTime', align: 'center', valign: 'middle', width: '300px'},
|
{title: '图片', field: 'baseMap', align: 'center', valign: 'middle', width: '100px',
|
formatter: function (value, row) {
|
return '<img src="' + value + '" onclick="showImg(this)" width="90px;"/>';
|
}
|
},
|
{title: '描述', field: 'description', align: 'center', valign: 'middle', width: '100px',
|
formatter: function (value, row) {
|
return '<span title="' + value + '">' + value + '</span>';
|
}
|
},
|
{title: '浏览人数', field: 'visitorsNumber', align: 'center', valign: 'middle', width: '100px',
|
formatter: function (value, row) {
|
return '<a href="#" onclick="CouponActivity.openClickUser(\'' + row.id + '\',1)">' + value + '</a>';
|
}
|
},
|
{title: '已买人数', field: 'buyers', align: 'center', valign: 'middle', sortable: true, width: '100px',
|
formatter: function (value, row) {
|
return '<a href="#" onclick="CouponActivity.openClickUser(\'' + row.id + '\',2)">' + value + '</a>';
|
}
|
},
|
{title: '已买数量', field: 'purchaseQuantity', align: 'center', valign: 'middle', sortable: true, width: '100px'},
|
{title: '售卖金额', field: 'salesAmount', align: 'center', valign: 'middle', sortable: true, width: '100px'},
|
{title: '售卖积分', field: 'salesCredits', align: 'center', valign: 'middle', width: '80px'},
|
{title: '预览', field: 'salesCredits', align: 'center', valign: 'middle', width: '100px',
|
formatter: function (value, row) {
|
return '<a onclick="CouponActivity.showQRCode(\'' + row.id + '\',\'' + row.name + '\')">预览主页</a>';
|
}
|
},
|
{title: '配置人', field: 'createUser', align: 'center', valign: 'middle', width: '100px'},
|
{title: '配置时间', field: 'updateTime', align: 'center', valign: 'middle', width: '150px'},
|
{title: '推荐排序', field: 'sort', align: 'center', valign: 'middle', width: '150px',
|
formatter: function (value, row) {
|
return '<input onblur="CouponActivity.updateSort(' + row.id + ',this)" value="' + (typeof value == "undefined" ? '' : value) + '" style="height: 50px;\n' +
|
' width: 100%;\n' +
|
' border: none;\n' +
|
' text-align: center;">';
|
}
|
},
|
{title: '状态', field: 'state', align: 'center', valign: 'middle', width: '80px',
|
formatter: function (value) {
|
switch (value) {
|
case 1:
|
return '已上架';
|
case 2:
|
return '已下架';
|
}
|
}
|
},
|
{title: '操作', field: 'forwardAndShare', align: 'center', valign: 'middle', width: '150px',
|
formatter: function (value, row) {
|
let str = '';
|
if(null != row.baseMap && row.baseMap != ''){
|
str += '<a onclick="CouponActivity.showQRCode(\'' + row.id + '\',\'' + row.name + '\')">查看链接/二维码</a><br><br><select onchange="CouponActivity.updateForwardShareState(\'' + row.id + '\',this)">';
|
if(row.forwardAndShare == 1){
|
str += '<option value="1" selected>开启转发</option><option value="0">关闭转发</option></select>';
|
}else{
|
str += '<option value="1">开启转发</option><option value="0" selected>关闭转发</option></select>';
|
}
|
}else{
|
return "-";
|
}
|
return str;
|
}
|
}
|
]
|
return columns;
|
};
|
|
|
/**
|
* 检查是否选中
|
*/
|
CouponActivity.check = function () {
|
var selected = $('#' + this.id).bootstrapTable('getSelections');
|
if (selected.length == 0) {
|
Feng.info("请先选中表格中的某一记录!");
|
return false;
|
} else {
|
CouponActivity.seItem = selected[0];
|
return true;
|
}
|
};
|
|
/**
|
* 点击添加
|
*/
|
CouponActivity.openAddCouponActivity = function () {
|
var index = layer.open({
|
type: 2,
|
title: '添加活动模板',
|
area: ['100%', '100%'], //宽高
|
fix: false, //不固定
|
maxmin: true,
|
content: Feng.ctxPath + '/couponActivity/openAddCouponActivity'
|
});
|
this.layerIndex = index;
|
};
|
|
/**
|
* 点击修改
|
*/
|
CouponActivity.openChangeCouponActivity = function () {
|
if (this.check()) {
|
var index = layer.open({
|
type: 2,
|
title: '编辑活动模板',
|
area: ['100%', '100%'], //宽高
|
fix: false, //不固定
|
maxmin: true,
|
content: Feng.ctxPath + '/couponActivity/openChangeCouponActivity?id=' + this.seItem.id
|
});
|
this.layerIndex = index;
|
}
|
};
|
|
|
CouponActivity.editCouponActivityStatus = function (status) {
|
if (this.check()) {
|
var operation = function () {
|
var ajax = new $ax(Feng.ctxPath + "/couponActivity/editCouponActivityStatus", function (data) {
|
if(data.code == 200 ){
|
Feng.success(status == 1 ? "上架成功" : status == 2 ? "下架成功" : "删除成功!");
|
CouponActivity.table.refresh();
|
}else{
|
Feng.error(data.msg);
|
}
|
}, function (data) {
|
Feng.error((status == 1 ? "上架失败" : status == 2 ? "下架失败" : "删除失败!") + data.responseJSON.message + "!");
|
});
|
ajax.set("id", CouponActivity.seItem.id);
|
ajax.set("status", status);
|
ajax.start();
|
};
|
|
Feng.confirm("是否" + (status == 1 ? "上架" : status == 2 ? "下架" : "删除") + "该活动模板?", operation);
|
}
|
};
|
|
|
CouponActivity.cloneCouponActivity = function () {
|
if (this.check()) {
|
var operation = function () {
|
var ajax = new $ax(Feng.ctxPath + "/couponActivity/cloneCouponActivity", function (data) {
|
if(data.code == 200 ){
|
Feng.success("克隆成功!");
|
CouponActivity.table.refresh();
|
}else{
|
Feng.error(data.msg);
|
}
|
}, function (data) {
|
Feng.error("克隆失败!" + data.responseJSON.message + "!");
|
});
|
ajax.set("id", CouponActivity.seItem.id);
|
ajax.start();
|
};
|
|
Feng.confirm("是否确认克隆?", operation);
|
}
|
};
|
|
|
/**
|
* 详情
|
* @param id
|
*/
|
CouponActivity.openCouponActivityInfo = function(id){
|
var index = layer.open({
|
type: 2,
|
title: '模板活动详情',
|
area: ['80%', '90%'], //宽高
|
fix: false, //不固定
|
maxmin: true,
|
content: Feng.ctxPath + '/couponActivity/openCouponActivityInfo?id=' + id
|
});
|
this.layerIndex = index;
|
}
|
|
|
/**
|
* 导出
|
*/
|
CouponActivity.exportCouponActivity = 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' +
|
'<form name="input" action="' + Feng.ctxPath + '/couponActivity/importData" method="post" enctype="multipart/form-data" target="_self">' +
|
'<input style="display: none;" type="text" id="id" name="id" value="' + CouponActivity.seItem.id + '">' +
|
' <div class="form-group" style="height: 50px;">\n' +
|
' <label class="col-sm-3 control-label">加油站选择</label>\n' +
|
' <div class="col-sm-6">\n' +
|
' <select id="gasStation" class="selectpicker show-tick form-control" multiple data-live-search="true" data-style="btn-info" title="选择加油站">' + gasStation + '</select>\n' +
|
' </div>\n' +
|
' <div class="col-sm-3">\n' +
|
' <input type="button" class="form-control" id="excel" onclick="CouponActivity.importData()" value="excel导入"/>\n' +
|
' </div>\n' +
|
' </div>\n' +
|
' <div class="form-group" style="height: 50px;">\n' +
|
' <label class="col-sm-3 control-label">excel</label>\n' +
|
' <div class="col-sm-8">\n' +
|
' <span id="excelName"></span>\n' +
|
' </div>\n' +
|
' </div>\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" name="params" placeholder="参数值1;参数值2">\n' +
|
' </div>\n' +
|
' </div>\n' +
|
'<input type="file" id="file" name="file" style="display: none" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel">' +
|
'<input type="submit" style="display: none" id="submit" value="Submit"/> ' +
|
'</form>' +
|
' </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 () {
|
if($('#file')[0].files.length == 0){
|
if(!$('#gasStation').val()){
|
Feng.error("加油站不能为空");
|
return
|
}
|
window.location.href = Feng.ctxPath + "/couponActivity/downloadQRCodeZip?id=" + CouponActivity.seItem.id + "&ids=" + $('#gasStation').val() + "¶ms=" + $('#params').val()
|
}else{
|
$('#submit').click();
|
$('#file').val('');
|
}
|
|
layer.closeAll();
|
},
|
});
|
$('#gasStation').selectpicker();
|
} else {
|
Feng.error(data.msg);
|
}
|
}, function (data) {
|
Feng.error("获取失败!" + data.responseJSON.message + "!");
|
});
|
ajax.start();
|
|
}
|
}
|
|
|
CouponActivity.importData = function(){
|
$('#file').val('');
|
$('#file').click();
|
$('#file').on('change', function () {
|
const file = $('#file')[0].files[0]
|
$('#excelName').text(file.name);
|
})
|
}
|
|
|
/**
|
* 点击用户列表
|
*/
|
CouponActivity.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 + '/couponActivity/openClickUser?id=' + id + "&type=" + type
|
});
|
this.layerIndex = index;
|
}
|
|
/**
|
* 修改转发状态
|
* @param id
|
* @param s
|
*/
|
CouponActivity.updateForwardShareState = function(id, s){
|
var ajax = new $ax(Feng.ctxPath + "/couponActivity/updateForwardShareState", function (data) {
|
if(data.code == 200 ){
|
Feng.success("修改成功!");
|
CouponActivity.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();
|
}
|
|
CouponActivity.updateSort = function(id, s){
|
var ajax = new $ax(Feng.ctxPath + "/couponActivity/updateSort", function (data) {
|
if(data.code == 200 ){
|
Feng.success("修改成功!");
|
CouponActivity.table.refresh();
|
}else{
|
Feng.error(data.msg);
|
}
|
}, function (data) {
|
Feng.error("修改失败!" + data.responseJSON.message + "!");
|
});
|
ajax.set("id", id);
|
ajax.set("sort", $(s).val());
|
ajax.start();
|
}
|
|
|
|
/**
|
* 查看二维码
|
*/
|
CouponActivity.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=4&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();
|
},
|
});
|
};
|
|
|
|
/**
|
* 搜索
|
*/
|
CouponActivity.search = function () {
|
var queryData = {};
|
queryData['code'] = $("#code").val();
|
queryData['name'] = $("#name").val();
|
queryData['payType'] = $("#payType").val();
|
queryData['state'] = $("#state").val();
|
queryData['createUser'] = $("#createUser").val();
|
CouponActivity.table.setQueryParams({});
|
CouponActivity.table.refresh({query: queryData});
|
}
|
|
/**
|
* 重置
|
*/
|
CouponActivity.resetSearch = function(){
|
var queryData = {};
|
$("#code").val('');
|
$("#name").val('');
|
$("#payType").val('');
|
$("#state").val('');
|
$("#createUser").val('');
|
CouponActivity.table.setQueryParams({});
|
CouponActivity.table.refresh({query: queryData});
|
}
|
|
|
|
$(function () {
|
var defaultColunms = CouponActivity.initColumn();
|
var table = new BSTable(CouponActivity.id, "/couponActivity/queryCouponActivityList", defaultColunms);
|
table.setPaginationType("server");
|
CouponActivity.table = table.init();
|
|
|
|
});
|