820 lines
29 KiB
Vue
820 lines
29 KiB
Vue
<template>
|
||
<section class="content">
|
||
<div class="box box-primary">
|
||
<section class="content-header">
|
||
<h1 id='itemTitle'></h1>
|
||
</section>
|
||
|
||
<section class="content">
|
||
|
||
<div id="table"></div>
|
||
|
||
<div id="toolbar">
|
||
|
||
<div class="col-sm-12">
|
||
<form action="" id="searchForm" method="POST">
|
||
|
||
转盘分类:<select name="jackpotType" id="jackpotType" data-btn-class="btn btn-warning">
|
||
<option value="1">幸运新人奖池</option>
|
||
<option value="2">幸运普通奖池</option>
|
||
<option value="3">幸运白名单奖池</option>
|
||
<option value="4">幸运偏差奖池</option>
|
||
<option value="12">幸运次数奖池</option>
|
||
<option value="13">普通管理奖池</option>
|
||
<option value="7">梦幻普通奖池</option>
|
||
<option value="9">梦幻偏差奖池</option>
|
||
<option value="10">梦幻新人奖池</option>
|
||
<option value="11">梦幻白名单奖池</option>
|
||
<option value="14">梦幻管理奖池</option>
|
||
</select>
|
||
<label class="deviateRange">
|
||
偏差范围:
|
||
<select name="deviateRange" id="deviateRange" data-btn-class="btn btn-warning">
|
||
</select>
|
||
</label>
|
||
<label class="diamondDeviateRange">
|
||
偏差范围:
|
||
<select name="diamondDeviateRange" id="diamondDeviateRange" data-btn-class="btn btn-warning">
|
||
</select>
|
||
</label>
|
||
</form>
|
||
<button class="btn btn-primary" id="searchBtn">搜索</button>
|
||
<button class="btn btn-primary" id="add">添加奖品</button>
|
||
</div>
|
||
|
||
<div class="col-sm-12 jackpot">
|
||
<p class="col-sm-12">
|
||
<span class="col-sm-3">许愿池类型</span>
|
||
<span class="col-sm-3">奖品种类数</span>
|
||
<span class="col-sm-3">奖品个数</span>
|
||
<span class="col-sm-3">总期望值(钻石)</span>
|
||
</p>
|
||
|
||
<p class="col-sm-12">
|
||
<span class="col-sm-3" id="jackpotName"></span>
|
||
<span class="col-sm-3" id="jackpotNum"></span>
|
||
<span class="col-sm-3" id="prizeNum"></span>
|
||
<span class="col-sm-3" id="expectNum"></span>
|
||
</p>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
</section>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- 添加弹窗 -->
|
||
<div class="modal fade" id="addModal" 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">x</span>
|
||
</button>
|
||
|
||
<h4 class="modal-title" id="addModalLabel">添加奖品</h4>
|
||
</div>
|
||
|
||
<div class="modal-body">
|
||
<form action="" class="form-horizontal" id="addForm">
|
||
|
||
<!-- 选择奖品 -->
|
||
<div class="form-group">
|
||
<label for="" class="col-sm-3 control-label">选择奖品:</label>
|
||
<div class="col-sm-8">
|
||
<select name="awardType" id="awardType" data-btn-class="btn btn-warning">
|
||
<!-- <option value=""></option> -->
|
||
</select>
|
||
|
||
<select name="awardChoose" id="awardChoose" data-btn-class="btn btn-warning">
|
||
<!-- <option value=""></option> -->
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 奖品个数 -->
|
||
<div class="form-group">
|
||
<label for="" class="col-sm-3 control-label">奖品个数:</label>
|
||
|
||
<div class="col-sm-8">
|
||
<input type="text" id="jackpotNumber" name="jackpotNumber" class=" validate[required]" placeholder="单行输入">
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 中奖率 -->
|
||
<div class="form-group">
|
||
<label for="" class="col-sm-3 control-label">实际中奖率:</label>
|
||
|
||
<div class="col-sm-8">
|
||
<input type="text" id="winningRate" name="winningRate" class=" validate[required]" placeholder="单行输入">%
|
||
<br />
|
||
<div class="tips">
|
||
<i class="glyphicon glyphicon-info-sign"></i>中奖率综合为100,当前概率不得超过100
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 展示中奖率 -->
|
||
<div class="form-group">
|
||
<label for="" class="col-sm-3 control-label">展示中奖率:</label>
|
||
|
||
<div class="col-sm-8">
|
||
<input type="text" id="showRate" name="showRate" class=" validate[required]" placeholder="单行输入">%
|
||
<br />
|
||
<div class="tips">
|
||
<i class="glyphicon glyphicon-info-sign"></i>中奖率综合为100,当前概率不得超过100
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label for="" class="col-sm-3 control-label">是否默认奖品:</label>
|
||
<div class="col-sm-8">
|
||
<select name="itemType" id="itemType" data-btn-class="btn btn-warning">
|
||
<option value="1"> 默认奖品 </option>
|
||
<option value="2"> 普通奖品 </option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 创建者 -->
|
||
<div class="form-group">
|
||
<label for="" class="col-sm-3 control-label">创建者:</label>
|
||
|
||
<div class="col-sm-8">
|
||
<input type="text" id="creator" name="creator" class="validate[required]" placeholder="必填项">
|
||
</div>
|
||
</div>
|
||
|
||
</form>
|
||
</div>
|
||
|
||
<div class="modal-footer">
|
||
<button class="btn btn-default" type="button" id="addReset">重置</button>
|
||
<button class="btn btn-primary" type="button" id="addSave">保存</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<!-- 编辑弹窗 -->
|
||
<div class="modal fade" id="editModal" 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">x</span>
|
||
</button>
|
||
<h4 class="modal-title" id="editModalLabel">编辑奖品</h4>
|
||
</div>
|
||
|
||
<div class="modal-body">
|
||
<form action="" class="form-horizontal" id="editForm">
|
||
<input type="hidden" id="editId">
|
||
<!-- 奖品个数 -->
|
||
<div class="form-group">
|
||
<label for="" class="col-sm-3 control-label">奖品个数:</label>
|
||
|
||
<div class="col-sm-8">
|
||
<input type="text" id="jackpotNumber2" name="jackpotNumber2" class=" validate[required]"
|
||
placeholder="单行输入">
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 中奖率 -->
|
||
<div class="form-group">
|
||
<label for="" class="col-sm-3 control-label">实际中奖率:</label>
|
||
|
||
<div class="col-sm-8">
|
||
<input type="text" id="winningRate2" name="winningRate2" class=" validate[required]" placeholder="单行输入">%
|
||
<br />
|
||
<div class="tips">
|
||
<i class="glyphicon glyphicon-info-sign"></i>中奖率综合为100,当前概率不得超过100
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 展示给用户看的中奖率 -->
|
||
<div class="form-group">
|
||
<label for="" class="col-sm-3 control-label">展示中奖率:</label>
|
||
|
||
<div class="col-sm-8">
|
||
<input type="text" id="showRate2" name="showRate2" class=" validate[required]" placeholder="单行输入">%
|
||
<br />
|
||
<div class="tips">
|
||
<i class="glyphicon glyphicon-info-sign"></i>中奖率综合为100,当前概率不得超过100
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="" class="col-sm-3 control-label">是否默认奖品:</label>
|
||
<div class="col-sm-8">
|
||
<select name="itemType" id="itemType2" data-btn-class="btn btn-warning">
|
||
<option value="1"> 默认奖品 </option>
|
||
<option value="2"> 普通奖品 </option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 创建者 -->
|
||
<div class="form-group">
|
||
<label for="" class="col-sm-3 control-label">创建者:</label>
|
||
|
||
<div class="col-sm-8">
|
||
<input type="text" id="creator2" name="creator2" class="validate[required]">
|
||
</div>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
|
||
<div class="modal-footer">
|
||
<button class="btn btn-default" type="button" id="editReset">重置</button>
|
||
<button class="btn btn-primary" type="button" id="editSave">保存</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
import TableHelper from '@/utils/bootstrap-table-helper';
|
||
|
||
var idObj = {};
|
||
var typeObj = {};
|
||
var pId = '', saveId = '';
|
||
|
||
var ACCURACY = 1000; // 小数点精度
|
||
var RATIO_PART = 100000; // 概率换算单位
|
||
export default {
|
||
name: "PrizeManageAdminView",
|
||
setup() {
|
||
return {};
|
||
},
|
||
created() {
|
||
this.initData();
|
||
|
||
},
|
||
mounted() {
|
||
|
||
},
|
||
methods: {
|
||
initData() {
|
||
this.$nextTick(function () {
|
||
var main = {
|
||
init: function () {
|
||
$('.deviateRange').hide();
|
||
$('.chargeDeviateRange').hide();
|
||
$('.diamondDeviateRange').hide();
|
||
this.eventRegister();
|
||
this.getDataFormBack();
|
||
this.initDeviateRangeSelect();
|
||
this.initDiamondDeviateRangeSelect();
|
||
//$('#selectReplacePrize').hide();
|
||
//this.initReplacePrizeSelect();
|
||
},
|
||
|
||
eventRegister: function () {
|
||
|
||
},
|
||
|
||
getDataFormBack: function () {
|
||
$.get('/admin/prize/total/list', {}, function (res) {
|
||
if (res.code == 200) {
|
||
// console.log(res);
|
||
for (var i = 0; i < res.data.length; i++) {
|
||
// id对象存储
|
||
var id = '' + res.data[i].id;
|
||
idObj[id] = res.data[i];
|
||
|
||
// Type对象存储
|
||
var type = '' + res.data[i].prizeType;
|
||
|
||
console.log(type);
|
||
|
||
if (!typeObj[type]) {
|
||
typeObj[type] = [];
|
||
}
|
||
typeObj[type].push(res.data[i]);
|
||
|
||
}
|
||
console.log(idObj, typeObj);
|
||
}
|
||
});
|
||
},
|
||
|
||
initDeviateRangeSelect: function () {
|
||
let options = $('#deviateRange').children();
|
||
if (options.length <= 0) {
|
||
$.get('/admin/deviateRange/list?type=1', {}, function (res) {
|
||
if (res.total > 0) {
|
||
var rows = res.rows;
|
||
for (var i = 0; i < rows.length; i++) {
|
||
var deviateRange = rows[i];
|
||
var str = '<option value=' + deviateRange.id + '>' + deviateRange.lowerLimit + '~' + deviateRange.upperLimit + '</option>';
|
||
$('#deviateRange').append(str);
|
||
}
|
||
}
|
||
});
|
||
}
|
||
},
|
||
|
||
initDiamondDeviateRangeSelect: function () {
|
||
let options = $('#diamondDeviateRange').children();
|
||
if (options.length <= 0) {
|
||
$.get('/admin/deviateRange/list?type=4', {}, function (res) {
|
||
if (res.total > 0) {
|
||
var rows = res.rows;
|
||
for (var i = 0; i < rows.length; i++) {
|
||
var deviateRange = rows[i];
|
||
var str = '<option value=' + deviateRange.id + '>' + deviateRange.lowerLimit + '~' + deviateRange.upperLimit + '</option>';
|
||
$('#diamondDeviateRange').append(str);
|
||
}
|
||
}
|
||
});
|
||
}
|
||
},
|
||
|
||
initReplacePrizeSelect: function () {
|
||
let options = $('#replaceAwardChoose').children();
|
||
if (options.length <= 0) {
|
||
$.get('/admin/prize/list/type?prizeType=2', {}, function (res) {
|
||
$('#replaceAwardChoose').find('option').remove();
|
||
for (var i in res.data) {
|
||
var str = '<option value=' + res.data[i].id + '>' + res.data[i].prizeName + '</option>';
|
||
$('#replaceAwardChoose').append(str);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
};
|
||
|
||
main.init();
|
||
|
||
var isEdit = false;
|
||
$('#table').bootstrapTable('destroy');
|
||
$('#table').bootstrapTable({
|
||
columns: [
|
||
{ field: 'id', title: '奖品编号', align: 'center', valign: 'middle', width: '10%' },
|
||
{
|
||
field: 'prizeName', title: '奖品名称', align: 'center', valign: 'middle', width: '10%', formatter: function (val, row, index) {
|
||
var key = row.prizeId;
|
||
console.log(key);
|
||
if (idObj[key]) {
|
||
return idObj[key].prizeName;
|
||
}
|
||
return '';
|
||
}
|
||
},
|
||
{
|
||
field: '', title: '奖品分类', align: 'center', valign: 'middle', width: '10%', formatter: function (val, row, index) {
|
||
var $prizeId = row.prizeId;
|
||
var $type;
|
||
if (idObj[$prizeId]) {
|
||
$type = idObj[$prizeId].prizeType;
|
||
}
|
||
switch ($type) {
|
||
case 8:
|
||
return '谢谢参与';
|
||
|
||
case 1:
|
||
return '钻石';
|
||
|
||
case 2:
|
||
return '在线礼物';
|
||
|
||
case 3:
|
||
return '座驾';
|
||
|
||
case 4:
|
||
return '头饰';
|
||
|
||
case 5:
|
||
return '背景';
|
||
|
||
case 6:
|
||
return '实体奖品';
|
||
|
||
case 7:
|
||
return '靓号';
|
||
|
||
}
|
||
|
||
}
|
||
},
|
||
{
|
||
field: '', title: '奖品个数', align: 'center', valign: 'middle', width: '10%', formatter: function (val, row, index) {
|
||
return row.prizeNum;
|
||
}
|
||
},
|
||
{
|
||
field: '', title: '平台价值', align: 'center', valign: 'middle', width: '10%', formatter: function (val, row, index) {
|
||
var key = row.prizeId;
|
||
if (idObj[key]) {
|
||
return idObj[key].platformValue;
|
||
}
|
||
return '';
|
||
}
|
||
},
|
||
{
|
||
field: '', title: '实际价值', align: 'center', valign: 'middle', width: '10%', formatter: function (val, row, index) {
|
||
var key = row.prizeId;
|
||
if (idObj[key]) {
|
||
return idObj[key].actualValue;
|
||
}
|
||
return '';
|
||
}
|
||
},
|
||
{
|
||
field: '', title: '实际中奖率', align: 'center', valign: 'middle', width: '10%', formatter: function (val, row, index) {
|
||
return row.occupationRatio / ACCURACY + '%';
|
||
}
|
||
},
|
||
{
|
||
field: '', title: '显示中奖率', align: 'center', valign: 'middle', width: '10%', formatter: function (val, row, index) {
|
||
return row.showRatio / ACCURACY + '%';
|
||
}
|
||
},
|
||
{
|
||
field: '', title: '期望值', align: 'center', valign: 'middle', width: '10%', formatter: function (val, row, index) {
|
||
var key = row.prizeId;
|
||
if (idObj[key]) {
|
||
return row.occupationRatio * idObj[key].actualValue / RATIO_PART;
|
||
}
|
||
return '';
|
||
}
|
||
},
|
||
{ field: 'usePrizeNum', title: '被抽中数量', align: 'center', valign: 'middle', width: '10%' },
|
||
{
|
||
field: '', title: '操作', align: 'center', valign: 'middle', width: '10%', formatter: function (val, row, index) {
|
||
var key = row.id;
|
||
return '<button class="btn btn-primary opt-edit" data-id="' + key + '">编辑</button> <button class="btn btn-primary remove" data-id="' + key + '">移除</button>';
|
||
}
|
||
}
|
||
],
|
||
cache: false,
|
||
striped: true,
|
||
showRefresh: false,
|
||
pageSize: 10,
|
||
pagination: true,
|
||
pageList: [10, 20, 30, 50],
|
||
sidePagination: 'server',
|
||
queryParamsType: 'undefined',
|
||
queryParams: function queryParams(params) {
|
||
|
||
var param = {
|
||
pageSize: params.pageSize,
|
||
pageNumber: params.pageNumber,
|
||
poolType: parseInt($('#jackpotType').val()),
|
||
deviateRangeId: getDeviateRangeId()
|
||
};
|
||
|
||
return param;
|
||
},
|
||
uniqueId: 'id',
|
||
toolbar: '#toolbar',
|
||
url: '/admin/prizePoolItem/list',
|
||
onLoadSuccess: function (res) {
|
||
console.log('load success');
|
||
console.log(res.rows);
|
||
var arr = [];
|
||
var Num = 0;
|
||
var expectNum = 0;
|
||
var typeObjArr = {
|
||
1: '幸运新人奖池',
|
||
2: '幸运普通奖池',
|
||
3: '幸运白名单奖池',
|
||
4: '幸运偏差奖池',
|
||
12: '幸运次数奖池',
|
||
7: '梦幻普通奖池',
|
||
9: '梦幻偏差奖池',
|
||
10: '梦幻新人奖池',
|
||
11: '梦幻白名单奖池',
|
||
}
|
||
for (var i in res.rows) {
|
||
|
||
$('#jackpotName').html(typeObjArr[res.rows[i].prizePoolType]);
|
||
if (arr.indexOf(res.rows[i].prizeId) == -1) {
|
||
arr.push(res.rows[i].prizeId);
|
||
$('#jackpotNum').html(arr.length)
|
||
}
|
||
Num += parseInt(res.rows[i].prizeNum);
|
||
$('#prizeNum').html(Num);
|
||
var $expect = res.rows[i].occupationRatio;
|
||
// console.log(idObj[res.rows[]]);
|
||
var $actual = 0;
|
||
if (res.rows[i] && idObj[res.rows[i].prizeId]) {
|
||
$actual = idObj[res.rows[i].prizeId].actualValue;
|
||
}
|
||
var $Num = parseInt($expect) * parseInt($actual) / RATIO_PART;
|
||
expectNum += $Num;
|
||
$('#expectNum').html(expectNum);
|
||
|
||
}
|
||
},
|
||
onLoadError: function () {
|
||
console.log('load fail');
|
||
}
|
||
});
|
||
// 搜索按钮事件
|
||
$('#searchBtn').on('click', function () {
|
||
$('#table').bootstrapTable('refreshOptions', { pageNumber: 1 });
|
||
TableHelper.doRefresh('#table');
|
||
});
|
||
|
||
$('#jackpotType').on('change', function () {
|
||
var key = $(this).val();
|
||
switch (key) {
|
||
case '4':
|
||
$('.deviateRange').show();
|
||
$('.diamondDeviateRange').hide();
|
||
break;
|
||
case '9':
|
||
$('.deviateRange').hide();
|
||
$('.chargeDeviateRange').hide();
|
||
$('.diamondDeviateRange').show();
|
||
break;
|
||
default:
|
||
$('.deviateRange').hide();
|
||
$('.chargeDeviateRange').hide();
|
||
$('.diamondDeviateRange').hide();
|
||
break;
|
||
}
|
||
});
|
||
|
||
// 添加按钮事件
|
||
$('#add').on('click', function () {
|
||
$('#awardType').find('option').remove();
|
||
for (var key in typeObj) {
|
||
var $prizeType = '';
|
||
switch (key) {
|
||
case '8':
|
||
$prizeType = '谢谢参与';
|
||
break;
|
||
case '1':
|
||
$prizeType = '钻石';
|
||
break;
|
||
case '2':
|
||
$prizeType = '礼物';
|
||
break;
|
||
case '3':
|
||
$prizeType = '座驾';
|
||
break;
|
||
case '4':
|
||
$prizeType = '头饰';
|
||
break;
|
||
case '5':
|
||
$prizeType = '背景';
|
||
break;
|
||
case '6':
|
||
$prizeType = '实体奖品';
|
||
break;
|
||
case '7':
|
||
$prizeType = '靓号';
|
||
break;
|
||
}
|
||
var str = '<option value=' + key + '>' + $prizeType + '</option>';
|
||
$('#awardType').append(str);
|
||
}
|
||
clearModal();
|
||
$('#addModal').modal('show');
|
||
});
|
||
|
||
// select监听事件
|
||
$('#addModal').find('#awardType').on('change', function () {
|
||
$('#awardChoose').find('option').remove();
|
||
var key = $(this).val();
|
||
console.log(key);
|
||
// var str = '<option></option>';
|
||
// $('#awardChoose').append(str);
|
||
var str;
|
||
for (var i in typeObj[key]) {
|
||
str = '<option value=' + typeObj[key][i].id + '>' + typeObj[key][i].prizeName + '</option>';
|
||
$('#awardChoose').append(str);
|
||
}
|
||
|
||
});
|
||
|
||
// 编辑按钮事件
|
||
$('#table').on('click', '.opt-edit', function () {
|
||
clearModal();
|
||
$('#editModal').modal('show');
|
||
var id = $(this).data('id');
|
||
var data = $('#table').bootstrapTable('getRowByUniqueId', id);
|
||
|
||
console.log(data);
|
||
$('#editModal').find('#jackpotNumber2').val(data.prizeNum);
|
||
$('#editModal').find('#winningRate2').val(data.occupationRatio / ACCURACY);
|
||
$('#editModal').find('#showRate2').val(data.showRatio / ACCURACY);
|
||
$('#editModal').find('#creator2').val(data.creator);
|
||
$('#editModal').find('#itemType2').val(data.itemType);
|
||
pId = data.prizeId;
|
||
saveId = id;
|
||
});
|
||
|
||
// 保存按钮事件
|
||
$('#addSave').on('click', function () {
|
||
if (parseFloat($('#winningRate').val()) % ACCURACY >= ACCURACY) {
|
||
// 小数位超过3位则不允许设置
|
||
$('#tipMsg').text('概率最多只允许设置到小数点后3位');
|
||
$('#tipModal').modal('show');
|
||
return;
|
||
}
|
||
if (parseFloat($('#winningRate').val()) > 100 || parseInt($('#winningRate').val()) < 0) {
|
||
$('#tipMsg').text('中奖概率只能是0到100的数值');
|
||
$('#tipModal').modal('show');
|
||
return;
|
||
}
|
||
if (parseFloat($('#showRate').val()) % ACCURACY >= ACCURACY) {
|
||
// 小数位超过3位则不允许设置
|
||
$('#tipMsg').text('概率最多只允许设置到小数点后3位');
|
||
$('#tipModal').modal('show');
|
||
return;
|
||
}
|
||
if (parseFloat($('#showRate').val()) > 100 || parseInt($('#showRate').val()) < 0) {
|
||
$('#tipMsg').text('中奖概率只能是0到100的数值');
|
||
$('#tipModal').modal('show');
|
||
return;
|
||
}
|
||
// var reg = /^[0-9]*$/;
|
||
var reg = /^[0-9]+([.]{1}[0-9]+){0,1}$/;
|
||
if (!reg.test($('#winningRate').val()) || !reg.test($('#jackpotNumber').val()) || !reg.test($('#showRate').val())) {
|
||
$('#tipMsg').text('奖品个数和概率只能是数值');
|
||
$('#tipModal').modal('show');
|
||
return;
|
||
}
|
||
if ($('#creator').val() == '' || $('#creator').val() == 'undefined') {
|
||
$('#tipMsg').text('创建者项是必填的');
|
||
$('#tipModal').modal('show');
|
||
return;
|
||
}
|
||
$.post('/admin/prizePoolItem/save', {
|
||
poolType: $('#jackpotType').val(),
|
||
deviateRangeId: getDeviateRangeId(),
|
||
id: -1,
|
||
prizeId: $('#awardChoose').val(),
|
||
prizeNum: $('#jackpotNumber').val(),
|
||
occupationRatio: $('#winningRate').val() * ACCURACY,
|
||
showRatio: $('#showRate').val() * ACCURACY,
|
||
creator: $('#creator').val(),
|
||
itemType: $('#itemType').val()
|
||
}, function (res) {
|
||
if (res.code == 200) {
|
||
$('#addModal').modal('hide');
|
||
$('#tipMsg').text('添加成功');
|
||
$('#tipModal').modal('show');
|
||
TableHelper.doRefresh('#table');
|
||
} else {
|
||
$('#tipMsg').text('保存失败,' + res.message);
|
||
$('#tipModal').modal('show');
|
||
}
|
||
})
|
||
});
|
||
|
||
$('#editSave').on('click', function () {
|
||
if (parseFloat($('#winningRate2').val()) % ACCURACY >= ACCURACY || parseFloat($('#showRate2').val()) % ACCURACY >= ACCURACY) {
|
||
// 小数位超过3位则不允许设置
|
||
$('#tipMsg').text('概率最多只允许设置到小数点后3位');
|
||
$('#tipModal').modal('show');
|
||
return;
|
||
}
|
||
|
||
if (parseFloat($('#winningRate2').val()) > 100 || parseInt($('#winningRate2').val()) < 0) {
|
||
$('#tipMsg').text('中奖概率只能是0到100的数值');
|
||
$('#tipModal').modal('show');
|
||
return;
|
||
}
|
||
|
||
if (parseFloat($('#showRate2').val()) > 100 || parseInt($('#showRate2').val()) < 0) {
|
||
$('#tipMsg').text('中奖概率只能是0到100的数值');
|
||
$('#tipModal').modal('show');
|
||
return;
|
||
}
|
||
// var reg = /^[0-9]*$/;
|
||
var reg = /^[0-9]+([.]{1}[0-9]+){0,1}$/;
|
||
if (!reg.test($('#winningRate2').val()) || !reg.test($('#jackpotNumber2').val()) || !reg.test($('#showRate2').val())) {
|
||
$('#tipMsg').text('奖品个数和概率只能是数值');
|
||
$('#tipModal').modal('show');
|
||
return;
|
||
}
|
||
if ($('#creator2').val() == '' || $('#creator2').val() == 'undefined') {
|
||
$('#tipMsg').text('创建者项是必填的');
|
||
$('#tipModal').modal('show');
|
||
return;
|
||
}
|
||
var data = $('#table').bootstrapTable('getRowByUniqueId', saveId);
|
||
$.post('/admin/prizePoolItem/save', {
|
||
poolType: $('#jackpotType').val(),
|
||
id: saveId,
|
||
deviateRangeId: data.deviateRangeId,
|
||
prizeId: pId,
|
||
prizeNum: $('#jackpotNumber2').val(),
|
||
occupationRatio: $('#winningRate2').val() * ACCURACY,
|
||
showRatio: $('#showRate2').val() * ACCURACY,
|
||
creator: $('#creator2').val(),
|
||
itemType: $('#itemType2').val()
|
||
}, function (res) {
|
||
if (res.code == 200) {
|
||
// console.log(res);
|
||
$('#editModal').modal('hide');
|
||
$('#tipMsg').text('添加成功');
|
||
$('#tipModal').modal('show');
|
||
TableHelper.doRefresh('#table');
|
||
} else {
|
||
$('#tipMsg').text('保存失败,' + res.message);
|
||
$('#tipModal').modal('show');
|
||
}
|
||
});
|
||
});
|
||
|
||
// 重置按钮事件
|
||
$('#addReset').on('click', function () {
|
||
clearModal();
|
||
});
|
||
|
||
$('#editReset').on('click', function () {
|
||
var $jackpotNumber = $('#jackpotNumber2').val();
|
||
var $winningRate = $('#winningRate2').val();
|
||
var $showRate = $('#showRate2').val();
|
||
var $creator = $('#creator2').val();
|
||
clearModal();
|
||
$('#jackpotNumber2').val($jackpotNumber);
|
||
$('#winningRate2').val($winningRate);
|
||
$('#showRate2').val($showRate);
|
||
$('#creator2').val($creator);
|
||
});
|
||
|
||
// 移除按钮事件
|
||
$('#table').on('click', '.remove', function () {
|
||
var id = parseInt($(this).data('id'));
|
||
var data = $('#table').bootstrapTable('getRowByUniqueId', id);
|
||
console.log(id);
|
||
$.post('/admin/prizePoolItem/delete', {
|
||
id: id,
|
||
poolType: data.prizePoolType,
|
||
deviateRangeId: data.deviateRangeId
|
||
}, function (res) {
|
||
if (res.code == 200) {
|
||
$('#tipMsg').text('删除成功');
|
||
$('#tipModal').modal('show');
|
||
TableHelper.doRefresh('#table');
|
||
} else {
|
||
$('#tipMsg').text('删除失败,' + res.message);
|
||
$('#tipModal').modal('show');
|
||
}
|
||
})
|
||
});
|
||
});
|
||
|
||
}
|
||
},
|
||
|
||
};
|
||
|
||
function clearModal() {
|
||
$('#addForm').find('input[type=text],select,input[type=hidden]').each(function () {
|
||
$(this).val('');
|
||
});
|
||
$('#editForm').find('input[type=text],select,input[type=hidden]').each(function () {
|
||
$(this).val('');
|
||
});
|
||
}
|
||
|
||
function getDeviateRangeId() {
|
||
if ($('#deviateRange').val()) {
|
||
var jackpotType = $('#jackpotType').val();
|
||
if (jackpotType == '4') {
|
||
return parseInt($('#deviateRange').val());
|
||
} else if (jackpotType == '5') {
|
||
return parseInt($('#chargeDeviateRange').val());
|
||
} else if (jackpotType == '9') {
|
||
return parseInt($('#diamondDeviateRange').val());
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
|
||
</script>
|
||
|
||
<style scoped>
|
||
.tips {
|
||
color: red;
|
||
}
|
||
|
||
.jackpot {
|
||
margin-top: 20px;
|
||
}
|
||
|
||
.jackpot p {
|
||
display: flex;
|
||
text-align: center;
|
||
align-items: center;
|
||
}
|
||
|
||
#toolbar>div:first-child {
|
||
margin-right: 10px;
|
||
}
|
||
</style> |