layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect'], function () { let $ = layui.jquery, form = layui.form, table = layui.table, layer = layui.layer, xmSelect = layui.xmSelect, miniTab = layui.miniTab; /**** index begin ***/ //index页面 if ($('.location-index-page').length > 0) { miniTab.listen(); // 渲染表格 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', even: true, limits: [10,20,50,100,200,500,1000], 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: 'id' , width: 80, title: 'ID'}, {templet: '#row-cover', title: '头像', style: 'height: 90px;'}, {templet:function(d){ if( d.account != undefined){ return d.account.nick_name } return ''; },title: '昵称'}, {templet: '#row-gender', title: '性别'}, {field: 'create_time', title: '评论时间'}, {templet: '#row-comment', minWidth: 350, title: '评论内容'}, {templet: '#row-state', title: '状态'}, {templet: '#row-operate', field: 'right', align: 'center', title: '操作',} ]], done: function () { Tools.setInsTb(insTb); } }); // 监听搜索操作 form.on('submit(data-search-btn)', function (data) { //执行搜索重载 table.reload('table-container', { page: {curr: 1} , where: data.field }, 'data'); 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'); let width = $($(this).context).data('width') ? $($(this).context).data('width') : '100%'; let height = $($(this).context).data('height') ? $($(this).context).data('height') : '100%'; let insTb = Tools.getInsTb(); switch (layEvent) { // 行 删除 case 'examine': $.post(url, {}, function (res) { layer.msg(res.msg) if (res.code === 0) { insTb.reload(); } }) return false; // 行 删除 case 'black': openLayer(url, title, width, height); return false; case 'del': delRow(url, [data.id], insTb); return false; } }); } /*** index end ***/ });