<!DOCTYPE html>
|
<html lang="en">
|
<head>
|
<meta charset="UTF-8">
|
<meta name="viewport" content="width=device-width, target-densitydpi=high-dpi, initial-scale=1.0, user-scalable=no"/>
|
<title>盘点</title>
|
<link rel="stylesheet" href="../../static/layui/css/layui.css" media="all">
|
<link rel="stylesheet" href="../../static/css/pda.css" media="all">
|
<script type="text/javascript" src="../../static/js/jquery/jquery-3.3.1.min.js"></script>
|
<script type="text/javascript" src="../../static/layui/layui.js" charset="utf-8"></script>
|
<script type="text/javascript" src="../../static/js/common.js" charset="utf-8"></script>
|
<script type="text/javascript" src="../../static/js/cool.js" charset="utf-8"></script>
|
<script type="text/javascript" src="../../static/js/handlebars/handlebars-v4.5.3.js"></script>
|
<style>
|
.quantity-input {
|
width: 100%;
|
height: 100%;
|
border: none;
|
text-align: center;
|
background-color: transparent;
|
color: blue;
|
}
|
</style>
|
</head>
|
<body>
|
<!-- 头部 -->
|
<header>
|
<div class="layui-input-inline">
|
<label class="layui-form-label">托盘条码</label>
|
<input class="layui-input" type="number" id="code" onkeyup="findCode(this)" oninput="if(value.length>8)value=value.slice(0,8)" placeholder="扫码 / 输入" autocomplete="off">
|
</div>
|
<div style="margin: 5px 5px">
|
<button id="mat-btn" type="button" class="layui-btn layui-btn-normal" onclick="getMat()"><i class="layui-icon">+</i>提取</button>
|
</div>
|
</header>
|
|
<!-- 主体 -->
|
<main>
|
<table class="layui-table" id="chooseData" lay-filter="chooseData"></table>
|
</main>
|
|
<!-- 尾部 -->
|
<footer>
|
<div class="layui-btn-container">
|
<button type="button" id="reset-btn" class="layui-btn layui-btn-primary" onclick="reset()">重置</button>
|
<button type="button" id="submit-btn" class="layui-btn layui-btn-normal " onclick="submitCheck()" style="margin-left: 20px">盘点</button>
|
<span id="tips"></span>
|
</div>
|
</footer>
|
</body>
|
<script>
|
var tableIns;
|
var matData = [];
|
var currentBarcode = '';
|
var currentWrkNo = null;
|
|
layui.use(['table','laydate', 'form'], function() {
|
var table = layui.table;
|
var $ = layui.jquery;
|
var layer = layui.layer;
|
var form = layui.form;
|
|
tableIns = table.render({
|
elem: '#chooseData',
|
data: matData,
|
limit: 500,
|
cellMinWidth: 50,
|
cols: [[
|
{fixed: 'left', align: 'center', field: 'anfme', title: '数量', style:'color: blue', width: 50, templet: function(d){
|
return '<input type="number" class="quantity-input" value="' + (d.anfme || 0) + '" ' +
|
'data-index="' + d.LAY_TABLE_INDEX + '" onblur="updateQuantity(this)" style="width: 100%">';
|
}},
|
{field: 'matnr', align: 'center', title: '商品编号'},
|
{field: 'maktx', align: 'center', title: '商品名称'},
|
{field: 'specs', align: 'center', title: '规格'},
|
{field: 'unit', align: 'center', title: '单位'},
|
{field: 'barcode', align: 'center', title: '条码'},
|
{field: 'stock', align: 'center', title: '托盘数量', style:'color: green', templet: function(d){
|
return d.stock || d.anfme || 0;
|
}}
|
]],
|
done: function (res, curr, anfme) {
|
// 绑定数量输入框事件
|
bindQuantityEvents();
|
}
|
});
|
|
function bindQuantityEvents() {
|
// 绑定输入框点击事件
|
$('.quantity-input').off('click').on('click', function(e){
|
e.stopPropagation();
|
$(this).select();
|
});
|
|
// 绑定回车键事件
|
$('.quantity-input').off('keydown').on('keydown', function(e){
|
if(e.keyCode === 13) {
|
e.preventDefault();
|
updateQuantity(this);
|
$(this).blur();
|
}
|
});
|
}
|
});
|
|
window.onload = function(){
|
document.getElementById("code").focus();
|
}
|
|
function findCode(el) {
|
if (el.value.length === 8) {
|
currentBarcode = el.value;
|
getCheckDetails(currentBarcode);
|
}
|
}
|
|
var matCodeLayerIdx;
|
function getMat() {
|
matCodeLayerIdx = layer.open({
|
type: 2,
|
title: '提取物料',
|
shade: [0.3,'#000'],
|
area: ['90%', '80%'],
|
content: 'matQuery.html',
|
success: function(layero, index){
|
$('.layui-layer-title').css('font-size', '16px');
|
},
|
end: function () {
|
$('#mat-btn').focus();
|
}
|
});
|
}
|
|
// 添加表格数据 - 来自物料选择弹窗
|
function addTableData(data) {
|
if (isEmpty(data.maktx)){
|
tips("提取失败", true);
|
return;
|
}
|
let toPush = true;
|
for (var j=0; j<matData.length; j++){
|
if (data.matnr === matData[j].matnr) {
|
// 如果是同一个物料,累加数量
|
matData[j].anfme = Number(matData[j].anfme) + Number(data.anfme);
|
toPush = false;
|
break;
|
}
|
}
|
if (toPush) {
|
// 新增物料,添加库存字段
|
var newItem = {
|
LAY_TABLE_INDEX: matData.length,
|
anfme: data.anfme || 0,
|
matnr: data.matnr || '',
|
maktx: data.maktx || '',
|
specs: data.specs || '',
|
unit: data.unit || '',
|
barcode: data.barcode || '',
|
stock: 0 // 手动添加的物料,库存为0
|
};
|
matData.push(newItem);
|
}
|
tips("提取成功");
|
tableIns.reload({data: matData});
|
}
|
|
// 获取盘点明细
|
function getCheckDetails(barcode) {
|
if (!barcode || barcode.length !== 8) {
|
tips("托盘条码必须为8位", true);
|
return;
|
}
|
|
if (!barcode.startsWith("5") &&
|
!barcode.startsWith("6") &&
|
!barcode.startsWith("7") &&
|
!barcode.startsWith("8")){
|
tips("托盘条码格式错误", true);
|
return;
|
}
|
|
tips("正在查询...", false);
|
|
$.ajax({
|
url: baseUrl + "/mobile/checkDetl/auth/v2?barcode=" + encodeURIComponent(barcode),
|
headers: {'token': localStorage.getItem('token')},
|
method: 'GET',
|
success: function (res) {
|
if (res.code === 200) {
|
if (res.data && res.data.wrkDetls && res.data.wrkDetls.length > 0) {
|
var result = res.data;
|
currentWrkNo = result.wrkNo;
|
|
matData = result.wrkDetls.map(function(item, index) {
|
return {
|
LAY_TABLE_INDEX: index,
|
anfme: item.anfme || 0,
|
matnr: item.matnr || '',
|
maktx: item.maktx || '',
|
specs: item.specs || '',
|
unit: item.unit || '',
|
barcode: item.barcode || '',
|
stock: item.anfme || 0,
|
detlNo: item.detlNo || '',
|
wrkNo: item.wrkNo || '',
|
detlId: item.detlId || null,
|
locno: item.locno || '',
|
batch: item.batch || '',
|
itemBatch: item.itemBatch || ''
|
};
|
});
|
|
tableIns.reload({data: matData});
|
tips("查询成功,共 " + matData.length + " 条记录");
|
} else {
|
matData = [];
|
tableIns.reload({data: matData});
|
tips("该托盘暂无盘点数据", false);
|
}
|
} else if (res.code === 403) {
|
tips("登录已过期,请重新登录", true);
|
setTimeout(function() {
|
top.location.href = baseUrl + "/pda";
|
}, 1500);
|
} else {
|
tips(res.msg || "查询失败,错误码:" + res.code, true);
|
}
|
},
|
error: function(xhr, status, error) {
|
if (xhr.responseJSON && xhr.responseJSON.code) {
|
var res = xhr.responseJSON;
|
if (res.code === 403) {
|
tips("登录已过期,请重新登录", true);
|
setTimeout(function() {
|
top.location.href = baseUrl + "/pda";
|
}, 1500);
|
} else {
|
tips(res.msg || "接口返回错误,错误码:" + res.code, true);
|
}
|
} else {
|
if (xhr.status === 404) {
|
tips("接口不存在(404),请检查URL路径", true);
|
} else if (xhr.status === 500) {
|
tips("服务器内部错误(500)", true);
|
} else if (xhr.status === 0) {
|
tips("无法连接到服务器,请检查网络", true);
|
} else {
|
tips("请求失败,状态码:" + xhr.status, true);
|
}
|
}
|
}
|
});
|
}
|
|
// 更新数量
|
function updateQuantity(input) {
|
var value = $(input).val();
|
var index = $(input).data('index');
|
|
if (value === '' || value === null) {
|
value = 0;
|
$(input).val(0);
|
}
|
|
value = parseFloat(value);
|
if (isNaN(value) || value < 0) {
|
value = 0;
|
$(input).val(0);
|
}
|
|
if (matData[index]) {
|
matData[index].anfme = value;
|
|
// 更新输入框的值
|
$(input).val(value);
|
|
// 高亮显示差异
|
var stock = matData[index].stock || 0;
|
if (value !== stock) {
|
$(input).css('color', '#ff5722'); // 橙色表示有差异
|
} else {
|
$(input).css('color', 'blue'); // 蓝色表示无差异
|
}
|
}
|
}
|
|
// 重置
|
function reset() {
|
$('#code').val("");
|
currentBarcode = '';
|
currentWrkNo = null;
|
matData = [];
|
tableIns.reload({data: matData});
|
document.getElementById("code").focus();
|
}
|
|
// 盘点提交 - 调用 /inventory/auth 接口
|
function submitCheck() {
|
let barcode = $('#code').val();
|
if (isEmpty(barcode)) {
|
tips("托盘条码为空", true);
|
return;
|
}
|
if (barcode.length !== 8) {
|
tips("条码必须为8位", true);
|
return;
|
}
|
if (!barcode.startsWith("5") &&
|
!barcode.startsWith("6") &&
|
!barcode.startsWith("7") &&
|
!barcode.startsWith("8")){
|
tips("托盘条码格式错误", true);
|
return;
|
}
|
if (matData.length === 0) {
|
tips("请盘点物料", true);
|
return;
|
}
|
|
// 构建 CombParam 数据结构
|
var combMats = matData.map(function(item) {
|
var combMat = {
|
detlId: item.detlId || null,
|
detId: item.detlNo || null,
|
matnr: item.matnr || '',
|
anfme: item.anfme || 0,
|
maktx: item.maktx || '',
|
specs: item.specs || '',
|
batch: item.batch || '',
|
itemBatch: item.itemBatch || ''
|
};
|
|
// 如果有其他字段也一并提交
|
if (item.proType) combMat.proType = item.proType;
|
if (item.temp2) combMat.temp2 = item.temp2;
|
if (item.outOrderNo) combMat.outOrderNo = item.outOrderNo;
|
if (item.memo) combMat.memo = item.memo;
|
|
return combMat;
|
});
|
|
// 构建完整的请求数据
|
var requestData = {
|
barcode: barcode,
|
locno: matData[0]?.locno || '', // 如果有库位信息
|
combMats: combMats
|
};
|
|
// 如果有单据编号,也一并提交
|
if (currentWrkNo) {
|
requestData.orderNo = currentWrkNo.toString();
|
requestData.billNo = currentWrkNo.toString();
|
}
|
|
console.log("提交数据:", JSON.stringify(requestData, null, 2));
|
|
tips("正在提交盘点数据...", false);
|
|
$.ajax({
|
url: baseUrl + "/mobile/inventory/auth",
|
headers: {'token': localStorage.getItem('token')},
|
data: JSON.stringify(requestData),
|
contentType:'application/json;charset=UTF-8',
|
method: 'POST',
|
success: function (res) {
|
if (res.code === 200) {
|
reset();
|
tips("盘点成功");
|
} else if (res.code === 403) {
|
tips("登录已过期,请重新登录", true);
|
setTimeout(function() {
|
top.location.href = baseUrl + "/pda";
|
}, 1500);
|
} else {
|
tips(res.msg || "盘点失败", true);
|
}
|
},
|
error: function(xhr, status, error) {
|
if (xhr.responseJSON && xhr.responseJSON.code) {
|
tips(xhr.responseJSON.msg || "提交失败", true);
|
} else {
|
tips("提交失败,状态码:" + xhr.status, true);
|
}
|
}
|
});
|
}
|
|
function tips(msg, warn) {
|
layer.msg(msg, {icon: warn?2:1})
|
}
|
|
document.onkeyup = function (e) {
|
if (window.event)
|
e = window.event;
|
var key = e.charCode || e.keyCode;
|
if (key === 115) { // F4键
|
$("#submit-btn").focus();
|
submitCheck();
|
} else if (key === 113) { // F2键
|
$("#code").val("");
|
$("#code").focus();
|
} else if (key === 114) { // F3键
|
getMat();
|
} else if (key === 116) { // F5键
|
if (currentBarcode) {
|
getCheckDetails(currentBarcode);
|
}
|
}
|
}
|
</script>
|
</html>
|