var pageCurr; var printMatCodeNos = []; var admin; // Local translation helper function t(key, params) { if (typeof I18n !== 'undefined' && typeof I18n.t === 'function') { return I18n.t(key, params); } return key; } function getCol() { var cols = [ {type: 'checkbox'} ,{field: 'tagId$', align: 'center',title: t('classification'), templet: '#tagTpl'} // ,{field: 'store_max', align: 'center',title: t('stock_upper_limit')} // ,{field: 'store_min', align: 'center',title: t('stock_lower_limit')} // ,{field: 'store_max_date', align: 'center',title: t('stock_age_upper_limit_days')} ,{field: 'areaId$', align: 'center',title: t('area'), templet: '#areaTpl'} ]; cols.push.apply(cols, getMatCols()); cols.push( {fixed: 'right', title: t('operation'), align: 'center', toolbar: '#operate', width:150} ) return cols; } layui.config({ base: baseUrl + "/static/layui/lay/modules/" }).extend({ dropdown: 'dropdown/dropdown', }).use(['table','laydate', 'form', 'treeTable', 'admin', 'xmSelect', 'dropdown', 'element'], function(){ var table = layui.table; var $ = layui.jquery; var layer = layui.layer; var layDate = layui.laydate; var form = layui.form; admin = layui.admin; var treeTable = layui.treeTable; var xmSelect = layui.xmSelect; // 区域数据 var areaData = []; // 加载区域数据 $.ajax({ url: baseUrl+'/area/list/auth', headers: {token: localStorage.getItem('token')}, method: 'GET', async: false, success: function (res) { if (res.code === 200 && res.data && res.data.records) { // 过滤掉空值 areaData = res.data.records.filter(function(item) { return item != null && item.areaId != null; }); console.log('区域数据加载成功:', areaData); } else { console.error('区域数据加载失败:', res); } }, error: function(err) { console.error('区域数据请求失败:', err); } }); // 商品分类数据 var insTb = treeTable.render({ elem: '#tag', url: baseUrl+'/tag/list/auth', headers: {token: localStorage.getItem('token')}, tree: { iconIndex: 2, // 折叠图标显示在第几列 isPidData: true, // 是否是id、pid形式数据 idName: 'id', // id字段名称 pidName: 'parentId' // pid字段名称 }, cols: [], done: function (data) { $('.ew-tree-table-box').css('height', '100%'); insTb.expandAll(); } }); // 数据渲染 var tableDone = function(res, curr, count) { if (res.code === 403) { top.location.href = baseUrl+"/"; } pageCurr=curr; limit(); form.on('checkbox(tableCheckbox)', function (data) { var _index = $(data.elem).attr('table-index')||0; if(data.elem.checked){ res.data[_index][data.value] = 'Y'; }else{ res.data[_index][data.value] = 'N'; } }); if (typeof I18n !== 'undefined') { I18n.updatePage(); I18n.updateLayuiPagination(); } }; tableIns = table.render({ elem: '#mat', headers: {token: localStorage.getItem('token')}, url: baseUrl+'/mat/list/auth', page: true, limit: 16, limits: [16, 30, 50, 100, 200, 500], toolbar: '#toolbar', cellMinWidth: 50, height: 'full-105', cols: [getCol()], request: { pageName: 'curr', pageSize: 'limit' }, parseData: function (res) { return { 'code': res.code, 'msg': res.msg, 'count': res.data.total, 'data': res.data.records } }, response: { statusCode: 200 }, done: tableDone }); // 监听排序事件 table.on('sort(locMast)', function (obj) { var searchData = {}; $.each($('#search-box [name]').serializeArray(), function() { searchData[this.name] = this.value; }); searchData['orderByField'] = obj.field; searchData['orderByType'] = obj.type; tableIns.reload({ where: searchData, page: { curr: 1 }, done: tableDone }); }); // 监听语言切换 $(document).on('i18n:languageChanged i18n:ready', function() { tableIns.reload({ cols: [getCol()], done: tableDone }); }); // 监听头工具栏事件 table.on('toolbar(mat)', function (obj) { var checkStatus = table.checkStatus(obj.config.id); switch(obj.event) { case 'addData': showEditModel() break; case 'deleteData': var data = checkStatus.data; if (data.length === 0){ layer.msg(I18n.t('please_select_data')); } else { layer.confirm(I18n.t('confirm_delete_prefix') + (data.length===1?I18n.t('this'):data.length) + I18n.t('confirm_delete_suffix'), function(){ $.ajax({ url: baseUrl+"/mat/delete/auth", headers: {'token': localStorage.getItem('token')}, data: {param: JSON.stringify(data)}, method: 'POST', traditional:true, success: function (res) { if (res.code === 200){ layer.closeAll(); tableReload(false); } else if (res.code === 403){ top.location.href = baseUrl+"/"; } else { layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 2}) } } }) }); } break; case 'exportData': layer.confirm(I18n.t('confirm_export_excel'), {shadeClose: true}, function(){ var titles=[]; var fields=[]; obj.config.cols[0].map(function (col) { if (col.type === 'normal' && col.hide === false && col.toolbar == null) { titles.push(col.title); fields.push(col.field); } }); var exportData = {}; $.each($('#search-box [name]').serializeArray(), function() { exportData[this.name] = this.value; }); var param = { 'mat': exportData, 'fields': fields }; $.ajax({ url: baseUrl+"/mat/export/auth", headers: {'token': localStorage.getItem('token')}, data: JSON.stringify(param), dataType:'json', contentType:'application/json;charset=UTF-8', method: 'POST', success: function (res) { layer.closeAll(); if (res.code === 200) { table.exportFile(titles,res.data,'xls'); } else if (res.code === 403) { top.location.href = baseUrl+"/"; } else { layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 2}) } } }); }); break; // 批量打印 case "btnPrintBatch": printMatCodeNos = []; var data = checkStatus.data; if (data.length === 0){ layer.msg(I18n.t('please_select_print_data')); } else { layer.open({ type: 1, title: I18n.t('batch_print_count', {count: data.length}), area: ['500px'], shadeClose: true, content: $('#printDataDiv'), success: function(layero, index){ for (var i = 0; i 0 ? areaData : [], initValue: mData && mData.areaId ? [mData.areaId] : [], model: {label: {type: 'text'}}, prop: { name: 'areaName', value: 'areaId' }, radio: true, clickClose: true, on: function(data) { } }); // 弹窗不出现滚动条 $(layero).children('.layui-layer-content').css('overflow', 'visible'); layui.form.render('select'); } }); } // 模板选择 form.on('radio(selectTemplateRadio)', function (data) { $('.template-preview').hide(); $('#template-preview-'+data.value).show(); }); // 开始打印 form.on('submit(doPrint)', function (data) { var templateNo = data.field.selectTemplate; $.ajax({ url: baseUrl+"/mat/print/auth", headers: {'token': localStorage.getItem('token')}, data: {param: printMatCodeNos}, method: 'POST', async: false, success: function (res) { if (res.code === 200){ layer.closeAll(); for (let i=0;i