You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

398 lines
15 KiB

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<!--#include file="/widget/head.html"-->
<script type="text/javascript" src="../js/template-web.js"></script>
<style>
.col-md-4, .col-md-1 {
display: inline !important;
float: left;
}
.inline {
display: inline !important;
}
.layui-table-cell {
text-align: center;
height: auto;
}
</style>
</head>
<body class="layui-layout-body" layadmin-themealias="default">
<div id="wrapper" >
<!--#include file="/widget/nav.html"-->
<div id="page-wrapper" class="layui-body layadmin-tabsbody-item layui-show layui-fluid layui-row layui-col-space15">
<div class="layui-card" id="card-page-wrapper">
<div class="layui-form row">
<div class="container" style="margin-left: 30px">
<div class="col-md-2" style="width:450px;font-size:18px;">
状态
<select class="layui-select" name="State" id="State" lay-search lay-filter="State">
<option value="0">全部</option>
<option value="1">生效中</option>
<option value="2">未生效</option>
<option value="3">已失效</option>
</select>
</div>
<div class="col-md-2" style="width:420px;font-size:18px;">
是否开启
<select class="layui-select" name="Status" id="Status" lay-search lay-filter="Status">
<option value="0">全部</option>
<option value="1">开启</option>
<option value="2">关闭</option>
</select>
</div>
<div class="col-md-1">
<button type="button" class="layui-btn " id="add">添加</button>
</div>
<div class="col-md-1">
<button type="button" class="layui-btn " id="batchadd">批量添加</button>
</div>
</div>
</div>
<div class="row table-responsive" id="form" style="width:90%">
<table class="table table-striped table-bordered table-hover inline" id="hero_table">
</table>
<div id="test1"></div>
</div>
</div>
</div>
<label style="color:blue;">关闭</label>
</div>
<script id="btn" type="text/template">
<div style="width:80px;">
{{if Type!=0}}
<input type="button" class="layui-btn layui-btn-xs" value="下载" onclick="downflie({{Id}},'{{ExchangeCode}}',)" />
{{/if}}
<br />
{{if Status==2}}
<input type="button" class="layui-btn layui-btn-xs" style="background-color:red;" value="开启" onclick="delnotice({{Id}},'{{ExchangeCode}}',1)" />
{{else}}
<input type="button" class="layui-btn layui-btn-xs" style="background-color:green;" value="禁用" onclick="delnotice({{Id}},'{{ExchangeCode}}',2)" />
{{/if}}
</div>
</script>
<!--#include file="/widget/tail.html"-->
<script type="text/javascript">
var m_limit = 0;
layui.use(['layer', 'jquery', 'form'], function () {
$ = layui.jquery;
layui.form.on('select(State)', function (data) {
FilterData();
});
layui.form.on('select(Status)', function(data) {
FilterData()
});
});
function FilterData() {
if (exchange_data == undefined) {
layer.msg("暂无数据")
}
debugger
var State = Number($('#State').select().val());
var Status = Number($('#Status').select().val());
var _exchange_data = exchange_data.concat();
if (State == 0 && Status == 0) {
_exchange_data = _exchange_data.filter(f => 1 == 1);
}
else {
if (State != 0) {
_exchange_data = _exchange_data.filter(f => f.State == State);
}
if (Status != 0) {
_exchange_data = _exchange_data.filter(f => f.Status == Status);
}
}
console.info(_exchange_data);
inihero_table(_exchange_data, m_limit);
}
function delnotice(id, text, status) {
var dotext = status == 2 ? "关闭" : "启用";
if (confirm("确定" + dotext + "《" + text + "》兑换码吗?")) {
$.get(Page.SvrIp + "/api/DoDisable_exchange", {
token: cookie.get("token"),
Id: id,
Status: status
}, function (data) {
if (data.ret == 0) {
alert(dotext + "成功!");
location.reload();
}
});
}
}
$("#add").click(function () {
opennotice(0);
});
$("#batchadd").click(function () {
openbatchnotice(0);
});
function opennotice(id) {
var title = "";
if (id == 0) {
title = "添加";
} else {
title = "编辑";
}
layer.open({
content: `/pages/EditExchange.html?id=${id}`,
type: 2,
title: title,
area: ['850px', '770px']
});
}
function openbatchnotice(id) {
var title = "";
if (id == 0) {
title = "批量" + "添加" + "礼包码";
} else {
title = "批量" + "编辑" + "礼包码";
}
layer.open({
content: `/pages/BatchAddExchange.html?id=${id}`,
type: 2,
title: title,
area: ['850px', '870px']
});
}
var herotable;
var exchange_data;
function ini_page(data) {
layui.laypage.render({
elem: 'test1',
count: data.count,
limits: [10, 20, 30, 40, 50, 80, 100],
limit: 20,
layout: ["count", "prev", "page", "next", "limit", "skip"],
jump: function (obj, first) {
if (!first) {
Select_data(obj.curr, obj.limit, 0);
}
}
});
}
function inihero_table(data, limit) {
m_limit = limit;
console.info(data);
herotable = layui.table.render({
elem: '#hero_table',
page: false,
data: data,
width: 1500,
height: 1200,
autoSort: true,
limit: limit,
cols: [[
{ field: 'Id', title: 'Id', sort: true, width: 80 },
{
field: '*', title: '生成<br/>方式', sort: true, width: 80, templet: function (d) {
return d.Type === 0 ? "单条" : "批量";
}
}
, {
field: 'BeginTime', title: '开始时间', sort: true, width: 160, templet: function (d) {
return d.BeginTime == 0 ? "不限制" : Page.formatDate(d.BeginTime);
}
}
, {
field: 'EndTime', title: '结束时间', sort: true, width: 160, templet: function (d) {
return d.EndTime == 0 ? "不限制" : Page.formatDate(d.EndTime);
}
}
, {
field: 'Content', title: '奖励内容', sort: true, width: 240, templet: function (d) {
var text = "";
if (d.Type == 0) {
for (var i in d.Content.AddGoods) {
var _d = d.Content.AddGoods[i];
text += `ID :${_d.ID} 类型 :${_d.Type} 数量 :${_d.Count} <br/>`;
}
} else {
for (var x in d.Content.Groups) {
var _x = d.Content.Groups[x];
text += `<b>组${(Number(x) + 1)} </b >`;
for (var i in _x.AddGoods) {
var _d = _x.AddGoods[i];
text += `ID :${_d.ID} 类型 :${_d.Type} 数量 :${_d.Count} <br/>`;
}
}
}
return text;
}
}
, { field: 'ExchangeCode', title: '兑换码', sort: true, width: 150 }
, {
field: 'Status', title: '启用', sort: true, width: 80, templet: function (d) {
if (d.Status == 1) {
return "<label style=\"color: green;\">开启</label>";
} else if (d.Status == 2) {
return "<label style=\"color: red;\">关闭</label> ";
}
else {
return "<label >未知</label>";
}
}
}
, {
field: 'State', title: '状态', sort: true, width: 80, templet: function (d) {
switch (d.State) {
case 2: return "<label style=\"color: blue;\">未生效</label>";
case 1: return "<label style=\"color: green;\">生效中</label>";
case 3: return "<label style=\"color: red;\">已失效</label>";
default: return "<label >未知</label>";
}
}
}
, { field: 'ExchangeNum', title: '已兑换<br/>数量', sort: true, width: 80 }
//, { field: 'Mainline', title: '主线关卡', sort: true, width: 120 }
, { field: 'MaxExchangeNum', title: '最大兑换<br/>数量', sort: true, width: 120 }
, {
field: '*', title: '编辑', width: 120, templet: function (d) {
return template("btn", d);
}
}
]]
});
}
function getLocalTime(nS) {
return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/, ' ');
}
function Select_data(page, limit, first) {
$.ajax({
type: "GET",
url: Page.SvrIp + "/api/select_exchange",
data: {
token: cookie.get("token"),
page: page,
limit: limit
},
dataType: "json",
beforeSend: function () {
layer.load(1, { shade: [0.8, '#393D49'] });
},
complete: function () {
layer.closeAll('loading');
},
success: function (d) {
if(d.ret==1){
layer.msg(d.msg);
return;
}
exchange_data = JSON.parse(d.data);
inihero_table(exchange_data, limit);
if (first === 1) {
ini_page(d);
}
}
});
}
$(function () {
initPage('礼包信息');
Select_data(1, 20, 1);
});
function downflie(dataid,Pre) {
var data = {};
data.token = cookie.get("token");
data.codeId = dataid;
data.exchangeCode = Pre;
$.ajax({
type: "get",
url: Page.SvrIp + "/api/export_exchangecode",
data: data,
dataType: "json",
success: function (d) {
if (d.ret == 0) {
download_txt(`批量礼包码_${data.exchangeCode}_${dataid}`, d.data);
}
},
error: function () {
alert("保存失败");
}
});
}
function download_txt(filename, texturl) {
var pom = document.createElement('a');
var decodedString = fromBase64(texturl);
pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(decodedString));
pom.setAttribute('download', filename+'.csv');
if (document.createEvent) {
var event = document.createEvent('MouseEvents');
event.initEvent('click', true, true);
pom.dispatchEvent(event);
} else {
pom.click();
}
}
function fromBase64(str){
//base64 转字符串,反过来即可
let code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
let res = '',binaryStr = '';
var tail = 0;//如果有=号则处理
for(let i=0,max = str.length;i<max;i++){
if(str[i]== '='){
tail ++;
}else{
let char = str[i],index = code.indexOf(char);
//每个字符6位
let temp = index.toString(2);
binaryStr += new Array(7 - temp.length).join('0') + temp;
}
}
//如果有=号,则需要重新处理下字符串
binaryStr = binaryStr.substr(0,binaryStr.length - tail * 2);
//split
for(let i=0,max=binaryStr.length;i<max;i+=8){
let temp = binaryStr.substr(i,8);
if(temp.length > 0){
let index = parseInt(temp,2);
let char = String.fromCodePoint(Math.abs(index));
res += char;
}
}
return res;
}
</script>
<script src="../js/coupon.js"></script>
<link href="../bower_components/select2/select2.min.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../bower_components/select2/select2.min.js"></script>
</body>
</html>