123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- layui.use(['laypage', 'layer', 'table', 'form'], function () {
- var laypage = layui.laypage //分页
- , $ = layui.jquery
- , layer = layui.layer //弹层
- , table = layui.table //表格
- , form = layui.form;
- var tableIds = 'toutiaolist'; //表格ID
- //第一个实例
- table.render({
- elem: '#' + tableIds
- , url: '/listclassnev/daytoutiaoform' //数据接口
- , where: {token: csrfToken}
- , method: 'post'
- , page: true //开启分页
- , text: '数据加载中'
- , id: 'tablerReload'
- , cols: [[ //表头
- // {type: "checkbox", width:50},
- {type: 'numbers', title: '序号', width: 50},
- {field: 'day_title', title: '栏目', align: 'center'},
- {field: 'day_email', width: 200, title: '邮箱', align: 'center'},
- {
- field: 'state', title: '审核状态', width: 100, align: 'center', templet: function (d) {
- switch (d.state) {
- case '2':
- return '<input type="checkbox" value="' + d.id + '" res="1" lay-skin="switch" lay-filter="switchTest" lay-text="通过|禁用">'
- break;
- case '1':
- return '<input type="checkbox" checked value="' + d.id + '" res="2" lay-skin="switch" lay-filter="switchTest" lay-text="通过|禁用">'
- break;
- }
- }
- },
- {field: 'create_time', title: '添加时间', align: 'center'},
- {
- field: 'sort',
- title: '排序',
- width: 100,
- event: 'sortData',
- edit: 'text',
- align: 'center',
- sort: true,
- templet: "#sortBox"
- },
- {fixed: 'right', title: '操作', width: 180, align: 'center', toolbar: '#toutiaofunc'}
- ]]
- });
- table.reload('tablerReload'); //重新加载
- //列表操作
- table.on('tool(' + tableIds + ')', function (obj) {
- var layEvent = obj.event,
- data = obj.data;
- if (layEvent === 'edit') {
- var index = layer.open({
- type: 2,
- title: '修改直播信息',
- area: ['50%', '35%'],
- content: '/listclassnev/daytoutiaoedit?id='+data.id,
- end: function () {
- table.reload('tablerReload'); //重新加载
- }
- });
- } else if (layEvent === 'del') {
- layer.confirm('您确定要删除吗?', {btn: ['确定', '取消']}, function () {
- setDaytoutiao('del',data.id);
- })
- } else if (layEvent === 'sortData') { //修改排序
- table.on('edit(' + tableIds + ')', function (obj) {
- var data = obj.data;
- setDaytoutiao('sort',data.id,data.sort);
- })
- }
- });
- //监听指定开关
- form.on('switch(switchTest)', function (data) {
- let id = $(data.elem).val();
- let state = $(data.elem).attr('res');
- layer.confirm('您确定要修改当前状态吗?', {btn: ['确认', '取消']}, function (index) {
- setDaytoutiao('state',id,state);
- }, function (index) {
- table.reload('tablerReload');
- layer.close(index)
- })
- return false;
- });
- // 新增
- var $ = layui.$, active = {
- addData: function () { //获取选中数据
- var index = layui.layer.open({
- type: 2,
- title: '添加栏目信息',
- closeBtn: 1, //不显示关闭按钮
- area: ['50%', '35%'],
- content: '/listclassnev/daytoutiaoadd' //iframe的url,no代表不显示滚动条
- , success: function (layero, index) {
- },
- end: function () {
- table.reload('tablerReload');
- }
- });
- }
- };
- $('.demoTable .layui-btn').on('click', function () {
- var type = $(this).data('type');
- active[type] ? active[type].call(this) : '';
- });
- //添加页面提交数据
- form.on('submit(adds)', function (data) {
- var formData = new FormData($('form')[0]);
- var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
- $.ajax({
- cache: false,
- type: "post",
- url: "/listclassnev/daytoutiaoaddform",
- data: formData, // 你的formid
- contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
- processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
- error: function (request) {
- layer.close(index);
- layer.msg("请联系管理员");
- },
- success: function (data) {
- layer.msg(data.msg);
- if(data.code == 200){
- parent.layer.close(index); //再执行关闭
- }
- }
- });
- return false;
- });
- form.on('submit(edits)', function (data) {
- var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
- var formData = new FormData($('form')[0]);
- $.ajax({
- type: "post",
- url: "/listclassnev/daytoutiaoeditform",
- data: formData,
- contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
- processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
- error: function (request) {
- layer.close(index);
- layer.msg("请联系管理员");
- },
- success: function (data) {
- layer.msg(data.msg);
- if(data.code == 200){
- parent.layer.close(index); //再执行关闭
- }
- }
- });
- return false;
- });
- //列表状态(审核,排序,删除)
- function setDaytoutiao(code,id,val = null) {
- $.post('/listclassnev/daytoutiaoset', {id: id,code:code,val:val}, function (data) {
- layer.msg(data.msg);
- if(data.code == 200){
- table.reload('tablerReload');
- }
- })
- }
- })
|