var pageCurr; var printMatCodeNos = []; layui.use(['table','laydate', 'form'], function(){ var table = layui.table; var $ = layui.jquery; var layer = layui.layer; var layDate = layui.laydate; var form = layui.form; // 数据渲染 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], even: true, toolbar: '#toolbar', cellMinWidth: 50, cols: [[ {type: 'checkbox'} // ,{field: 'id', title: 'ID', sort: true,align: 'center', fixed: 'left', width: 80} // ,{field: 'id', align: 'center',title: 'ID'} // ,{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': layer.open({ type: 2, title: '新增', maxmin: true, area: [top.detailWidth, top.detailHeight], content: 'mat_detail.html', success: function(layero, index){ layer.getChildFrame('#data-detail-submit-edit', index).hide(); clearFormVal(layer.getChildFrame('#detail', index)); layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"}); } }); 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 ($(window).height()*0.9)) { height = ($(window).height()*0.8); } layer.style(index, { // top: (($(window).height()-height)/3)+"px", height: height+'px' }); } $('body').keydown(function () { if (event.keyCode === 13) { $("#search").click(); } });