Files
peko-admin-web/src/views/users/GiftLimitCompoundView.vue
2023-09-24 21:00:03 +08:00

296 lines
13 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">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1 id="itemTitle"></h1>
</section>
<div id="toolbar">
<div class="col-sm-12">
<button id="btnAdd" class="btn btn-default">
<i class="glyphicon glyphicon-plus"></i>增加
</button>
</div>
</div>
</div>
<!-- .content -->
<div id="table"></div>
</div>
</section>
<div class="modal fade" id="roomTagModal" 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">&times;</span>
</button>
<h4 class="modal-title" id="modalLabel">新增</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" id="addForm">
<input type="hidden" name="id" id="id" />
<div class="form-group" id="txtBox">
<label for="giftId" class="col-sm-3 control-label">礼物id<font color="red">*</font></label>
<div class="col-sm-9">
<input type="text" class="form-control validate[required]" name="giftId" id="giftId"
placeholder="请输入对应的id">
</div>
</div>
<div class="form-group">
<label for="orderNo" class="col-sm-3 control-label">展示排序<font color="red">*</font></label>
<div class="col-sm-9">
<input type="text" class="form-control validate[required]" name="orderNo" id="orderNo"
placeholder="数字小的排前面,必填">
</div>
</div>
<div class="form-group">
<label for="expendValue" class="col-sm-3 control-label">合成消耗<font color="red">*</font></label>
<div class="col-sm-9">
<input type="text" class="form-control validate[required]" name="expendValue"
id="expendValue" 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" id="add">确定</button>
</div>
</div>
</div>
</div>
</template>
<script>
import TableHelper from '@/utils/bootstrap-table-helper';
import { serverError } from '@/utils/maintainer';
export default {
name: "GiftLimitCompoundView",
setup() {
return {};
},
created() {
this.$nextTick(function () {
this.initData();
});
},
methods: {
initData() {
$(function () {
$('#table').bootstrapTable('destroy');
$('#table').bootstrapTable({
columns: [
{ field: 'id', title: 'ID', align: 'center', valign: 'middle', width: '10%' },
{ field: 'giftId', title: '礼物id', align: 'center', valign: 'middle', width: '10%' },
{ field: 'goldPrice', title: '礼物价值', align: 'center', valign: 'middle', width: '10%' },
{ field: 'expendValue', title: '合成消耗', align: 'center', valign: 'middle', width: '10%' },
{ field: 'giftName', title: '礼物名称', align: 'left', valign: 'middle', width: '10%' },
{ field: 'orderNo', title: '显示排序', align: 'center', valign: 'middle', width: '10%' },
{
field: 'id',
title: '操作',
align: 'center',
width: '10%',
formatter: function (val, row, index) {
return '<button id="btnEdit" name="btnEdit" class="btn btn-sm btn-success opt-edit" data-id=' + val + '>' +
'<i class="glyphicon glyphicon-edit"></i> 编辑</button>' +
'&nbsp;&nbsp;<button class="btn btn-sm btn-danger opt-remove" data-id=' + val + ' data-new-status=' + 2 +
'><i class="glyphicon glyphicon-remove"></i>删除</button>';
}
}
],
undefinedText: "-",
cache: false,
striped: true,
showRefresh: false,
pageSize: 50,
pagination: true,
pageList: [20, 50, 100, 200, 300, 500],
search: false,
sidePagination: "server", //表示服务端请求
queryParamsType: "undefined",
queryParams: function queryParams(params) { //设置查询参数
var param = {
pageNum: params.pageNumber,
pageSize: params.pageSize
};
return param;
},
ajax: function (request) { //使用ajax请求
$.ajax({
type: "GET",
url: '/admin/gift/compound/getLimitGiftList.action',
contentType: 'application/json;charset=utf-8',
dataType: 'json',
data: request.data,
success: function (res) {
apiResult(res);
request.success({
rows: res.data.rows,
total: res.data.total,
});
},
error: function (req) {
serverError(req);
}
})
},
toolbar: '#toolbar',
onLoadSuccess: function () { //加载成功时执行
console.log("load success");
},
onLoadError: function () { //加载失败时执行
console.log("load fail");
}
});
// 查询刷新
$('#btnSearch').on('click', function () {
TableHelper.doRefresh('#table');
});
//新建标签
$("#btnAdd").click(function () {
clearModal();
$("#txtBox").show();
$("#roomTagModal").modal('show');
});
$("#add").click(function () {
var id = $("#id").val();
var giftId = $('#giftId').val();
var expendValue = $("#expendValue").val();
var orderNo = $('#orderNo').val();
if ($("#addForm").validationEngine('validate')) {
$.ajax({
type: "post",
url: "/admin/gift/compound/saveReward.action",
data: {
id: id,
giftId: giftId,
expendValue: expendValue,
orderNo: orderNo,
rewardType: 2,
},
dataType: "json",
success: function (json) {
if (json.code == 200) {
$("#tipMsg").text("保存成功");
$("#tipModal").modal('show');
TableHelper.doRefresh("#table");
$("#roomTagModal").modal('hide');
} else {
$("#tipMsg").text("保存失败." + json.message);
$("#tipModal").modal('show');
TableHelper.doRefresh("#table");
$("#roomTagModal").modal('hide');
}
}
});
}
});
$("#table").on("click", '.opt-edit', function () {
var id = $(this).attr("data-id");
clearModal();
$("#txtBox").hide();
$.ajax({
type: "get",
url: "/admin/gift/compound/getLimitGtifById.action",
data: { id: id },
dataType: "json",
success: function (res) {
var json = res.data;
if (json) {
$("#id").val(id);
$('#giftId').val(json.giftId);
$('#orderNo').val(json.orderNo);
$('#expendValue').val(json.expendValue);
// 打开编辑弹窗
$("#roomTagModal").modal('show');
$("#modalLabel").text("编辑");
} else {
$("#tipMsg").text("获取信息出错");
$("#tipModal").modal('show');
}
}
});
});
$("#table").on("click", '.opt-remove', function () {
var id = $(this).attr("data-id");
console.log("data-id", id)
if (confirm("你确认删除该记录吗? \r\n 删除后再也不能找回,请谨慎操作!")) {
const requestParam = {
id: id
}
$.ajax({
type: "get",
url: "/admin/gift/compound/deleteReward",
data: requestParam,
dataType: "json",
contentType: 'application/json',
success: function (json) {
if (json.code == 200) {
$("#tipMsg").text("修改成功");
$("#tipModal").modal('show');
TableHelper.doRefresh("#table");
} else {
$("#tipMsg").text("修改失败." + json.message);
$("#tipModal").modal('show');
}
}
});
}
});
function apiResult(json) {
if (json.code == 200 && json.message == 'success') {
return true;
}
$("#tipMsg").text("请求失败,错误信息:" + json.message);
$("#tipModal").modal('show');
return false;
}
function clearModal() {
$('#iconImgUrl').attr('src', '');
$('#addForm').find('input[type=text],input[type=hidden],input[type=file]').each(function () {
$(this).val('');
})
$('#type').val(1);
}
$("#type").change(function () {
var optVal = $(this).val();
});
});
}
},
};
</script>
<style scoped></style>