文件

184 行
5.9 KiB
HTML
可执行文件

<!--[1.5.84]-->
<style>
table {
border: 1px solid #f1f1f1;
margin-top: 40px;
}
.layui-table-cell {
height: auto;
text-align: center;
}
.layui-laypage .layui-laypage-curr .layui-laypage-em {
background-color: #409EFF;
}
.layui-table-page .layui-laypage a:hover, .layui-table-page .layui-laypage span:hover {
color: #409EFF;
}
.layui-btn {
background-color: #409EFF;
border-radius: 3px;
}
.layui-btn:hover {
opacity: 0.8;
color: #409EFF !important;
}
.layui-form-onswitch {
border-color: #409EFF;
background-color: #409EFF;
}
</style>
<div class="goodsBox">
<if condition="$authArr['add'] eq true">
<button type="button" class="layui-btn" style="padding: 5px 15px;line-height: 12px" id="add">添加</button>
</if>
<table class="layui-hide" id="test" lay-filter="demo"></table>
<script type="text/html" id="switchTpl">
<!-- 这里的 checked 的状态只是演示 -->
<if condition="$authArr['upstatus'] eq true">
<input type="checkbox" name="status" date-value="{{d.status}}" data-id="{{d.id}}" value="{{d.status}}"
lay-skin="switch" lay-text="开启|关闭" lay-filter="sexDemo" {{ d.status== 1 ? 'checked' : '' }}>
</if>
</script>
</div>
<script type="text/html" id="barDemo">
<if condition="$authArr['delimg'] eq true">
<button class="layui-btn layui-btn-xs layui-btn-danger" style="color: #999;background-color: transparent"
lay-event="del">删除
</button>
</if>
</script>
<script>
layui.use(['form', 'table'], function () {
// 日期
var form = layui.form;
var table = layui.table;
//展示已知数据
table.render({
elem: '#test',
url: "{:U('getData')}",
method: 'post',
cols: [
[{
field: 'index',
title: '序号',
width: 60
}, {
field: 'typename',
title: '类型',
width: 100,
align: 'center'
}, {
field: 'image',
title: '图片',
style: 'height:100%;',
align: 'center',
templet: '<div><img src="{{ d.image}}" style="max-width: 200px!important;"></div>'
}, {
field: 'status',
title: '状态',
templet: '#switchTpl',
align: 'center'
},
{
field: 'right',
title: '操作',
align: 'center',
toolbar: '#barDemo',
align: 'center'
}]
],
page: {
layout: ['count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
}, //是否开启分页
});
//监听状态操作
form.on('switch(sexDemo)', function (obj) {
console.log($(this).attr('date-value'));
this.value = this.value == 1 ? 2 : 1;
var status = this.value;
var id = $(obj.elem).attr('data-id');
// console.log(status);
// console.log(id);
$.ajax({
url: "{:U('upstatus')}",
type: 'POST',
data: {
status: status,
id: id
},
success: function (res) {
if (res.status == 1) {
top.layer.msg(res.msg, {
icon: 1, time: 800, function() {
MenuApp.refreshWindow();
}
})
} else {
top.layer.msg(res.msg, {icon: 4, time: 5000})
}
}
})
});
$('#Preservation').click(function () {
table.reload('test', {
page: {
curr: 1 //重新从第 1 页开始
}
, where: {
keyword: $('#keyword').val()
}
});
})
table.on('tool(demo)', function (obj) {
var data = obj.data;
var layEvent = obj.event;
var tr = obj.tr;
if (layEvent === 'detail') { //查看
//do somehing
window.location.href = "{:U('shiftingdetail')}?id=" + data.id;
} else if (layEvent === 'del') { //删除
layer.confirm('确定删除这个图片吗?', function (index) {
layer.close(index);
//向服务端发送删除指令
$.ajax({
url: "{:U('delimg')}",
data: {id: data.id},
type: 'post',
success: function (res) {
if (res.status == 1) {
top.layer.msg(res.msg, {icon: 1, time: 1000})
obj.del();
} else {
top.layer.msg(res.msg, {icon: 4, time: 1000})
}
}
})
});
}
});
$('#add').click(function () {
layer.open({
type: 2,
content: "{:U('add')}",
title: "添加图片",
area: ['calc(100% - 160px)', 'calc(100% - 65px)'],
offset: 'rb',
btnAlign: 'c',
shade: 0,
end: function () {
table.reload('test', {});
}
})
})
})
</script>