layui.use(['jquery', 'laytpl', 'table', 'form', 'miniTab', 'xmSelect', 'laydate'], function () { let $ = layui.jquery, form = layui.form, table = layui.table, layer = layui.layer, laydate = layui.laydate, xmSelect = layui.xmSelect, miniTab = layui.miniTab; let modifyUrl = $('#row-modify').data('url'); /**** index begin ***/ //index页面 if ($('.location-index-page').length > 0) { miniTab.listen(); laydate.render({ elem: '#publish-date', }); laydate.render({ elem: '#end-date', }); // 渲染表格 let listUrl = $('#table-container').data('url'); let insTb = table.render({ elem: '#table-container', toolbar: '#toolbar-tpl', defaultToolbar: [{ //自定义头部工具栏右侧图标。如无需自定义,去除该参数即可 title: '搜索' , layEvent: 'search' , icon: 'layui-icon-search' }], url: listUrl, method: 'post', request: { pageName: 'page', limitName: 'size', }, parseData: function (res) { return { "code": res.code, //解析接口状态 "msg": res.msg, //解析提示文本 "count": res.data.total, //解析数据长度 "data": res.data.list //解析数据列表 }; }, page: true, cols: [[ {type: 'checkbox'}, {field: 'operator', minWidth: 200, title: '昵称'}, {field: 'name', minWidth: 200, title: '用户名'}, {field: 'content', minWidth: 200, title: '操作地址'}, {field: 'request_type', minWidth: 200, title: '操作方式'}, {field: 'create_time', minWidth: 200, title: '操作时间'}, // {templet: '#row-operate', fixed: 'right',align: 'center', title: '操作'} ]], done: function () { } }); //监听单元格编辑 table.on('edit(table-container)', function (obj) { $.post(modifyUrl, {id: obj.data.id, field: obj.field, value: obj.value}, function (res) { layer.msg(res.msg) if (res.code === 0) { insTb.reload(); } }) }); //监听工具条 注意区别toolbar和tool toolbar是表头上的工具条 tool是行中的工具条 table.on('toolbar(table-container)', function (obj) { let layEvent = obj.event; if (layEvent === 'del') { let checkStatus = table.checkStatus('table-container'); if (checkStatus.data.length <= 0) { layer.msg('请先选择数据'); return false; } let selected = checkStatus.data; let ids = []; let url = $($(this).context).data('href') $.each(selected, function (index, val) { ids.push(val.id); }) del(url, ids); return false; } if (layEvent === 'refresh') { insTb.reload(); return false; } if (layEvent === 'add') { let url = $($(this).context).data('href') let title = $($(this).context).data('title') openLayer(url, title); return false; } // toolbar 搜索 if (layEvent === 'search') { let search = $('.table-search-fieldset'); if (search.hasClass('div-show')) { search.css('display', 'none').removeClass('div-show'); } else { search.css('display', 'block').addClass('div-show'); } return false; } }); //删除 function del(url, ids) { let index = layer.confirm('确认删除吗?', { btn: ['确认', '取消'], //按钮 title: '操作提示', }, function () { $.post(url, {ids: ids}, function (res) { layer.msg(res.msg) if (res.code === 0) { insTb.reload(); } }) }, function () { layer.close(index) return false; }); } //监听工具条 table.on('tool(table-container)', function (obj) { let data = obj.data; let layEvent = obj.event; let url = $($(this).context).data('href'); let title = $($(this).context).data('title'); if (layEvent === 'del') { let ids = [data.id]; del(url, ids); return false; } }); } /*** index end ***/ });