dongfeng-pay/legend/views/template-edit.html
2021-05-16 15:21:52 +08:00

484 lines
25 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html class="x-admin-sm">
<head>
<meta charset="UTF-8">
<title>充值商户后台</title>
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="stylesheet" href="../static/x-admin/css/font.css">
<link rel="stylesheet" href="../static/x-admin/css/xadmin.css">
<!-- <link rel="stylesheet" href="./css/theme5.css"> -->
<script src="../static/x-admin/lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="../static/x-admin/js/xadmin.js"></script>
<script type="text/javascript" src="../static/js/jquery-3.5.1.min.js"></script>
<!-- 让IE8/9支持媒体查询从而兼容栅格 -->
<!--[if lt IE 9]>
<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="layui-fluid">
<div class="layui-card">
<div class="layui-card-header"><b>编辑模板</b></div>
<div class="layui-card-body">
<div class="layui-row">
<form class="layui-form" action="" method="post">
<div class="layui-collapse">
<div class="layui-colla-item">
<h1 class="layui-colla-title">基础配置</h1>
<div class="layui-colla-content layui-show">
<div class="layui-form-item">
<label class="layui-form-label"><strong>模板名称</strong></label>
<div class="layui-input-inline">
<input type="text" readonly="readonly" name="scaleTemplateName" value="{{.scaleTemplateName}}" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><strong>用户标识</strong></label>
<div class="layui-input-inline">
<input type="text" name="scaleUserName" required lay-verify="required" autocomplete="off" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">可填写角色名或者角色ID不可为空</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><strong>用户标识提示</strong></label>
<div class="layui-input-inline">
<input type="text" name="scaleUserNamePoint" placeholder="如通过角色属性面板查看角色ID" autocomplete="off" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">此提示会在充值页面显示提示玩家如何查看用户标识</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><strong>金额类型</strong></label>
<div class="layui-input-block">
<input type="radio" lay-filter="money-type-filter" name="moneyType" value="radio-any-money" title="任意金额" checked>
<input type="radio" lay-filter="money-type-filter" name="moneyType" value="radio-fixed-money" title="固定金额">
</div>
</div>
<!-- 任意金额的样式 -->
<div id="any-money-style">
<div class="layui-form-item">
<label class="layui-form-label"><strong>游戏币名称</strong></label>
<div class="layui-input-inline">
<input type="text" name="gameMoneyName" placeholder="" autocomplete="off" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">默认是元宝也可以是钻石点券</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><strong>游戏币比例</strong></label>
<div class="layui-input-inline">
<input type="text" name="gameMoneyScale" autocomplete="off" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">默认是100既充值1元人命币转为100游戏币</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><strong>最低充值金额</strong></label>
<div class="layui-input-inline">
<input type="text" name="limitLowMoney" autocomplete="off" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">默认最低为10元</div>
</div>
</div>
<!-- 固定金额的样式-->
<div id="fixed-money-style" class="layui-row" style="margin-left: 40px;">
<div id="fixed-money-child-style"></div>
<div class="layui-btn" style="margin-left: 10px;" onclick="addFixedMoenyStyle();"><i class="layui-icon layui-icon-add-circle">添加</i></div>
<div style="color: red; margin-left: 10px;"><h3><p>说明请根据游戏内设置的商品道具进行设置切勿乱填</p><p>可购次数填0代表不限填1代表一个帐号仅可购买一次依此类推</p></h3></div>
</div>
</div>
</div>
<div class="layui-colla-item">
<h1 class="layui-colla-title">激励赠送</h1>
<div class="layui-colla-content layui-show">
<div class="layui-form-item">
<label class="layui-form-label"><strong>赠送方式</strong></label>
<div class="layui-input-block">
<input type="radio" lay-filter="present-type-filter" name="presentType" value="close-present" title="关闭" checked>
<input type="radio" lay-filter="present-type-filter" name="presentType" value="fixed-money-present" title="固定金额赠送">
<input type="radio" lay-filter="present-type-filter" name="presentType" value="scale-present" title="按百分比赠送">
</div>
</div>
<!-- 按金额赠送-->
<div id="present-type-money-style">
<div id="present-type-money-child-style"></div>
<div class="layui-btn" style="margin-left: 50px;" onclick="addPresentTypeMoneyStyle();"><i class="layui-icon layui-icon-add-circle"></i>添加</div>
</div>
<!-- 按百分比赠送-->
<div id="present-type-scale-style">
<div id="present-type-scale-child-style"></div>
<div class="layui-btn" style="margin-left: 50px;" onclick="addPresentTypeScaleStyle();"><i class="layui-icon layui-icon-add-circle"></i>添加</div>
</div>
</div>
</div>
</div>
<div class="layui-form-item">
<br>
<button class="layui-btn" lay-filter="add" lay-submit="">更新</button>
<div class="layui-btn layui-btn-danger" onclick="back();">返回当前页</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
let fixMoneyFlag = true
let presentFixMoneyFlag = true
let presentScaleMoneyFlag = true
// 动态添加固定金额赠送input框
function addPresentTypeMoneyStyle() {
let s = randomString(20)
let str = '<div class="layui-form-item"><label class="layui-form-label"><strong>充值</strong></label><div class="layui-input-inline">' +
'<input type="text" name="present-fix-money" placeholder="金额(元)" autocomplete="off" class="layui-input present-fix-money">' +
'<input type="hidden" name="present-fix-uid" value="' + s + '" autocomplete="off" class="layui-input present-fix-uid">' +
'</div><div class="layui-input-inline">' +
'<input type="text" name="present-fix-present-money" placeholder="赠送金额(元)" autocomplete="off" class="layui-input present-fix-present-money">' +
'</div><div class="layui-inline"><div class="layui-btn layui-btn-danger fixed-money-child-del"><i class="layui-icon layui-icon-delete">删除</i></div></div></div>';
$("#present-type-money-child-style").append(str);
}
// 动态添加按百分比赠送input框
function addPresentTypeScaleStyle() {
let s = randomString(20)
let str = '<div class="layui-form-item"><label class="layui-form-label"><strong>充值</strong></label><div class="layui-input-inline">' +
'<input type="text" name="present-scale-money" placeholder="金额(元)" autocomplete="off" class="layui-input present-scale-money">' +
'<input type="hidden" name="present-scale-uid" value="' + s + '" autocomplete="off" class="layui-input present-scale-uid">' +
'</div><div class="layui-input-inline"><input type="text" name="present-scale" placeholder="赠送比例(%" autocomplete="off" class="layui-input present-scale">' +
'</div><div class="layui-inline"><div class="layui-btn layui-btn-danger fixed-money-child-del"><i class="layui-icon layui-icon-delete">删除</i></div></div></div>';
$("#present-type-scale-child-style").append(str);
}
// 动态添加固定金额的input输入框
function addFixedMoenyStyle() {
let s = randomString(20)
let str = '<div class="layui-form-item">' +
'<div class="layui-col-md1" style="margin-left: 10px;">' +
'<input type="text" name="fix-price" placeholder="售价(元)" autocomplete="off" class="layui-input fix-price">' +
'<input type="hidden" name="fix-uid" autocomplete="off" class="layui-input fix-uid" value="' + s + '">' +
'</div><div class=" layui-col-md2" style="margin-left: 10px;">' +
'<input type="text" name="fix-goods-name" placeholder="商品名称" autocomplete="off" class="layui-input fix-goods-name">' +
'</div><div class="layui-col-md2" style="margin-left: 10px;">' +
'<input type="text" name="fix-goods-no" placeholder="商品编号" autocomplete="off" class="layui-input fix-goods-no">' +
'</div><div class="layui-col-md1" style="margin-left: 10px;"><input type="text" name="fix-limit-low" placeholder="可够次数" autocomplete="off" class="layui-input fix-limit-low">' +
'</div><div class="layui-inline" style="margin-left: 10px;">' +
'<div class="layui-btn layui-btn-danger fixed-money-child-del"><i class="layui-icon layui-icon-delete"> 删除</i></div></div></div>';
$("#fixed-money-child-style").append(str);
}
function renderScaleInfo(res) {
console.log(res)
if (res.Code !== 0) {
alert("获取比例模板信息失败!")
return false
}
let templateInfo = res.TemplateInfo
let anyMoneyInfo = res.AnyMoneyInfo
let fixMoneyInofs = res.FixMoneyInfos
let presentFixMoneyInfos = res.PresentFixMoneyInfos
let presentScaleMoneyInfos = res.PresentScaleMoneyInfos
console.log(anyMoneyInfo)
$('input[name="scaleUserName"]').val(templateInfo.UserUid)
$('input[name="scaleUserNamePoint"]').val(templateInfo.UserWarn)
$('input[name="gameMoneyName"]').val(anyMoneyInfo.GameMoneyName)
$('input[name="gameMoneyScale"]').val(anyMoneyInfo.GameMoneyScale)
$('input[name="limitLowMoney"]').val(anyMoneyInfo.LimitLow)
$('input:radio[name="moneyType"]').each(function() {
if ($(this).index() === 0) {
$(this).attr('checked', "checked");
}
});
}
function showPresentFixMoney(res) {
for (let i = 0; i < res.PresentFixMoneyInfos.length; i ++) {
let presentFixMoneyInfo = res.PresentFixMoneyInfos[i]
console.log(presentFixMoneyInfo)
let str = '<div class="layui-form-item"><label class="layui-form-label"><strong>充值</strong></label><div class="layui-input-inline">' +
'<input type="text" name="present-fix-money" placeholder="金额(元)" value="' + presentFixMoneyInfo.Money + '" class="layui-input present-fix-money">' +
'<input type="hidden" name="present-fix-uid" value="' + presentFixMoneyInfo.Uid + '" autocomplete="off" class="layui-input present-fix-uid">' +
'</div><div class="layui-input-inline">' +
'<input type="text" name="present-fix-present-money" placeholder="赠送金额(元)" value="' + presentFixMoneyInfo.PresentMoney + '" class="layui-input present-fix-present-money">' +
'</div><div class="layui-inline"><div class="layui-btn layui-btn-danger fixed-money-child-del"><i class="layui-icon layui-icon-delete">删除</i></div></div></div>';
$("#present-type-money-child-style").append(str);
}
}
function showPresentScaleMoney(res) {
for (let i = 0; i < res.PresentScaleMoneyInfos.length; i ++) {
let presentScaleMoneyInfo = res.PresentScaleMoneyInfos[i]
console.log(presentScaleMoneyInfo)
let str = '<div class="layui-form-item"><label class="layui-form-label"><strong>充值</strong></label><div class="layui-input-inline">' +
'<input type="text" name="present-scale-money" placeholder="金额(元)" value="' + presentScaleMoneyInfo.Money + '" class="layui-input present-scale-money">' +
'<input type="hidden" name="present-scale-uid" value="' + presentScaleMoneyInfo.Uid + '" autocomplete="off" class="layui-input present-scale-uid">' +
'</div><div class="layui-input-inline"><input type="text" name="present-scale" placeholder="赠送比例(%" value="' + presentScaleMoneyInfo.PresentScale + '" class="layui-input present-scale">' +
'</div><div class="layui-inline"><div class="layui-btn layui-btn-danger fixed-money-child-del"><i class="layui-icon layui-icon-delete">删除</i></div></div></div>';
$("#present-type-scale-child-style").append(str);
}
}
function showFixMoney(res) {
let fixMoneyInfos = res.FixMoneyInfos
for (let i = 0; i < fixMoneyInfos.length; i ++ ) {
let fixMoneyInfo = fixMoneyInfos[i];
console.log(fixMoneyInfo)
let str = '<div class="layui-form-item">' +
'<div class="layui-col-md1" style="margin-left: 10px;">' +
'<input type="text" name="fix-price" placeholder="售价(元)" autocomplete="off" class="layui-input fix-price" value="' + fixMoneyInfo.Price + '">' +
'<input type="hidden" name="fix-uid" autocomplete="off" class="layui-input fix-uid" value="' + fixMoneyInfo.Uid + '">' +
'</div><div class=" layui-col-md2" style="margin-left: 10px;">' +
'<input type="text" name="fix-goods-name" placeholder="商品名称" autocomplete="off" class="layui-input fix-goods-name" value="' + fixMoneyInfo.GoodsName + '">' +
'</div><div class="layui-col-md2" style="margin-left: 10px;">' +
'<input type="text" name="fix-goods-no" placeholder="商品编号" autocomplete="off" value="' + fixMoneyInfo.GoodsNo + '" class="layui-input fix-goods-no">' +
'</div><div class="layui-col-md1" style="margin-left: 10px;"><input type="text" name="fix-limit-low" value="' + fixMoneyInfo.BuyTimes + '" placeholder="可够次数" autocomplete="off" class="layui-input fix-limit-low">' +
'</div><div class="layui-inline" style="margin-left: 10px;">' +
'<div class="layui-btn layui-btn-danger fixed-money-child-del"><i class="layui-icon layui-icon-delete"> 删除</i></div></div></div>';
$("#fixed-money-child-style").append(str);
}
}
layui.use(['form', 'layer', 'element'], function() {
$ = layui.jquery;
let form = layui.form,
layer = layui.layer;
// 进入该页面首先做的事情
$(document).ready(function () {
$("#fixed-money-style").hide();
$("#any-money-style").show();
$("#present-type-money-style").hide();
$("#present-type-scale-style").hide();
// ajax获取比例模板信息
let scaleTemplateName = $('input[name=scaleTemplateName]').val()
$.ajax({
url: "/template/info",
data: {
"scaleTemplateName": scaleTemplateName
},
success: function (res) {
renderScaleInfo(res)
},
error: function () {
alert("系统异常,请稍后在尝试!")
}
})
return false
})
// 监听赠送类型的radio
form.on('radio(present-type-filter)', function (data) {
let radioValue = data.value;
if ("close-present" === radioValue) {
$("#present-type-money-style").hide();
$("#present-type-scale-style").hide();
} else if ("fixed-money-present" === radioValue) {
$("#present-type-money-style").show();
$("#present-type-scale-style").hide();
if (!presentFixMoneyFlag) {
return
}
let scaleTemplateName = $('input[name=scaleTemplateName]').val()
$.ajax({
url: "/template/info",
data: {
"scaleTemplateName": scaleTemplateName
},
success: function (res) {
showPresentFixMoney(res)
presentFixMoneyFlag = false
},
error: function () {
alert("系统异常,请稍后在尝试!")
}
})
} else if ("scale-present" === radioValue) {
$("#present-type-money-style").hide();
$("#present-type-scale-style").show();
if (!presentScaleMoneyFlag) {
return
}
let scaleTemplateName = $('input[name=scaleTemplateName]').val()
$.ajax({
url: "/template/info",
data: {
"scaleTemplateName": scaleTemplateName
},
success: function (res) {
// $("#fixed-money-child-style").remove()
showPresentScaleMoney(res)
presentScaleMoneyFlag = false
},
error: function () {
alert("系统异常,请稍后在尝试!")
}
})
}
})
// 监听金额类型的radio
form.on('radio(money-type-filter)', function (data) {
let value = data.value;
if ("radio-any-money" === value) {
//处理任何金额
$("#any-money-style").show();
$("#fixed-money-style").hide();
} else {
// 处理固定金额
$("#any-money-style").hide();
$("#fixed-money-style").show();
if (!fixMoneyFlag) {
return
}
let scaleTemplateName = $('input[name=scaleTemplateName]').val()
$.ajax({
url: "/template/info",
data: {
"scaleTemplateName": scaleTemplateName
},
success: function (res) {
// $("#fixed-money-child-style").remove()
showFixMoney(res)
fixMoneyFlag = false
},
error: function () {
alert("系统异常,请稍后在尝试!")
}
})
}
})
//监听提交
form.on('submit(add)', function(data) {
let jsonObj = {}
jsonObj.scaleTemplateName = data.field.scaleTemplateName
jsonObj.scaleUserName = data.field.scaleUserName
jsonObj.scaleUserNamePoint = data.field.scaleUserNamePoint
jsonObj.moneyType = data.field.moneyType
jsonObj.gameMoneyName = data.field.gameMoneyName
jsonObj.gameMoneyScale = data.field.gameMoneyScale
if (data.field.limitLowMoney === "" || data.field.limitLowMoney === null) {
jsonObj.limitLowMoney = "10"
} else {
jsonObj.limitLowMoney = data.field.limitLowMoney
}
jsonObj.presentType = data.field.presentType
jsonObj.fixPrices = getArrays(".fix-price")
jsonObj.goodsNames = getArrays(".fix-goods-name")
jsonObj.goodsNos = getArrays(".fix-goods-no")
jsonObj.limits = getArrays(".fix-limit-low")
jsonObj.presentFixMoneys = getArrays(".present-fix-money")
jsonObj.presentFixPresentMoneys = getArrays(".present-fix-present-money")
jsonObj.presentScaleMoneys =getArrays(".present-scale-money")
jsonObj.presentScales = getArrays(".present-scale")
jsonObj.fixUids = getArrays(".fix-uid")
jsonObj.presentScaleUids = getArrays(".present-scale-uid")
jsonObj.presentFixUids = getArrays(".present-fix-uid")
console.log(JSON.stringify(jsonObj))
//发异步把数据提交给php
$.ajax({
url: "/add/template?type=edit",
data: jsonObj,
success: function (res) {
alert(res.Msg)
if (res.Code === 0) {
window.history.back(-1);
}
},
error: function () {
layer.alert("系统异常")
}
});
return false;
});
});
function getArrays(obj) {
let arrays = []
$(obj).each(function () {
let v = $(this).val();
if (v === null || v.length <=0) {
arrays.push(0)
} else {
arrays.push(v)
}
})
return arrays.join(",")
}
// 删除固金额input
$("div").on('click', '.fixed-money-child-del', function () {
$(this).parent().parent().remove();
})
function back() {
window.history.back(-1);
}
function randomString(n) {
let chars = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
let res = "";
for(let i = 0; i < n ; i ++) {
let id = Math.ceil(Math.random()*35);
res += chars[id];
}
return res;
}
</script>
</body>
</html>