layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect','laydate'], function () { let $ = layui.jquery, form = layui.form, table = layui.table, layer = layui.layer, xmSelect = layui.xmSelect, laydate = layui.laydate, 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'}, {field: 'name', title: '名称'}, {field: 'business_name', title: '所属商家'}, {field: 'business_subtitle', title: '商家简称'}, {field: 'agency_text', title: '渠道商名称'}, // {field: 'money', title: '金额'}, {field: 'deduction_money', title: '扣除金额'}, {field: 'start_time', title: '开始时间'}, {field: 'end_time', title: '结束时间'}, {templet: '#row-on_shelf', title: '上下架'}, {field: 'state_text', title: '状态'}, {field: 'create_time', 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; }); //日期时间选择器 laydate.render({ elem: '#start_time' ,type: 'date' }); //日期时间选择器 laydate.render({ elem: '#end_time' ,type: 'date' }); //监听工具条 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(); if (layEvent === 'shelf') { $.post(url, null, function (res) { layer.msg(res.msg) if (res.code === 0) { insTb.reload(); } }) return false; } if (layEvent === 'info') { openLayer(url, title, width, height); return false; } if (layEvent === 'distribution') { let ids = [$(this).data('value')]; setDistribution(url, ids); return false; } }); //监听工具条 注意区别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 'refresh': refreshTab(insTb); return false; case 'distribution': 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); }); setDistribution(url, ids); return false; // 其他 默认为打开弹出层 default: if (layEvent !== 'LAYTABLE_COLS' && layEvent !== 'LAYTABLE_EXPORT') { openLayer(url, title, width, height); return false; } } }); //删除 function setDistribution(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; }); } } /*** index end ***/ if ($('.location-operate-page').length > 0){ //日期时间选择器 laydate.render({ elem: '#start_time' ,type: 'date' }); //日期时间选择器 laydate.render({ elem: '#end_time' ,type: 'date' }); } });