|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var initCountVal = 0; | 
|---|
|  |  |  | var matCodeData = []; | 
|---|
|  |  |  | function getCol() { | 
|---|
|  |  |  | var cols = [ | 
|---|
|  |  |  | {fixed: 'left', field: 'count', title: '数量(必填)', align: 'center', edit:'text', width: 120,  style:'color: blue;font-weight: bold'} | 
|---|
|  |  |  | ]; | 
|---|
|  |  |  | cols.push.apply(cols, matCols); | 
|---|
|  |  |  | cols.push({fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:80}) | 
|---|
|  |  |  | return cols; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | layui.use(['table','laydate', 'form'], function() { | 
|---|
|  |  |  | var table = layui.table; | 
|---|
|  |  |  | var $ = layui.jquery; | 
|---|
|  |  |  | 
|---|
|  |  |  | limit: 500, | 
|---|
|  |  |  | cellMinWidth: 50, | 
|---|
|  |  |  | toolbar: '#toolbar', | 
|---|
|  |  |  | 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} | 
|---|
|  |  |  | ]], | 
|---|
|  |  |  | cols: [getCol()], | 
|---|
|  |  |  | done: function (res, curr, count) { | 
|---|
|  |  |  | $('td[data-field=count] div').html(initCountVal); | 
|---|
|  |  |  | setMatCodeData(res.data); | 
|---|
|  |  |  | limit(); | 
|---|
|  |  |  | getInBound(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 监听排序事件 | 
|---|
|  |  |  | table.on('sort(chooseData)', function (obj) { | 
|---|
|  |  |  | var searchData = {}; | 
|---|
|  |  |  | $.each($('#search-box [name]').serializeArray(), function() { | 
|---|
|  |  |  | searchData[this.name] = this.value; | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | searchData['orderByField'] = obj.field; | 
|---|
|  |  |  | searchData['orderByType'] = obj.type; | 
|---|
|  |  |  | matQueryTable.reload({ | 
|---|
|  |  |  | where: searchData, | 
|---|
|  |  |  | page: { | 
|---|
|  |  |  | curr: 1 | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | done: function (res, curr, count) { | 
|---|
|  |  |  | if (res.code === 403) { | 
|---|
|  |  |  | top.location.href = baseUrl+"/"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | pageCurr=curr; | 
|---|
|  |  |  | limit(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | // 页面修改 | 
|---|
|  |  |  | table.on('edit(chooseData)', function (obj) { | 
|---|
|  |  |  | updateMatCodeData(obj.data.matNo, Number(obj.value)); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 监听头工具栏事件 | 
|---|
|  |  |  | 
|---|
|  |  |  | var data = checkStatus.data; | 
|---|
|  |  |  | switch(obj.event) { | 
|---|
|  |  |  | case 'comb': | 
|---|
|  |  |  | if (data.length === 0){ | 
|---|
|  |  |  | layer.msg('请选择数据'); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | layer.open({ | 
|---|
|  |  |  | type: 1, | 
|---|
|  |  |  | title: '组盘', | 
|---|
|  |  |  | maxmin: true, | 
|---|
|  |  |  | shadeClose: true, | 
|---|
|  |  |  | content: $('#combDiv'), | 
|---|
|  |  |  | success: function (layero, index) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | // 判断是否存在物料 | 
|---|
|  |  |  | if (matCodeData.length === 0) { | 
|---|
|  |  |  | layer.msg("请先添加物料"); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 判断物料数量是否存在异常 | 
|---|
|  |  |  | for (var i=0;i<matCodeData.length;i++){ | 
|---|
|  |  |  | if (isNaN(matCodeData[i].count)) { | 
|---|
|  |  |  | layer.msg("请输入数字"); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (matCodeData[i].count === 0){ | 
|---|
|  |  |  | layer.msg("数量不能为零"); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | $.ajax({ | 
|---|
|  |  |  | url: baseUrl+"/full/store/put/start", | 
|---|
|  |  |  | headers: {'token': localStorage.getItem('token')}, | 
|---|
|  |  |  | data: JSON.stringify({ | 
|---|
|  |  |  | devpNo: Number($('#putSiteSelect').val()), | 
|---|
|  |  |  | list: matCodeData | 
|---|
|  |  |  | }), | 
|---|
|  |  |  | contentType:'application/json;charset=UTF-8', | 
|---|
|  |  |  | method: 'POST', | 
|---|
|  |  |  | async: false, | 
|---|
|  |  |  | success: function (res) { | 
|---|
|  |  |  | if (res.code === 200){ | 
|---|
|  |  |  | layer.msg("入库启动成功,目标库位:" + res.data); | 
|---|
|  |  |  | matCodeData = []; | 
|---|
|  |  |  | tableIns.reload({data: matCodeData,done:function (res) { limit(); getInBound();}}); | 
|---|
|  |  |  | } else if (res.code === 403){ | 
|---|
|  |  |  | top.location.href = baseUrl+"/"; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | layer.msg(res.msg) | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 监听行工具事件 | 
|---|
|  |  |  | table.on('tool(chooseData)', function(obj){ | 
|---|
|  |  |  | var data = obj.data; | 
|---|
|  |  |  | switch (obj.event) { | 
|---|
|  |  |  | case 'remove': | 
|---|
|  |  |  | for (var i = matCodeData.length - 1; i >= 0; i--) { | 
|---|
|  |  |  | if (matCodeData[i].matNo === data.matNo) { | 
|---|
|  |  |  | matCodeData.splice(i, 1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | tableIns.reload({data: matCodeData,done:function (res) { | 
|---|
|  |  |  | limit(); | 
|---|
|  |  |  | getInBound(); | 
|---|
|  |  |  | // 覆盖render方法的done | 
|---|
|  |  |  | }}); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | function setMatCodeData(data) { | 
|---|
|  |  |  | matCodeData = data; | 
|---|
|  |  |  | for (var i=0;i<matCodeData.length;i++){ | 
|---|
|  |  |  | matCodeData[i]["count"] = initCountVal; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | function updateMatCodeData(matNo, count) { | 
|---|
|  |  |  | if (isNaN(count)) { | 
|---|
|  |  |  | layer.msg("请输入数字"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (count > 0) { | 
|---|
|  |  |  | for (var i=0;i<matCodeData.length;i++){ | 
|---|
|  |  |  | if (matCodeData[i]["matNo"] === matNo){ | 
|---|
|  |  |  | matCodeData[i]["count"] = count; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | layer.msg("数量必须大于零"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | tableIns.reload({data: matCodeData,done:function (res) { | 
|---|
|  |  |  | limit(); | 
|---|
|  |  |  | getInBound(); | 
|---|
|  |  |  | // 覆盖render方法的done | 
|---|
|  |  |  | }}); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 获取可用入库站点 | 
|---|
|  |  |  | 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) | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 提取物料 | 
|---|
|  |  |  | var matCodeLayerIdx; | 
|---|
|  |  |  | function getMat() { | 
|---|
|  |  |  | tableIns.reload({data: []}); | 
|---|
|  |  |  | matCodeLayerIdx = layer.open({ | 
|---|
|  |  |  | type: 2, | 
|---|
|  |  |  | title: '提取物料', | 
|---|
|  |  |  | 
|---|
|  |  |  | success: function(layero, index){ | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 添加表格数据 | 
|---|
|  |  |  | function addTableData(data) { | 
|---|
|  |  |  | for (var i=0;i<data.length;i++){ | 
|---|
|  |  |  | let pass = false; | 
|---|
|  |  |  | for (var j=0;j<matCodeData.length;j++){ | 
|---|
|  |  |  | if (data[i].matNo === matCodeData[j].matNo) { | 
|---|
|  |  |  | pass = true; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pass) { | 
|---|
|  |  |  | data.splice(i--, 1); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | data[i]["count"] = initCountVal; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | matCodeData.push.apply(matCodeData, data); | 
|---|
|  |  |  | tableIns.reload({data: matCodeData}); | 
|---|
|  |  |  | layer.close(matCodeLayerIdx); | 
|---|
|  |  |  | } | 
|---|