文件

306 行
12 KiB
HTML
可执行文件

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<!--[1.7.90]-->
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Retail/css/coupons.css"/>
<div class="goodsBox">
<div class="goods_title">
<div class="goods_title_inner">
线上优惠券 <span style="color:#009688">(此处优惠券只允许在小程序商城使用,且只能在本店使用)</span>
</div>
</div>
<div class="goods_edit">
<form id="select_serach">
<div class="goods_edit_select">
<select name="status" id="coupon_status">
<option value="0">--优惠券状态--</option>
<option value="1">可用优惠券</option>
<option value="2">下架优惠券</option>
<option value="3">过期优惠券</option>
</select>
</div>
</form>
<div class="layui-btn " id="serach_icon" style="margin-left: -10px;" data-type="reload">搜索
</div>&nbsp;&nbsp;
<if condition="($authArr['couponSet'] eq true) AND (empty($global_store_jurisdiction['store_coupon']) eq true OR $global_store_jurisdiction['store_coupon'] == 1)">
<div class="layui-btn " id="newlyIncreased">新增</div>
</if>
<if condition="$authArr['couponLogs'] eq true">
<button id="checkcollar" class=" layui-btn ">查看领取记录</button>
</if>
</div>
<div class="goods_table">
<table class="layui-hide" id="test" lay-filter="demo"></table>
<script type="text/html" id="barDemo">
<if condition="$authArr['changeCoupon'] eq true">
<a class="layui-btn layui-btn-xs" lay-event="change">修改状态</a>
</if>
<if condition="$authArr['deleteCoupon'] eq true">
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</if>
</script>
</div>
<div class="goodsAlert">
<form id="create_cate">
<input type="hidden" name="id" id="class_id" value="">
<div class="gA_inner">
<div class="gA_inner_left">优惠券名称:</div>
<div class="gA_inner_right">
<input type="te" name="coupon_name" id="coupon_name" value="" placeholder="如满50减10元,建议填写10元卷"/>
</div>
</div>
<div class="gA_inner">
<div class="gA_inner_left">优惠券数量:</div>
<div class="gA_inner_right">
<input type="number" name="coupon_num" id="coupon_num" value="" placeholder="请填写发放的优惠券总数量 "/>
</div>
</div>
<div class="gA_inner">
<div class="gA_inner_left">消费金额:</div>
<div class="gA_inner_right">
<input type="number" name="needmoney" id="needmoney" value="" placeholder="消费金额"/>
</div>
</div>
<div class="gA_inner">
<div class="gA_inner_left">减免金额:</div>
<div class="gA_inner_right">
<input type="number" name="reductionmoney" id="reductionmoney" value="" placeholder="减免金额"/>
</div>
</div>
<div class="gA_inner">
<div class="gA_inner_left">有效日期:</div>
<div class="gA_inner_right">
<input type="text" name="usetime" id="usetime" value="" placeholder="选择优惠券使用截止时间"/>
</div>
</div>
</form>
</div>
</div>
<script type="text/javascript">
layui.use('table', function () {
var table = layui.table;
//展示已知数据
table.render({
elem: '#test',
url: "{:U('Coupon/couponList')}",
method:'post',
cols: [
[ //标题栏
{
field: 'key',
title: '序号',
width: 60
}, {
field: 'coupon_name',
title: '优惠券名称',
}, {
field: 'rule',
title: '优惠规则'
}, {
field: 'begin_time',
title: '开始使用时间'
}, {
field: 'end_time',
title: '有效使用截止日期'
}, {
field: 'coupon_num',
title: '发放总量',
}, {
field: 'quantity',
title: '库存',
}, {
field: 'receive_num',
title: '已领取',
}, {
field: 'status_s',
title: '优惠券状态'
}, {
fixed: 'right',
title: '操作',
width: 150,
align: 'center',
toolbar: '#barDemo'
}
]
],
id: 'couponReload',
page: {
layout: ['count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
}, //是否开启分页
});
var $ = layui.$, active = {
reload: function () {
var coupon_status = $('#coupon_status').val();
//执行重载
table.reload('couponReload', {
page: {
curr: 1 //重新从第 1 页开始
}
, where: {
status: coupon_status
}
});
}
};
$('#serach_icon').on('click', function () {
var type = $(this).data('type');
active[type] ? active[type].call(this) : '';
});
//监听工具条
table.on('tool(demo)', function (obj) {
var data = obj.data;
var id = data.id;
if (obj.event === 'detail') {
layer.msg('ID:' + data.id + ' 的查看操作');
} else if (obj.event === 'del') {
layer.confirm('确认删除该优惠券吗(已领取的用户可正常使用)', function (index) {
$.ajax({
url: "{:U('Coupon/deleteCoupon')}",
type: "POST",
data: {id: id},
success: function (data) {
if (data.status == 1) {
top.layer.msg(data.msg, {
icon: 1,
time: 1000 //2秒关闭(如果不配置,默认是3秒)
}, function () {
obj.del();
active['reload'] ? active['reload'].call(this) : '';
layer.close(index);
});
}
}
})
});
} else if (obj.event === 'change') {
var c_status = data.status;
if (c_status == 1) {
var str = "确认要开启该优惠券吗?";
var new_status = 2;
var status_name = '正常';
} else if (c_status == 2) {
var str = "确认要下架该优惠券吗?";
var new_status = 1;
var status_name = '已下架';
}
layer.confirm(str, function (index) {
$.ajax({
url: "{:U('Coupon/changeCoupon')}",
type: "POST",
data: {id: id, status: new_status},
success: function (data) {
if (data.status == 1) {
top.layer.msg(data.msg, {
icon: 1,
time: 1000 //2秒关闭(如果不配置,默认是3秒)
}, function () {
// obj.del();
layer.close(index);
});
//同步更新缓存对应的值
obj.update({
status_s: status_name,
status: new_status,
});
} else {
top.layer.msg(data.msg, {
icon: 1,
time: 1000 //2秒关闭(如果不配置,默认是3秒)
}, function () {
// obj.del();
layer.close(index);
});
}
}
})
});
}
});
layui.use('layer', function () {
var layer = layui.layer;
$("#newlyIncreased").click(function () {
layer.open({
type: 1,
content: $('.goodsAlert'),
title: "创建优惠券",
area: ['650px', '450px'],
btn: ['保存', '取消'],
btnAlign: 'c',
shade: false,
yes: function () {
var coupon_name = $("#coupon_name").val();
//优惠券数量
var coupon_num = $('#coupon_num').val();
var needmoney = $('#needmoney').val(); //消费金额
var reductionmoney = $('#reductionmoney').val(); //减免金额
var usetime = $('#usetime').val();
if (!coupon_name || !coupon_num || !needmoney || !reductionmoney || !usetime) {
top.layer.msg("请完善表单信息", {icon: 2});
return false;
}
if (coupon_num < 0 || needmoney < 0 || reductionmoney < 0) {
top.layer.msg("信息有误,请重新输入", {icon: 2});
return false;
}
console.log(parseFloat(reductionmoney), parseFloat(needmoney));
if (parseFloat(reductionmoney) >= parseFloat(needmoney)) {
top.layer.msg("减免金额不得大于等于消费金额", {icon: 2});
return false;
}
$.ajax({
url: "{:U('Coupon/couponSet')}",
type: "POST",
data: $("#create_cate").serialize(),
success: function (data) {
if (data.status == 1) {
top.layer.msg(data.msg, {
icon: 1,
time: 1000 //2秒关闭(如果不配置,默认是3秒)
}, function () {
top.layer.closeAll();
active['reload'] ? active['reload'].call(this) : '';
});
}
}
})
}
})
})
});
})
//用户领取记录
$("#checkcollar").click(function () {
layer.open({
type: 2,
title: '记录',
shade: 0,
area: ['calc(100% - 160px)', 'calc(100% - 65px)'],
offset: 'rb',
content: "{:U('Coupon/couponLogs')}"
});
//window.location.href = "{:U('Coupon/couponLogs')}"
})
//日期
layui.use('laydate', function () {
var laydate = layui.laydate;
//日期时间范围
laydate.render({
elem: '#usetime'
, theme: '#3f4c73'
, min: 0 //设定最小日期为当前日期
// ,max: 30//最大日期
// ,type: 'datetime'
, range: true
});
})
</script>