494 lines
22 KiB
Vue
494 lines
22 KiB
Vue
<template>
|
||
<section class="content">
|
||
<div class="box box-primary">
|
||
<div class="box-body">
|
||
<!-- Content Header (Page header) -->
|
||
<section class="content-header">
|
||
<div id="itemTitle"></div>
|
||
</section>
|
||
<!-- .content -->
|
||
<section>
|
||
<div id="table"></div>
|
||
</section>
|
||
<div id="toolbar">
|
||
<div class="col-sm-12">
|
||
<button id="btnAdd" class="btn btn-default">
|
||
<i class="glyphicon glyphicon-plus-sign"></i>添加
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<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">×</span>
|
||
</button>
|
||
<h4 class="modal-title" id="modalLabel">添加</h4>
|
||
</div>
|
||
<div class="modal-body">
|
||
<form class="form-horizontal">
|
||
<input type="hidden" name="id" id="id" />
|
||
<input type="hidden" name="rewardId" id="rewardId" />
|
||
<input type="hidden" name="propIds" id="propIds" />
|
||
<input type="hidden" name="propNums" id="propNums" />
|
||
<div class="form-group">
|
||
<label for="type" class="col-sm-3 control-label">兑换类型:</label>
|
||
<div class="col-sm-9">
|
||
<select name="type" id="type" class="form-control validate[required]" oninput="switchElf()">
|
||
<option value="1">精灵召唤</option>
|
||
<option value="2">碎片召唤</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="rewardType" class="col-sm-3 control-label">装饰类型:</label>
|
||
<div class="col-sm-9">
|
||
<select name="rewardType" id="rewardType" class="form-control" oninput="getReward()">
|
||
<option value="">无</option>
|
||
<option value="activityProps">活动道具</option>
|
||
<option value="gift">礼物</option>
|
||
<option value="namePlate">铭牌</option>
|
||
<option value="car">座驾</option>
|
||
<option value="headwear">头饰</option>
|
||
<option value="chatBubble">气泡</option>
|
||
<option value="infoCard">资料卡</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="seq" class="col-sm-3 control-label">前端排序:</label>
|
||
<div class="col-sm-9">
|
||
<input type="text" class="form-control" id="seq">
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="rewardName" class="col-sm-3 control-label">装饰ID:</label>
|
||
<div class="col-sm-9" id="rewardDiv">
|
||
<input type="text" class="form-control" id="rewardName">
|
||
</div>
|
||
</div>
|
||
<div class="form-group" id="expendNumDiv">
|
||
<label for="expendNum" class="col-sm-3 control-label">消耗碎片数:</label>
|
||
<div class="col-sm-9">
|
||
<input type="text" class="form-control" id="expendNum">
|
||
</div>
|
||
</div>
|
||
<div class="form-group" id="effectDayDiv">
|
||
<label for="effectDay" class="col-sm-3 control-label">有效期(天):</label>
|
||
<div class="col-sm-9">
|
||
<input type="text" class="form-control" id="effectDay">
|
||
</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 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';
|
||
|
||
export default {
|
||
name: "SeizeTreasureConvertItemView",
|
||
setup() {
|
||
function getReward() {
|
||
var rewardId = $('#rewardId').val();
|
||
var rewardType = $('#rewardType').val();
|
||
if (rewardType == 'activityProps' || rewardType == 'gift') {
|
||
$('#effectDayDiv').hide();
|
||
} else {
|
||
$('#effectDayDiv').show();
|
||
}
|
||
var options = [];
|
||
$.ajax({
|
||
type: "get",
|
||
url: "/admin/seize-treasure/reward/list?rewardType=" + rewardType,
|
||
dataType: "json",
|
||
async: false,
|
||
success: function (json) {
|
||
if (json.success == 'true' || json.code == 200) {
|
||
var data = json.data;
|
||
for (var i = 0, len = data.length; i < len; i++) {
|
||
var reward = data[i];
|
||
options[i] = {
|
||
value: reward.id,
|
||
text: reward.rewardName
|
||
};
|
||
}
|
||
}
|
||
}
|
||
});
|
||
$('#rewardName').remove();
|
||
if (options.length > 0) {
|
||
var $div = $('#rewardDiv');
|
||
var $select = $('<select/>');
|
||
$select.attr('class', 'form-control validate[required]');
|
||
$select.attr('id', 'rewardName');
|
||
for (let i = 0, len = options.length; i < len; i++) {
|
||
var option = options[i];
|
||
var $option = $('<option/>');
|
||
$option.attr('value', option.value);
|
||
$option.attr('data-id', option.value);
|
||
$option.attr('data-name', option.text);
|
||
if (rewardId && rewardId == option.value) {
|
||
$option.attr('selected', true);
|
||
}
|
||
$option.html(option.text);
|
||
$select.append($option);
|
||
}
|
||
$div.append($select);
|
||
}
|
||
}
|
||
|
||
function switchElf() {
|
||
var type = $('#type').val();
|
||
if (type == 1) {
|
||
$('#expendNumDiv').hide();
|
||
} else if (type == 2) {
|
||
$('#expendNumDiv').show();
|
||
}
|
||
var propIds = $('#propIds').val().split(',');
|
||
var propNums = $('#propNums').val().split(',');
|
||
var options = [];
|
||
$.ajax({
|
||
type: "get",
|
||
url: "/admin/seize-treasure/prop/list?type=3&level=3",
|
||
dataType: "json",
|
||
async: false,
|
||
success: function (json) {
|
||
if (json.success == 'true' || json.code == 200) {
|
||
var data = json.data;
|
||
for (var i = 0, len = data.length; i < len; i++) {
|
||
var prop = data[i];
|
||
options[i] = {
|
||
value: prop.id,
|
||
text: prop.name
|
||
};
|
||
}
|
||
}
|
||
}
|
||
});
|
||
if (options.length == 0) {
|
||
return;
|
||
}
|
||
if (!type || type == 2) {
|
||
for (let i = 0; i < options.length; i++) {
|
||
$('#elf' + i).remove();
|
||
}
|
||
return;
|
||
}
|
||
var $form = $('#editModal .modal-body .form-horizontal');
|
||
for (let i = 0; i < options.length; i++) {
|
||
var propId = propIds[i];
|
||
var propNum = propNums[i];
|
||
var $formGroup = $('<div/>');
|
||
$formGroup.attr('class', 'form-group');
|
||
$formGroup.attr('id', 'elf' + i);
|
||
var $label = $('<label/>');
|
||
$label.attr('class', 'col-sm-3 control-label');
|
||
$label.html('消耗精灵' + (i + 1) + ':');
|
||
$formGroup.append($label);
|
||
var $div = $('<div/>');
|
||
$div.attr('class', 'col-sm-9');
|
||
var $select = $('<select/>');
|
||
$select.attr('class', 'form-control validate[required]');
|
||
$select.attr('id', 'elfId' + i);
|
||
for (let j = 0; j < options.length; j++) {
|
||
var option = options[j];
|
||
var $option = $('<option/>');
|
||
$option.attr('value', option.value);
|
||
$option.html(option.text);
|
||
if (propId && propId == option.value) {
|
||
$option.attr('selected', true);
|
||
}
|
||
$select.append($option);
|
||
$div.append($select);
|
||
}
|
||
var $input = $('<input/>');
|
||
$input.attr('type', 'text');
|
||
$input.attr('name', 'elfNum' + i);
|
||
$input.attr('class', 'form-control');
|
||
$input.attr('id', 'elfNum' + i);
|
||
if (propNum) {
|
||
$input.attr('value', propNum);
|
||
}
|
||
$div.append($input);
|
||
$formGroup.append($div);
|
||
$form.append($formGroup);
|
||
}
|
||
}
|
||
window.getReward = getReward;
|
||
window.switchElf = switchElf;
|
||
return {
|
||
getReward,
|
||
switchElf
|
||
};
|
||
},
|
||
created() {
|
||
this.$nextTick(function () {
|
||
this.initData();
|
||
});
|
||
},
|
||
methods: {
|
||
initData() {
|
||
$(function () {
|
||
var elfArray = getElf();
|
||
$('#table').bootstrapTable('destroy');
|
||
$('#table').bootstrapTable({
|
||
columns: [
|
||
{ field: 'seq', title: '前端排序', align: 'center', width: '5%' },
|
||
{
|
||
field: 'type',
|
||
title: '兑换类型',
|
||
align: 'center',
|
||
width: '5%',
|
||
formatter: function (val, row, index) {
|
||
var value = '';
|
||
if (val == 1) {
|
||
value = '精灵召唤';
|
||
} else if (val == 2) {
|
||
value = '碎片召唤';
|
||
}
|
||
return value;
|
||
}
|
||
},
|
||
{
|
||
field: 'rewardType',
|
||
title: '类型',
|
||
align: 'center',
|
||
width: '5%',
|
||
formatter: function (val, row, index) {
|
||
var value = '';
|
||
if (val == 'activityProps') {
|
||
value = '活动道具';
|
||
} else if (val == 'gift') {
|
||
value = '礼物';
|
||
} else if (val == 'namePlate') {
|
||
value = '铭牌';
|
||
} else if (val == 'car') {
|
||
value = '座驾';
|
||
} else if (val == 'headwear') {
|
||
value = '头饰';
|
||
} else if (val == 'chatBubble') {
|
||
value = '气泡';
|
||
} else if (val == 'infoCard') {
|
||
value = '资料卡';
|
||
} else {
|
||
value = '-';
|
||
}
|
||
return value;
|
||
}
|
||
},
|
||
{ field: 'rewardRefId', title: 'ID', align: 'center', width: '5%' },
|
||
{ field: 'rewardName', title: '名称', align: 'center', width: '5%' },
|
||
{
|
||
field: 'effectDay',
|
||
title: '有效期',
|
||
align: 'center',
|
||
width: '5%',
|
||
formatter: function (val, row, index) {
|
||
var value = '';
|
||
if (val) {
|
||
value = val + '天';
|
||
} else {
|
||
value = '-';
|
||
}
|
||
return value;
|
||
}
|
||
},
|
||
{ field: 'expendNum', title: '消耗碎片数', align: 'center', width: '5%' },
|
||
{ field: 'rewardValue', title: '单价(钻)', align: 'center', width: '5%' },
|
||
{
|
||
field: 'id',
|
||
title: '操作',
|
||
align: 'center',
|
||
width: '5%',
|
||
valign: 'middle',
|
||
formatter: function (val, row, index) {
|
||
return '<button class="btn btn-sm btn-success opt-edit" data-index="' + index + '">编辑</button>';
|
||
}
|
||
}
|
||
],
|
||
cache: false,
|
||
striped: true,
|
||
showRefresh: false,
|
||
pageSize: 20,
|
||
pagination: true,
|
||
pageList: [20, 50, 100],
|
||
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/seize-treasure/convert/item/page',
|
||
onLoadSuccess: function () { //加载成功时执行
|
||
console.log("load success");
|
||
},
|
||
onLoadError: function () { //加载失败时执行
|
||
console.log("load fail");
|
||
}
|
||
});
|
||
|
||
$('#btnAdd').on('click', function () {
|
||
for (let i = 0, len = elfArray.length; i < len; i++) {
|
||
$('#elf' + i).remove();
|
||
}
|
||
$("#id").val('');
|
||
$("#rewardId").val('');
|
||
$("#type").val('');
|
||
$("#seq").val('');
|
||
$("#rewardType").val('');
|
||
$("#rewardName").val('');
|
||
$('#expendNum').val('');
|
||
$("#effectDay").val('');
|
||
$("#propIds").val('');
|
||
$("#propNums").val('');
|
||
$("#editModal").modal('show');
|
||
});
|
||
|
||
$('#table').on('click', '.opt-edit', function () {
|
||
for (let i = 0, len = elfArray.length; i < len; i++) {
|
||
$('#elf' + i).remove();
|
||
}
|
||
const currentData = $('#table').bootstrapTable('getData')[$(this).data('index')];
|
||
var id = currentData.id;
|
||
var rewardId = currentData.rewardId;
|
||
var type = currentData.type;
|
||
var seq = currentData.seq;
|
||
var rewardType = currentData.rewardType;
|
||
var rewardName = currentData.rewardName;
|
||
var expendNum = currentData.expendNum
|
||
var effectDay = currentData.effectDay;
|
||
var propIds = currentData.propIds;
|
||
var propNums = currentData.propNums;
|
||
$("#id").val(id);
|
||
$("#rewardId").val(rewardId);
|
||
$("#type").val(type);
|
||
$("#seq").val(seq);
|
||
$("#rewardType").val(rewardType);
|
||
$('#rewardName').val(rewardName);
|
||
$("#expendNum").val(expendNum);
|
||
$("#effectDay").val(effectDay);
|
||
$("#propIds").val(propIds);
|
||
$("#propNums").val(propNums);
|
||
window.getReward();
|
||
$("#editModal").modal('show');
|
||
});
|
||
|
||
$("#save").click(function () {
|
||
const msg = '确定要保存吗?';
|
||
if (confirm(msg)) {
|
||
var id = $("#id").val();
|
||
var type = $('#type').val();
|
||
var seq = $('#seq').val();
|
||
var rewardType = $("#rewardType").val();
|
||
var rewardId = $("#rewardName").attr('data-id');
|
||
var rewardName = $("#rewardName").attr('data-name');
|
||
var expendNum = $("#expendNum").val();
|
||
var effectDay = $("#effectDay").val();
|
||
var propIds = [];
|
||
var propNums = [];
|
||
for (let i = 0, len = elfArray.length; i < len; i++) {
|
||
var propId = $('#elfId' + i).val();
|
||
var propNum = $('#elfNum' + i).val();
|
||
if (propId && propNum) {
|
||
propIds[i] = propId;
|
||
propNums[i] = propNum;
|
||
} else {
|
||
propIds[i] = 0;
|
||
propNums[i] = 0;
|
||
}
|
||
}
|
||
var data = {
|
||
type: type,
|
||
seq: seq,
|
||
rewardType: rewardType,
|
||
rewardId: rewardId,
|
||
rewardName: rewardName,
|
||
expendNum: expendNum,
|
||
effectDay: effectDay,
|
||
propIdsJson: JSON.stringify(propIds),
|
||
propNumsJson: JSON.stringify(propNums),
|
||
};
|
||
if (id) {
|
||
data.id = id;
|
||
}
|
||
$.ajax({
|
||
type: "post",
|
||
url: "/admin/seize-treasure/convert/item/save",
|
||
data: data,
|
||
dataType: "json",
|
||
success: function (json) {
|
||
if (json.success == 'true' || json.code == 200) {
|
||
$("#tipMsg").text("保存成功");
|
||
$("#tipModal").modal('show');
|
||
TableHelper.doRefresh("#table");
|
||
$("#editModal").modal('hide');
|
||
} else {
|
||
$("#tipMsg").text("保存失败." + json.message);
|
||
$("#tipModal").modal('show');
|
||
$("#editModal").modal('hide');
|
||
}
|
||
}
|
||
});
|
||
}
|
||
});
|
||
});
|
||
}
|
||
},
|
||
};
|
||
|
||
function getElf() {
|
||
var options = [];
|
||
$.ajax({
|
||
type: "get",
|
||
url: "/admin/seize-treasure/prop/list?type=3&level=3",
|
||
dataType: "json",
|
||
async: false,
|
||
success: function (json) {
|
||
if (json.success == 'true' || json.code == 200) {
|
||
var data = json.data;
|
||
for (var i = 0, len = data.length; i < len; i++) {
|
||
var prop = data[i];
|
||
options[i] = {
|
||
value: prop.id,
|
||
text: prop.name
|
||
};
|
||
}
|
||
}
|
||
}
|
||
});
|
||
return options;
|
||
}
|
||
</script>
|
||
|
||
<style scoped></style> |