layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect', 'laydate', 'skuTable'], function () { let $ = layui.jquery, table = layui.table, xmSelect = layui.xmSelect, miniTab = layui.miniTab, laydate = layui.laydate, skuTable = layui.skuTable, 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: '限时折扣列表', 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: 'begin_at', title: '开始时间', minWidth: 150}, {field: 'end_at', title: '结束时间', minWidth: 150}, {field: 'activity_status', title: '活动状态', width: 100}, {field: 'status_text', title: '状态', width: 100}, {templet: '#row-operate', width: 350, title: '操作'} ]], done: function () { Tools.setInsTb(insTb); } }); //监听工具条 注意区别toolbar和tool toolbar是表头上的工具条 tool是行中的工具条 table.on('toolbar(table-container-limit)', 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) { // toolbar 删除 case 'del': 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-limit)', 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(); let ids = []; switch (layEvent) { // 行 结束 case 'end': ids = [data.id]; delRow(url, ids, insTb, '确认立即结束活动吗?'); return false; // 行 重启活动 case 'restart': ids = [data.id]; delRow(url, ids, insTb, '确认重启活动吗?'); return false; // 行 删除 case 'del': ids = [data.id]; delRow(url, ids, insTb); return false; //其他 默认为打开弹出层 default: openLayer(url, title, width, height); return false; } }); 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) { let productId = $('#fairy-sku-table').data('id'); let productTypeId = $('#fairy-sku-table').data('type'); let multiSpec = $('#fairy-sku-table').data('multi'); if (productId > 0) { renderSku(productId, productTypeId, multiSpec) } let spuEle = $('#spu-list'); let spuJson = spuEle.data('data') ? spuEle.data('data') : []; xmSelect.render({ el: '#spu-list', paging: true, autoRow: true, radio: true, clickClose: true, name: 'spu_id', tips: '请选择商品', direction: 'auto', height: 'auto', model: { icon: 'hidden', }, prop: { name: 'name', value: 'id', }, tree: { show: true, strict: false, clickCheck: true, expandedKeys: true, clickExpand: false }, theme: { color: '#1e84ff', }, filterable: true, toolbar: {show: true}, remoteSearch: true, data: spuJson, on: function (data) { //arr: 当前多选已选中的数据 let arr = data.arr; //change, 此次选择变化的数据,数组 let change = data.change; //isAdd, 此次操作是新增还是删除 if (arr.length > 0) { $.post('/manager/mall/spu/get-spu', {id: arr[0].id}, function (res) { if (res.code === 0) { renderSku(arr[0].id, res.data.spu_type_id, res.data.multi_spec) } }); } }, remoteMethod: function (val, cb, show) { $.post('/manager/mall/spu/get-spu-list', {keyword: val}, function (res) { if (res.code === 0) { cb(res.data.list, res.data.total); } }); }, }); laydate.render({ elem: '#begin-at', type: 'datetime', }); laydate.render({ elem: '#end-at', type: 'datetime', }); } if ($('.location-detail-page').length > 0) { miniTab.listen(); //监听行工具条 table.on('tool(table-container)', function (obj) { let layEvent = obj.event; let insTb = Tools.getInsTb(); switch (layEvent) { // 行 删除 case 'check-sku': layer.confirm('本次操作将核销剩余所有数量,请确认操作', {icon: 3}, function(index) { $.post('/manager/mall/order/check-sku', {coding: obj.data.coding, id:obj.data.id, num: obj.data.not_check_num}, function (res) { layer.msg(res.msg); if (res.code === 0) { refreshTab(insTb); } }); layer.close(index) }) return false; //其他 默认为打开弹出层 default: openLayer(url, title, width, height); return false; } }); // 渲染表格 let listUrl = $('#table-container').data('url'); let insTb = table.render({ elem: '#table-container', toolbar: '#toolbar-tpl-detail', 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: [[ {type: 'checkbox', fixed: 'left'}, {field: 'nickname', title: '昵称', minWidth: 150}, {field: 'real_name', title: '真实姓名', minWidth: 150}, {field: 'phone', title: '手机号', minWidth: 150}, {field: 'created_at', title: '下单时间', minWidth: 180}, {field: 'status_text', title: '订单状态', minWidth: 180}, {field: 'num', title: '数量', minWidth: 165}, // {minWidth: 100, fixed:'right', title: '操作', templet: '#child-row-operate'} ]], done: function () { Tools.setInsTb(insTb); } }); // 渲染表格 let groupListUrl = $('#table-container-group').data('url'); let groupInsTb = table.render({ elem: '#table-container-group', toolbar: '#toolbar-tpl-detail', defaultToolbar: [], url: groupListUrl, 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', fixed: 'left'}, {field: 'nickname', title: '昵称', minWidth: 150}, {field: 'real_name', title: '真实姓名', minWidth: 150}, {field: 'phone', title: '手机号', minWidth: 150}, {field: 'created_at', title: '下单时间', minWidth: 180}, ]], done: function () { Tools.setInsTb(groupInsTb); } }); } });