385 lines
19 KiB
Vue
385 lines
19 KiB
Vue
<template>
|
||
<section class="content">
|
||
<div class="box box-primary">
|
||
<div class="box-body">
|
||
<!-- Content Header (Page header) -->
|
||
<section class="content-header">
|
||
<h1 id="itemTitle"></h1>
|
||
</section>
|
||
<!-- .content -->
|
||
<section class="content">
|
||
<div id="table"></div>
|
||
<div id="toolbar">
|
||
<button id="ticket-add" class="btn btn-default">
|
||
<i class="glyphicon glyphicon-plus"></i>新建门票
|
||
</button>
|
||
</div>
|
||
</section><!-- .content -->
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<div class="modal fade" id="ticketModal" tabindex="-1" role="dialog" aria-labelledby="modalLabel">
|
||
<div class="modal-dialog" role="document">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
|
||
aria-hidden="true">×</span>
|
||
</button>
|
||
<h4 class="modal-title" id="modalLabel">门票信息</h4>
|
||
</div>
|
||
<div class="modal-body">
|
||
<form class="form-horizontal" id="ticketForm">
|
||
<input type="hidden" name="ticketId" id="ticketId" />
|
||
<div class="form-group">
|
||
<label class="col-sm-2 control-label">状态</label>
|
||
<div class="col-sm-3">
|
||
<label class="radio-inline"><input type="radio" name="status" value="1" checked>上架</label>
|
||
<label class="radio-inline"><input type="radio" name="status" value="0">下架</label>
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="ticketName" class="col-sm-2 control-label">名称</label>
|
||
<div class="col-sm-10">
|
||
<input type="text" class="form-control validate[required]" name="ticketName"
|
||
id="ticketName">
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="buyType" class="col-sm-2 control-label">购买方式</label>
|
||
<div class="col-sm-10">
|
||
<select name="buyType" id="buyType" data-btn-class="btn-warning">
|
||
<option value="1">充值币</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="price" class="col-sm-2 control-label">价格</label>
|
||
<div class="col-sm-10">
|
||
<input type="text" class="form-control validate[required]" name="price" id="price">
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="seq" class="col-sm-2 control-label">排序</label>
|
||
<div class="col-sm-10">
|
||
<input type="text" class="form-control validate[required]" placeholder="请输入正整数,数字小的在前面"
|
||
name="seq" id="seq">
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="description" class="col-sm-2 control-label">说明</label>
|
||
<div class="col-sm-10">
|
||
<input type="text" class="form-control validate[required]" name="description"
|
||
id="description">
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="stock" class="col-sm-2 control-label">库存</label>
|
||
<div class="col-sm-10">
|
||
<input type="text" class="form-control validate[required]" name="stock" id="stock">
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label class="col-sm-2 control-label">图片:</label>
|
||
<div class="col-sm-10">
|
||
<img src="" id="picImage" style="width:250px;height:90px;" alt="">
|
||
<input type="file" id="picUploadFile" name="file">
|
||
<button class="btn btn-success" type="button" id="picUploadBtn">上传</button>
|
||
<input type="hidden" id="picUrl" name="picUrl" class="form-control validate[required]" />
|
||
<span id="picImgInfo" style="color:red;"></span>
|
||
</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" id="save">保存</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="modal first fade" id="tipModal" tabindex="-1" role="dialog" aria-labelledby="modalLabel">
|
||
<div class="modal-dialog" role="document">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h4 class="modal-title">提示信息</h4>
|
||
</div>
|
||
<div class="modal-body" id="tipMsg"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
import TableHelper from '@/utils/bootstrap-table-helper';
|
||
import ComboboxHelper from '@/assets/plugins/bootstrap-combobox/js/bootstrap-combobox-helper';
|
||
|
||
export default {
|
||
name: "TicketManageView",
|
||
setup() {
|
||
return {};
|
||
},
|
||
created() {
|
||
this.$nextTick(function () {
|
||
this.initData();
|
||
});
|
||
},
|
||
methods: {
|
||
initData() {
|
||
ComboboxHelper.build(null, '#buyType');
|
||
$(function () {
|
||
let pageList = [];
|
||
$('#table').bootstrapTable('destroy');
|
||
$('#table').bootstrapTable({
|
||
columns: [
|
||
{ field: 'ticketId', title: 'ID', align: 'center', width: '5%' },
|
||
{ field: 'ticketName', title: '名称', align: 'center', width: '5%' },
|
||
{
|
||
field: 'buyType', title: '购买方式', align: 'center', width: '15%',
|
||
formatter: function (val, row, index) {
|
||
if (val == 1) {
|
||
return '充值币';
|
||
} else {
|
||
return '-';
|
||
}
|
||
}
|
||
},
|
||
{ field: 'price', title: '价格', align: 'center', width: '5%' },
|
||
{
|
||
field: 'expireTime', title: '过期时间', align: 'center', width: '15%',
|
||
formatter: function (val) {
|
||
if (val) {
|
||
var date = new Date(val);
|
||
return date.format("yyyy-MM-dd hh:mm:ss");
|
||
} else {
|
||
return '-';
|
||
}
|
||
}
|
||
},
|
||
{ field: 'stock', title: '剩余库存', align: 'center', width: '5%' },
|
||
{ field: 'saledCount', title: '累计消耗', align: 'center', width: '5%' },
|
||
{ field: 'seq', title: '排序', align: 'center', width: '5%' },
|
||
{
|
||
field: 'status',
|
||
title: '状态',
|
||
align: 'center',
|
||
width: '10%',
|
||
formatter: function (val, row, index) {
|
||
if (val == 1) {
|
||
return '上架';
|
||
} else if (val == 0) {
|
||
return '下架';
|
||
} else {
|
||
return '-';
|
||
}
|
||
}
|
||
},
|
||
{
|
||
field: 'ticketId', title: '操作', align: 'center', width: '15%', formatter: function (val, row, index) {
|
||
const actions = [];
|
||
actions.push('<button class="btn btn-sm btn-success opt-edit" data-id=' + val + '>' +
|
||
'<i class="glyphicon glyphicon-edit"></i>编辑</button>');
|
||
if (row.status == 1) {
|
||
actions.push('<button class="btn btn-sm btn-danger opt-change-status" data-id=' + val + ' data-status="0">' +
|
||
'<i class="glyphicon glyphicon-edit"></i>下架</button>')
|
||
} else if (row.status == 0) {
|
||
actions.push('<button class="btn btn-sm btn-warning opt-change-status" data-id=' + val + ' data-status="1">' +
|
||
'<i class="glyphicon glyphicon-edit"></i>上架</button>')
|
||
}
|
||
return actions.join(" ");
|
||
|
||
}
|
||
}
|
||
],
|
||
cache: false,
|
||
striped: true,
|
||
showRefresh: true,
|
||
pageSize: 10,
|
||
pagination: true,
|
||
pageList: [1, 10, 20, 30, 50],
|
||
search: false,
|
||
sidePagination: "server", //表示服务端请求
|
||
//设置为undefined可以获取pageNumber,pageSize,searchText,sortName,sortOrder
|
||
//设置为limit可以获取limit, offset, search, sort, order
|
||
queryParamsType: "undefined",
|
||
queryParams: function queryParams(params) { //设置查询参数
|
||
var param = {
|
||
page: params.pageNumber,
|
||
pageSize: params.pageSize,
|
||
};
|
||
return param;
|
||
},
|
||
toolbar: '#toolbar',
|
||
url: '/admin/gameManage/listTicketByPage',
|
||
onLoadSuccess: function (data) { //加载成功时执行
|
||
console.log("load success", data);
|
||
pageList = data;
|
||
},
|
||
onLoadError: function () { //加载失败时执行
|
||
console.log("load fail");
|
||
}
|
||
});
|
||
|
||
$("#table").on("click", '.opt-change-status', function () {
|
||
var id = $(this).attr("data-id");
|
||
var status = $(this).attr("data-status");
|
||
if (id == 'undefined') {
|
||
$("#tipMsg").text("id参数有误");
|
||
$("#tipModal").modal('show');
|
||
return;
|
||
}
|
||
let tips = '';
|
||
if (status == 1) {
|
||
tips = "上架"
|
||
} else {
|
||
tips = "下架"
|
||
}
|
||
if (confirm(`你确认${tips}该门票吗?`)) {
|
||
$.ajax({
|
||
type: 'post',
|
||
url: "/admin/gameManage/changeTicketStatus",
|
||
data: { 'ticketId': id, 'newStatus': status },
|
||
dataType: "json",
|
||
success: function (json) {
|
||
if (json.code == 200) {
|
||
$("#tipMsg").text(`${tips}成功`);
|
||
$("#tipModal").modal('show');
|
||
TableHelper.doRefresh("#table");
|
||
} else {
|
||
$("#tipMsg").text(`${tips}失败`);
|
||
$("#tipModal").modal('show');
|
||
}
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
|
||
$("#ticket-add").click(function () {
|
||
// 打开编辑弹窗
|
||
$("#ticketModal").modal('show');
|
||
$("#ticketForm")[0].reset();
|
||
|
||
$('#picUrl').val('');
|
||
$('#picImage').attr("src", '');
|
||
$("#picImgInfo").html('');
|
||
$("#picUploadFile").val('');
|
||
$("#seq").val('');
|
||
$("#ticketId").val('');
|
||
ComboboxHelper.setDef("#buyType", '2');
|
||
});
|
||
|
||
$('#picUploadBtn').on('click', function () {
|
||
$.ajaxFileUpload({
|
||
fileElementId: 'picUploadFile', //需要上传的文件域的ID,即<input type="file">的ID。
|
||
url: '/admin/gift/upload', //后台方法的路径
|
||
type: 'post', //当要提交自定义参数时,这个参数要设置成post
|
||
dataType: 'json', //服务器返回的数据类型。可以为xml,script,json,html。如果不填写,jQuery会自动判断。
|
||
secureuri: false, //是否启用安全提交,默认为false。
|
||
async: true, //是否是异步
|
||
success: function (json) { //提交成功后自动执行的处理函数,参数data就是服务器返回的数据。
|
||
if (json.path) {
|
||
$('#picUrl').val(json.path);
|
||
$('#picImage').attr("src", json.path);
|
||
if (json.path != '') {
|
||
$("#picImgInfo").html('已上传成功');
|
||
} else {
|
||
$("#picImgInfo").html('未上传成功');
|
||
}
|
||
console.log(json.path);
|
||
|
||
} else {
|
||
$("#tipMsg").text(json.msg);
|
||
$("#tipModal").modal('show');
|
||
}
|
||
},
|
||
error: function (data, status, e) { //提交失败自动执行的处理函数。
|
||
console.error(e);
|
||
}
|
||
});
|
||
})
|
||
|
||
function parseNum(val) {
|
||
if (val == undefined || val == 'false' || val == 0) {
|
||
return 0;
|
||
}
|
||
else {
|
||
return 1;
|
||
}
|
||
}
|
||
|
||
$("#table").on("click", '.opt-edit', function () {
|
||
console.log("btnEdit");
|
||
var id = $(this).attr("data-id");
|
||
$.ajax({
|
||
type: "get",
|
||
url: "/admin/gameManage/getTicket",
|
||
data: { ticketId: id },
|
||
dataType: "json",
|
||
success: function (json) {
|
||
if (json.code == 200 && json.data) {
|
||
$("#ticketId").val(json.data.ticketId);
|
||
|
||
if (json.data.status == 1) {
|
||
$("input:radio[name='status']")[0].checked = true;
|
||
} else {
|
||
$("input:radio[name='status']")[1].checked = true;
|
||
}
|
||
ComboboxHelper.setDef("#buyType", json.data.buyType);
|
||
|
||
$("#ticketName").val(json.data.ticketName);
|
||
$("#price").val(json.data.price);
|
||
|
||
$("#seq").val(json.data.seq);
|
||
$("#description").val(json.data.description);
|
||
$("#stock").val(json.data.stock);
|
||
|
||
// 设置图片
|
||
$("#picUploadFile").val('');
|
||
$('#picUrl').val(json.data.picUrl);
|
||
$('#picImage').attr("src", json.data.picUrl);
|
||
if (json.data.picUrl != '') {
|
||
$("#picImgInfo").html('已上传');
|
||
} else {
|
||
$("#picImgInfo").html('未上传');
|
||
}
|
||
|
||
// 打开编辑弹窗
|
||
$("#ticketModal").modal('show');
|
||
} else {
|
||
$("#tipMsg").text("获取门票信息出错");
|
||
$("#tipModal").modal('show');
|
||
}
|
||
}
|
||
});
|
||
});
|
||
|
||
$("#save").click(function () {
|
||
if ($("#ticketForm").validationEngine('validate')) {
|
||
$.ajax({
|
||
type: "post",
|
||
url: "/admin/gameManage/saveTicket",
|
||
data: $('#ticketForm').serialize(),
|
||
dataType: "json",
|
||
success: function (json) {
|
||
if (json.code == 200) {
|
||
$("#ticketModal").modal('hide');
|
||
$("#tipMsg").text("保存成功");
|
||
$("#tipModal").modal('show');
|
||
TableHelper.doRefresh("#table");
|
||
} else {
|
||
$("#tipMsg").text("保存失败." + json.msg);
|
||
$("#tipModal").modal('show');
|
||
}
|
||
}
|
||
});
|
||
}
|
||
});
|
||
});
|
||
}
|
||
},
|
||
|
||
};
|
||
</script>
|
||
|
||
<style scoped></style> |