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; let modifyUrl = $('#row-modify').data('url'); /**** 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: [null], 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'}, {field: 'nickname', minWidth: 200, title: '昵称'}, {field: 'username', minWidth: 200, title: '用户名'}, {field: 'mobile', minWidth: 200, title: '手机号'}, {templet: '#row-status', minWidth: 200, title: '状态'}, {templet: '#row-operate', minWidth: 150, field: 'right', align: 'center', title: '操作', fixed: 'right'} ]], 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; }); //监听状态改变 form.on('switch(changeStatus)', function(obj){ let val = obj.elem.checked ? 1 : 0; $.post(modifyUrl, {id: this.value, field: this.name, value: val}, function (res) { layer.msg(res.msg) if (res.code === 0) { setTimeout(function () { insTb.reload(); }, 1000) } }) }); /** td edit **/ table.on('edit(table-container)', function (obj) { let id = obj.data.id; if (obj.field == 'sort') { $.ajax('/manager/slide/sort', { data: { "sort": obj.value, "id": id } ,dataType : 'json' ,type: 'POST' }) .done(function () { insTb.reload(); }) } }); } /*** index end ***/ /** add and edit **/ if ($('.location-operate-page').length > 0) { //监听提交 form.on('submit(saveMember)', function (data) { let url = $(data.elem).data('url'); $.post(url, data.field, function (res) { layer.msg(res.msg); if (res.code === 0) { //刷新父级列表 parent.layui.$('[data-table-refresh]').trigger("click"); setTimeout(function () { //关闭当前弹出层 let iframeIndex = parent.layer.getFrameIndex(window.name); parent.layer.close(iframeIndex); }, 1000) } }); return false; }); } });