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.

542 lines
22 KiB

1 month ago
<!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>
.layui-form-label {
width: 120px !important;
}
#mdiv .layui-form-item {
margin-bottom: 5px !important;
}
.layui-tab-card > .layui-tab-title {
background-color: #009688 !important;
}
.none {
cursor: not-allowed !important;
}
#itemdiv .layui-form-item {
border: 1px solid #808080;
}
</style>
</head>
<body>
<div id="wrapper">
<input type="file" id="imgfile" method="post" onchange="ToBase64()" enctype="multipart/form-data" style="display:none;">
<form class="layui-form" lay-filter="mform">
<div style="height:300px;" id="mdiv">
<div style="height:200px;">
<div style="float:left;width:49%;">
<div class="layui-form-item">
<label class="layui-form-label">礼包码前缀</label>
<div class="layui-input-inline">
<input type="text" name="exchangeCodePre" id="exchangeCodePre" required placeholder="请输入礼包码前缀" autocomplete="off" class="layui-input" oninput="value=value.replace(/[^a-zA-Z]/g,'')">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">兑换开始时间</label>
<div class="layui-input-inline">
<input type="text" name="BeginTime" id="BeginTime" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">兑换结束时间</label>
<div class="layui-input-inline">
<input type="text" name="EndTime" id="EndTime" autocomplete="off" class="layui-input">
<label style="color:red;"> 不填为不限制结束时间 </label>
</div>
</div>
</div>
<div style="float:right;width:49%;">
<div class="layui-form-item" >
<label class="layui-form-label">最大兑换数量</label>
<div class="layui-input-inline" style="width:200px">
<input type="text" name="MaxExchangeNum" id="MaxExchangeNum" placeholder="请输入最大兑换数量" required lay-verify="number" value="99999999" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">是否开启</label>
<div class="layui-input-inline">
<label> <input type="radio" name="Status" checked="checked" data-Status="1" lay-ignore value="1" /> 开启 </label>
<label> <input type="radio" name="Status" lay-ignore data-Status="2" value="2" /> 关闭 </label>
</div>
</div>
</div>
</div>
<div class="layui-tab layui-tab-card" lay-allowClose="true" lay-filter="demo">
<ul class="layui-tab-title"></ul>
<div class="layui-tab-content" id="tab-content"></div>
</div>
<div class="layui-input-inline" style="text-align: center;float: none;margin: 0px auto;display: block;user-select:initial;">
<div class="layui-input-inline" style=" margin-top: 10px;">
<button class="layui-btn layui-bg-red" id="addgroup" style="cursor: pointer; background-color: deepskyblue; color: white; " type="button">添加分组</button>
<button class="layui-btn layui-bg-red" type="button" id="subbtn" lay-submit lay-filter="formDemo">批量生成</button>
</div>
</div>
</div>
</form>
<script type="text/template" id="grouptemp">
<div style="border: 1px solid #ccc; border-radius: 4px;padding-top: 5px;padding-bottom: 3px;">
<input type="text" data-id="groupId" value="{{groupId}}" style="display:none;" />
{{ if (dataid=="0")}}
<div class="layui-form-item">
<label class="layui-form-label">该礼包数量</label>
<div class="layui-input-inline" style="width:200px">
<input type="text" name="codeCount" data-id="codeCount" placeholder="请输入礼包数量" required lay-verify="number"
value="{{codeCount}}" autocomplete="off" class="layui-input">
</div>
<!-- <button type="button" class="btn btn-danger" data-id="downcode" onclick="downflie({{groupId}})" style="cursor:pointer; background-color:chartreuse;color:white; ">-->
<!-- 下载礼包码-->
<!-- </button>-->
</div>
{{/if}}
</div>
<div style="border: 1px solid #ccc; border-radius: 4px;padding-bottom: 5px;" id="djdiv">
<div class="form-group" style="margin-top:10px;" data-id="djdiv">
<div style="padding-bottom: 5px;" id="djdiv">
<div class="form-group" style="margin-top:10px;" data-id="djdiv" data-group="{{groupId}}">
</div>
</div>
<button type="button" class="btn btn-danger" onclick="adddj({{groupId}})" style="cursor:pointer; background-color:deepskyblue;color:white; ">
增加道具
</button>
</div>
</div>
</script>
<script type="text/template" id="djhtml">
<div class="layui-form-item" data-id="djdiv{{djnum}}" data-djdiv='djdiv' data-group="{{groupId}}">
<label class="layui-form-label">道具id</label>
<div class="layui-input-inline" style="width:180px;">
<!-- <input type="text" name="dj{{djnum}}" value="{{ID}}" lay-verify="number" data-id="dj" id="dj{{djnum}}" autocomplete="off" class="layui-input">-->
<select class="form-control zero" data-id="dj" id="dj{{djnum}}">
<option value="-1">-----请选择-----</option>
</select>
</div>
<label class="layui-form-label">道具数量</label>
<div class="layui-input-inline" style="width:80px;">
<input type="text" name="dj{{djnum}}" value="0" lay-verify="number" data-id="djCount" id="djCount{{djnum}}" autocomplete="off" class="layui-input">
</div>
<button type="button" class="btn btn-danger col-sm-2" data-toggle="modal" onclick="deldj({{djnum}})" style="float:left;">
删除道具
</button>
</div>
</script>
<script>
var languagelist;
var itemList;
function AddItemList(uiId){
var data =new Array();
$('#'+uiId).html('');
for (let [key, value] of Object.entries(itemList)) {
data.push({id:key,text:value})
$('#'+uiId).append('<option value="'+key+'">'+value+'</option>');
}
layui.form.render('select');
}
function Load_ItemList() {
$.get(Page.SvrIp + "/api/select_itemlist",
{ token: cookie.get("token") }
, function (d) {
itemList = d.data;
//AddItemList("dj1");
});
}
var groupnum = 0;
var djnum = 0;
var curnum = 0;
function delcur(i) {
--curnum;
$("div[data-id=curdiv" + i + "]").remove();
}
function deldj(i) {
--djnum;
$("div[data-id=djdiv" + i + "]").remove();
}
function addcur(groupid) {
++curnum;
$("div[data-id=curdiv][data-group=" + groupid + "]").append(template("curhtml", {
curnum: curnum,
Type: 1,
curCount: 1,
Count: 1,
ID: 0,
groupid: groupid
}));
}
function adddj(groupid) {
++djnum;
$("div[data-id=djdiv][data-group=" + groupid + "]").append(template("djhtml", {
djnum: djnum,
Type: 1,
djCount: 1,
Count: 1,
ID: 0,
groupid: groupid
}));
AddItemList("dj"+djnum);
}
$("#addgroup").click(function () {
if ($("#tab-content").find(".layui-tab-item").length >= 6) {
alert("分组数量不能多于6种");
return;
}
add_group();
});
function curid(t) {
var val = $(t).val();
$(t).parents("[data-curdiv='curdiv']").find("[data-id='curCount']").attr('disabled', false)
$(t).parents("[data-curdiv='curdiv']").find("[data-id='curCount']").removeClass('none')
}
function sub_Exchange_add() {
layui.form.on('submit(formDemo)', function (data) {
console.info(data);
if(data.field.exchangeCodePre.length != 4) {
layer.msg('礼包码前缀长度只能为4')
return;
}
data.field.token = cookie.get("token");
data.field.BeginTime = data.field.BeginTime == '' ? 0 : (new Date(new Date(data.field.BeginTime)).getTime() / 1000);
data.field.EndTime = data.field.EndTime == '' ? 0 : (new Date(new Date(data.field.EndTime)).getTime() / 1000);
var Content = [];
var curhaszero = false;
var curallzero = false;
var djhaszero = false;
var djallzero = false;
var stop = false;
$("#tab-content .layui-tab-item").each(function (i, e) {
var itemstr = "";
$(e).find("div[data-curdiv='curdiv']").each(function (i, e) {
var curtype = 2;
var curcount = $(e).find("input[data-id='curCount']").val();
var curid = $(e).find("select[data-id='curid']").val();
if (curcount == 0 || curid == 0)
{
curhaszero = true
}
else{
if (i != 0) {
itemstr += '#';
}
itemstr += `${curtype}|${curid}|${curnum}`;
}
});
if(curhaszero) {
layer.msg('货币存在非法输入!')
stop = ture;
return ;
}
$(e).find("div[data-djdiv='djdiv']").each(function (i, e) {
debugger
var djtype =1; //$(e).find("input[data-id='djtype']").val();
var djid = $(e).find("select[data-id='dj']").val();
var djcount = $(e).find("input[data-id='djCount']").val();
if (djtype == 0 || djcount == 0 || djid == 0)
{
djhaszero = true
}
else{
if (itemstr != "") {
itemstr += '#';
}
itemstr += `${djtype}|${djid}|${djnum}`;
}
});
if(djhaszero) {
layer.msg('道具存在非法输入!')
stop = ture;
return ;
}
Content.push({
codeCount: $(e).find("[data-id='codeCount']").val() ?
Number($(e).find("[data-id='codeCount']").val()) : 0,
maxExchangeNum: $(e).find("[data-id='maxExchangeNum']").val() ?
Number($(e).find("[data-id='maxExchangeNum']").val()) : 0,
groupId: $(e).find("[data-id='groupId']").val() ?
Number($(e).find("[data-id='groupId']").val()) : 0,
content: itemstr
});
});
if(stop) {
return;
}
data.field.exchangeGroup = JSON.stringify(Content);
$.ajax({
type: "get",
url: Page.SvrIp + "/api/create_exchangecode",
data: data.field,
dataType: "json",
success: function (d) {
alert(d.msg);
if (d.ret == 0) {
parent.layer.close(parent.layer.getFrameIndex(window.name));
parent.location.reload();
}
},
error: function () {
alert("保存失败");
}
});
return false;
})
}
function sub_Exchange_Edit() {
layui.form.on('submit(formDemo)', function (data) {
console.info(data);
if(data.field.exchangeCodePre.length != 4) {
layer.msg('礼包码前缀长度只能为4')
return;
}
data.field.token = cookie.get("token");
data.field.BeginTime = data.field.BeginTime == '' ? 0 : (new Date(new Date(data.field.BeginTime)).getTime() / 1000);
data.field.EndTime = data.field.EndTime == '' ? 0 : (new Date(new Date(data.field.EndTime)).getTime() / 1000);
data.field.Id = dataid;
var Content = [];
$("#tab-content .layui-tab-item").each(function (i, e) {
var itemstr = "";
$(e).find("div[data-curdiv='curdiv']").each(function (i, e) {
var curtype = 2;
var curnum = $(e).find("input[data-id='curCount']").val();
var curid = $(e).find("select[data-id='curid']").val();
if (i != 0) {
itemstr += '#';
}
itemstr += `${curtype}|${curid}|${curnum}`;
});
$(e).find("div[data-djdiv='djdiv']").each(function (i, e) {
var djtype =1; //$(e).find("input[data-id='djtype']").val();
var djid = $(e).find("select[data-id='dj']").val();
var djnum = $(e).find("input[data-id='djCount']").val();
if (itemstr != "") {
itemstr += '#';
}
itemstr += `${djtype}|${djid}|${djnum}`;
});
Content.push({
codeCount: $(e).find("[data-id='codeCount']").val() ?
Number($(e).find("[data-id='codeCount']").val()) : 0,
maxExchangeNum: $(e).find("[data-id='maxExchangeNum']").val() ?
Number($(e).find("[data-id='maxExchangeNum']").val()) : 0,
groupId: $(e).find("[data-id='groupId']").val() ?
Number($(e).find("[data-id='groupId']").val()) : 0,
content: itemstr
});
});
data.field.exchangeGroup = JSON.stringify(Content);
$.ajax({
type: "get",
url: Page.SvrIp + "/api/update_exchangecode_group",
data: data.field,
dataType: "json",
success: function (d) {
alert(d.msg);
if (d.ret == 0) {
parent.layer.close(parent.layer.getFrameIndex(window.name));
parent.location.reload();
}
},
error: function () {
alert("保存失败");
}
});
return false;
})
}
function djnumfunLoad(groupid, data) {
if ($("div[data-group=" + groupid + "][data-itemdiv=itemdiv]").length >= 6) {
alert("道具数量不能多于6种");
return;
}
++djnum;
$("div[data-id=itemdiv][data-group=" + groupid + "]").append(template("itemhtml", {
djnum: djnum,
Type: data.Type,
Count: data.Count,
ID: data.ID,
groupid: groupid
}));
}
</script>
<script>
//兑换码id 0表示新增 非0编辑
var dataid = Page.GetQueryString("id");
template.defaults.imports.dataid = dataid;
function add_group() {
++groupnum;
layui.element.tabAdd('demo', {
title: "礼包" + groupnum
, content: template("grouptemp", {
groupid: groupnum,
codeCount: 0,
groupId: groupnum
})
, id: groupnum
});
layui.element.tabChange('demo', groupnum);
}
//编辑时加载
function add_groupLoad(data) {
++groupnum;
layui.element.tabAdd('demo', {
title: "礼包" + groupnum
, content: template("grouptemp", {
MaxExchangeNum: data.MaxExchangeNum,
groupId: data.GroupId,
})
, id: groupnum
});
layui.element.tabChange('demo', groupnum);
}
function LoadExchange(id) {
if (id == "0") {
sub_Exchange_add();
$("button[data-id=downcode]").hide();
return;
} else {
$("#subbtn").text("修改礼包码");
$("#Id").addClass("none");
$("#addgroup").hide();
sub_Exchange_Edit();
}
var data = {
id: id,
token: cookie.get("token")
};
$.ajax({
type: "get",
url: Page.SvrIp + "/api/select_exchange",
data: data,
dataType: "json",
success: function (d) {
if (d.ret == 0) {
d.data = JSON.parse(d.data)[0];
LoadExchange_data(d.data);
}
},
error: function () {
alert("加载失败");
}
});
}
function LoadExchange_data(data) {
console.info(data);
var field = ["Id", "ExchangeCode", "MaxExchangeNum", "ExchangeNum"];
for (var i in field) {
var name = field[i];
$("#" + name).val(data[name]);
}
if (data.BeginTime != 0) {
$("#BeginTime").val(Page.formatDate(data.BeginTime));
}
if (data.EndTime != 0) {
$("#EndTime").val(Page.formatDate(data.EndTime));
}
$("input[data-Status=" + data.Status + "]").attr("checked", "checked");
$("#exchangeCodePre").val(data.ExchangeCode);
$("#codeCount").attr("disabled", "disabled");
for (var x in data.Content.Groups) {
var _x = data.Content.Groups[x];
add_groupLoad(_x);
for (var i in _x.AddGoods) {
var _d = _x.AddGoods[i];
djnumfunLoad(_x.GroupId, _d);
}
}
$(".layui-icon.layui-icon-close.layui-unselect.layui-tab-close").hide();
}
$(function () {
layui.laydate.render({
elem: '#BeginTime',
type: "datetime"
});
layui.laydate.render({
elem: '#EndTime',
type: "datetime"
});
LoadExchange(dataid);
Load_ItemList();
layui.form.render(null, "mform");
});
</script>
</div>
</body>
</html>