/**
|
* 角色管理的单例
|
*/
|
var ViewSubCodes = {
|
id: "VipChannelTable", //表格id
|
seItem: null, //选中的条目
|
table: null,
|
layerIndex: -1
|
};
|
|
/**
|
* 初始化表格的列
|
*/
|
ViewSubCodes.initColumn = function () {
|
var columns = [
|
{field: 'select_item', radio: true},
|
{title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
|
{title: '子渠道码名称', field: 'name', align: 'center', valign: 'middle', width: '200px'},
|
{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="ViewSubCodes.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="ViewSubCodes.downloadQRCode(\'' + row.id + '\')">下载</a>';
|
}
|
}
|
]
|
return columns;
|
};
|
|
|
/**
|
* 检查是否选中
|
*/
|
ViewSubCodes.check = function () {
|
var selected = $('#' + this.id).bootstrapTable('getSelections');
|
if (selected.length == 0) {
|
Feng.info("请先选中表格中的某一记录!");
|
return false;
|
} else {
|
ViewSubCodes.seItem = selected[0];
|
return true;
|
}
|
};
|
|
|
/**
|
* 添加
|
*/
|
ViewSubCodes.addViewSubCodes = function(){
|
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 id="name1" class="form-control"/>\n' +
|
' </div>\n' +
|
' </div>\n' +
|
' </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(){
|
var name = $('#name1').val();
|
if(null == name || '' == name){
|
Feng.error("请填写子渠道名称");
|
return;
|
}
|
var ajax = new $ax(Feng.ctxPath + "/vipChannel/addSubVipChannel", function (data) {
|
if(data.code == 200 ){
|
Feng.success("添加成功!");
|
ViewSubCodes.table.refresh();
|
layer.closeAll();
|
}else{
|
Feng.error(data.msg);
|
}
|
}, function (data) {
|
Feng.error("添加失败!" + data.responseJSON.message + "!");
|
});
|
ajax.set("vipChannelId", $('#vipChannelId').val());
|
ajax.set("name", $('#name1').val());
|
ajax.start();
|
},
|
});
|
}
|
|
|
ViewSubCodes.importViewSubCodes = function () {
|
$('#file').click();
|
};
|
|
|
|
|
/**
|
* 删除
|
*/
|
ViewSubCodes.delViewSubCodes = function () {
|
if (this.check()) {
|
var operation = function () {
|
var ajax = new $ax(Feng.ctxPath + "/vipChannel/delViewSubCodes", function (data) {
|
if(data.code == 200 ){
|
Feng.success("删除成功!");
|
ViewSubCodes.table.refresh();
|
}else{
|
Feng.error(data.msg);
|
}
|
}, function (data) {
|
Feng.error("删除失败!" + data.responseJSON.message + "!");
|
});
|
ajax.set("id", ViewSubCodes.seItem.id);
|
ajax.start();
|
};
|
|
Feng.confirm("是否刪除该子渠道?", operation);
|
}
|
};
|
|
|
|
|
|
|
/**
|
* 查看二维码
|
*/
|
ViewSubCodes.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=2"/>\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();
|
});
|
},
|
});
|
};
|
|
|
ViewSubCodes.downloadQRCode = function(id){
|
window.location.href = Feng.ctxPath + "/vipChannel/downloadQRCodeZip?id=" + id + "&vipChannelType=2";
|
}
|
|
|
/**
|
* 搜索
|
*/
|
ViewSubCodes.search = function () {
|
var queryData = {};
|
queryData['name'] = $("#name").val();
|
queryData['vipChannelId'] = $("#vipChannelId").val();
|
ViewSubCodes.table.setQueryParams({});
|
ViewSubCodes.table.refresh({query: queryData});
|
}
|
|
ViewSubCodes.resetSearch = function () {
|
var queryData = {};
|
$("#name").val('');
|
ViewSubCodes.table.setQueryParams({});
|
ViewSubCodes.table.refresh({query: queryData});
|
}
|
|
|
$(function () {
|
var defaultColunms = ViewSubCodes.initColumn();
|
var table = new BSTable(ViewSubCodes.id, "/vipChannel/queryViewSubCodesList", defaultColunms);
|
table.setQueryParams({"vipChannelId": $('#vipChannelId').val()});
|
table.setPaginationType("server");
|
ViewSubCodes.table = table.init();
|
|
$('#file').change(function () {
|
var formData = new FormData() //创建一个forData
|
formData.append('file', $('#file')[0].files[0]) //把file添加进去 name命名为img
|
formData.append("vipChannelId", $('#vipChannelId').val());
|
layer.load(); //上传loading
|
$.ajax({
|
url: Feng.ctxPath + "/vipChannel/importViewSubCodes",
|
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("添加成功");
|
ViewSubCodes.search();
|
}else{
|
Feng.error(res.msg);
|
}
|
}
|
})
|
})
|
});
|