596 lines
28 KiB
Vue
596 lines
28 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 -->
|
||
<div id="table"></div>
|
||
<div id="toolbar">
|
||
<div class="col-sm-12">
|
||
|
||
tab名称:<input type="text" name="tabName" id="name" placeholder="请输入tab名称">
|
||
|
||
平台号:
|
||
<input type="text" name="erbanNo" id="erbanNo" placeholder="请输入用户ID">
|
||
</div>
|
||
|
||
<div class="col-sm-12">
|
||
<button id="btnSearch" class="btn btn-primary">
|
||
<i class="glyphicon"></i>查询
|
||
</button>
|
||
|
||
<button id="addRoom" class="btn btn-default">
|
||
<i class="glyphicon"></i>添加房间
|
||
</button>
|
||
<!-- <button id="btnMultiDel" class="btn btn-default">
|
||
<i class="glyphicon"></i>删除选中
|
||
</button>-->
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<input type="hidden" name="id" id="id">
|
||
<input type="hidden" name="roomUid" id="roomUid">
|
||
<div class="modal fade" id="addTabRoomModal" 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="addTabRoomModalLabel">添加房间</h4>
|
||
</div>
|
||
<div class="modal-body">
|
||
<form id="addTabRoom" class="form-horizontal">
|
||
|
||
<div class="form-group">
|
||
<label for="tabName" class="col-sm-3 control-label">选择tab:</label>
|
||
<div class="col-sm-9">
|
||
<select name="tabName" id="tabName">
|
||
<option value="">-- 请选择 --</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<div class="form-group erbanNo">
|
||
<label for="erbanNo" class="col-sm-3 control-label">用户ID:</label>
|
||
<div class="col-sm-10">
|
||
<input type="text" id="uid" name="erbanNo" class="form-control validate[required]">
|
||
</div>
|
||
</div>
|
||
<!--<div class="form-group seqNo">
|
||
<label for="seqNo" class="col-sm-3 control-label">排序:</label>
|
||
<div class="col-sm-8 control-label">
|
||
<input type="text" class="form-control validate[required]" name="seqNo" id="seqNo"
|
||
placeholder="相同tab的房间排序不可重复">
|
||
</div>
|
||
</div>-->
|
||
<div class="form-group status">
|
||
<label class="col-sm-3 control-label">展示状态:</label>
|
||
<div class="col-sm-8">
|
||
<select name="status" id="status" class="col-sm-2">
|
||
<option value="1">展示</option>
|
||
<option value="0">隐藏</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<!--<div class="form-group">
|
||
<label for="roomBadge" class="col-sm-3 control-label">角标:</label>
|
||
<div class="col-sm-9">
|
||
<img src="" id="roomBadgeUrl" style="width:250px;height:90px;" alt="">
|
||
<input type="file" id="uploadRoomBadgeFile" name="uploadRoomBadgeFile"
|
||
accept="image/gif,image/jpeg,image/jpg,image/png,image/svg">
|
||
<button class="btn btn-success" type="button" id="uploadBtn">上传</button>
|
||
<input type="hidden" class="form-control validate[required]" name="roomBadge"
|
||
id="roomBadge"
|
||
style="width:400px">
|
||
</div>
|
||
</div>-->
|
||
<div class="form-group">
|
||
<label class="col-sm-3 control-label">角标:</label>
|
||
<div class="col-sm-8">
|
||
<img src="" id="addImgUrl" style="width:250px;height:90px;" alt="">
|
||
<input type="file" id="addUploadFile" name="uploadFile"
|
||
accept="image/gif,image/jpeg,image/jpg,image/png,image/svg">
|
||
<button class="btn btn-success" type="button" id="addUploadBtn">上传</button>
|
||
<input type="hidden" id="addRoomBadge" name="roomBadge"
|
||
class="form-control validate[required]" />
|
||
</div>
|
||
</div>
|
||
<!--<div class="form-group roomBadge">
|
||
<label for="roomBadge" class="col-sm-3 control-label">角标:</label>
|
||
<div class="col-sm-8 control-label">
|
||
<input type="text" class="form-control" name="roomBadge" id="roomBadge">
|
||
</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="saveRoom">保存</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="modal fade" id="editTabModal" 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="editTabModalLabel">编辑房间</h4>
|
||
</div>
|
||
<div class="modal-body">
|
||
<form id="editTab" class="form-horizontal">
|
||
<div class="form-group">
|
||
<label for="tabName" class="col-sm-3 control-label">tab名称:</label>
|
||
<span id="e_tabName"></span>
|
||
</div>
|
||
<div class="form-group seqNo">
|
||
<label for="erbanNo" class="col-sm-3 control-label">用户ID:</label>
|
||
<span id="erbanNoEdit"></span>
|
||
</div>
|
||
<!--<div class="form-group seqNo">
|
||
<label for="seqNo" class="col-sm-3 control-label">排序:</label>
|
||
<div class="col-sm-8 control-label">
|
||
<input type="text" class="form-control validate[custom[integer]]" name="seqNo" id="e_seqNo">
|
||
</div>
|
||
</div>-->
|
||
<!--<div class="form-group">
|
||
<span style="padding-left: 70px">*数字越小,房间排序越靠前,排序数字不可重复</span>
|
||
</div>-->
|
||
<div class="form-group showStatus">
|
||
<label class="col-sm-3 control-label">展示状态:</label>
|
||
<div class="col-sm-8">
|
||
<select name="status" id="roomStatus" class="col-sm-2">
|
||
<option value="1">展示</option>
|
||
<option value="0">隐藏</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label class="col-sm-3 control-label">角标:</label>
|
||
<div class="col-sm-8">
|
||
<img src="" id="imgUrl" style="width:250px;height:90px;" alt="">
|
||
<input type="file" id="uploadFile" name="uploadFile"
|
||
accept="image/gif,image/jpeg,image/jpg,image/png,image/svg">
|
||
<button class="btn btn-success" type="button" id="uploadBtn">上传</button>
|
||
<span class="attention">注意:图片尺寸750*250,选择图片后请点击上传按钮</span>
|
||
<input type="hidden" id="roomBadge" name="roomBadge"
|
||
class="form-control validate[required]" />
|
||
<a href="javascript:void(0)" id="removeBadge">下角标</a>
|
||
</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="edit">保存</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
import TableHelper from '@/utils/bootstrap-table-helper';
|
||
|
||
export default {
|
||
name: "FirstPageTabRoomView",
|
||
setup() {
|
||
return {};
|
||
},
|
||
created() {
|
||
this.$nextTick(function () {
|
||
this.initData();
|
||
});
|
||
},
|
||
methods: {
|
||
initData() {
|
||
$(function () {
|
||
getTitles();
|
||
function getTitles() {
|
||
$.get('/admin/firstpagetab/getTabNameList', {}, function (res) {
|
||
if (res.rows.length > 0) {
|
||
renderSelect(res.rows);
|
||
}
|
||
})
|
||
}
|
||
|
||
function renderSelect(data) {
|
||
var $select = $('#tabName');
|
||
for (var i = 0; i < data.length; i++) {
|
||
var $option = $('<option value="' + data[i].tabId + '" />');
|
||
$option.html(data[i].name);
|
||
$select.append($option);
|
||
}
|
||
}
|
||
|
||
$('#table').bootstrapTable('destroy');
|
||
$('#table').bootstrapTable({
|
||
cache: false,
|
||
striped: true,
|
||
showRefresh: false,
|
||
pageSize: 10,
|
||
pagination: true,
|
||
pageList: [10, 20, 30, 50],
|
||
sidePagination: "server", //表示服务端请求
|
||
//设置为undefined可以获取pageNumber,pageSize,searchText,sortName,sortOrder
|
||
//设置为limit可以获取limit, offset, search, sort, order
|
||
queryParamsType: "undefined",
|
||
queryParams: function queryParams(params) { //设置查询参数
|
||
var param = {
|
||
pageSize: params.pageSize,
|
||
pageNumber: params.pageNumber,
|
||
tabName: $('#name').val(),
|
||
erbanNo: $('#erbanNo').val()
|
||
};
|
||
return param;
|
||
},
|
||
uniqueId: 'id',
|
||
toolbar: '#toolbar',
|
||
url: '/admin/firstpagetabroom/list.action',
|
||
onLoadSuccess: function () { //加载成功时执行
|
||
console.log("load success");
|
||
},
|
||
onLoadError: function () { //加载失败时执行
|
||
console.log("load fail");
|
||
},
|
||
columns: [
|
||
{ field: 'id', title: '序号', align: 'center', valign: 'middle', width: '1%', visible: false },
|
||
{ field: 'tabId', title: '', align: 'center', valign: 'middle', width: '1%', visible: false },
|
||
{ field: 'tabName', title: 'tab名称', align: 'center', valign: 'middle', width: '10%' },
|
||
{ field: 'erbanNo', title: '平台号', align: 'center', valign: 'middle', width: '5%' },
|
||
{ field: 'roomTitle', title: '房间标题', align: 'center', valign: 'middle', width: '15%' },
|
||
{
|
||
field: 'status',
|
||
title: '状态',
|
||
align: 'center',
|
||
width: '5%',
|
||
valign: 'middle',
|
||
formatter: function (val, row, index) {
|
||
console.log(val);
|
||
switch (val) {
|
||
case 1:
|
||
return '展示';
|
||
|
||
case 0:
|
||
return '隐藏';
|
||
|
||
}
|
||
}
|
||
},
|
||
//{field: 'seqNo', title: '排序', align: 'center', valign: 'middle', width: '5%'},
|
||
//{field: 'roomBadge', title: '角标', align: 'center', valign: 'middle', width: '10%'},
|
||
{
|
||
field: 'roomBadge',
|
||
title: '角标',
|
||
align: 'center',
|
||
width: '5%',
|
||
formatter: function (val, row, index) {
|
||
if (val == null || val == '') {
|
||
return '-';
|
||
}
|
||
return "<img src='" + val + "' width='60' height='50'>";
|
||
}
|
||
},
|
||
{
|
||
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: 'tmp',
|
||
title: '操作',
|
||
align: 'center',
|
||
width: '12%',
|
||
valign: 'middle',
|
||
formatter: function (val, row, index) {
|
||
var key = row.id;
|
||
var status = row.status;
|
||
|
||
var str;
|
||
str = "<button class='btn btn-sm btn-success opt-edit' style='margin-right: 4px;' data-id=" + key + ">编辑</button>";
|
||
str += "<button class='btn btn-sm btn-danger opt-del' data-id=" + key + ">删除</button>";
|
||
|
||
return str;
|
||
}
|
||
}
|
||
|
||
]
|
||
})
|
||
|
||
var picker1 = $('#startTime').datetimepicker({
|
||
format: 'yyyy-mm-dd hh:ii:00',
|
||
autoclose: true
|
||
})
|
||
var picker2 = $("#endTime").datetimepicker({
|
||
format: 'yyyy-mm-dd hh:ii:00',
|
||
autoclose: true
|
||
});
|
||
|
||
$('#table').on('click', '.opt-del', function () {
|
||
var id = $(this).attr("data-id");
|
||
if (id == 'undefined') {
|
||
$("#tipMsg").text("id参数有误");
|
||
$("#tipModal").modal('show');
|
||
return;
|
||
}
|
||
if (confirm("你确认删除吗?")) {
|
||
$.ajax({
|
||
type: 'post',
|
||
url: '/admin/firstpagetabroom/delete.action',
|
||
data: { 'id': id },
|
||
dataType: 'json',
|
||
success: function (json) {
|
||
if (json.success == 'true') {
|
||
$("#tipMsg").text("删除成功");
|
||
$("#tipModal").modal('show');
|
||
TableHelper.doRefresh("#table");
|
||
} else {
|
||
$("#tipMsg").text("删除失败,错误码:" + json.msg);
|
||
$("#tipModal").modal('show');
|
||
}
|
||
}
|
||
});
|
||
}
|
||
});
|
||
$('#table').on('click', '.opt-edit', function () {
|
||
var id = $(this).data('id');
|
||
if (id == 'undefined' || !id) {
|
||
return;
|
||
}
|
||
var data = $('#table').bootstrapTable('getRowByUniqueId', id);
|
||
console.log(data);
|
||
$('#id').val(id);
|
||
$('#e_tabName').html(data.tabName);
|
||
$('#erbanNoEdit').html(data.erbanNo);
|
||
$("#roomStatus").val(data.status == true ? 1 : 0);
|
||
//$("#e_seqNo").val(data.seqNo);
|
||
$("#roomUid").val(data.roomUid);
|
||
$('#imgUrl').attr('src', data.roomBadge);
|
||
$("#roomBadge").val(data.roomBadge);
|
||
$('#editTabModal').modal('show');
|
||
})
|
||
|
||
/*$('#table').on('click', '.opt-show', function () {
|
||
var id = $(this).data('id');
|
||
if (id == 'undefined' || !id) {
|
||
return;
|
||
}
|
||
var data = $('#table').bootstrapTable('getRowByUniqueId', id);
|
||
|
||
var status = (data.status == false) ? 1 : 0;
|
||
$.ajax({
|
||
type: 'post',
|
||
url: '/admin/firstpagetabroom/changeRoomStatus.action',
|
||
data: {
|
||
status: status,
|
||
id: id
|
||
},
|
||
dataType: 'json',
|
||
success: function (res) {
|
||
if (res.code == 200) {
|
||
$("#tipMsg").text("修改状态成功");
|
||
$("#tipModal").modal('show');
|
||
TableHelper.doRefresh("#table");
|
||
} else {
|
||
$("#tipMsg").text("修改失败,错误码:" + res.code);
|
||
$("#tipModal").modal('show');
|
||
}
|
||
}
|
||
})
|
||
})*/
|
||
|
||
function cleanModal(obj) {
|
||
$('#addTabRoom').find('input[type=text],input[type=hidden],input[type=file]').each(function () {
|
||
$(this).val('');
|
||
})
|
||
$('#addTabRoom').find('img').attr('src', '');
|
||
//清空输入框
|
||
obj.find('input:text').val('');
|
||
//清空隐藏域
|
||
obj.find('input:hidden').val('');
|
||
//清空单选按钮
|
||
obj.find('input:radio').attr("checked", false);
|
||
//清空文本域
|
||
obj.find('textarea').val('');
|
||
//清空图片
|
||
obj.find('img').attr("src", "");
|
||
//清空select
|
||
obj.find('select').val("");
|
||
}
|
||
|
||
$('#edit').on('click', function () {
|
||
if ($('#editTab').validationEngine('validate')) {
|
||
$.ajax({
|
||
type: 'post',
|
||
url: '/admin/firstpagetabroom/update.action',
|
||
dataType: 'json',
|
||
data: {
|
||
id: $('#id').val(),
|
||
//seqNo: $('#e_seqNo').val(),
|
||
status: $('#roomStatus').val(),
|
||
roomBadge: $('#roomBadge').val(),
|
||
roomUid: $('#roomUid').val()
|
||
},
|
||
success: function (res) {
|
||
if (res.success == 'true') {
|
||
$("#editTabModal").modal('hide');
|
||
$("#tipMsg").text("编辑成功");
|
||
$("#tipModal").modal('show');
|
||
//$('.seqNo').show();
|
||
$(".showStatus").show();
|
||
$(".roomBadge").show();
|
||
TableHelper.doRefresh("#table");
|
||
} else {
|
||
$("#tipMsg").text("编辑失败,错误码:" + res.code);
|
||
$("#tipModal").modal('show');
|
||
}
|
||
}
|
||
})
|
||
}
|
||
})
|
||
|
||
$("#addRoom").on('click', function () {
|
||
cleanModal($("addTabRoom"));
|
||
$('#addTabRoomModal').modal('show');
|
||
})
|
||
|
||
$('#saveRoom').on('click', function () {
|
||
if ($('#addTabRoom').validationEngine('validate')) {
|
||
$.ajax({
|
||
type: "post",
|
||
url: "/admin/firstpagetabroom/add.action?tabId=" + $('#tabName').val()
|
||
+ "&tabName=" + $("#tabName").find("option:selected").text(),
|
||
dataType: 'json',
|
||
data: $('#addTabRoom').serialize(),
|
||
success: function (json) {
|
||
if (json.success == 'true') {
|
||
$("#addTabRoomModal").modal('hide');
|
||
$("#tipMsg").text(json.msg);
|
||
$("#tipModal").modal('show');
|
||
TableHelper.doRefresh("#table");
|
||
} else {
|
||
$("#tipMsg").text("保存失败,错误:" + json.msg);
|
||
$("#tipModal").modal('show');
|
||
}
|
||
}
|
||
})
|
||
}
|
||
});
|
||
|
||
$('#addUploadBtn').on('click', function () {
|
||
var options = {
|
||
type: 'post',
|
||
url: '/admin/firstpagebanner/headimg.action',
|
||
dataType: 'json',
|
||
success: function (json) {
|
||
if (json.path) {
|
||
$('#addRoomBadge').val(json.path);
|
||
$('#addImgUrl').attr('src', json.path);
|
||
console.log(json.path);
|
||
} else {
|
||
$('#tipMsg').text(json.msg);
|
||
$('#tipModal').modal('show');
|
||
}
|
||
}
|
||
}
|
||
$('#addTabRoom').ajaxSubmit(options);
|
||
});
|
||
$('#uploadBtn').on('click', function () {
|
||
var options = {
|
||
type: 'post',
|
||
url: '/admin/firstpagebanner/headimg.action',
|
||
dataType: 'json',
|
||
success: function (json) {
|
||
if (json.path) {
|
||
$('#roomBadge').val(json.path);
|
||
$('#imgUrl').attr("src", json.path);
|
||
console.log(json.path);
|
||
} else {
|
||
$("#tipMsg").text(json.msg);
|
||
$("#tipModal").modal('show');
|
||
}
|
||
}
|
||
};
|
||
$("#editTab").ajaxSubmit(options);
|
||
});
|
||
// 查询刷新
|
||
$('#btnSearch').on('click', function () {
|
||
TableHelper.doRefresh('#table');
|
||
});
|
||
$('#removeBadge').on('click', function () {
|
||
$('#imgUrl').attr('src', '');
|
||
$('#uploadFile').val('');
|
||
$('#roomBadge').val('');
|
||
});
|
||
|
||
$('#btnMultiDel').on('click', function () {
|
||
var rows = $("#table").bootstrapTable("getSelections");
|
||
if (rows.length == 0) {
|
||
alert("请先选择要删除的记录");
|
||
return;
|
||
}
|
||
|
||
console.log("rows: " + rows.length);
|
||
var idArr = [];
|
||
var moduleIdArr = null;
|
||
var uidArr = [];
|
||
|
||
for (var i = 0; i < rows.length; i++) {
|
||
idArr.push(rows[i]['id']);
|
||
if (moduleIdArr == null) {
|
||
moduleIdArr = rows[i]['moduleId'] + "#" + rows[i]['uid'];
|
||
} else {
|
||
moduleIdArr += "," + rows[i]['moduleId'] + "#" + rows[i]['uid'];
|
||
}
|
||
uidArr.push(rows[i]['uid']);
|
||
}
|
||
console.log(idArr);
|
||
|
||
if (confirm("你确认删除选中房间吗?")) {
|
||
$.ajax({
|
||
type: 'post',
|
||
url: "/admin/firstpagetabroom/delete.action",
|
||
data: {
|
||
'ids': JSON.stringify(idArr),
|
||
'moduleIds': moduleIdArr,
|
||
'uids': JSON.stringify(uidArr)
|
||
},
|
||
dataType: "json",
|
||
success: function (json) {
|
||
if (json.code == 200) {
|
||
$("#tipMsg").text("已删除选中房间");
|
||
$("#tipModal").modal('show');
|
||
TableHelper.doRefresh("#table");
|
||
} else {
|
||
$("#tipMsg").text("操作失败");
|
||
$("#tipModal").modal('show');
|
||
}
|
||
}
|
||
});
|
||
}
|
||
});
|
||
});
|
||
}
|
||
},
|
||
unmounted() {
|
||
$('#table').bootstrapTable('destroy');
|
||
}
|
||
};
|
||
</script>
|
||
|
||
<style scoped>
|
||
.col-sm-1 {
|
||
width: 15.333333%;
|
||
}
|
||
|
||
.col-sm-2 {
|
||
width: 34.666667%;
|
||
}
|
||
|
||
.col-sm-10 {
|
||
width: 73.333333%;
|
||
}
|
||
|
||
#removeBadge {
|
||
margin-left: 10px;
|
||
}
|
||
</style> |