| | |
| | | var pageCurr; |
| | | layui.use(['table','laydate', 'form'], function(){ |
| | | layui.use(['table','laydate', 'form','upload'], function(){ |
| | | var table = layui.table; |
| | | var $ = layui.jquery; |
| | | var layer = layui.layer; |
| | | var layDate = layui.laydate; |
| | | var upload = layui.upload; |
| | | var form = layui.form; |
| | | |
| | | // 数据渲染 |
| | |
| | | title: '新增', |
| | | maxmin: true, |
| | | area: [top.detailWidth, top.detailHeight], |
| | | shadeClose: true, |
| | | shadeClose: false, |
| | | content: 'matCode_detail.html', |
| | | success: function(layero, index){ |
| | | layer.getChildFrame('#data-detail-submit-edit', index).hide(); |
| | |
| | | layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"}); |
| | | } |
| | | }); |
| | | break; |
| | | case 'refreshData': |
| | | tableIns.reload({ |
| | | page: { |
| | | curr: pageCurr |
| | | } |
| | | }); |
| | | limit(); |
| | | break; |
| | | case 'deleteData': |
| | | var data = checkStatus.data; |
| | |
| | | }); |
| | | } |
| | | break; |
| | | // 导出 |
| | | case 'exportData': |
| | | layer.confirm('确定导出Excel吗', 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 = { |
| | | 'matCode': exportData, |
| | | 'fields': fields |
| | | }; |
| | | $.ajax({ |
| | | url: baseUrl+"/matCode/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) |
| | | } |
| | | } |
| | | }); |
| | | layer.open({ |
| | | type: 1, |
| | | title: '数据导出', |
| | | shadeClose: true, |
| | | content: $('#exportDataDiv'), |
| | | success: function(layero, index){ |
| | | |
| | | }, |
| | | end: function () { |
| | | $("#exportFileName").val(""); |
| | | $("#exportRowCount").val(""); |
| | | } |
| | | }) |
| | | break; |
| | | // 导入 |
| | | case 'intoData': |
| | | layer.open({ |
| | | type: 1, |
| | | title: '数据导入', |
| | | shadeClose: true, |
| | | content: $('#importDataDiv'), |
| | | success: function(layero, index){ |
| | | uploader.reload(); |
| | | }, |
| | | end: function () { |
| | | $('#uploadDesc').show(); |
| | | $('#uploadDemoView').hide(); |
| | | $('#fileMame').html(""); |
| | | } |
| | | }); |
| | | break; |
| | | // 批量打印 |
| | | case "btnPrintBatch": |
| | | layer.open({ |
| | | type: 1, |
| | | title: '批量打印', |
| | | shadeClose: true, |
| | | content: $('#printDataDiv'), |
| | | success: function(layero, index){ |
| | | |
| | | }, |
| | | end: function () { |
| | | } |
| | | }); |
| | | break; |
| | | } |
| | | }); |
| | | |
| | | // 导出excel |
| | | form.on('submit(exportDo)', function(data) { |
| | | layer.closeAll(); |
| | | layer.load(1, {shade: [0.1,'#fff']}); |
| | | location.href = baseUrl + "/matCode/export/auth?fileName="+$("#exportFileName").val()+"&rowCount="+$("#exportRowCount").val(); |
| | | layer.closeAll('loading'); |
| | | return false; |
| | | }); |
| | | |
| | | // 导入excel |
| | | var uploader = upload.render({ |
| | | elem: '#uploadEx' |
| | | , url: baseUrl + '/matCode/import/auth' |
| | | , headers: {token: localStorage.getItem('token')} |
| | | , accept: 'file' |
| | | , exts: 'xls|excel|xlsx' |
| | | , auto: false |
| | | , bindAction: '#uploadDo' |
| | | , before: function(obj){ |
| | | layer.closeAll(); |
| | | layer.load(1, {shade: [0.1,'#fff']}); |
| | | } |
| | | , choose: function(obj){ |
| | | $('#uploadDesc').hide(); |
| | | $('#uploadDemoView').show(); |
| | | obj.preview(function(index, file, result){ |
| | | $('#fileMame').html(file.name); |
| | | }); |
| | | } |
| | | , done: function (res) { |
| | | limit(); |
| | | $('#uploadDesc').show(); |
| | | $('#uploadDemoView').hide(); |
| | | $('#fileMame').html(""); |
| | | layer.closeAll('loading'); |
| | | layer.msg(res.msg); |
| | | } |
| | | , error: function(index, upload){ |
| | | layer.closeAll('loading'); |
| | | } |
| | | }) |
| | | |
| | | // 监听行工具事件 |
| | | table.on('tool(matCode)', function(obj){ |
| | |
| | | title: '详情', |
| | | maxmin: true, |
| | | area: [top.detailWidth, top.detailHeight], |
| | | shadeClose: false, |
| | | shadeClose: true, |
| | | content: 'matCode_detail.html', |
| | | success: function(layero, index){ |
| | | setFormVal(layer.getChildFrame('#detail', index), data, true); |
| | |
| | | }); |
| | | } |
| | | break; |
| | | // 打印 |
| | | case "btnPrint": |
| | | layer.open({ |
| | | type: 1, |
| | | title: '打印', |
| | | shadeClose: true, |
| | | content: $('#printDataDiv'), |
| | | success: function(layero, index){ |
| | | |
| | | }, |
| | | end: function () { |
| | | } |
| | | }); |
| | | break; |
| | | } |
| | | }); |
| | | |