layui.use(['laytpl', 'table', 'jquery', '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(); // 渲染表格 let listUrl = $('#table-container').data('url'); let insTb = table.render({ elem: '#table-container', toolbar: '#toolbar-tpl', defaultToolbar: [], url: listUrl, method: 'post', even: true, limits: [10, 20, 50, 100, 200, 500, 1000, 2000], 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: [[ {field: 'rule', minWidth: 150, title: '规则',edit: 'text'}, {templet: '#row-status', minWidth: 120, align: 'center', title: '状态'}, {templet: '#row-operate', minWidth: 250, title: '操作'}, ]], done: function () { Tools.setInsTb(insTb); } }); //监听工具条 注意区别toolbar和tool toolbar是表头上的工具条 tool是行中的工具条 table.on('toolbar(table-container)', function (obj) { let layEvent = obj.event; let insTb = Tools.getInsTb(); 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%'; // debugger; switch (layEvent) { // toolbar 分配指定员工 分配客户标签 到店设置 来源设置 // toolbar 刷新 case 'refresh': refreshTab(insTb); return false; case 'add': openLayer(url, title); return false; // 其他 默认为打开弹出层 default: if (layEvent !== 'LAYTABLE_COLS' && layEvent !== 'LAYTABLE_EXPORT') { openLayer(url, title, width, height); return false; } } }); //监听单元格编辑 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(); } }) }); } /*** index end ***/ if ($('.location-operate-page').length > 0) { //监听提交 form.on('submit(submitAll)', function (data) { let url = $(data.elem).data('url'); $.post(url, data.field, function (res) { layer.msg(res.msg); if (res.code === 0) { setTimeout(function () { //关闭当前弹出层 let iframeIndex = parent.layer.getFrameIndex(window.name); parent.layer.close(iframeIndex); }, 1000) } }); return false; }); } });