var pageCurr; var printMatCodeNos = []; layui.config({ base: baseUrl + "/static/layui/lay/modules/" }).use(['table','laydate', 'form', 'treeTable', 'admin', 'xmSelect'], function(){ var table = layui.table; var $ = layui.jquery; var layer = layui.layer; var layDate = layui.laydate; var form = layui.form; var admin = layui.admin; var treeTable = layui.treeTable; var xmSelect = layui.xmSelect; // 商品分类数据 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: [[ {type: 'checkbox'} ,{type: 'numbers'} ,{field: 'name', align: 'left',title: '名称', minWidth: 150} ,{field: 'type$', align: 'center',title: '类型'} ,{field: 'leading', align: 'center',title: '负责人'} ,{field: 'img', align: 'center',title: '图片', hide: true} ,{field: 'sort', align: 'center',title: '排序', hide: true} ,{field: 'status$', align: 'center',title: '状态'} ,{field: 'updateTime$', align: 'center',title: '修改时间'} ,{field: 'updateBy$', align: 'center',title: '修改人员', hide: true} ,{field: 'memo', align: 'center',title: '备注', hide: true} ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:150} ]], done: function (data) { $('.ew-tree-table-box').css('height', '100%'); insTb.expandAll(); } }); // 数据渲染 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: [[ {type: 'checkbox'} // ,{field: 'uuid', align: 'center',title: '编号'} // ,{field: 'nodeId$', align: 'center',title: '所属区域',event: 'nodeId', style: 'cursor:pointer'} ,{field: 'tagId$', align: 'center',title: '归类', templet: '#tagTpl'} ,{field: 'matnr', align: 'center',title: '商品编号'} ,{field: 'maktx', align: 'center',title: '商品名称', minWidth: 300} // ,{field: 'name', align: 'center',title: '名称'} ,{field: 'specs', align: 'center',title: '规格'} ,{field: 'model', align: 'center',title: '型号', hide: true} ,{field: 'batch', align: 'center',title: '批号', hide: true} ,{field: 'unit', align: 'center',title: '单位'} ,{field: 'barcode', align: 'center',title: '条码', hide: true} // ,{field: 'docId', align: 'center',title: '单据类型'} // ,{field: 'docNum', align: 'center',title: '单据编号'} // ,{field: 'custName', align: 'center',title: '客户名称'} ,{field: 'itemNum', align: 'center',title: '品项数', hide: true} ,{field: 'count', align: 'center',title: '库存余量', hide: true} ,{field: 'weight', align: 'center',title: '重量', hide: true} // ,{field: 'status', align: 'center',title: '状态'} // ,{field: 'createBy$', align: 'center',title: '添加人员'} // ,{field: 'createTime$', align: 'center',title: '添加时间'} // ,{field: 'updateBy$', align: 'center',title: '修改人员'} // ,{field: 'updateTime$', align: 'center',title: '修改时间'} ,{field: 'memo', align: 'center',title: '备注', hide: true} ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:150} ]], 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: 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'; } }); } }); // 监听排序事件 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: function (res, curr, count) { if (res.code === 403) { top.location.href = baseUrl+"/"; } pageCurr=curr; limit(); } }); }); // 监听头工具栏事件 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('请选择数据'); } else { layer.confirm('确定删除'+(data.length===1?'此':data.length)+'条数据吗', 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(res.msg) } } }) }); } break; case 'exportData': layer.confirm('确定导出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(res.msg) } } }); }); break; // 批量打印 case "btnPrintBatch": printMatCodeNos = []; var data = checkStatus.data; if (data.length === 0){ layer.msg('请选择打印数据'); } else { layer.open({ type: 1, title: '批量打印 [数量'+ data.length +']', area: ['500px'], shadeClose: true, content: $('#printDataDiv'), success: function(layero, index){ for (var i = 0; i