layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect', 'laydate'], function () { let $ = layui.jquery, table = layui.table, xmSelect = layui.xmSelect, miniTab = layui.miniTab, laydate = layui.laydate, form = layui.form; /**** index begin ***/ if ($('.location-index-page').length > 0) { miniTab.listen(); let modifyUrl = $('#row-modify').data('url'); // 渲染表格 let listUrl = $('#table-container').data('url'); let insTb = table.render({ elem: '#table-container', title: 'SKU商品列表', defaultToolbar: ['filter', 'exports', { title: '搜索' //自定义头部工具栏右侧图标。如无需自定义,去除该参数即可 , layEvent: 'search' , icon: 'layui-icon-search' }], toolbar: '#toolbar-tpl', method: 'POST', url: listUrl, page: true, limit: 20, limits: [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 //解析数据列表 }; }, cols: [[ {type: 'checkbox'}, {field: 'name', title: '商品名称', minWidth: 200}, {field: 'activity_begin_at', title: '开始时间', minWidth: 150}, {field: 'activity_end_at', title: '结束时间', minWidth: 150}, {field: 'stock', title: '活动库存', minWidth: 100}, // {field: 'amount', title: '成团订单数', minWidth: 100}, // {field: 'amount', title: '成团人数', minWidth: 100}, {field: 'status_text', title: '状态', width: 100}, {templet: '#row-check', field: 'is_check', minWidth: 120,align: 'center', title: '商品审核'}, {templet: '#row-operate', width: 350, 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%'; let checkStatus = table.checkStatus('table-container'); let selected = checkStatus.data; let ids = []; // debugger; switch (layEvent) { case 'check': if (checkStatus.data.length <= 0) { layer.msg('请先选择数据'); return false; } $.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 'del': if (checkStatus.data.length <= 0) { layer.msg('请先选择数据'); return false; } // let selected = checkStatus.data; // let ids = []; $.each(selected, function (index, val) { ids.push(val.id); }) delRow(url, ids, insTb); return false; // toolbar 立即结束 case 'end': if (checkStatus.data.length <= 0) { layer.msg('请先选择数据'); return false; } $.each(selected, function (index, val) { ids.push(val.id); }) delRow(url, ids, insTb, '确认立即结束?'); 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; } } }); //监听行工具条 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 'del': let ids = [data.id]; delRow(url, ids, insTb); return false; // 复制小程序路径 case 'path': let path = $($(this).context).data('path'); let categoryId = $($(this).context).data('category'); // layer.msg('路径复制成功 '+ path + '?id='+data.id+'&category_id='+categoryId+'&is_activity=1'); new ClipboardJS('.clipboard-btn', { text: function() { return path + '?id='+data.id+'&category_id='+categoryId+'&is_activity=1'; } }); layer.msg('路径复制成功!'); return false; //其他 默认为打开弹出层 default: openLayer(url, title, width, height); return false; } }); // switch变更 function changeSwitch(filter) { form.on('switch(' + filter + ')', 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) { //操作不成功则刷新页面 insTb.reload(); } }) }); } changeSwitch('changeCheck');//监听内容审核 // 病种筛选 let diseaseSearch = $('#search-disease-list'); let diseaseSearchJson = diseaseSearch.data('menu') ? diseaseSearch.data('menu') : []; xmSelect.render({ el: '#search-disease-list', paging: false, autoRow: true, radio: true, clickClose: true, name: 'disease_id', tips: '请选择病种', direction: 'auto', height: 'auto', model: { icon: 'hidden', }, prop: { name: 'name', value: 'id', }, theme: { color: '#1e84ff', }, tree: { show: true, showFolderIcon: true, showLine: true, indent: 20, expandedKeys: true, strict: false, }, data: diseaseSearchJson, }); table.on('edit(table-container)', function (obj) { let id = obj.data.id; $.ajax(modifyUrl, { data: {"id": id, "field": obj.field, "value": obj.value} ,dataType : 'json' ,type: 'POST' }) .done(function (res) { if (res.code === 0) { insTb.reload(); } }) }); // 监听搜索操作 form.on('submit(data-search-btn)', function (data) { //执行搜索重载 table.reload('table-container', { page: {curr: 1} , where: data.field }, 'data'); return false; }); } /*** index end ***/ if ($('.location-operate-page').length > 0) { // 添加规格 $('.panel-sku-add').on('click', function () { let panelNum = $('.panel-sku').length; let html = `