<div class="layui-fluid layui-anim febs-anim" id="febs-activity-order" lay-title="活动订单管理">
|
<div class="layui-row febs-container">
|
<div class="layui-col-md12">
|
<div class="layui-card">
|
<div class="layui-card-body febs-table-full">
|
<form class="layui-form layui-table-form" lay-filter="activity-order-table-form">
|
<div class="layui-row">
|
<div class="layui-col-md10">
|
<div class="layui-form-item">
|
<div class="layui-inline">
|
<label class="layui-form-label layui-form-label-sm">名称</label>
|
<div class="layui-input-inline">
|
<input type="text" placeholder="名称" name="name" autocomplete="off" class="layui-input">
|
</div>
|
</div>
|
<div class="layui-inline">
|
<label class="layui-form-label layui-form-label-sm">状态</label>
|
<div class="layui-input-inline">
|
<select name="state">
|
<option value="">请选择</option>
|
<option value="1">待支付</option>
|
<option value="2">待使用</option>
|
<option value="3">已使用</option>
|
<option value="4">售后</option>
|
<option value="5">已评价</option>
|
<option value="7">已失效</option>
|
</select>
|
</div>
|
</div>
|
<div class="layui-inline">
|
<label class="layui-form-label layui-form-label-sm">活动</label>
|
<div class="layui-input-inline">
|
<select name="activityId" class="activity-type">
|
<option value="">请选择</option>
|
</select>
|
</div>
|
</div>
|
</div>
|
|
</div>
|
<div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
|
<div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="query">
|
<i class="layui-icon"></i>
|
</div>
|
<div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action" id="reset">
|
<i class="layui-icon"></i>
|
</div>
|
</div>
|
</div>
|
</form>
|
<table lay-filter="orderActivityTable" lay-data="{id: 'orderActivityTable'}"></table>
|
</div>
|
</div>
|
</div>
|
</div>
|
</div>
|
<!-- 表格操作栏 start -->
|
<script type="text/html" id="user-option">
|
<span shiro:lacksPermission="list:view,add:add,votesActivityUpdate:update">
|
<span class="layui-badge-dot febs-bg-orange"></span> 无权限
|
</span>
|
<a lay-event="edit" shiro:hasPermission="votesActivityUpdate:update"><i
|
class="layui-icon febs-edit-area febs-blue"></i></a>
|
</script>
|
<script type="text/html" id="orderActivityToolbar">
|
<div class="layui-btn-container">
|
<button class="layui-btn layui-btn-normal layui-btn-sm" type="button" shiro:hasPermission="orderActivity:update" lay-event="checkOrder">手动核销</button>
|
</div>
|
</script>
|
|
<script type="text/html" id="orderActivityOption">
|
<!-- <button class="layui-btn layui-btn-normal layui-btn-sm" type="button" shiro:hasPermission="orderActivity:info" lay-event="orderActivity">详情</button>-->
|
<button class="layui-btn layui-btn-danger layui-btn-sm" type="button" shiro:hasPermission="orderActivity:info" lay-event="orderActivityDel">删除</button>
|
<!-- <button class="layui-btn layui-btn-danger layui-btn-sm" type="button" shiro:hasPermission="orderActivity:returnOrder" lay-event="returnOrder">售后退款</button>-->
|
</script>
|
<script type="text/html" id="orderStateOption">
|
{{#
|
var state = {
|
1: {title: '待支付', color: 'blue'},
|
2: {title: '待使用', color: 'orange'},
|
3: {title: '已使用', color: 'green'},
|
4: {title: '售后', color: 'red'},
|
5: {title: '已评价', color: 'black'},
|
6: {title: '删除', color: 'black'},
|
7: {title: '已失效', color: 'black'},
|
}[d.state];
|
}}
|
<span class="layui-badge febs-bg-{{state.color}}">{{ state.title }}</span>
|
</script>
|
<script type="text/html" id="payStateOption">
|
{{#
|
var payState = {
|
0: {title: '待支付', color: 'blue'},
|
1: {title: '成功', color: 'green'},
|
2: {title: '失败', color: 'red'},
|
}[d.payState];
|
}}
|
<span class="layui-badge febs-bg-{{payState.color}}">{{ payState.title }}</span>
|
</script>
|
<script type="text/html" id="payTypeOption">
|
{{#
|
var payType = {
|
1: {title: '余额', color: 'blue'},
|
2: {title: '微信', color: 'green'},
|
3: {title: '积分', color: 'orange'},
|
0: {title: '免费', color: 'red'},
|
}[d.payType];
|
}}
|
<span class="layui-badge febs-bg-{{payType.color}}">{{ payType.title }}</span>
|
</script>
|
|
<style>
|
.layui-form-onswitch {
|
background-color: #5FB878 !important;
|
}
|
</style>
|
<!-- 表格操作栏 end -->
|
<script data-th-inline="none" type="text/javascript">
|
// 引入组件并初始化
|
layui.use([ 'jquery', 'form', 'table', 'febs'], function () {
|
var $ = layui.jquery,
|
febs = layui.febs,
|
form = layui.form,
|
table = layui.table,
|
$view = $('#febs-activity-order'),
|
$query = $view.find('#query'),
|
$reset = $view.find('#reset'),
|
$searchForm = $view.find('form'),
|
sortObject = {field: 'phone', type: null},
|
tableIns;
|
|
form.render();
|
//(下拉框)
|
$.get(ctx + 'admin/happyActivity/allOrderActivities', function (res) {
|
var data = res.data;
|
for (let k in data)
|
{
|
$(".activity-type").append("<option value='" + data[k].id + "'>" + data[k].name + "</option>");
|
}
|
layui.use('form', function () {
|
var form = layui.form;
|
form.render();
|
});
|
});
|
|
// 表格初始化
|
initorderActivityTable();
|
// 初始化表格操作栏各个按钮功能
|
table.on('tool(orderActivityTable)', function (obj) {
|
var data = obj.data,
|
layEvent = obj.event;
|
if (layEvent === 'orderActivityDel') {
|
febs.modal.confirm('删除', '确认删除?', function () {
|
orderActivityDel(data.id);
|
});
|
}
|
if (layEvent === 'groupInfo') {
|
febs.modal.open('编辑','modules/votesActivity/groupInfo/' + data.id, {
|
btn: ['提交', '取消'],
|
area: ['100%', '100%'],
|
yes: function (index, layero) {
|
$('#febs-group-info').find('#submit').trigger('click');
|
},
|
btn2: function () {
|
layer.closeAll();
|
}
|
});
|
}
|
});
|
function orderActivityDel(id) {
|
febs.get(ctx + 'admin/happyActivity/activityOrderDel/' + id, null, function (data) {
|
febs.alert.success(data.message);
|
$query.click();
|
});
|
}
|
|
// 初始化表格操作栏各个按钮功能
|
table.on('toolbar(orderActivityTable)', function (obj) {
|
let event = obj.event;
|
let id = obj.config.id;
|
let checkStatus = table.checkStatus(id);
|
|
if (event === 'checkOrder') {
|
let data = checkStatus.data;
|
|
// 校验 data 是否为空或未定义
|
if (!Array.isArray(data) || data.length === 0) {
|
febs.alert.warn('请选择需要核销的订单');
|
return;
|
}
|
|
let ids = [];
|
let hasInvalidOrder = false;
|
|
// 遍历数据,筛选符合条件的订单
|
for (let i = 0; i < data.length; i++) {
|
if (data[i].state !== 2) {
|
hasInvalidOrder = true;
|
break; // 提前中断循环,避免无意义的继续遍历
|
} else {
|
ids.push(data[i].id);
|
}
|
}
|
|
if (hasInvalidOrder) {
|
febs.alert.warn('请选择待使用的订单');
|
return;
|
}
|
|
if (ids.length === 0) { // 正确判断数组是否为空
|
febs.alert.warn('请选择需要核销的订单');
|
return;
|
}
|
|
// 封装 AJAX 请求为独立函数
|
function sendCheckOrderRequest(ids, successCallback, errorCallback) {
|
$.ajax({
|
url: ctx + 'admin/happyActivity/checkOrder', // 硬编码路径建议提取为配置项
|
type: 'post',
|
dataType: 'json',
|
headers: { 'Content-Type': 'application/json;charset=utf-8' },
|
traditional: true,
|
data: JSON.stringify(ids), // 确保传递的是 JSON 格式
|
success: function (response) {
|
if (response.code === 200) {
|
successCallback(response);
|
} else {
|
errorCallback(response.message);
|
}
|
},
|
error: function (xhr, status, error) {
|
errorCallback(`服务器繁忙: ${error}`); // 捕获具体错误信息
|
}
|
});
|
}
|
|
// 调用封装的请求函数
|
sendCheckOrderRequest(ids,
|
function onSuccess(response) {
|
febs.alert.success('操作成功');
|
$query.click();
|
},
|
function onError(message) {
|
febs.alert.warn(message);
|
}
|
);
|
}
|
});
|
|
|
|
function initorderActivityTable() {
|
tableIns = febs.table.init({
|
elem: $view.find('table'),
|
id: 'orderActivityTable',
|
url: ctx + 'admin/happyActivity/activityOrderList',
|
toolbar:"#orderActivityToolbar",
|
defaultToolbar:[],
|
cols: [[
|
{type: 'checkbox'},
|
{type: 'numbers', title: '', width: 80},
|
{title: '操作', toolbar: '#orderActivityOption', minWidth: 200, align: 'center'},
|
{field: 'name', title: '名称', minWidth: 100,align:'center'},
|
{field: 'orderNo', title: '订单编号', minWidth: 100,align:'center'},
|
{field: 'activityName', title: '活动名称', minWidth: 100,align:'center'},
|
{field: 'price', title: '单价', minWidth: 100,align:'center'},
|
{field: 'numCnt', title: '数量', minWidth: 100,align:'center'},
|
{field: 'amount', title: '总价', minWidth: 100,align:'center'},
|
{title: '订单状态', templet: '#orderStateOption', minWidth: 100,align:'center'},
|
{title: '支付状态', templet: '#payStateOption', minWidth: 100,align:'center'},
|
{title: '支付方式', templet: '#payTypeOption', minWidth: 100,align:'center'},
|
{field: 'createdTime', title: '创建时间', minWidth: 150,align:'left'}
|
]]
|
});
|
}
|
|
// 查询按钮
|
$query.on('click', function () {
|
var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
|
tableIns.reload({where: params, page: {curr: 1}});
|
});
|
|
// 刷新按钮
|
$reset.on('click', function () {
|
$searchForm[0].reset();
|
sortObject.type = 'null';
|
tableIns.reload({where: getQueryParams(), page: {curr: 1}, initSort: sortObject});
|
});
|
// 获取查询参数
|
function getQueryParams() {
|
return {
|
name: $searchForm.find('input[name="name"]').val().trim(),
|
state: $searchForm.find("select[name='state']").val(),
|
activityId: $searchForm.find("select[name='activityId']").val(),
|
};
|
}
|
|
})
|
</script>
|