222 行
7.7 KiB
HTML
可执行文件
222 行
7.7 KiB
HTML
可执行文件
<!--[1.5.22]-->
|
||
<style>
|
||
* {
|
||
margin: 0;
|
||
padding: 0;
|
||
}
|
||
|
||
table {
|
||
border: 1px solid #f1f1f1;
|
||
margin-top: 40px;
|
||
}
|
||
|
||
.layui-table-cell {
|
||
height: 85px;
|
||
line-height: 85px;
|
||
padding: 0 15px;
|
||
position: relative;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.layui-laypage .layui-laypage-curr .layui-laypage-em {
|
||
background-color: #409EFF;
|
||
}
|
||
|
||
.layui-btn-danger {
|
||
background-color: #bbb;
|
||
}
|
||
|
||
.layui-form-onswitch {
|
||
background-color: #409EFF;
|
||
border-color: #409EFF;
|
||
}
|
||
</style>
|
||
<div>
|
||
<form action="#" class="form-inline PromotionForm">
|
||
<if condition="$authArr['addgroup'] eq true">
|
||
<button type="button" class="layui-btn" id="add" style="background-color:#409EFF;">添加等级
|
||
</button>
|
||
</if>
|
||
</form>
|
||
<table class="layui-hide" id="test" lay-filter="demo"></table>
|
||
</div>
|
||
<script type="text/html" id="statusTpl">
|
||
<if condition="$authArr['change'] eq true">
|
||
<input type="checkbox" name="status" value="{{d.status}}" lay-skin="switch" data-id="{{d.id}}" lay-text="启用|禁用"
|
||
lay-filter="status" {{ d.status== 1 ? 'checked' : '' }}>
|
||
<else/>
|
||
{{d.status==1?'启用':'禁用'}}
|
||
</if>
|
||
</script>
|
||
<script type="text/html" id="barDemo">
|
||
<if condition="$authArr['addgroup'] eq true">
|
||
<button class="layui-btn layui-btn-xs" lay-event="edit" style="background-color:#409EFF">编辑</button>
|
||
</if>
|
||
<if condition="$authArr['delgroup'] eq true">
|
||
<button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</button>
|
||
</if>
|
||
</script>
|
||
<script>
|
||
layui.use(['form', 'layedit', 'laydate', 'table'], function () {
|
||
// 日期
|
||
var laydate = layui.laydate;
|
||
var table = layui.table;
|
||
var form = layui.form;
|
||
//展示已知数据
|
||
table.render({
|
||
elem: '#test',
|
||
url: "{:U('indexshow')}",
|
||
method: 'post',
|
||
cols: [
|
||
[{
|
||
field: 'id',
|
||
title: '序号',
|
||
align: 'center',
|
||
width: 60
|
||
}, {
|
||
field: 'name',
|
||
title: '代理商等级名称',
|
||
align: 'center',
|
||
}, {
|
||
field: 'discount',
|
||
title: '代理折扣',
|
||
align: 'center',
|
||
width: 150
|
||
}, {
|
||
field: 'addtime',
|
||
title: '添加时间',
|
||
align: 'center',
|
||
align: 'center',
|
||
}, {
|
||
field: 'status',
|
||
title: '状态',
|
||
width: 100,
|
||
templet: '#statusTpl',
|
||
}, {
|
||
field: 'right',
|
||
title: '操作',
|
||
align: 'center',
|
||
align: 'center',
|
||
toolbar: '#barDemo'
|
||
}]
|
||
],
|
||
page: {
|
||
layout: ['count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
|
||
}, //是否开启分页
|
||
});
|
||
// 日期
|
||
lay('.test-item').each(function () {
|
||
laydate.render({
|
||
elem: this,
|
||
trigger: 'click'
|
||
});
|
||
});
|
||
table.on('tool(demo)', function (obj) { //注:tool是工具条事件名,test是table原始容器的属性 lay-filter="对应的值"
|
||
var data = obj.data; //获得当前行数据
|
||
var layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值)
|
||
var tr = obj.tr; //获得当前行 tr 的DOM对象
|
||
if (layEvent === 'del') { //删除
|
||
layer.confirm('确定删除吗?', function (index) {
|
||
layer.close(index);
|
||
//向服务端发送删除指令
|
||
$.ajax({
|
||
url: "{:U('delgroup')}",
|
||
data: {id: data.id},
|
||
type: 'post',
|
||
success: function (res) {
|
||
// console.log(res)
|
||
if (res.status == 1) {
|
||
top.layer.msg(res.msg, {time: 1000}, function () {
|
||
|
||
})
|
||
table.reload('test', {
|
||
page: {
|
||
curr: 1 //重新从第 1 页开始
|
||
}
|
||
});
|
||
} else {
|
||
top.layer.msg(res.msg, {icon: 4, time: 1000})
|
||
}
|
||
}
|
||
})
|
||
});
|
||
} else if (layEvent === 'edit') { //编辑
|
||
top.layer.open({
|
||
type: 2,
|
||
content: "{:U('addgroup')}?id=" + data.id,
|
||
title: "编辑-代理商等级",
|
||
area: ["600px", '350px'],
|
||
btnAlign: 'c',
|
||
end: function () {
|
||
table.reload('test', {});
|
||
}
|
||
})
|
||
|
||
}
|
||
});
|
||
$('#add').click(function () {
|
||
top.layer.open({
|
||
type: 2,
|
||
content: "{:U('addgroup')}",
|
||
title: "添加代理商等级",
|
||
area: ["600px", '450px'],
|
||
btnAlign: 'c',
|
||
end: function () {
|
||
table.reload('test', {});
|
||
}
|
||
})
|
||
|
||
})
|
||
//监听状态操作
|
||
form.on('switch(status)', function (obj) {
|
||
var id = $(this).attr("data-id")
|
||
var status = obj.elem.checked ? '1' : '2';
|
||
$.ajax({
|
||
url: "{:U('change')}",
|
||
type: "POST",
|
||
data: {id: id, status: status},
|
||
success: function (res) {
|
||
if (res.status == 1) {
|
||
top.layer.msg(res.msg, {time: 1500});
|
||
} else {
|
||
top.layer.msg(res.msg, {time: 1500}, function () {
|
||
table.reload('test');
|
||
});
|
||
}
|
||
}
|
||
})
|
||
});
|
||
$('#submit').click(function () {
|
||
var money = $('#money').val();
|
||
if (!money) {
|
||
layer.msg('请先完善您的表单信息', {time: 2000})
|
||
return false;
|
||
} else {
|
||
$.ajax({
|
||
url: "{:U('addAgentmoney')}",
|
||
type: 'post',
|
||
data: {
|
||
money: money,
|
||
},
|
||
success: function (res) {
|
||
if (res.status == 1) {
|
||
top.layer.msg(res.msg, {icon: 1, time: 1200}, function () {
|
||
layer.closeAll();
|
||
window.location.reload();
|
||
})
|
||
} else {
|
||
layer.msg(res.msg, {time: 1200})
|
||
}
|
||
},
|
||
error: function (error) {
|
||
console.log(error);
|
||
}
|
||
})
|
||
}
|
||
})
|
||
})
|
||
</script>
|