| var pageCurr; | 
| var printMatCodeNos = []; | 
| 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; | 
|   | 
|     // 数据渲染 | 
|     tableIns = table.render({ | 
|         elem: '#matCode', | 
|         headers: {token: localStorage.getItem('token')}, | 
|         url: baseUrl+'/matCode/list/auth', | 
|         page: true, | 
|         limit: 16, | 
|         limits: [16, 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: 'matNo', align: 'center',title: '物料编码'} | 
|             ,{field: 'barcode', align: 'center',title: '条码'} | 
|             ,{field: 'matName', align: 'center',title: '物料名称'} | 
|             ,{field: 'str1', align: 'center',title: '物料单位'} | 
|             ,{field: 'str2', align: 'center',title: '物料规格'} | 
|             // ,{field: 'str3', align: 'center',title: ''} | 
|             // ,{field: 'str4', align: 'center',title: ''} | 
|             // ,{field: 'str5', align: 'center',title: ''} | 
|             // ,{field: 'str6', align: 'center',title: ''} | 
|             // ,{field: 'str7', align: 'center',title: ''} | 
|             // ,{field: 'str8', align: 'center',title: ''} | 
|             // ,{field: 'str9', align: 'center',title: ''} | 
|             // ,{field: 'str10', align: 'center',title: ''} | 
|             // ,{field: 'str11', align: 'center',title: ''} | 
|             // ,{field: 'str12', align: 'center',title: ''} | 
|             // ,{field: 'str13', align: 'center',title: ''} | 
|             // ,{field: 'str14', align: 'center',title: ''} | 
|             // ,{field: 'str15', align: 'center',title: ''} | 
|             // ,{field: 'str16', align: 'center',title: ''} | 
|             // ,{field: 'str17', align: 'center',title: ''} | 
|             // ,{field: 'str18', align: 'center',title: ''} | 
|             // ,{field: 'str19', align: 'center',title: ''} | 
|             // ,{field: 'str20', align: 'center',title: ''} | 
|             // ,{field: 'str21', align: 'center',title: ''} | 
|             // ,{field: 'str22', align: 'center',title: ''} | 
|             // ,{field: 'str23', align: 'center',title: ''} | 
|             // ,{field: 'num1', align: 'center',title: ''} | 
|             // ,{field: 'num2', align: 'center',title: ''} | 
|             // ,{field: 'num3', align: 'center',title: ''} | 
|             // ,{field: 'num4', align: 'center',title: ''} | 
|             // ,{field: 'num5', align: 'center',title: ''} | 
|             // ,{field: 'num6', align: 'center',title: ''} | 
|             // ,{field: 'date1$', align: 'center',title: ''} | 
|             // ,{field: 'appeUser$', align: 'center',title: '创建者',event: 'appeUser', style: 'cursor:pointer'} | 
|             // ,{field: 'appeTime$', align: 'center',title: '添加时间'} | 
|             // ,{field: 'modiUser$', align: 'center',title: '修改人员',event: 'modiUser', style: 'cursor:pointer'} | 
|             // ,{field: 'modiTime$', align: 'center',title: '修改时间'} | 
|             // ,{field: 'status', align: 'center',title: ''} | 
|   | 
|             ,{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(matCode)', 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], | 
|                     shadeClose: false, | 
|                     content: 'matCode_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+"/matCode/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.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": | 
|                 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<data.length;i++) { | 
|                                 printMatCodeNos.push(data[i].matNo); | 
|                             } | 
|                         }, | 
|                         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){ | 
|         var data = obj.data; | 
|         switch (obj.event) { | 
|             // 详情 | 
|             case 'detail': | 
|                 layer.open({ | 
|                     type: 2, | 
|                     title: '详情', | 
|                     maxmin: true, | 
|                     area: [top.detailWidth, top.detailHeight], | 
|                     shadeClose: true, | 
|                     content: 'matCode_detail.html', | 
|                     success: function(layero, index){ | 
|                         setFormVal(layer.getChildFrame('#detail', index), data, true); | 
|                         top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true); | 
|                         layer.getChildFrame('#data-detail-submit-save,#data-detail-submit-edit,#prompt', index).hide(); | 
|                         layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"}); | 
|                         layero.find('iframe')[0].contentWindow.layui.form.render('select'); | 
|                         layero.find('iframe')[0].contentWindow.layui.form.render('checkbox'); | 
|                     } | 
|                 }); | 
|                 break; | 
|             // 编辑 | 
|             case 'edit': | 
|                 layer.open({ | 
|                     type: 2, | 
|                     title: '修改', | 
|                     maxmin: true, | 
|                     area: [top.detailWidth, top.detailHeight], | 
|                     shadeClose: false, | 
|                     content: 'matCode_detail.html', | 
|                     success: function(layero, index){ | 
|                         layer.getChildFrame('#data-detail-submit-save', index).hide(); | 
|                         setFormVal(layer.getChildFrame('#detail', index), data, false); | 
|                         top.convertDisabled(layer.getChildFrame('#data-detail :input', index), false); | 
|                         top.convertDisabled(layer.getChildFrame('#matNo', index), true); | 
|                         layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"}); | 
|                         layero.find('iframe')[0].contentWindow.layui.form.render('select'); | 
|                         layero.find('iframe')[0].contentWindow.layui.form.render('checkbox'); | 
|                     } | 
|                 }); | 
|                 break; | 
|             // 打印 | 
|             case "btnPrint": | 
|                 printMatCodeNos = []; | 
|                 layer.open({ | 
|                     type: 1, | 
|                     title: data.matNo + ' [数量:1]', | 
|                     area: ['500px'], | 
|                     shadeClose: true, | 
|                     content: $('#printDataDiv'), | 
|                     success: function(layero, index){ | 
|                         layer.iframeAuto(index); | 
|                         printMatCodeNos.push(data.matNo); | 
|                     }, | 
|                     end: function () { | 
|                     } | 
|                 }); | 
|                 break; | 
|         } | 
|     }); | 
|   | 
|     // 模板选择 | 
|     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+"/macCode/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<res.data.length;i++){ | 
|                         var templateDom = $("#templatePreview"+templateNo); | 
|                         var className = templateDom.attr("class"); | 
|                         if (className === 'template-barcode') { | 
|                             res.data[i]["barcodeUrl"]=baseUrl+"/macCode/code/auth?type=1¶m="+res.data[i].barcode; | 
|                         } else { | 
|                             res.data[i]["barcodeUrl"]=baseUrl+"/macCode/code/auth?type=2¶m="+res.data[i].barcode; | 
|                         } | 
|                     } | 
|                     var tpl = templateDom.html(); | 
|                     var template = Handlebars.compile(tpl); | 
|                     var html = template(res); | 
|                     let box = $("#box"); | 
|                     box.html(html);box.show();box.print();box.hide(); | 
|                 } else if (res.code === 403){ | 
|                     top.location.href = baseUrl+"/"; | 
|                 }else { | 
|                     layer.msg(res.msg) | 
|                 } | 
|             } | 
|         }) | 
|     }) | 
|   | 
|     // 数据保存动作 | 
|     form.on('submit(save)', function () { | 
|         if (banMsg != null){ | 
|             layer.msg(banMsg); | 
|             return; | 
|         } | 
|         method("add"); | 
|     }); | 
|   | 
|     // 数据修改动作 | 
|     form.on('submit(edit)', function () { | 
|         method("update") | 
|     }); | 
|   | 
|     function method(name){ | 
|         var index = layer.load(1, { | 
|             shade: [0.5,'#000'] | 
|         }); | 
|         var data = { | 
|             matNo: $('#matNo').val(), | 
|             barcode: $('#barcode').val(), | 
|             matName: $('#matName').val(), | 
|             str1: $('#str1').val(), | 
|             str2: $('#str2').val(), | 
|             str3: $('#str3').val(), | 
|             str4: $('#str4').val(), | 
|             str5: $('#str5').val(), | 
|             str6: $('#str6').val(), | 
|             str7: $('#str7').val(), | 
|             str8: $('#str8').val(), | 
|             str9: $('#str9').val(), | 
|             str10: $('#str10').val(), | 
|             str11: $('#str11').val(), | 
|             str12: $('#str12').val(), | 
|             str13: $('#str13').val(), | 
|             str14: $('#str14').val(), | 
|             str15: $('#str15').val(), | 
|             str16: $('#str16').val(), | 
|             str17: $('#str17').val(), | 
|             str18: $('#str18').val(), | 
|             str19: $('#str19').val(), | 
|             str20: $('#str20').val(), | 
|             str21: $('#str21').val(), | 
|             str22: $('#str22').val(), | 
|             str23: $('#str23').val(), | 
|             num1: $('#num1').val(), | 
|             num2: $('#num2').val(), | 
|             num3: $('#num3').val(), | 
|             num4: $('#num4').val(), | 
|             num5: $('#num5').val(), | 
|             num6: $('#num6').val(), | 
|             date1: top.strToDate($('#date1\\$').val()), | 
|             appeUser: $('#appeUser').val(), | 
|             appeTime: top.strToDate($('#appeTime\\$').val()), | 
|             modiUser: $('#modiUser').val(), | 
|             modiTime: top.strToDate($('#modiTime\\$').val()), | 
|             status: $('#status').val(), | 
|   | 
|         }; | 
|         $.ajax({ | 
|             url: baseUrl+"/matCode/"+name+"/auth", | 
|             headers: {'token': localStorage.getItem('token')}, | 
|             data: top.reObject(data), | 
|             method: 'POST', | 
|             success: function (res) { | 
|                 if (res.code === 200){ | 
|                     parent.layer.closeAll(); | 
|                     parent.$(".layui-laypage-btn")[0].click(); | 
|                     $("#data-detail :input").each(function () { | 
|                         $(this).val(""); | 
|                     }); | 
|                 } else if (res.code === 403){ | 
|                     top.location.href = baseUrl+"/"; | 
|                 }else { | 
|                     layer.msg(res.msg) | 
|                 } | 
|                 layer.close(index); | 
|             } | 
|         }) | 
|     } | 
|   | 
|     // 复选框事件 | 
|     form.on('checkbox(detailCheckbox)', function (data) { | 
|         var el = data.elem; | 
|         if (el.checked) { | 
|             $(el).val('Y'); | 
|         } else { | 
|             $(el).val('N'); | 
|         } | 
|     }); | 
|   | 
|     // 搜索栏搜索事件 | 
|     form.on('submit(search)', function (data) { | 
|         pageCurr = 1; | 
|         tableReload(false); | 
|     }); | 
|   | 
|     // 搜索栏重置事件 | 
|     form.on('submit(reset)', function (data) { | 
|         pageCurr = 1; | 
|         clearFormVal($('#search-box')); | 
|         tableReload(false); | 
|     }); | 
|   | 
|     // 时间选择器 | 
|     layDate.render({ | 
|         elem: '#date1\\$', | 
|         type: 'datetime' | 
|     }); | 
|     layDate.render({ | 
|         elem: '#appeTime\\$', | 
|         type: 'datetime' | 
|     }); | 
|     layDate.render({ | 
|         elem: '#modiTime\\$', | 
|         type: 'datetime' | 
|     }); | 
|   | 
|   | 
| }); | 
|   | 
| // 关闭动作 | 
| $(document).on('click','#data-detail-close', function () { | 
|     parent.layer.closeAll(); | 
| }); | 
|   | 
| function tableReload(child) { | 
|     var searchData = {}; | 
|     $.each($('#search-box [name]').serializeArray(), function() { | 
|         searchData[this.name] = this.value; | 
|     }); | 
|     (child ? parent.tableIns : tableIns).reload({ | 
|         where: searchData, | 
|         page: { | 
|             curr: pageCurr | 
|         }, | 
|         done: function (res, curr, count) { | 
|             if (res.code === 403) { | 
|                 top.location.href = baseUrl+"/"; | 
|             } | 
|             pageCurr=curr; | 
|             if (res.data.length === 0 && count !== 0) { | 
|                 tableIns.reload({ | 
|                     where: searchData, | 
|                     page: { | 
|                         curr: pageCurr-1 | 
|                     } | 
|                 }); | 
|                 pageCurr -= 1; | 
|             } | 
|             limit(child); | 
|         } | 
|     }); | 
| } | 
|   | 
| function setFormVal(el, data, showImg) { | 
|     for (var val in data) { | 
|         var find = el.find(":input[id='" + val + "']"); | 
|         if (find[0]!=null){ | 
|             if (find[0].type === 'checkbox'){ | 
|                 if (data[val]==='Y'){ | 
|                     find.attr("checked","checked"); | 
|                     find.val('Y'); | 
|                 } else { | 
|                     find.remove("checked"); | 
|                     find.val('N'); | 
|                 } | 
|                 continue; | 
|             } | 
|         } | 
|         find.val(data[val]); | 
|         if (showImg){ | 
|             var next = find.next(); | 
|             if (next.get(0)){ | 
|                 if (next.get(0).localName === "img") { | 
|                     find.hide(); | 
|                     next.attr("src", data[val]); | 
|                     next.show(); | 
|                 } | 
|             } | 
|         } | 
|     } | 
| } | 
|   | 
| function clearFormVal(el) { | 
|     $(':input', el) | 
|         .val('') | 
|         .removeAttr('checked') | 
|         .removeAttr('selected'); | 
| } | 
|   | 
| function detailScreen(index) { | 
|     var detail = layer.getChildFrame('#data-detail', index); | 
|     var height = detail.height()+60; | 
|     if (height > ($(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(); | 
|     } | 
| }); |