index.html
6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
<fieldset class="layui-elem-field layui-field-title">
<legend>{:lang('ad')}管理</legend>
</fieldset>
<div class="demoTable">
<div class="layui-inline">
<input class="layui-input" name="key" id="key" placeholder="{:lang('pleaseEnter')}关键字">
</div>
<button class="layui-btn" id="search" data-type="reload">{:lang('search')}</button>
<a href="{:url('index')}" class="layui-btn">显示全部</a>
<button type="button" class="layui-btn layui-btn-danger" id="delAll">批量删除</button>
<a href="{:url('add')}" class="layui-btn" style="float:right;"><i class="fa fa-plus" aria-hidden="true"></i>{:lang('add')}{:lang('ad')}</a>
<div style="clear: both;"></div>
</div>
<table class="layui-table" id="list" lay-filter="list"></table>
</div>
{include file="common/foot"/}
<script type="text/html" id="name">
{{d.name}}{{# if(d.pic){ }}<img src="/static/admin/images/image.gif" onmouseover="layer.tips('<img src={{d.pic}}>',this,{tips: [1, '#fff']});" onmouseout="layer.closeAll();">{{# } }}
</script>
<script type="text/html" id="order">
<input name="{{d.ad_id}}" data-id="{{d.ad_id}}" class="list_order layui-input" value=" {{d.sort}}" size="10"/>
</script>
<script type="text/html" id="open">
<input type="checkbox" name="open" value="{{d.ad_id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="open" {{ d.open == 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="action">
<a href="{:url('edit')}?ad_id={{d.ad_id}}" class="layui-btn layui-btn-xs">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
layui.use(['table','form'], function() {
var table = layui.table,form = layui.form,$ = layui.jquery;
var tableIn = table.render({
id: 'ad',
elem: '#list',
url: '{:url("index")}',
method: 'post',
page:true,
cols: [[
{checkbox: true, fixed: true},
{field: 'ad_id', title: '{:lang("id")}', width: 80, fixed: true},
{field: 'name', title: '广告名称', width: 400,templet: '#name'},
{field: 'typename', title: '所属位置', width: 160},
{field: 'addtime', title: '{:lang("add")}{:lang("time")}',width: 150},
{field: 'sort', align: 'center', title: '{:lang("order")}', width: 120, templet: '#order'},
{field: 'open', align: 'center', title: '{:lang("status")}', width: 100, toolbar: '#open'},
{width: 160, align: 'center', toolbar: '#action'}
]],
limit:10
});
form.on('switch(open)', function(obj){
loading =layer.load(1, {shade: [0.1,'#fff']});
var id = this.value;
var open = obj.elem.checked===true?1:0;
$.post('{:url("editState")}',{'id':id,'open':open},function (res) {
layer.close(loading);
if (res.status==1) {
tableIn.reload();
}else{
layer.msg(res.msg,{time:1000,icon:2});
return false;
}
})
});
//搜索
$('#search').on('click', function () {
var key = $('#key').val();
if ($.trim(key) === '') {
layer.msg('{:lang("pleaseEnter")}关键字!', {icon: 0});
return;
}
tableIn.reload({ page: {page: 1}, where: {key: key}});
});
table.on('tool(list)', function(obj) {
var data = obj.data;
if (obj.event === 'del'){
layer.confirm('您确定要删除该广告吗?', function(index){
var loading = layer.load(1, {shade: [0.1, '#fff']});
$.post("{:url('del')}",{ad_id:data.ad_id},function(res){
layer.close(loading);
if(res.code===1){
layer.msg(res.msg,{time:1000,icon:1});
tableIn.reload();
}else{
layer.msg('操作失败!',{time:1000,icon:2});
}
});
layer.close(index);
});
}
});
$('body').on('blur','.list_order',function() {
var ad_id = $(this).attr('data-id');
var sort = $(this).val();
var loading = layer.load(1, {shade: [0.1, '#fff']});
$.post('{:url("adOrder")}',{ad_id:ad_id,sort:sort},function(res){
layer.close(loading);
if(res.code === 1){
layer.msg(res.msg, {time: 1000, icon: 1});
tableIn.reload();
}else{
layer.msg(res.msg,{time:1000,icon:2});
}
})
});
$('#delAll').click(function(){
layer.confirm('确认要删除选中的广告吗?', {icon: 3}, function(index) {
layer.close(index);
var checkStatus = table.checkStatus('ad'); //test即为参数id设定的值
var ids = [];
$(checkStatus.data).each(function (i, o) {
ids.push(o.ad_id);
});
if(ids==''){
layer.msg('请选择要删除的数据!', {time: 1000, icon: 2});
return false;
}
var loading = layer.load(1, {shade: [0.1, '#fff']});
$.post("{:url('delall')}", {ids: ids}, function (data) {
layer.close(loading);
if (data.code === 1) {
layer.msg(data.msg, {time: 1000, icon: 1});
tableIn.reload();
} else {
layer.msg(data.msg, {time: 1000, icon: 2});
}
});
});
})
})
</script>