Files
peko-admin-web/src/views/activity/ActivityPackAdminView.vue
2023-11-14 17:59:51 +08:00

780 lines
39 KiB
Vue
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.

<template>
<section class="content">
<div class="box box-primary">
<div class="box-body">
<section class="content-header">
<h1 id="itemTitle"></h1>
</section>
<section class="content">
<div id="table"></div>
<div id="toolbar">
<div class="big-tips">
礼包的数据前端是写死的配置时应跟前端一一对应起来后台只会返回有效的礼包并按序号从小到大排序配置好之后不要随意修改<br />
有新的礼包需要上架时请直接新增礼包而不是对现有礼包进行编辑修改方便查数
</div>
礼包状态:
<select name="status" id="statusSelect" data-btn-class="btn-warning">
<option value="0" selected="selected">全部</option>
<option value="1">有效</option>
<option value="2">无效</option>
</select>
活动类型:
<select name="status" id="packTypeSelect" data-btn-class="btn-warning">
<option value="" selected="selected">全部</option>
<option value="0">普通活动</option>
<option value="1">转盘活动</option>
<option value="2">周星榜活动</option>
<option value="3">深海奇缘活动</option>
<option value="6">守护星球</option>
<option value="10">航海冒险</option>
<option value="13">夺宝精灵</option>
</select>
<button class="btn btn-default" id="search">
<i class="glyphicon glyphicon-wrench"></i>查询
</button>
<button class="btn btn-primary" id="add">
<i class="glyphicon glyphicon-plus"></i>增加
</button>
</div>
</section>
</div>
</div>
</section>
<!-- 弹窗 -->
<div class="modal fade" id="packModal" rabindex='-1' role="dialog" aria-labelledby="modalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">x</span>
</button>
<div class="modal-title" id="editModalLabel">奖品设置</div>
</div>
<div class="modal-body">
<form action="" id="addForm" class="form-horizontal">
<div class="form-group name">
<label for="name" class="col-sm-3 control-label">礼包名称</label>
<div class="col-sm-8">
<input type="text" class="validate[required]" name="name" id="name" placeholder="单行输入">
</div>
</div>
<div class="form-group status">
<label for="status" class="col-sm-3 control-label">礼包状态</label>
<div class="col-sm-8">
<select id="status">
<option value="1">有效</option>
<option value="2">无效</option>
</select>
<div class="tips">
<i class="glyphicon glyphicon-info-sign"></i>无效状态的礼包不会返回前端也不允许购买
</div>
</div>
</div>
<div class="form-group imgUrl">
<label class="col-sm-3 control-label">礼包图片</label>
<div class="col-sm-8">
<img src="" alt="" id="imgUrl" style="width: 50px; height: 50px;">
<input type="file" id="uploadFile" name="uploadFile"
accept="image/gif,image/jpeg,image/jpg,image/png,image/svg">
<button class="btn btn-success" type="button" id="uploadBtn">上传</button>
<input type="hidden" id="alertWinPic" name="alertWinPic"
class="form-control validate[required]">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">活动类型</label>
<div class="col-sm-9">
<label class="radio-inline"><input type="radio" onclick="changeType(this.value)"
name="packType" value="0" checked>普通活动</label>
<label class="radio-inline"><input type="radio" onclick="changeType(this.value)"
name="packType" value="1">转盘活动</label>
<label class="radio-inline"><input type="radio" onclick="changeType(this.value)"
name="packType" value="2">周星榜活动</label>
<label class="radio-inline"><input type="radio" onclick="changeType(this.value)"
name="packType" value="3">深海奇缘活动</label>
<label class="radio-inline"><input type="radio" onclick="changeType(this.value)"
name="packType" value="6">守护星球活动</label>
<label class="radio-inline"><input type="radio" onclick="changeType(this.value)"
name="packType" value="10">航海冒险活动</label>
<label class="radio-inline"><input type="radio" onclick="changeType(this.value)"
name="packType" value="13">夺宝精灵活动</label>
</div>
</div>
<div id="ticketNumDiv" class="form-group ticketNum" style="display: none">
<label for="sellingPrice" class="col-sm-3 control-label">赠送门票数量</label>
<div class="col-sm-8">
<input type="text" class="validate[required]" name="ticketNum" id="ticketNum"
placeholder="单行输入">
</div>
</div>
<div class="form-group sellingPrice">
<label for="sellingPrice" class="col-sm-3 control-label">售价</label>
<div class="col-sm-8">
<input type="text" class="validate[required]" name="sellingPrice" id="sellingPrice"
placeholder="单行输入">
</div>
</div>
<div class="form-group originalPrice">
<label for="originalPrice" class="col-sm-3 control-label">原价</label>
<div class="col-sm-8">
<input type="text" class="validate[required]" name="originalPrice" id="originalPrice"
placeholder="单行输入">
</div>
</div>
<div class="form-group stock">
<label for="stock" class="col-sm-3 control-label">库存</label>
<div class="col-sm-8">
<input type="text" class="validate[required]" name="stock" id="stock" placeholder="单行输入">
<br />
<div class="tips">
<i class="glyphicon glyphicon-info-sign"></i>-1代表不限量
</div>
</div>
</div>
<div class="form-group allowBuyNum">
<label for="allowBuyNum" class="col-sm-3 control-label">允许购买数量</label>
<div class="col-sm-8">
<input type="text" class="validate[required]" name="allowBuyNum" id="allowBuyNum"
placeholder="单行输入">
<br />
<div class="tips">
<i class="glyphicon glyphicon-info-sign"></i>-1代表不限量
</div>
</div>
</div>
<div class="form-group validity">
<label class="col-sm-3 control-label">礼包开放日期</label>
<div class="col-sm-8">
<input type="text" name="startDate" id="timeBegin" class="input-sm" placeholder="起始时间">
- <input type="text" name="endDate" id="timeEnd" class="input-sm" placeholder="结束时间">
</div>
</div>
<div class="form-group seqNo">
<label class="col-sm-3 control-label">序号</label>
<div class="col-sm-8">
<input type="text" class="validate[required]" name="seqNo" id="seqNo" placeholder="单行输入">
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="button" class="btn btn-primary" data-primary="addSave" id="save">保存</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="addAwardModal" rabindex='-1' role="dialog" aria-labelledby="modalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">x</span>
</button>
<div class="modal-title" id="addModalLabel">添加奖品</div>
</div>
<div class="modal-body">
<form action="" id="addAwardForm" class="form-horizontal">
<div class="form-group">
<label for="award" class="col-sm-3 control-label">奖品</label>
<select id="award" name="award" class="validate[required]">
<option value="0">---选择奖品---</option>
</select>
</div>
<div class="form-group">
<label for="awardNum" class="col-sm-3 control-label">奖品数量</label>
<input type="text" class="validate[required]" name="awardNum" id="awardNum"
placeholder="单行输入数字">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
<button type="button" class="btn btn-primary" data-primary="saveAwardData" id="saveAward">保存</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="packItemListModal" tabindex="-1" role="dialog" aria-labelledby="modalLabel">
<div class="modal-dialog" role="document" style="width:55%">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">x</span></button>
<h4 class="modal-title" id="assignRoomsLabel">奖池列表</h4>
</div>
<div class="modal-body">
<div id="packItemListTable"></div>
</div>
</div>
</div>
</div>
</template>
<script>
import TableHelper from '@/utils/bootstrap-table-helper';
export default {
name: "ActivityPackAdminView",
setup() {
function changeType(value) {
// alert(value);
if (value == 0) {
$("#ticketNumDiv").hide();
var num = $("#ticketNum").val();
if (num == null || num == "" || num == undefined) {
$("#ticketNum").val(0);
}
} else {
$("#ticketNumDiv").show();
}
}
window.changeType = changeType;
return {
changeType
};
},
created() {
this.$nextTick(function () {
this.initData();
});
},
methods: {
initData() {
$(function () {
var picker1 = $('#timeBegin').datepicker({
format: 'yyyy-mm-dd',
autoclose: true
});
var picker2 = $('#timeEnd').datepicker({
format: 'yyyy-mm-dd',
autoclose: true
});
picker1.on('changeDate', function () {
var date = $('#timeBegin').datepicker('getDate');
picker2.datepicker('setStartDate', date);
});
picker2.on('changeDate', function () {
var date = $('#timeEnd').datepicker('getDate');
picker1.datepicker('setEndDate', date);
});
var main = {
init: function () {
this.eventRegister();
this.initData();
},
eventRegister: function () {
// 编辑按钮点击事件
$('#table').on('click', '.opt-edit', function () {
clearModal();
$('#packModal').modal('show');
var id = parseInt($(this).data('id'));
editId = id;
if (id == 'undefined' || !id) {
return;
}
var data = $('#table').bootstrapTable('getRowByUniqueId', id);
$('#name').val(data.name);
$('#imgUrl').attr('src', data.imgUrl);
$('#sellingPrice').val(data.sellingPrice);
if (data.packType == 1) {
$("input:radio[name='packType']")[1].checked = true;
$("#ticketNumDiv").show();
} else if (data.packType == 3) {
$("input:radio[name='packType']")[3].checked = true;
$("#ticketNumDiv").show();
} else {
$("input:radio[name='packType']")[0].checked = true;
}
$('#ticketNum').val(data.ticketNum);
$('#originalPrice').val(data.originalPrice);
$('#stock').val(data.stock);
$("#allowBuyNum").val(data.allowBuyNum);
$('#status').val(data.status);
$('#timeBegin').val(new Date(data.beginTime).format('yyyy-MM-dd'));
$('#timeEnd').val(new Date(data.endTime).format('yyyy-MM-dd'));
$('#seqNo').val(data.seqNo);
});
$('#table').on('click', '.opt-award', function () {
var id = parseInt($(this).data('id'));
editId = id;
$('#addAwardModal').modal('show');
});
$('#table').on('click', '.opt-awardList', function () {
var id = parseInt($(this).data('id'));
editId = id;
initPackItemsListTable(id);
$('#packItemListModal').modal('show');
});
$('#table').on("click", '.opt-close', function () {
var $btn = $(this);
var packId = $btn.attr("data-id");
$btn.attr('disabled', true);
if (confirm("确定关闭?")) {
$.ajax({
type: 'post',
url: '/admin/activity/pack/close',
data: {
packId: packId
},
dataType: 'json',
success: function (res) {
$btn.attr('disabled', false);
if (res.code == 200) {
$("#tipMsg").text("关闭成功");
$("#tipModal").modal('show');
TableHelper.doRefresh("#table");
} else {
$("#tipMsg").text("关闭失败." + res.msg);
$("#tipModal").modal('show');
}
}
});
}
});
$('#packItemListTable').on("click", '.opt-del', function () {
var $btn = $(this);
var itemId = $btn.attr("data-id");
$btn.attr('disabled', true);
if (confirm("确定删除?")) {
$.ajax({
type: 'post',
url: '/admin/activity/pack/delPackItem',
data: {
itemId: itemId
},
dataType: 'json',
success: function (res) {
$btn.attr('disabled', false);
if (res.code == 200) {
$("#tipMsg").text("删除成功");
$("#tipModal").modal('show');
TableHelper.doRefresh("#packItemListTable");
} else {
$("#tipMsg").text("删除失败." + res.msg);
$("#tipModal").modal('show');
}
}
});
}
});
// 添加事件
$('#add').on('click', function () {
editId = 0;
clearModal();
$('#packModal').modal('show');
});
// 上传图片
$('#uploadBtn').on('click', function () {
if ($('#uploadFile').val() == '') {
$('#tipMsg').text('上传图片为空');
$('#tipModal').modal('show');
return;
}
var options = {
type: 'post',
url: '/admin/upload/img',
dataType: 'json',
success: function (res) {
if (res.path) {
$('#alertWinPic').val(res.path);
$('#imgUrl').attr('src', res.path);
console.log(res.path);
} else {
$('#tipMsg').text(res.msg);
$('#tipModal').modal('show');
}
}
}
$('#addForm').ajaxSubmit(options);
});
// 保存
$('#save').on('click', function () {
if ($('#addForm').validationEngine('validate')) {
var param = {};
param.id = editId;
param.name = $('#name').val();
param.imgUrl = $('#imgUrl').attr('src');
param.sellingPrice = $('#sellingPrice').val();
param.packType = $('input[name="packType"]:checked').val();
param.ticketNum = $('#ticketNum').val();
param.ticketNum = param.ticketNum == "" ? 0 : param.ticketNum;
param.originalPrice = $('#originalPrice').val();
param.stock = $('#stock').val();
param.allowBuyNum = $('#allowBuyNum').val();
param.status = $('#status').val();
param.beginTime = $('#timeBegin').val() + " 00:00:00";
param.endTime = $('#timeEnd').val() + " 23:59:59";
param.seqNo = $('#seqNo').val();
$.ajax({
type: 'post',
url: '/admin/activity/pack/saveOrUpdate',
data: param,
dataType: 'json',
success: function (res) {
if (res.code == 200) {
$('#packModal').modal('hide');
$('#tipMsg').text('保存成功');
$('#tipModal').modal('show');
TableHelper.doRefresh('#table')
} else {
$('#tipMsg').text('保存失败,错误码:' + res.message);
$('#tipModal').modal('show');
}
}
})
}
});
$('#saveAward').on('click', function () {
if ($('#addAwardForm').validationEngine('validate')) {
// 获取时间参数
var param = {};
param.packId = editId;
param.awardId = $('#award').val();
param.num = $('#awardNum').val();
$('#saveAward').attr('disabled', true);
// 保存请求
$.ajax({
type: "POST",
url: "/admin/activity/pack/savePackItem",
dataType: "json",
data: param,
success: function (data) {
$('#saveAward').attr('disabled', false);
if (data.code == 200) {
$('#addAwardModal').modal('hide');
$('#tipMsg').text('保存成功');
$('#tipModal').modal('show');
$('#addModal').modal('hide');
TableHelper.doRefresh('#table');
} else {
$('#tipMsg').text(data.message);
$('#tipModal').modal('show');
}
}
});
}
});
$("#search").on('click', function () {
TableHelper.doRefresh('#table');
});
},
initData: function () {
$.get('/admin/activityAward/total', {}, function (res) {
if (res.code == 200) {
for (var i = 0; i < res.data.length; i++) {
var str = '<option value="' + res.data[i].id + '">' + res.data[i].prizeName + '</option>';
$('#award').append(str);
}
}
})
}
};
main.init();
var editId = 0;
$('#table').bootstrapTable('destroy');
$('#table').bootstrapTable({
columns: [
{ field: 'id', title: '礼包ID', align: 'center', valign: 'middle', width: '5%' },
{ field: 'name', title: '礼包名称', align: 'center', valign: 'middle', width: '10%' },
{
field: 'imgUrl', title: '礼包图片', align: 'center', valign: 'middle', width: '10%', formatter: function (val, row, index) {
return '<img src="' + val + '" alt="" style="width: 30px; height: 30px;">';
}
},
{
field: 'packType', title: '活动类型', align: 'center', valign: 'middle', width: '5%', formatter: function (val, row, index) {
switch (val) {
case 0:
return '普通活动';
case 1:
return '转盘活动';
case 2:
return '周星榜活动';
case 3:
return '深海奇缘活动';
case 6:
return '守护星球活动';
case 10:
return '航海冒险活动';
case 13:
return '夺宝精灵活动';
}
}
},
{ field: 'ticketNum', title: '赠送门票数量', align: 'center', valign: 'middle', width: '10%' },
// {field: 'type', title: '礼包类型', align: 'center', valign: 'middle', width: '5%',formatter: function(val,row,index){
// switch (val) {
// case 1:
// return '普通礼包';
// break;
// case 2:
// return '特殊礼包';
// }
// }},
{
field: 'status', title: '礼包状态', align: 'center', valign: 'middle', width: '10%', formatter: function (val, row, index) {
switch (val) {
case 1:
return '有效';
case 2:
return '无效';
}
}
},
{ field: 'sellingPrice', title: '售价', align: 'center', valign: 'middle', width: '5%' },
{ field: 'originalPrice', title: '原价', align: 'center', valign: 'middle', width: '5%' },
{ field: 'stock', title: '库存量', align: 'center', valign: 'middle', width: '5%' },
{ field: 'allowBuyNum', title: '允许购买数量', align: 'center', valign: 'middle', width: '5%' },
{
field: 'beginTime', title: '开放购买时间', align: 'center', valign: 'middle', width: '10%', formatter: function (val, row, index) {
if (val) {
var date = new Date(val);
return date.format('yyyy-MM-dd hh:mm:ss');
} else {
return '-';
}
}
},
{
field: 'endTime', title: '截止购买时间', align: 'center', valign: 'middle', width: '10%', formatter: function (val, row, index) {
if (val) {
var date = new Date(val);
return date.format('yyyy-MM-dd hh:mm:ss');
} else {
return '-';
}
}
},
{
field: 'seqNo', title: '排序序号', align: 'center', valign: 'middle', width: '5%', formatter: function (val, row, index) {
return '<span style="color: red">' + val + '</span>';
}
},
{
field: 'tmp', title: '操作', align: 'center', valign: 'middle', width: '10%', formatter: function (val, row, index) {
var key = row.id;
var status = row.status;
var str = '<button class="btn btn-primary btn-sm opt-edit" data-id="' + key + '">编辑礼包</button>';
if (status == 1) {
str += '<button class="btn btn-primary btn-sm opt-close" data-id="' + key + '">关闭礼包</button>';
}
str += '<button class="btn btn-primary btn-sm opt-award" data-id="' + key + '">添加奖品</button>' +
'<button class="btn btn-primary btn-sm opt-awardList" data-id="' + key + '">奖品列表</button>';
return str;
}
}
],
cache: false,
striped: true,
showRefresh: false,
pageSize: 10,
pagination: false,
pageList: [10, 20, 30, 50],
sidePagination: 'server',
queryParamsType: 'undefined',
queryParams: function queryParams() {
var param = {
status: $('#statusSelect').val(),
packType: $('#packTypeSelect').val()
};
return param;
},
uniqueId: 'id',
toolbar: '#toolbar',
url: '/admin/activity/pack/list',
onLoadSuccess: function () {
console.log('load success');
},
onLoadError: function () {
console.log('load fail');
}
});
function clearModal() {
$('#addForm').find('input[type=text],select,input[type=hidden]').each(function () {
$(this).val('');
});
$('#addForm').find('img').attr('src', '');
$('#addForm').find('.combobox-container').removeClass('combobox-selected');
}
function initPackItemsListTable(packId) {
$('#packItemListTable').bootstrapTable('destroy');
$('#packItemListTable').bootstrapTable({
columns: [
{ field: 'id', title: 'ID', align: 'center', width: '5%', valign: 'middle', visible: false },
{ field: 'name', title: '奖品名称', align: 'center', width: '5%', valign: 'middle' },
{
field: 'type', title: '奖品类型', align: 'center', width: '5%', valign: 'middle', formatter: function (val, row, index) {
switch (val) {
case 1:
return '金币';
case 2:
return '在线礼物';
case 3:
return '座驾';
case 4:
return '头饰';
case 5:
return '背景';
case 6:
return '实物';
case 7:
return '靓号';
case 8:
return '全麦礼物';
case 9:
return '随机靓号';
case 10:
return '锤子';
case 11:
return '贵族爵位';
case 12:
return '萝卜';
case 14:
return '铭牌';
}
}
},
{
field: 'imgUrl', title: '奖品图片', align: 'center', width: '5%', valign: 'middle', formatter: function (val, row, index) {
return '<img src="' + val + '" alt="" style="width: 30px; height: 30px;">';
}
},
{ field: 'referenceValue', title: '使用天数', align: 'center', width: '5%', valign: 'middle' },
{ field: 'num', title: '数量', align: 'center', width: '5%', valign: 'middle' },
{
field: 'createTime',
title: '创建时间',
align: 'center',
width: '5%',
valign: 'middle',
formatter: function (val, row, index) {
if (val) {
var date = new Date(val);
return date.format("yyyy-MM-dd hh:mm:00");
} else {
return '-';
}
}
},
{
field: 'temp',
title: '操作',
align: 'center',
width: '5%',
valign: 'middle',
formatter: function (val, row, index) {
return '<button class="btn btn-sm btn-success opt-del" data-id=' + row.id + '>' +
'<i class="glyphicon glyphicon-move"></i> 删除</button>';
}
}
],
cache: false,
striped: true,
showRefresh: false,
pageSize: 20,
pagination: true,
pageList: [20, 50, 100, 200, 300, 500],
search: false,
sidePagination: "server", //表示服务端请求
queryParamsType: "undefined",
queryParams: function queryParams() { //设置查询参数
var param = {
packId: packId
};
return param;
},
url: '/admin/activity/pack/listPackItems',
onLoadSuccess: function () { //加载成功时执行
console.log("load success");
},
onLoadError: function () { //加载失败时执行
console.log("load fail");
}
})
}
})
}
},
};
</script>
<style scoped>
input {
outline: none;
padding: 3px;
}
.tips {
color: red;
}
.big-tips {
color: red;
font-size: larger;
font-weight: bold;
}
</style>