/**
|
* 角色管理的单例
|
*/
|
var Coupon = {
|
id: "CouponTable", //表格id
|
seItem: null, //选中的条目
|
table: null,
|
layerIndex: -1
|
};
|
|
/**
|
* 初始化表格的列
|
*/
|
Coupon.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: '200px',
|
formatter: function (value, row) {
|
return '<a href="#" onclick="Coupon.openCouponInfo(\'' + row.id + '\')" title="' + value + '">' + value + '</a>';
|
}
|
},
|
{title: '预览', field: '', align: 'center', valign: 'middle', width: '100px',
|
formatter: function (value, row) {
|
return '<a onclick="Coupon.previewQRCode(\'' + row.id + '\')">预览主页</a>';
|
}
|
},
|
{title: '价值', field: 'price', align: 'center', valign: 'middle', width: '80px'},
|
{title: '售卖金额', field: 'unitPrice', align: 'center', valign: 'middle', width: '80px'},
|
{title: '活动价格', field: 'activityPrice', align: 'center', valign: 'middle', width: '80px'},
|
{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: 'pointTime', align: 'center', valign: 'middle', width: '300px',
|
formatter:function (value,row){
|
if(value!=null && value!=undefined){
|
value = value.replace("[","(").replace("]",")")
|
}
|
return value;
|
}
|
},
|
{title: '图片', field: 'img', align: 'center', valign: 'middle', width: '100px',
|
formatter: function (value, row) {
|
return '<img src="' + value + '" onclick="showImg(this)" width="90px;"/>';
|
}
|
},
|
{title: '描述', field: 'listDescribe', align: 'center', valign: 'middle', width: '100px',
|
formatter: function (value, row) {
|
return '<span title="' + value + '">' + value + '</span>';
|
}
|
},
|
{title: '数量上限', field: 'total', align: 'center', valign: 'middle', width: '80px'},
|
{title: '剩余数量', field: 'surplusNumber', align: 'center', valign: 'middle', sortable: true, width: '100px'},
|
{title: '单人限购', field: 'restrictedQuantity', align: 'center', valign: 'middle', width: '80px'},
|
{title: '浏览人数', field: 'views', align: 'center', valign: 'middle', sortable: true, width: '100px',
|
formatter: function (value, row) {
|
return '<a href="#" onclick="Coupon.openClickUser(\'' + row.id + '\',1)">' + value + '</a>';
|
}
|
},
|
{title: '已买人数', field: 'pay', align: 'center', valign: 'middle', sortable: true, width: '100px',
|
formatter: function (value, row) {
|
return '<a href="#" onclick="Coupon.openClickUser(\'' + row.id + '\',2)">' + value + '</a>';
|
}
|
},
|
{title: '发放数量', field: 'number', align: 'center', valign: 'middle', width: '80px'},
|
{title: '配置人', field: 'createUser', align: 'center', valign: 'middle', width: '80px'},
|
{title: '配置时间', field: 'updateTime', align: 'center', valign: 'middle', width: '150px'},
|
{title: '券包类型', field: 'seckillState', align: 'center', valign: 'middle', width: '80px',
|
formatter: function (value) {
|
switch (value) {
|
case 0:
|
return '普通';
|
case 1:
|
return '秒杀';
|
}
|
}
|
},
|
{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 = '';
|
if(null != row.backgroundImg && row.backgroundImg != ''){
|
str += '<a onclick="Coupon.showQRCode(\'' + row.id + '\',\'' + row.name + '\')">查看链接/二维码</a><br><br><select onchange="Coupon.updateForwardShareState(\'' + row.id + '\',this)">';
|
if(row.forwardShareState == 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;
|
};
|
|
|
/**
|
* 检查是否选中
|
*/
|
Coupon.check = function () {
|
var selected = $('#' + this.id).bootstrapTable('getSelections');
|
if (selected.length == 0) {
|
Feng.info("请先选中表格中的某一记录!");
|
return false;
|
} else {
|
Coupon.seItem = selected[0];
|
return true;
|
}
|
};
|
|
/**
|
* 点击添加
|
*/
|
Coupon.openAddCoupon = function () {
|
var index = layer.open({
|
type: 2,
|
title: '添加券包',
|
area: ['100%', '100%'], //宽高
|
fix: false, //不固定
|
maxmin: true,
|
content: Feng.ctxPath + '/coupon/openAddCoupon'
|
});
|
this.layerIndex = index;
|
};
|
|
/**
|
* 点击修改
|
*/
|
Coupon.openChangeCoupon = function () {
|
if (this.check()) {
|
var index = layer.open({
|
type: 2,
|
title: '编辑券包',
|
area: ['100%', '100%'], //宽高
|
fix: false, //不固定
|
maxmin: true,
|
content: Feng.ctxPath + '/coupon/openChangeCoupon?id=' + this.seItem.id
|
});
|
this.layerIndex = index;
|
}
|
};
|
|
/**
|
* 删除
|
*/
|
Coupon.delCoupon = function () {
|
if (this.check()) {
|
var operation = function () {
|
var ajax = new $ax(Feng.ctxPath + "/coupon/delCoupon", function (data) {
|
if(data.code == 200 ){
|
Feng.success("删除成功!");
|
Coupon.table.refresh();
|
}else{
|
Feng.error(data.msg);
|
}
|
}, function (data) {
|
Feng.error("删除失败!" + data.responseJSON.message + "!");
|
});
|
ajax.set("id", Coupon.seItem.id);
|
ajax.start();
|
};
|
|
Feng.confirm("是否刪除该券包?", operation);
|
}
|
};
|
|
/**
|
* 上架
|
*/
|
Coupon.putCoupon = function () {
|
if (this.check()) {
|
var operation = function () {
|
var ajax = new $ax(Feng.ctxPath + "/coupon/putCoupon", function (data) {
|
if(data.code == 200 ){
|
Feng.success("上架成功!");
|
Coupon.table.refresh();
|
}else{
|
Feng.error(data.msg);
|
}
|
}, function (data) {
|
Feng.error("上架失败!" + data.responseJSON.message + "!");
|
});
|
ajax.set("id", Coupon.seItem.id);
|
ajax.start();
|
};
|
|
Feng.confirm("是否确认上架?", operation);
|
}
|
};
|
|
/**
|
* 下架
|
*/
|
Coupon.offCoupon = function () {
|
if (this.check()) {
|
var operation = function () {
|
var ajax = new $ax(Feng.ctxPath + "/coupon/offCoupon", function (data) {
|
if(data.code == 200 ){
|
Feng.success("下架成功!");
|
Coupon.table.refresh();
|
}else{
|
Feng.error(data.msg);
|
}
|
}, function (data) {
|
Feng.error("下架失败!" + data.responseJSON.message + "!");
|
});
|
ajax.set("id", Coupon.seItem.id);
|
ajax.start();
|
};
|
|
Feng.confirm("是否确认下架?", operation);
|
}
|
};
|
|
|
/**
|
* 详情
|
* @param id
|
*/
|
Coupon.openCouponInfo = function(id){
|
var index = layer.open({
|
type: 2,
|
title: '券包详情',
|
area: ['80%', '90%'], //宽高
|
fix: false, //不固定
|
maxmin: true,
|
content: Feng.ctxPath + '/coupon/openCouponInfo?id=' + id
|
});
|
this.layerIndex = index;
|
}
|
|
|
/**
|
* 导出
|
*/
|
Coupon.exportCoupon = 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 + '/coupon/importData" method="post" enctype="multipart/form-data" target="_self">' +
|
'<input style="display: none;" type="text" id="id" name="id" value="' + Coupon.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="Coupon.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 + "/coupon/downloadQRCodeZip?id=" + Coupon.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();
|
|
}
|
}
|
|
|
Coupon.importData = function(){
|
$('#file').val('');
|
$('#file').click();
|
$('#file').on('change', function () {
|
const file = $('#file')[0].files[0]
|
$('#excelName').text(file.name);
|
})
|
}
|
|
|
/**
|
* 点击用户列表
|
*/
|
Coupon.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 + '/coupon/openClickUser?id=' + id + "&type=" + type
|
});
|
this.layerIndex = index;
|
}
|
|
/**
|
* 修改转发状态
|
* @param id
|
* @param s
|
*/
|
Coupon.updateForwardShareState = function(id, s){
|
var ajax = new $ax(Feng.ctxPath + "/coupon/updateForwardShareState", function (data) {
|
if(data.code == 200 ){
|
Feng.success("修改成功!");
|
Coupon.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();
|
}
|
|
/**
|
* 拷贝
|
*/
|
Coupon.openCloneCoupon = function () {
|
if (this.check()) {
|
var operation = function () {
|
var ajax = new $ax(Feng.ctxPath + "/coupon/cloneCoupon", function (data) {
|
if(data.code == 200 ){
|
Feng.success("克隆成功!");
|
Coupon.table.refresh();
|
}else{
|
Feng.error(data.msg);
|
}
|
}, function (data) {
|
Feng.error("克隆失败!" + data.responseJSON.message + "!");
|
});
|
ajax.set("id", Coupon.seItem.id);
|
ajax.start();
|
};
|
|
Feng.confirm("是否确认克隆?", operation);
|
}
|
};
|
/**
|
* 预览二维码
|
* @param id
|
*/
|
Coupon.previewQRCode = 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=1&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>'
|
,btnAlign: 'c' //按钮居中
|
,shade: 0.5 //不显示遮罩
|
});
|
}
|
|
/**
|
* 查看二维码
|
*/
|
Coupon.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=1&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();
|
},
|
});
|
};
|
|
|
|
/**
|
* 搜索
|
*/
|
Coupon.search = function () {
|
var queryData = {};
|
queryData['code'] = $("#code").val();
|
queryData['name'] = $("#name").val();
|
queryData['state'] = $("#state").val();
|
queryData['seckillState'] = $("#seckillState").val();
|
queryData['createUser'] = $("#createUser").val();
|
Coupon.table.setQueryParams({});
|
Coupon.table.refresh({query: queryData});
|
}
|
|
/**
|
* 重置
|
*/
|
Coupon.resetSearch = function(){
|
var queryData = {};
|
$("#code").val('');
|
$("#name").val('');
|
$("#state").val('');
|
$("#seckillState").val('');
|
$("#createUser").val('');
|
Coupon.table.setQueryParams({});
|
Coupon.table.refresh({query: queryData});
|
}
|
|
|
|
$(function () {
|
var defaultColunms = Coupon.initColumn();
|
var table = new BSTable(Coupon.id, "/coupon/queryCouponList", defaultColunms);
|
table.setPaginationType("server");
|
Coupon.table = table.init();
|
|
|
|
});
|