204 行
6.6 KiB
HTML
可执行文件
204 行
6.6 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: transparent;
|
|
color: #409EFF;
|
|
}
|
|
|
|
.layui-btn-danger {
|
|
color: #999;
|
|
}
|
|
.layui-form-onswitch {
|
|
border-color: #409EFF;
|
|
background-color: #409EFF;
|
|
}
|
|
</style>
|
|
<div id="commodity" class="goodsBox" v-cloak>
|
|
<if condition="$authArr['add'] eq true">
|
|
<el-button type="primary" size="small" id="add">添加产品</el-button>
|
|
</if>
|
|
<table class="layui-hide" id="test" lay-filter="demo"></table>
|
|
</div>
|
|
<script type="text/html" id="switchTpl">
|
|
<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>
|
|
<script type="text/html" id="barDemo">
|
|
<if condition="$authArr['update'] eq true">
|
|
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
|
|
</if>
|
|
<if condition="$authArr['delUser'] eq true">
|
|
<button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</button>
|
|
</if>
|
|
</script>
|
|
<script>
|
|
new Vue({
|
|
el: '#commodity',
|
|
methods: {}
|
|
})
|
|
layui.use(['table'], function () {
|
|
// 日期
|
|
var form = layui.form;
|
|
var table = layui.table;
|
|
//展示已知数据
|
|
table.render({
|
|
elem: '#test',
|
|
url: "{:U('getData')}",
|
|
method: 'post',
|
|
cols: [
|
|
[{
|
|
field: 'index',
|
|
title: '序号',
|
|
align: 'center',
|
|
width: 60
|
|
}, {
|
|
field: 'title',
|
|
title: '产品名称',
|
|
align: 'center',
|
|
width: 200
|
|
}, {
|
|
field: 'docuat',
|
|
title: '产品简介',
|
|
align: 'center',
|
|
width: 250
|
|
}, {
|
|
field: 'image',
|
|
title: '产品图片',
|
|
style: 'height:100%;',
|
|
align: 'center',
|
|
templet: '<div><img src="{{ d.image}}" style="width: 80px;"></div>',
|
|
width: 110
|
|
}, {
|
|
field: 'status',
|
|
title: '状态',
|
|
templet: '#switchTpl',
|
|
align: 'center',
|
|
width: 100
|
|
}, {
|
|
field: 'content',
|
|
title: '产品详情',
|
|
align: 'center',
|
|
}, {
|
|
field: 'right',
|
|
title: '操作',
|
|
align: 'center',
|
|
toolbar: '#barDemo',
|
|
width: 120
|
|
}]
|
|
],
|
|
page: {
|
|
layout: ['count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
|
|
}, //是否开启分页
|
|
});
|
|
$('#Preservation').click(function () {
|
|
table.reload('test', {
|
|
page: {
|
|
curr: 1 //重新从第 1 页开始
|
|
}
|
|
, where: {
|
|
keyword: $('#keyword').val()
|
|
}
|
|
});
|
|
});
|
|
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('修改成功', {icon: 1, time: 500})
|
|
} else {
|
|
top.layer.msg('修改失败', {icon: 4, time: 500})
|
|
}
|
|
}
|
|
})
|
|
});
|
|
// 删除
|
|
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('delUser')}",
|
|
data: {id: data.id},
|
|
type: 'post',
|
|
success: function (res) {
|
|
if (res.status == 1) {
|
|
obj.del();
|
|
} else {
|
|
top.layer.msg(res.msg, {icon: 4, time: 1000})
|
|
}
|
|
}
|
|
})
|
|
});
|
|
} else if (layEvent === 'edit') { //编辑
|
|
console.log(data.id);
|
|
layer.open({
|
|
type: 2,
|
|
content: "{:U('add')}?id=" + data.id,
|
|
title: "编辑产品",
|
|
area: ['calc(100% - 160px)', 'calc(100% - 65px)'],
|
|
offset: 'rb',
|
|
shade: 0,
|
|
btnAlign: 'c',
|
|
end: function () {
|
|
table.reload('test', {});
|
|
}
|
|
})
|
|
}
|
|
});
|
|
$('#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> |