|  |  | 
 |  |  | layui.use(['table','laydate', 'form'], function() { | 
 |  |  | var matCodeLayerIdx; | 
 |  |  | var initCountVal = 0; | 
 |  |  | var matCodeData = []; | 
 |  |  | function getCol() { | 
 |  |  |     var cols = [ | 
 |  |  |         {fixed: 'left', field: 'anfme', title: '数量(必填)', align: 'center', edit:'text', width: 120,  style:'color: blue;font-weight: bold'}, | 
 |  |  |         {field: 'batch', title: '批号(选填)', align: 'center', edit:'text', width: 200,  style:'color: block;font-weight: bold'} | 
 |  |  |     ]; | 
 |  |  |     cols.push.apply(cols, matCols); | 
 |  |  |     cols.push({fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width: 80}) | 
 |  |  |     return cols; | 
 |  |  | } | 
 |  |  |  | 
 |  |  | layui.config({ | 
 |  |  |     base: baseUrl + "/static/layui/lay/modules/" | 
 |  |  | }).use(['admin', 'table','laydate', 'form'], function() { | 
 |  |  |     var table = layui.table; | 
 |  |  |     var $ = layui.jquery; | 
 |  |  |     var layer = layui.layer; | 
 |  |  |     var layDate = layui.laydate; | 
 |  |  |     var form = layui.form; | 
 |  |  |     var admin = layui.admin; | 
 |  |  |  | 
 |  |  |     tableIns = table.render({ | 
 |  |  |         elem: '#chooseData', | 
 |  |  | 
 |  |  |         even: true, | 
 |  |  |         limit: 500, | 
 |  |  |         cellMinWidth: 50, | 
 |  |  |         cols: [[ | 
 |  |  |             {type: 'checkbox'}, | 
 |  |  |             {field: 'matNo', align: 'center', title: '物料编码', sort: 'true'}, | 
 |  |  |             {field: 'barcode', align: 'center', title: '条码'}, | 
 |  |  |             {field: 'matName', align: 'center', title: '物料名称'}, | 
 |  |  |             {field: 'str1', align: 'center', title: '物料单位'}, | 
 |  |  |             {field: 'str2', align: 'center', title: '物料规格'}, | 
 |  |  |             {field: 'count', title: '数量', align: 'center', edit:'text', width: 100} | 
 |  |  |         ]], | 
 |  |  |         toolbar: '#toolbar', | 
 |  |  |         cols: [getCol()], | 
 |  |  |         done: function (res, curr, count) { | 
 |  |  |             limit(); | 
 |  |  |             getInBound(); | 
 |  |  |         } | 
 |  |  |     }); | 
 |  |  |  | 
 |  |  |     // 页面修改 | 
 |  |  |     table.on('edit(chooseData)', function (obj) { | 
 |  |  |         let index = obj.tr.attr("data-index"); | 
 |  |  |         let data = matCodeData[index]; | 
 |  |  |         let modify = true; | 
 |  |  |         if (obj.field === 'anfme'){ | 
 |  |  |             let vle = Number(obj.value); | 
 |  |  |             if (isNaN(vle)) { | 
 |  |  |                 layer.msg("请输入数字", {icon: 2}); | 
 |  |  |                 modify = false; | 
 |  |  |             } else { | 
 |  |  |                 if (vle <= 0) { | 
 |  |  |                     layer.msg("数量必须大于零", {icon: 2}); | 
 |  |  |                     modify = false; | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         if (modify) { | 
 |  |  |             data[obj.field] = obj.value; | 
 |  |  |         } | 
 |  |  |         tableIns.reload({data: matCodeData}); | 
 |  |  |     }); | 
 |  |  |  | 
 |  |  |     // 监听头工具栏事件 | 
 |  |  |     table.on('toolbar(chooseData)', function (obj) { | 
 |  |  |         var checkStatus = table.checkStatus(obj.config.id); | 
 |  |  |         var data = checkStatus.data; | 
 |  |  |         switch(obj.event) { | 
 |  |  |             case 'comb': | 
 |  |  |                 // 判断是否存在物料 | 
 |  |  |                 if (matCodeData.length === 0) { | 
 |  |  |                     layer.msg("请先提取商品", {icon: 2}); | 
 |  |  |                     return; | 
 |  |  |                 } | 
 |  |  |                 // 判断物料数量是否存在异常 | 
 |  |  |                 for (var i=0;i<matCodeData.length;i++){ | 
 |  |  |                     if (isNaN(matCodeData[i].anfme)) { | 
 |  |  |                         layer.msg("请输入数字", {icon: 2}); | 
 |  |  |                         return; | 
 |  |  |                     } | 
 |  |  |                     if (matCodeData[i].anfme <= 0){ | 
 |  |  |                         layer.msg("数量必须大于零", {icon: 2}); | 
 |  |  |                         return; | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |                 let devpNo = $('#putSiteSelect').val(); | 
 |  |  |                 if (isEmpty(devpNo)) { | 
 |  |  |                     layer.msg("请选择入库站", {icon: 2}); | 
 |  |  |                     return; | 
 |  |  |                 } | 
 |  |  |                 $.ajax({ | 
 |  |  |                     url: baseUrl+"/full/store/put/start", | 
 |  |  |                     headers: {'token': localStorage.getItem('token')}, | 
 |  |  |                     data: JSON.stringify({ | 
 |  |  |                         devpNo: Number(devpNo), | 
 |  |  |                         list: matCodeData | 
 |  |  |                     }), | 
 |  |  |                     contentType:'application/json;charset=UTF-8', | 
 |  |  |                     method: 'POST', | 
 |  |  |                     async: false, | 
 |  |  |                     success: function (res) { | 
 |  |  |                         if (res.code === 200){ | 
 |  |  |                             layer.msg("入库启动成功,目标库位:" + res.data, {icon: 1}); | 
 |  |  |                             matCodeData = []; | 
 |  |  |                             $('#focusMatByMat').val(""); | 
 |  |  |                             tableIns.reload({data: matCodeData,done:function (res) { limit(); getInBound();}}); | 
 |  |  |                         } else if (res.code === 403){ | 
 |  |  |                             top.location.href = baseUrl+"/"; | 
 |  |  |                         }else { | 
 |  |  |                             layer.msg(res.msg, {icon: 2}) | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                 }) | 
 |  |  |                 break; | 
 |  |  |             default: | 
 |  |  |                 break; | 
 |  |  |         } | 
 |  |  |     }); | 
 |  |  |  | 
 |  |  |     // 监听行工具事件 | 
 |  |  |     table.on('tool(chooseData)', function(obj){ | 
 |  |  |         switch (obj.event) { | 
 |  |  |             case 'remove': | 
 |  |  |                 let index = obj.tr.attr("data-index"); | 
 |  |  |                 matCodeData.splice(index, 1); | 
 |  |  |                 tableIns.reload({data: matCodeData}); | 
 |  |  |                 break; | 
 |  |  |         } | 
 |  |  |     }); | 
 |  |  |  | 
 |  |  |     // 获取可用入库站点 | 
 |  |  |     function getInBound() { | 
 |  |  |         $.ajax({ | 
 |  |  |             url: baseUrl + "/available/put/site", | 
 |  |  |             headers: {'token': localStorage.getItem('token')}, | 
 |  |  |             method: 'POST', | 
 |  |  |             success: function (res) { | 
 |  |  |                 if (res.code === 200) { | 
 |  |  |                     var tpl = $("#putSiteSelectTemplate").html(); | 
 |  |  |                     var template = Handlebars.compile(tpl); | 
 |  |  |                     var html = template(res); | 
 |  |  |                     $('#putSiteSelect').append(html); | 
 |  |  |                     form.render('select'); | 
 |  |  |                 } else if (res.code === 403) { | 
 |  |  |                     top.location.href = baseUrl + "/"; | 
 |  |  |                 } else { | 
 |  |  |                     layer.msg(res.msg, {icon: 2}) | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         }) | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     // 提取物料 | 
 |  |  |     $(document).on('click','#mat-query', function () { | 
 |  |  |         let loadIndex = layer.msg('请求中...', {icon: 16, shade: 0.01, time: false}); | 
 |  |  |         matCodeLayerIdx = admin.open({ | 
 |  |  |             type: 2, | 
 |  |  |             title: false, | 
 |  |  |             closeBtn: false, | 
 |  |  |             maxmin: false, | 
 |  |  |             area: ['90%', '85%'], | 
 |  |  |             shadeClose: true, | 
 |  |  |             content: 'matQuery.html', | 
 |  |  |             success: function(layero, index){ | 
 |  |  |                 layer.close(loadIndex); | 
 |  |  |             } | 
 |  |  |         }); | 
 |  |  |     }) | 
 |  |  |  | 
 |  |  | }); | 
 |  |  |  | 
 |  |  |  | 
 |  |  | // 提取物料 | 
 |  |  | var matCodeLayerIdx; | 
 |  |  | function getMat() { | 
 |  |  |     tableIns.reload({data: []}); | 
 |  |  |     matCodeLayerIdx = layer.open({ | 
 |  |  |         type: 2, | 
 |  |  |         title: '库位物料', | 
 |  |  |         maxmin: true, | 
 |  |  |         area: [top.detailWidth, top.detailHeight], | 
 |  |  |         shadeClose: true, | 
 |  |  |         content: 'matQuery.html', | 
 |  |  |         success: function(layero, index){ | 
 |  |  |  | 
 |  |  | // 扫码 | 
 |  |  | function focusMat(el) { | 
 |  |  |     if (isEmpty(el.value)) { | 
 |  |  |         return | 
 |  |  |     } | 
 |  |  |     $.ajax({ | 
 |  |  |         url: baseUrl + "/mat/" + el.value + "/auth", | 
 |  |  |         headers: {'token': localStorage.getItem('token')}, | 
 |  |  |         method: 'GET', | 
 |  |  |         success: function (res) { | 
 |  |  |             if (res.code === 200) { | 
 |  |  |                 matCodeData = []; | 
 |  |  |                 var param = new Array(); | 
 |  |  |                 param[0] = res.data; | 
 |  |  |                 addTableData(param); | 
 |  |  |             } else if (res.code === 403) { | 
 |  |  |                 top.location.href = baseUrl + "/"; | 
 |  |  |             } else { | 
 |  |  |                 layer.msg(res.msg, {icon: 2}) | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |     }); | 
 |  |  | } | 
 |  |  |     }) | 
 |  |  | } | 
 |  |  |  | 
 |  |  | // 添加表格数据 | 
 |  |  | function addTableData(list) { | 
 |  |  |     list.map(function (d) { | 
 |  |  |         d['anfme'] = initCountVal; | 
 |  |  |     }) | 
 |  |  |     matCodeData.push.apply(matCodeData, list); | 
 |  |  |     tableIns.reload({data: matCodeData}); | 
 |  |  |     layer.close(matCodeLayerIdx); | 
 |  |  | } |