509 lines
24 KiB
Vue
509 lines
24 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>
|
||
<div id="toolbar">
|
||
<div class="col-sm-12">
|
||
<button id="btnSearch" class="btn btn-default">
|
||
<i class="glyphicon glyphicon-search"></i>查询
|
||
</button>
|
||
<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">×</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="name" 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="name" id="name"
|
||
placeholder="特权名称填写">
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="description" class="col-sm-3 control-label">特权描述:</label>
|
||
<div class="col-sm-9">
|
||
<input type="text" class="form-control" name="description" id="description"
|
||
placeholder="请输入,5个字符内">
|
||
</div>
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label for="type" class="col-sm-3 control-label">特权类型<font color="red">*</font>:</label>
|
||
<div class="col-sm-9">
|
||
<select name="type" id="type" class="form-control validate[required]">
|
||
<option value="1">铭牌</option>
|
||
<option value="2">特权礼物</option>
|
||
<option value="3">入团礼物</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="form-group" id="normalIdBox">
|
||
<label for="normalId" 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="normalId" id="normalId"
|
||
placeholder="特权ID(正常)填写">
|
||
</div>
|
||
</div>
|
||
<div class="form-group" id="negativeIdBox">
|
||
<label for="negativeId" 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="negativeId" id="negativeId"
|
||
placeholder="特权ID(不活跃)填写">
|
||
</div>
|
||
</div>
|
||
<div class="form-group" id="activeIdBox">
|
||
<label for="activeId" 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="activeId" id="activeId"
|
||
placeholder="特权ID(活跃)填写">
|
||
</div>
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label for="seq" 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="seq" id="seq"
|
||
placeholder="特权ID(活跃)填写">
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="isShow" class="col-sm-3 control-label">是否展示<font color="red">*</font>:</label>
|
||
<div class="col-sm-9">
|
||
<select name="isShow" id="isShow" class="form-control validate[required]">
|
||
<!--<option value="0"></option>-->
|
||
<option value="1">是</option>
|
||
<option value="0">否</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label for="status" class="col-sm-3 control-label">状态<font color="red">*</font>:</label>
|
||
<div class="col-sm-9">
|
||
<select name="status" id="status" class="form-control validate[required]">
|
||
<!--<option value="0"></option>-->
|
||
<option value="1">有效</option>
|
||
<option value="0">无效</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<!--底部配置-->
|
||
<div class="form-group" id="imgBox">
|
||
<label class="col-sm-3 control-label">特权图标</label>
|
||
<div class="col-sm-8">
|
||
<img src="" id="iconImgUrl" style='width:108px;height:45px;' alt="">
|
||
<input type="file" id="iconFile" name='uploadFile'
|
||
accept='image/gif,image/jpeg,image/jpg,image/png,image/svg'>
|
||
<button class="btn btn-success" type='button' id="iconBtn">上传</button>
|
||
<input type="hidden" id="iconUrl" name='alertWinPic'
|
||
class="form-control validate[required]">
|
||
</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';
|
||
|
||
export default {
|
||
name: "AnchorFansPrivilegeView",
|
||
setup() {
|
||
return {};
|
||
},
|
||
created() {
|
||
this.$nextTick(function () {
|
||
this.initData();
|
||
});
|
||
},
|
||
methods: {
|
||
initData() {
|
||
$(function () {
|
||
|
||
$('.datetime').datetimepicker({
|
||
format: 'yyyy-mm-dd hh:ii:00',
|
||
autoclose: true
|
||
});
|
||
|
||
$('#table').bootstrapTable('destroy');
|
||
$('#table').bootstrapTable({
|
||
columns: [
|
||
|
||
{ field: 'id', title: '序号', align: 'center', valign: 'middle', width: '5%' },
|
||
{ field: 'name', title: '特权名称', align: 'center', valign: 'middle', width: '10%' },
|
||
{ field: 'description', title: '特权描述', align: 'center', valign: 'middle', width: '10%' },
|
||
{ field: 'normalId', title: '特权ID', align: 'center', valign: 'middle', width: '10%' },
|
||
{
|
||
field: 'icon', title: '特权图片', align: 'center', valign: 'middle', width: '10%',
|
||
formatter: function (val, row, index) {
|
||
return "<img src='" + val + "' width='60' height='50'>";
|
||
}
|
||
},
|
||
{
|
||
field: 'type', title: '特权类型', align: 'center', valign: 'middle', width: '10%',
|
||
formatter: function (val, row, index) {
|
||
if (val == 1) {
|
||
return '铭牌'
|
||
} else if (val == 2) {
|
||
return '专属礼物'
|
||
} else if (val == 3) {
|
||
return '特权礼物'
|
||
} {
|
||
return val;
|
||
}
|
||
}
|
||
},
|
||
{ field: 'seq', title: '展示排序', align: 'center', valign: 'middle', width: '5%' },
|
||
{
|
||
field: 'isShow', title: '是否展示', align: 'center', width: '5%',
|
||
formatter: function (val, row, index) {
|
||
if (val == 0) {
|
||
return '不展示'
|
||
} else if (val == 1) {
|
||
return '展示'
|
||
} else {
|
||
return '未知'
|
||
}
|
||
}
|
||
},
|
||
{
|
||
field: 'status', title: '状态', align: 'center', width: '5%',
|
||
formatter: function (val, row, index) {
|
||
if (val == 0) {
|
||
return '无效'
|
||
} else if (val == 1) {
|
||
return '有效'
|
||
} else {
|
||
return '未知'
|
||
}
|
||
}
|
||
},
|
||
{
|
||
field: 'createTime', 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: '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>' +
|
||
' <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: 10,
|
||
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/anchorFansPrivilege/privilegeList',
|
||
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();
|
||
$("#roomTagModal").modal('show');
|
||
});
|
||
|
||
$("#add").click(function () {
|
||
var id = $("#id").val();
|
||
var name = $('#name').val();
|
||
var description = $('#description').val();
|
||
var normalId = $('#normalId').val();
|
||
var activeId = $('#activeId').val();
|
||
var negativeId = $('#negativeId').val();
|
||
var type = $('#type').val();
|
||
var seq = $('#seq').val();
|
||
var status = $('#status').val();
|
||
var isShow = $('#isShow').val();
|
||
var icon = $('#iconImgUrl').attr('src');
|
||
|
||
if (type == 1 && (icon == null || icon == '')) {
|
||
$("#tipMsg").text("保存失败,请先上传图片!");
|
||
$("#tipModal").modal('show');
|
||
return;
|
||
}
|
||
|
||
if ($("#addForm").validationEngine('validate')) {
|
||
console.log(2333)
|
||
$.ajax({
|
||
type: "post",
|
||
url: "/admin/anchorFansPrivilege/savePrivilege",
|
||
data: {
|
||
id: id,
|
||
name: name,
|
||
description: description,
|
||
normalId: normalId,
|
||
activeId: activeId,
|
||
negativeId: negativeId,
|
||
type: type,
|
||
seq: seq,
|
||
status: status,
|
||
icon: icon,
|
||
isShow: isShow,
|
||
},
|
||
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();
|
||
|
||
$.ajax({
|
||
type: "get",
|
||
url: "/admin/anchorFansPrivilege/getPrivilegeInfo",
|
||
data: { id: id },
|
||
dataType: "json",
|
||
success: function (res) {
|
||
debugger
|
||
var json = res.data;
|
||
if (json) {
|
||
$("#id").val(id);
|
||
$('#name').val(json.name);
|
||
$('#description').val(json.description);
|
||
$('#normalId').val(json.normalId);
|
||
$('#activeId').val(json.activeId);
|
||
$('#negativeId').val(json.negativeId);
|
||
$('#type').val(json.type);
|
||
$('#seq').val(json.seq);
|
||
$('#status').val(json.status);
|
||
$('#isShow').val(json.isShow);
|
||
$('#iconImgUrl').attr('src', json.icon);
|
||
if (json.type == 1) {
|
||
$("#activeIdBox").show();
|
||
$("#negativeIdBox").show();
|
||
} else {
|
||
$("#activeIdBox").hide();
|
||
$("#negativeIdBox").hide();
|
||
}
|
||
|
||
// 打开编辑弹窗
|
||
$("#roomTagModal").modal('show');
|
||
$("#modalLabel").text("编辑特权");
|
||
} else {
|
||
$("#tipMsg").text("获取信息出错");
|
||
$("#tipModal").modal('show');
|
||
}
|
||
}
|
||
});
|
||
});
|
||
|
||
$("#table").on("click", '.opt-remove', function () {
|
||
var id = $(this).attr("data-id");
|
||
|
||
if (confirm("你确认删除该记录吗? \r\n 删除后再也不能找回,请谨慎操作!")) {
|
||
const requestParam = {
|
||
id: id
|
||
}
|
||
|
||
$.ajax({
|
||
type: "get",
|
||
url: "/admin/anchorFansPrivilege/delPrivilege",
|
||
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;
|
||
}
|
||
|
||
|
||
$('#iconBtn').on('click', function () {
|
||
if ($('#iconFile').val() == '') {
|
||
$('#tipMsg').text('上传图片为空');
|
||
$('#tipModal').modal('show');
|
||
return;
|
||
}
|
||
$.ajaxFileUpload({
|
||
fileElementId: 'iconFile', //需要上传的文件域的ID,即<input type="file">的ID。
|
||
url: '/admin/upload/img', //后台方法的路径
|
||
type: 'post', //当要提交自定义参数时,这个参数要设置成post
|
||
dataType: 'json', //服务器返回的数据类型。可以为xml,script,json,html。如果不填写,jQuery会自动判断。
|
||
secureuri: false, //是否启用安全提交,默认为false。
|
||
async: true, //是否是异步
|
||
success: function (json) { //提交成功后自动执行的处理函数,参数data就是服务器返回的数据。
|
||
if (json.path) {
|
||
$('#iconUrl').val(json.path);
|
||
$('#iconImgUrl').attr("src", json.path);
|
||
|
||
console.log(json.path);
|
||
|
||
} else {
|
||
$("#tipMsg").text(json.msg);
|
||
$("#tipModal").modal('show');
|
||
}
|
||
},
|
||
error: function (data, status, e) { //提交失败自动执行的处理函数。
|
||
console.error(e);
|
||
}
|
||
});
|
||
})
|
||
|
||
function clearModal() {
|
||
$('#iconImgUrl').attr('src', '');
|
||
|
||
$('#addForm').find('input[type=text],input[type=hidden],input[type=file]').each(function () {
|
||
$(this).val('');
|
||
})
|
||
|
||
$('#type').val(1);
|
||
|
||
$("#activeIdBox").show();
|
||
$("#negativeIdBox").show();
|
||
}
|
||
|
||
|
||
$("#type").change(function () {
|
||
var optVal = $(this).val();
|
||
if (optVal == 1) {
|
||
$("#activeIdBox").show();
|
||
$("#negativeIdBox").show();
|
||
} else {
|
||
$("#activeIdBox").hide();
|
||
$("#negativeIdBox").hide();
|
||
}
|
||
|
||
});
|
||
|
||
function serverError(req) {
|
||
$("#tipMsg").text(req.responseJSON.message);
|
||
$("#tipModal").modal('show');
|
||
}
|
||
});
|
||
}
|
||
},
|
||
|
||
};
|
||
</script>
|
||
|
||
<style scoped></style> |