var locDetlLayerIdx; var locDetlData = []; function getCol() { var cols = [ {field: 'count', align: 'center',title: '出库数量', edit:'text', width: 130, style:'color: blue;font-weight: bold'} ,{field: 'anfme', align: 'center',title: '库存数量'} ,{field: 'locNo$', align: 'center',title: '库位号'} ]; arrRemove(detlCols, 'field', 'anfme'); cols.push.apply(cols, detlCols); cols.push({fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width: 80}) return cols; } function getColbiao() { var colsbiao = [ {type: 'checkbox'} ,{type: 'numbers', title: '#'} ,{field: 'orderNo', align: 'center',title: '单据编号', templet: '#orderNoTpl', width: 160} ,{field: 'matnr', align: 'center',title: '商品编码', width: 160} ,{field: 'maktx', align: 'center',title: '商品名称', width: 200} ,{field: 'batch', align: 'center',title: '批号'} ,{field: 'specs', align: 'center',title: '规格'} // ,{field: 'anfme', align: 'center',title: '数量'} // ,{field: 'qty', align: 'center',title: '作业数量', style: 'font-weight: bold'} ,{field: 'enableQty', align: 'center',title: '待出数量', style: 'font-weight: bold'} // ,{field: 'name', align: 'center',title: '名称'} // ,{field: 'model', align: 'center',title: '型号'} ,{field: 'unit', align: 'center',title: '单位', hide: true} ,{field: 'barcode', align: 'center',title: '商品条码', hide: true} // ,{field: 'supplier', align: 'center',title: '供应商'} // ,{field: 'unitPrice', align: 'center',title: '单价'} // ,{field: 'itemNum', align: 'center',title: '品项数'} // ,{field: 'count', align: 'center',title: '数量'} // ,{field: 'weight', align: 'center',title: '重量'} // ,{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: '备注'} ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate1', width: 200} ]; return colsbiao; } layui.config({ base: baseUrl + "/static/layui/lay/modules/" }).extend({ notice: 'notice/notice', }).use(['table','laydate', 'form', 'tableMerge', 'admin' , 'notice'], function() { var table = layui.table; var $ = layui.jquery; var layer = layui.layer; var form = layui.form; var admin = layui.admin; var tableMerge = layui.tableMerge; var notice = layui.notice; tableIns = table.render({ elem: '#chooseData', headers: {token: localStorage.getItem('token')}, data: [], even: true, toolbar: '#toolbar', cellMinWidth: 50, limit: 500, cols: [getCol()], done: function(res, curr, count) { limit(); getOutBound(); } }); tableInss = table.render({ elem: '#chooseDatas', headers: {token: localStorage.getItem('token')}, data: [], even: true, toolbar: '#toolbar', cellMinWidth: 50, limit: 500, cols: [getColbiao()], done: function(res, curr, count) { limit(); getOutBound(); } }); tableInss.reload({data:parent.da}) // 页面修改 table.on('edit(chooseData)', function (obj) { let index = obj.tr.attr("data-index"); let data = locDetlData[index]; let modify = true; if (obj.field === 'count'){ 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 (vle > Number(data.anfme)) { layer.msg("出库数量不得大于库存数量", {icon: 2}); modify = false; } } } if (modify) { data[obj.field] = obj.value; } tableIns.reload({data: locDetlData}); }); // 监听头工具栏事件 table.on('toolbar(chooseData)', function (obj) { switch (obj.event) { case 'outbound1': if (locDetlData.length === 0) { layer.msg("请选择数据"); return; } console.log(locDetlData); pakoutPreview(parent.da[0].id, locDetlData); break; } }); function pakoutPreview(id, data) { console.log("id=" + id) let loadIndex = layer.load(2); var da = { "id": JSON.stringify(id), "list": data } $.ajax({ url: baseUrl + "/out/pakout/preview/auth1", headers: {'token': localStorage.getItem('token')}, contentType: 'application/json;charset=UTF-8', data: JSON.stringify(da), method: 'POST', success: function (res) { layer.close(loadIndex); var tableCache; if (res.code === 200) { layer.open({ type: 1 , title: false , closeBtn: false , offset: '50px' , area: ['1200px', '700px'] , shade: 0.5 , shadeClose: false , btn: ['立即出库', '稍后处理'] , btnAlign: 'c' , moveType: 1 //拖拽模式,0或者1 , content: $('#pakoutPreviewBox').html() , success: function (layero, index) { res.data.forEach((item, index) => { console.log(`项 ${index + 1}:`, item); }); stoPreTabIdx = table.render({ elem: '#stoPreTab2', data: res.data, height: 520, page: false, limit: Number.MAX_VALUE, cellMinWidth: 100, cols: [[ // {type: 'checkbox', merge: ['orderNo']}, {field: 'orderNo', title: '单据编号', merge: true, align: 'center'}, {field: 'title', title: '商品', merge: true, align: 'center', width: 350}, {field: 'batch', title: '批号', align: 'center'}, { field: 'anfme', title: '数量', align: 'center', width: 90, style: 'font-weight: bold' }, { field: 'locNo', title: '货位', align: 'center', width: 100, templet: '#locNoTpl' }, { field: 'staNos', align: 'center', title: '出库站', merge: ['locNo'], templet: '#tbBasicTbStaNos' }, {type: 'checkbox', merge: ['locNo']}, ]], done: function (res) { tableMerge.render(this); $('.layui-table-body.layui-table-main').css("overflow", "auto"); tableCache = tableData = table.cache.stoPreTab2; } }); // 修改出库站 form.on('select(tbBasicTbStaNos)', function (obj) { let index = obj.othis.parents('tr').attr("data-index"); let data = tableCache[index]; for (let i = 0; i < tableCache.length; i++) { if (tableCache[i].locNo === data.locNo) { tableCache[i]['staNo'] = Number(obj.elem.value); } } obj.othis.children().find("input").css("color", "blue"); return false; }); // 批量修改出库站 form.on('submit(batchModifySta)', function () { let stoPreTabData = layui.table.checkStatus('stoPreTab1').data; if (stoPreTabData.length < 1) { layer.msg("请至少选择一条以上合并数据", {icon: 7}); return false; } modifySta(stoPreTabData); }); // 批量修改出库站 - 站点选择 function modifySta(stoPreTabData) { // 出库站取交集 let staBatchSelectVal = []; for (let i = 0; i < stoPreTabData.length; i++) { let staNos = stoPreTabData[i].staNos; if (staNos !== null) { if (staBatchSelectVal.length === 0) { staBatchSelectVal = staNos; } else { staBatchSelectVal = staBatchSelectVal.filter(val => { return new Set(staNos).has(val) } ) } } } if (staBatchSelectVal.length === 0) { layer.msg("出库站没有交集,无法批量修改", {icon: 2}); return; } admin.open({ type: 1, area: '300px', offset: 'auto', title: '请选择站点', content: $('#staBatchSelectDialog').html(), success: function (layero, ddIndex) { // 渲染下拉框 let template = Handlebars.compile($('#batchStaSelectTpl').html()); $('#batchSelectStaBox').html(template({list: staBatchSelectVal})); // 确认 form.on('submit(staBatchSelectConfirm)', function (obj) { let loadIdx = layer.load(2); let batchSta = Number(obj.field.batchSta); let arr = []; for (let j = 0; j < stoPreTabData.length; j++) { for (let i = 0; i < tableCache.length; i++) { if (tableCache[i].orderNo === stoPreTabData[j].orderNo && tableCache[i].matnr === stoPreTabData[j].matnr && tableCache[i].locNo === stoPreTabData[j].locNo) { tableCache[i]['staNo'] = batchSta; arr.push(i); } } } stoPreTabIdx.reload({data: tableCache}); console.info("stoPreTabData"+stoPreTabData) console.info("tableCache"+tableCache) arr.forEach(item => { $('div[lay-id=stoPreTab1] tr[data-index="' + item + '"] .order-sta-select').val(batchSta); }); layui.form.render('select'); arr.forEach(item => { $('div[lay-id=stoPreTab1] tr[data-index="' + item + '"] .layui-select-title').find("input").css("color", "blue"); }); layer.close(loadIdx); layer.close(ddIndex); return false; }); // 弹窗不出现滚动条 $(layero).children('.layui-layer-content').css('overflow', 'visible'); layui.form.render('select'); }, }) } } , yes: function (index, layero) { //按钮【立即出库】的回调 pakout(tableCache, index); } , btn2: function (index, layero) { //按钮【稍后处理】的回调 layer.close(index) //return false 开启该代码可禁止点击该按钮关闭 } }); } else if (res.code === 403) { top.location.href = baseUrl + "/"; } else { layer.msg(res.msg, {icon: 2}) } } }) } function pakout(tableCache, layerIndex) { // let loadIndex = layer.load(2); notice.msg('正在生成出库任务......', {icon: 4}); console.info(tableCache); $.ajax({ url: baseUrl + "/out/pakout2/auth", headers: {'token': localStorage.getItem('token')}, contentType: 'application/json;charset=UTF-8', data: JSON.stringify(tableCache), method: 'POST', success: function (res) { notice.destroy(); if (res.code === 200) { layer.close(layerIndex); layer.msg(res.msg, {icon: 1}); tableIns.reload({where: null}); tableIns.reload({data: null}); tableInss.reload({where: null, page: {curr: 1}}); } else if (res.code === 403) { top.location.href = baseUrl + "/"; } else { layer.msg(res.msg, {icon: 2}) } } }); } // 监听行工具事件 table.on('tool(chooseData)', function(obj){ switch (obj.event) { case 'remove': let index = obj.tr.attr("data-index"); locDetlData.splice(index, 1); tableIns.reload({data: locDetlData}); break; } }); // 监听行工具事件 table.on('tool(chooseDatas)', function(obj){ var data = obj.data; switch (obj.event) { case 'tq': outLocDetlQuery([data.matnr],[data.id],[data.enableQty]) break; } }); // 提取库存 function outLocDetlQuery(matnr,id,enableQty) { let loadIndex = layer.msg('请求中...', {icon: 16, shade: 0.01, time: false}); matnR=matnr; ID=id; anfme=enableQty; locDetlLayerIdx = layer.open({ type: 2, title: false, closeBtn: false, maxmin: false, area: ['90%', '85%'], shadeClose: true, content: 'outLocDetlQuery1.html', success: function(layero, index){ layer.close(loadIndex); } }); } // 获取出库口 function getOutBound(){ $.ajax({ url: baseUrl+"/available/take/site", headers: {'token': localStorage.getItem('token')}, method: 'POST', async: false, success: function (res) { if (res.code === 200){ var tpl = $("#takeSiteSelectTemplate").html(); var template = Handlebars.compile(tpl); var html = template(res); $('#staNoSelect').append(html); form.render('select'); } else if (res.code === 403){ top.location.href = baseUrl+"/"; }else { layer.msg(res.msg) } } }) } $(document).on('click','#mat-query', function () { let loadIndex = layer.msg('请求中...', {icon: 16, shade: 0.01, time: false}); locDetlLayerIdx = layer.open({ type: 2, title: false, closeBtn: false, maxmin: false, area: ['90%', '85%'], shadeClose: true, content: 'outLocDetlQuery1.html', success: function(layero, index){ layer.close(loadIndex); } }); }) }) // 添加表格数据 function addTableData(data) { console.log("data"+data) for (var i=0;i