var insTb, insTb2;
|
layui.config({
|
base: baseUrl + "/static/layui/lay/modules/"
|
}).extend({
|
notice: 'notice/notice',
|
tableMerge: 'tableMerge'
|
}).use(['table', 'laydate', 'form', 'util', 'admin', 'notice', 'xmSelect', 'tableMerge', 'tableX'], function(){
|
var table = layui.table;
|
var $ = layui.jquery;
|
var layer = layui.layer;
|
var form = layui.form;
|
var admin = layui.admin;
|
var notice = layui.notice;
|
var tableMerge = layui.tableMerge;
|
var tableX = layui.tableX;
|
|
/****************************************** 左侧检验订单表 *************************************************/
|
function getLeftCols() {
|
return [[
|
{field: 'orderTime', title: typeof I18n !== 'undefined' ? I18n.t('date') : '日期', width: 100},
|
{field: 'orderNo', title: typeof I18n !== 'undefined' ? I18n.t('order_no') : '单据编号', align: 'center'}
|
]];
|
}
|
|
var initLeftTable = function() {
|
insTb = table.render({
|
elem: '#originTable',
|
url: baseUrl + '/order/inspect/list/auth',
|
headers: {token: localStorage.getItem('token')},
|
height: 'full-180',
|
page: false,
|
request: { pageName: 'curr', pageSize: 'limit' },
|
parseData: function (res) {
|
return { 'code': res.code, 'msg': res.msg, 'data': res.data };
|
},
|
response: { statusCode: 200 },
|
text: { none: typeof I18n !== 'undefined' ? I18n.t('no_data') : '暂无数据' },
|
cols: getLeftCols(),
|
done: function (res, curr, count) {
|
if (typeof I18n !== 'undefined' && I18n.isReady()) {
|
I18n.updatePage();
|
if (count === 0) { $('.layui-table-empty').text(I18n.t('no_data')); }
|
}
|
// 默认选中第一行
|
$('#originTable+.layui-table-view .layui-table-body tbody>tr:first').trigger('click');
|
|
// 绑定右键一键出库
|
tableX.bindCtxMenu('originTable', function (d) {
|
return [{
|
icon: 'layui-icon layui-icon-ok',
|
name: typeof I18n !== 'undefined' ? I18n.t('one_click_outbound') : '一键出库',
|
click: function (d) { autoOut(d.id); }
|
}]
|
});
|
}
|
});
|
};
|
|
/****************************************** 右侧订单明细表 *************************************************/
|
function getRightCols() {
|
return [[
|
{type: 'checkbox', merge: 'origin'},
|
{field: 'origin', align: 'center', title: typeof I18n !== 'undefined' ? I18n.t('pallet_code') : '托盘码', merge: true, width: 140},
|
{field: 'matnr', align: 'center', title: typeof I18n !== 'undefined' ? I18n.t('mat_code') : '商品编码', width: 140},
|
{field: 'maktx', align: 'center', title: typeof I18n !== 'undefined' ? I18n.t('mat_name') : '商品名称', width: 180},
|
{field: 'batch', align: 'center', title: typeof I18n !== 'undefined' ? I18n.t('serial_code') : '批号'},
|
{field: 'specs', align: 'center', title: typeof I18n !== 'undefined' ? I18n.t('spec') : '规格'},
|
{field: 'color', align: 'center', title: typeof I18n !== 'undefined' ? I18n.t('color') : '颜色'},
|
// {field: 'origin', align: 'center', title: typeof I18n !== 'undefined' ? I18n.t('locationNo') : '库位号'},
|
{field: 'enableQty', align: 'center', title: typeof I18n !== 'undefined' ? I18n.t('outbound_pending_qty') : '待出库数量', style: 'font-weight: bold'},
|
{fixed: 'right', title: typeof I18n !== 'undefined' ? I18n.t('operation') : '操作', align: 'center', toolbar: '#operate', width: 120, merge: 'origin'}
|
]];
|
}
|
|
var initRightTable = function() {
|
insTb2 = table.render({
|
elem: '#orderDetlTable',
|
headers: {token: localStorage.getItem('token')},
|
url: baseUrl + '/orderDetl/pakout/inspectionList/auth',
|
page: true,
|
limit: 15,
|
height: 'full-180',
|
toolbar: '#orderDetToolbar',
|
text: { none: typeof I18n !== 'undefined' ? I18n.t('no_data') : '暂无数据' },
|
where: { order_id: -1 },
|
cols: getRightCols(),
|
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 (typeof I18n !== 'undefined' && I18n.isReady()) {
|
I18n.updatePage();
|
I18n.updateLayuiPagination();
|
}
|
tableMerge.render(this);
|
}
|
});
|
};
|
|
// 监听语言切换事件
|
$(document).on('i18n:languageChanged', function() {
|
if (typeof I18n !== 'undefined') {
|
I18n.updatePage();
|
}
|
if (insTb) {
|
insTb.reload({
|
cols: getLeftCols(),
|
text: { none: typeof I18n !== 'undefined' ? I18n.t('no_data') : '暂无数据' }
|
});
|
}
|
if (insTb2) {
|
insTb2.reload({
|
cols: getRightCols(),
|
text: { none: typeof I18n !== 'undefined' ? I18n.t('no_data') : '暂无数据' }
|
});
|
}
|
});
|
|
// 初始化加载
|
if (typeof I18n !== 'undefined' && I18n.isReady()) {
|
initLeftTable();
|
initRightTable();
|
} else {
|
$(document).on('i18n:ready', function() {
|
initLeftTable();
|
initRightTable();
|
});
|
}
|
|
// 监听左侧行单击
|
var currentOrderId = -1;
|
table.on('row(originTable)', function (obj) {
|
currentOrderId = obj.data.id;
|
obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
|
insTb2.reload({ where: { order_id: currentOrderId }, page: { curr: 1 } });
|
});
|
|
// 搜索与重置
|
form.on('submit(originTableSearch)', function (data) {
|
insTb.reload({ where: data.field });
|
return false;
|
});
|
|
form.on('submit(sensorTbSearch)', function (data) {
|
insTb2.reload({ where: data.field, page: { curr: 1 } });
|
return false;
|
});
|
|
// 表格操作
|
table.on('toolbar(orderDetlTable)', function (obj) {
|
var checkStatus = table.checkStatus(obj.config.id).data;
|
if (obj.event === 'pakoutPreview') {
|
if (checkStatus.length === 0) {
|
layer.msg(typeof I18n !== 'undefined' ? I18n.t('select_at_least_one_outbound_detail') : '请至少选择一条出库明细', {icon: 2});
|
return;
|
}
|
pakoutPreview(checkStatus.map(d => d.id));
|
} else if (obj.event === 'oneClickOut') {
|
if (currentOrderId === -1) {
|
layer.msg(typeof I18n !== 'undefined' ? I18n.t('please_select_order') : '请先选择订单', {icon: 2});
|
return;
|
}
|
autoOut(currentOrderId);
|
} else if (obj.event === 'inspectPass') {
|
if (currentOrderId === -1) {
|
layer.msg(typeof I18n !== 'undefined' ? I18n.t('please_select_order') : '请先选择订单', {icon: 2});
|
return;
|
}
|
inspectPass(currentOrderId);
|
} else if (obj.event === 'inspectFail') {
|
if (currentOrderId === -1) {
|
layer.msg(typeof I18n !== 'undefined' ? I18n.t('please_select_order') : '请先选择订单', {icon: 2});
|
return;
|
}
|
inspectFail(currentOrderId);
|
}
|
});
|
|
table.on('tool(orderDetlTable)', function (obj) {
|
if (obj.event === 'pakoutPreview') {
|
// 获取当前 origin 分组的所有明细 ID
|
var origin = obj.data.origin;
|
var tableData = table.cache['orderDetlTable'];
|
var groupIds = [];
|
if (origin) {
|
for (var i = 0; i < tableData.length; i++) {
|
if (tableData[i].origin === origin && tableData[i].enableQty > 0) {
|
groupIds.push(tableData[i].id);
|
}
|
}
|
} else {
|
groupIds = [obj.data.id];
|
}
|
|
if (groupIds.length === 0) {
|
layer.msg(typeof I18n !== 'undefined' ? I18n.t('no_available_qty') : '没有可出库数量', {icon: 2});
|
return;
|
}
|
pakoutPreview(groupIds);
|
}
|
});
|
|
// 出库预览与确认逻辑
|
function pakoutPreview(ids) {
|
let loadIndex = layer.load(2);
|
$.ajax({
|
url: baseUrl + "/out/pakout/preview/auth",
|
headers: {'token': localStorage.getItem('token')},
|
contentType: 'application/json;charset=UTF-8',
|
data: JSON.stringify(ids),
|
method: 'POST',
|
success: function (res) {
|
layer.close(loadIndex);
|
if (res.code === 200) {
|
var tableCache;
|
layer.open({
|
type: 1, title: false, closeBtn: false, offset: '50px', area: ['1000px', '600px'], shade: 0.5,
|
btn: [I18n.t('immediate_outbound'), I18n.t('process_later')], btnAlign: 'c',
|
content: $('#pakoutPreviewBox').html(),
|
success: function(layero, index) {
|
I18n.updatePage($(layero));
|
var stoPreTabIdx = table.render({
|
elem: '#stoPreTab', data: res.data, height: 420, page: false, limit: 1000,
|
cols: [[
|
{field: 'orderNo', title: I18n.t('order_no'), align: 'center'},
|
{field: 'batch', title: I18n.t('serial_code'), align: 'center'},
|
{field: 'anfme', title: I18n.t('quantity'), align: 'center', width: 90},
|
{field: 'locNo', title: I18n.t('location'), align: 'center', width: 120, templet: '#locNoTpl', merge: true},
|
{field: 'staNos', align: 'center', title: I18n.t('station_outbound'), templet: '#tbBasicTbStaNos', merge: 'locNo'},
|
{type: 'checkbox', merge: 'locNo'}
|
]],
|
done: function() {
|
tableCache = table.cache.stoPreTab;
|
I18n.updatePage($('.layui-table-view[lay-id="stoPreTab"]'));
|
form.render('select');
|
tableMerge.render(this);
|
}
|
});
|
|
form.on('select(tbBasicTbStaNos)', function (obj) {
|
let idx = obj.othis.parents('tr').attr("data-index");
|
let currentLocNo = tableCache[idx]['locNo'];
|
let selectedStaNo = Number(obj.elem.value);
|
|
// 同一库位的所有记录同步选择相同的站点
|
for (let i = 0; i < tableCache.length; i++) {
|
if (tableCache[i]['locNo'] === currentLocNo) {
|
tableCache[i]['staNo'] = selectedStaNo;
|
// 同时更新界面上该库位对应的所有下拉框(如果有多个的话)
|
let $selects = $(layero).find('tr[data-index="' + i + '"] select.order-sta-select');
|
if ($selects.length > 0) {
|
$selects.val(obj.elem.value);
|
}
|
}
|
}
|
form.render('select');
|
});
|
|
form.on('submit(batchModifySta)', function (data) {
|
let checkStatus = table.checkStatus('stoPreTab').data;
|
if (checkStatus.length === 0) {
|
layer.msg(typeof I18n !== 'undefined' ? I18n.t('select_at_least_one_outbound_detail') : '请至少选择一条记录', {icon: 2});
|
return false;
|
}
|
|
// 获取第一个选中的有效站点作为基准
|
let baseStaNo = null;
|
for (let i = 0; i < checkStatus.length; i++) {
|
if (checkStatus[i].staNo) {
|
baseStaNo = checkStatus[i].staNo;
|
break;
|
}
|
}
|
|
if (!baseStaNo) {
|
layer.msg('请先为其中一个选中项选择站点', {icon: 2});
|
return false;
|
}
|
|
// 应用到所有选中的行,并同步同库位的行
|
for (let i = 0; i < checkStatus.length; i++) {
|
let targetLocNo = checkStatus[i].locNo;
|
for (let j = 0; j < tableCache.length; j++) {
|
if (tableCache[j].locNo === targetLocNo) {
|
tableCache[j].staNo = baseStaNo;
|
$(layero).find('tr[data-index="' + j + '"] select.order-sta-select').val(baseStaNo);
|
}
|
}
|
}
|
form.render('select');
|
return false;
|
});
|
},
|
yes: function(index) { pakout(tableCache, index); },
|
btn2: function(index) { layer.close(index); }
|
});
|
} else {
|
layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 2});
|
}
|
}
|
});
|
}
|
|
function pakout(tableCache, layerIndex) {
|
notice.msg(typeof I18n !== 'undefined' ? I18n.t('generating_outbound_task') : '正在生成出库任务...', {icon: 4});
|
$.ajax({
|
url: baseUrl + "/out/pakout/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(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 1});
|
insTb.reload();
|
insTb2.reload({ page: { curr: 1 } });
|
} else {
|
layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 2});
|
}
|
}
|
});
|
}
|
|
function autoOut(orderId) {
|
let loadIndex = layer.msg(typeof I18n !== 'undefined' ? I18n.t('requesting') : '请求中...', {icon: 16, shade: 0.01, time: false});
|
$.ajax({
|
url: baseUrl + "/out/pakout/orderDetlIds/auth",
|
headers: {'token': localStorage.getItem('token')},
|
data: { orderId : orderId },
|
method: 'POST',
|
success: function (res) {
|
layer.close(loadIndex);
|
if (res.code === 200) { pakoutPreview(res.data); }
|
else { layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 2}); }
|
}
|
});
|
}
|
|
function inspectPass(orderId) {
|
var data = table.cache['originTable'];
|
var orderNo = "";
|
for (var i = 0; i < data.length; i++) {
|
if (data[i].id == orderId) {
|
orderNo = data[i].orderNo;
|
break;
|
}
|
}
|
|
layer.confirm(typeof I18n !== 'undefined' ? I18n.t('confirm_inspect_pass') : '确认检验通过?', {icon: 3}, function (index) {
|
layer.close(index);
|
let loadIndex = layer.msg(typeof I18n !== 'undefined' ? I18n.t('processing') : '处理中...', {icon: 16, shade: 0.01, time: false});
|
$.ajax({
|
url: baseUrl + "/order/checkInspection/auth",
|
headers: {'token': localStorage.getItem('token')},
|
data: { orderNo: orderNo, inspectNumber: 1 },
|
method: 'POST',
|
success: function (res) {
|
layer.close(loadIndex);
|
if (res.code === 200) {
|
layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 1});
|
insTb.reload();
|
insTb2.reload({ where: { order_id: -1 }, page: { curr: 1 } });
|
currentOrderId = -1;
|
} else {
|
layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 2});
|
}
|
}
|
});
|
});
|
}
|
|
function inspectFail(orderId) {
|
var data = table.cache['originTable'];
|
var orderNo = "";
|
for (var i = 0; i < data.length; i++) {
|
if (data[i].id == orderId) {
|
orderNo = data[i].orderNo;
|
break;
|
}
|
}
|
|
layer.confirm(typeof I18n !== 'undefined' ? I18n.t('confirm_inspect_fail') : '确认检验不通过?', {icon: 3}, function (index) {
|
layer.close(index);
|
let loadIndex = layer.msg(typeof I18n !== 'undefined' ? I18n.t('processing') : '处理中...', {icon: 16, shade: 0.01, time: false});
|
$.ajax({
|
url: baseUrl + "/order/checkInspection/auth",
|
headers: {'token': localStorage.getItem('token')},
|
data: { orderNo: orderNo, inspectNumber: 2 },
|
method: 'POST',
|
success: function (res) {
|
layer.close(loadIndex);
|
if (res.code === 200) {
|
layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 1});
|
insTb.reload();
|
insTb2.reload({ where: { order_id: -1 }, page: { curr: 1 } });
|
currentOrderId = -1;
|
} else {
|
layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 2});
|
}
|
}
|
});
|
});
|
}
|
|
// 暴露函数
|
window.autoOut = autoOut;
|
window.inspectPass = inspectPass;
|
window.inspectFail = inspectFail;
|
});
|