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; /**** index begin ***/ //index页面 if ($('.location-index-page').length > 0) { miniTab.listen(); laydate.render({ elem: '#publish-date', }); // 渲染表格 let listUrl = $('#table-container').data('url'); let insTb = table.render({ elem: '#table-container', toolbar: '#toolbar-tpl', defaultToolbar: ['filter', 'exports', { //自定义头部工具栏右侧图标。如无需自定义,去除该参数即可 title: '搜索' , layEvent: 'search' , icon: 'layui-icon-search' }], 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: [[ {type: 'checkbox'}, {field: 'id', minWidth: 50, title: '编号'}, {field: 'nickname', title: '昵称'}, {field: 'real_name', title: '真实姓名'}, {field: 'mobile',title: '电话'}, {field: 'created_at', title: '注册时间'}, {field: 'score', title: '积分'}, {field: 'balance', title: '余额'}, {templet: '#row-operate',minWidth: 150, 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 分配指定员工 分配客户标签 到店设置 来源设置 case 'staff': case 'tag': case 'sign': case 'recharge-coin': case 'source': let checkStatus = table.checkStatus('table-container'); if (checkStatus.data.length <= 0) { layer.msg('请先选择数据'); return false; } let selected = checkStatus.data; let ids = []; $.each(selected, function (index, val) { ids.push(val.id); }) if (ids.length > 500) { layer.msg('一次操作请不要超过500条'); return false; } url += '?id=' + ids; openLayer(url, title, width, height); return false; // toolbar 刷新 case 'refresh': refreshTab(insTb); return false; // toolbar 搜索 case '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; // 其他 默认为打开弹出层 default: if (layEvent !== 'LAYTABLE_COLS' && layEvent !== 'LAYTABLE_EXPORT') { openLayer(url, title, width, height); return false; } } }); // 监听搜索操作 form.on('submit(data-search-btn)', function (data) { //执行搜索重载 table.reload('table-container', { page: {curr: 1} , where: {searchParams: data.field} }, 'data'); return false; }); } /*** index end ***/ });