367 lines
17 KiB
Vue
367 lines
17 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">
|
||
<!-- <button id="addBtn" class="btn btn-default">
|
||
<i class="glyphicon glyphicon-plus"></i>增加
|
||
</button> -->
|
||
tab名称: <input type="text" id='seachName'>
|
||
|
||
状态: <select name="status" id="seachStatus" class="input-m">
|
||
<option value="">--全部--</option>
|
||
<option value="1">展示</option>
|
||
<option value="2">隐藏</option>
|
||
</select>
|
||
<button id="btnSearch" class="btn btn-sm btn-primary">查询</button>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
</section>
|
||
<div class="modal fade" id="actModal" 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 class="form-horizontal" id="actForm">
|
||
<input type="hidden" name="id" id="id" value="0">
|
||
<div class="form-group">
|
||
<div class="form-group">
|
||
<label for="name" class="col-sm-3 control-label">名称:</label>
|
||
<div class="col-sm-9">
|
||
<input type="text" class="form-control validate[required]" name="name" id="name"
|
||
style="width:400px">
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="status" class="col-sm-3 control-label">状态:</label>
|
||
<select name="status" id="status" class="col-sm-2">
|
||
<option value="1">展示</option>
|
||
<option value="2">隐藏</option>
|
||
</select>
|
||
</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="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 class="form-horizontal" id="editForm">
|
||
<input type="hidden" name="id" id="e_id">
|
||
<div class="form-group">
|
||
<label for="name" class="col-sm-3 control-label">名称:</label>
|
||
<div class="col-sm-9">
|
||
<input type="text" class="form-control validate[required]" name="name" id="e_name"
|
||
style="width:400px">
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="status" class="col-sm-3 control-label">状态:</label>
|
||
<select name="status" id="e_status" class="col-sm-2">
|
||
<option value="1">展示</option>
|
||
<option value="2">隐藏</option>
|
||
</select>
|
||
</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>
|
||
<div class="modal fade" id="sureModal" tabindex="-1" role="dialog" aria-labelledby="modalLabel">
|
||
<div class="modal-dialog" role="document">
|
||
<div class="modal-content">
|
||
<div class="modal-footer">
|
||
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
|
||
<button type="button" class="btn btn-primary" id="sure">确定</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
import TableHelper from '@/utils/bootstrap-table-helper';
|
||
|
||
export default {
|
||
name: "FirstPageOptView",
|
||
setup() {
|
||
return {};
|
||
},
|
||
created() {
|
||
this.$nextTick(function () {
|
||
this.initData();
|
||
});
|
||
},
|
||
methods: {
|
||
initData() {
|
||
$(function () {
|
||
$('#table').bootstrapTable('destroy');
|
||
initTable();
|
||
// 查询刷新
|
||
$('#btnSearch').on('click', function () {
|
||
$('#table').bootstrapTable('destroy');
|
||
initTable();
|
||
});
|
||
|
||
$('#addBtn').on('click', function () {
|
||
cleanModal();
|
||
$("#actForm")[0].reset();
|
||
$('#actModal').modal('show');
|
||
});
|
||
$('#table').on('click', '.opt-edit', function () {
|
||
var id = $(this).attr("data-id-1");
|
||
var name = $(this).attr("data-id-2");
|
||
var status = $(this).attr("data-id-3");
|
||
cleanModal();
|
||
|
||
$('#e_id').val(id);
|
||
$('#e_name').val(name);
|
||
$('#e_status').val(status);
|
||
$('#editModal').modal('show');
|
||
});
|
||
$('#save').on('click', function () {
|
||
if ($('#actForm').validationEngine('validate')) {
|
||
$.ajax({
|
||
type: "post",
|
||
url: "/admin/firstpageopt/add.action",
|
||
data: $('#actForm').serialize(),
|
||
dataType: 'json',
|
||
success: function (json) {
|
||
if (json.success == 'true') {
|
||
$("#actModal").modal('hide');
|
||
$("#tipMsg").text(json.msg);
|
||
$("#tipModal").modal('show');
|
||
TableHelper.doRefresh("#table");
|
||
} else {
|
||
$("#tipMsg").text("保存失败,错误码:" + json.message);
|
||
$("#tipModal").modal('show');
|
||
}
|
||
}
|
||
})
|
||
}
|
||
});
|
||
$('#edit').on('click', function () {
|
||
if ($('#editForm').validationEngine('validate')) {
|
||
$.ajax({
|
||
type: "post",
|
||
url: "/admin/firstpageopt/update.action",
|
||
data: $('#editForm').serialize(),
|
||
dataType: 'json',
|
||
success: function (json) {
|
||
if (json.success == 'true') {
|
||
$("#editModal").modal('hide');
|
||
$("#tipMsg").text(json.msg);
|
||
$("#tipModal").modal('show');
|
||
TableHelper.doRefresh("#table");
|
||
} else {
|
||
$("#tipMsg").text("修改失败,错误码:" + json.message);
|
||
$("#tipModal").modal('show');
|
||
}
|
||
}
|
||
})
|
||
}
|
||
});
|
||
$("#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/firstpageopt/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.message);
|
||
$("#tipModal").modal('show');
|
||
}
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
function cleanModal() {
|
||
$('#actForm').find('input[type=text],input[type=hidden],input[type=file]').each(function () {
|
||
$(this).val('');
|
||
})
|
||
$('#actForm').find('img').attr('src', '');
|
||
}
|
||
function initTable() {
|
||
$('#table').bootstrapTable({
|
||
columns: [
|
||
{ field: 'id', title: '序号', align: 'center', valign: 'middle', width: '5%' },
|
||
{ field: 'name', title: '名称', align: 'center', valign: 'middle', width: '5%' },
|
||
{
|
||
field: 'status',
|
||
title: '状态',
|
||
align: 'center',
|
||
width: '5%',
|
||
valign: 'middle',
|
||
formatter: function (val, row, index) {
|
||
console.log(val);
|
||
switch (val) {
|
||
case 1:
|
||
return '展示';
|
||
|
||
case 2:
|
||
return '隐藏';
|
||
|
||
}
|
||
}
|
||
},
|
||
{
|
||
field: 'type',
|
||
title: '类型',
|
||
align: 'center',
|
||
width: '5%',
|
||
valign: 'middle',
|
||
formatter: function (val, row, index) {
|
||
console.log(val);
|
||
switch (val) {
|
||
case 1:
|
||
return '男';
|
||
|
||
case 2:
|
||
return '女';
|
||
|
||
case 3:
|
||
return '不限';
|
||
|
||
}
|
||
}
|
||
},
|
||
{
|
||
field: 'updateTime',
|
||
title: '更新时间',
|
||
align: 'center',
|
||
width: '10%',
|
||
valign: 'middle',
|
||
formatter: function (val, row, index) {
|
||
if (val) {
|
||
var date = new Date(val);
|
||
return date.format("yyyy-MM-dd hh:mm:ss");
|
||
} else {
|
||
return '-';
|
||
}
|
||
}
|
||
},
|
||
{
|
||
field: 'createTime',
|
||
title: '创建时间',
|
||
align: 'center',
|
||
width: '10%',
|
||
valign: 'middle',
|
||
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: '10%',
|
||
valign: 'middle',
|
||
formatter: function (val, row, index) {
|
||
var id = row.id;
|
||
var name = row.name;
|
||
var status = row.status;
|
||
return '<button class="btn btn-sm btn-success opt-edit" data-id-1 ="' + id + ' "data-id-2="' + name + '" data-id-3="' + status + '">' + '编辑</button>';
|
||
|
||
}
|
||
}
|
||
],
|
||
cache: false,
|
||
striped: true,
|
||
showRefresh: false,
|
||
pageSize: 20,
|
||
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,
|
||
name: $("#seachName").val(),
|
||
status: ($('#seachStatus').val()) ? $('#seachStatus').val() : null
|
||
};
|
||
// console.log(param);
|
||
return param;
|
||
},
|
||
uniqueId: 'name',
|
||
toolbar: '#toolbar',
|
||
url: '/admin/firstpageopt/list.action',
|
||
onLoadSuccess: function () { //加载成功时执行
|
||
console.log("load success");
|
||
},
|
||
onLoadError: function () { //加载失败时执行
|
||
console.log("load fail");
|
||
}
|
||
})
|
||
}
|
||
})
|
||
}
|
||
},
|
||
|
||
};
|
||
</script>
|
||
|
||
<style scoped>
|
||
#imgMask {
|
||
position: absolute;
|
||
top: 0;
|
||
left: 0;
|
||
width: 250px;
|
||
height: 600px;
|
||
padding: 4px;
|
||
background: #fff;
|
||
z-index: 999;
|
||
display: none;
|
||
}
|
||
|
||
#imgMask img {
|
||
width: 100%;
|
||
height: 100%;
|
||
vertical-align: top;
|
||
}
|
||
</style> |