|
|
@@ -1,7 +1,7 @@
|
|
|
<style>
|
|
|
table tr th, table tr td {
|
|
|
border: thin #ddd dashed;
|
|
|
- padding: 5px
|
|
|
+ padding: 5px;
|
|
|
}
|
|
|
|
|
|
.select2-container {
|
|
|
@@ -152,10 +152,43 @@
|
|
|
font-weight: bold;
|
|
|
background-color: #f5f5f5;
|
|
|
}
|
|
|
+
|
|
|
+ .tray-count-select {
|
|
|
+ width: 80px;
|
|
|
+ padding: 5px;
|
|
|
+ border: 1px solid #ccc;
|
|
|
+ border-radius: 4px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .layer-height-select {
|
|
|
+ width: 80px;
|
|
|
+ padding: 5px;
|
|
|
+ border: 1px solid #ccc;
|
|
|
+ border-radius: 4px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .quantity-input.invalid {
|
|
|
+ border-color: red;
|
|
|
+ background-color: #ffeeee;
|
|
|
+ }
|
|
|
+
|
|
|
+ .items-per-box {
|
|
|
+ width: 80px;
|
|
|
+ padding: 5px;
|
|
|
+ border: 1px solid #ccc;
|
|
|
+ border-radius: 4px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .unit-select {
|
|
|
+ width: 80px;
|
|
|
+ padding: 5px;
|
|
|
+ border: 1px solid #ccc;
|
|
|
+ border-radius: 4px;
|
|
|
+ }
|
|
|
</style>
|
|
|
|
|
|
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
|
|
|
- <fieldset style="width: 1200px;margin:10px 10px 0px 10px ;padding: 10px 10px 0px 10px ;border:solid thin #c0c0c0">
|
|
|
+ <fieldset style="width: 1280px;margin:10px 10px 0px 10px ;padding: 10px 10px 0px 10px ;border:solid thin #c0c0c0">
|
|
|
<legend style="padding: 0px;margin: 0px">生成厂商信息</legend>
|
|
|
<div class="form-group">
|
|
|
<label class="control-label col-xs-2 col-sm-1">生产厂商:</label>
|
|
|
@@ -183,19 +216,18 @@
|
|
|
</div>
|
|
|
</fieldset>
|
|
|
|
|
|
- <fieldset style="width: 1200px;margin:10px 10px 0px 10px ;padding: 10px 10px 0px 10px ;border: solid thin #c0c0c0">
|
|
|
- <legend style="padding: 0px;margin: 0px">打托选择列表</legend>
|
|
|
- <div style="margin-bottom: 10px;">
|
|
|
- <input type="text" id="searchInput" placeholder="请输入关键字搜索..." style="width: 300px;height: 35px; "/>
|
|
|
- <button type="text" id="searchBtn" className="btn btn-primary" style="height: 34px">查询</button>
|
|
|
-
|
|
|
+ <fieldset style="width:1280px;margin:10px 10px 0;padding:10px;border:solid thin #c0c0c0">
|
|
|
+ <legend style="padding:0;margin:0">打托选择列表</legend>
|
|
|
+ <div style="margin-bottom:10px">
|
|
|
+ <input type="text" id="searchInput" placeholder="请输入关键字搜索..." style="width:300px;height:35px">
|
|
|
+ <button type="button" id="searchBtn" className="btn btn-primary" style="height:34px">查询</button>
|
|
|
<button id="sadBtn" class="btn btn-success">
|
|
|
<i class="fas fa-plus"></i> 新增产品
|
|
|
</button>
|
|
|
</div>
|
|
|
|
|
|
<div id="table-container">
|
|
|
- <table id="table" style="width: 100%;border-collapse: collapse;">
|
|
|
+ <table id="table" style="width:100%;border-collapse:collapse">
|
|
|
<thead>
|
|
|
<tr>
|
|
|
<th>销售订单号</th>
|
|
|
@@ -207,8 +239,7 @@
|
|
|
<th>剩余数</th>
|
|
|
</tr>
|
|
|
</thead>
|
|
|
- <tbody id="tableBody">
|
|
|
- </tbody>
|
|
|
+ <tbody id="tableBody"></tbody>
|
|
|
</table>
|
|
|
</div>
|
|
|
<div id="pagination-wrapper">
|
|
|
@@ -219,25 +250,30 @@
|
|
|
</div>
|
|
|
</fieldset>
|
|
|
|
|
|
- <fieldset style="width: 1200px;margin:10px 10px 0px 10px ;padding: 10px 10px 0px 10px ;border: solid thin #c0c0c0">
|
|
|
- <legend style="padding: 0px;margin: 0px">打托选品列表</legend>
|
|
|
+ <fieldset style="width:1280px;margin:10px 10px 0;padding:10px;border:solid thin #c0c0c0">
|
|
|
+ <legend style="padding:0;margin:0">打托选品列表</legend>
|
|
|
<div id="table-container1">
|
|
|
- <table id="table1" style="width: 100%;border-collapse: collapse;">
|
|
|
+ <table id="table1" style="width:100%;border-collapse:collapse">
|
|
|
<thead>
|
|
|
<tr>
|
|
|
- <th>序号</th>
|
|
|
- <th>产品名称</th>
|
|
|
- <th>应发货数量</th>
|
|
|
- <th>实际发货数量</th>
|
|
|
- <th>备注</th>
|
|
|
- <th>操作</th>
|
|
|
+ <th style="width: 3%">序号</th>
|
|
|
+ <th style="width: 15%">产品名称</th>
|
|
|
+ <th style="width: 7%">可发数量</th>
|
|
|
+ <th style="width: 4%">每箱个数</th>
|
|
|
+ <th style="width: 4%">单位</th>
|
|
|
+ <th style="width: 4%">打托数</th>
|
|
|
+ <th style="width: 4%">层高</th>
|
|
|
+ <th style="width: 9%">实际发货数量</th>
|
|
|
+ <th style="width: 15%">备注</th>
|
|
|
+ <th style="width: 4%">操作</th>
|
|
|
</tr>
|
|
|
</thead>
|
|
|
- <tbody id="tableBody1">
|
|
|
- </tbody>
|
|
|
- <tfoot id="tableFooter1" style="display: none;">
|
|
|
+ <tbody id="tableBody1"></tbody>
|
|
|
+ <tfoot id="tableFooter1" style="display:none">
|
|
|
<tr className="total-row">
|
|
|
- <td colSpan="2">合计</td>
|
|
|
+ <td colSpan="3">合计</td>
|
|
|
+ <td></td>
|
|
|
+ <td></td>
|
|
|
<td id="totalQuantity">0</td>
|
|
|
<td colSpan="2"></td>
|
|
|
</tr>
|
|
|
@@ -271,8 +307,7 @@
|
|
|
};
|
|
|
|
|
|
function addToShipment(row) {
|
|
|
- console.log($(row).data('remaining_quantity'))
|
|
|
- if($(row).data('remaining_quantity') == 0){
|
|
|
+ if ($(row).data('remaining_quantity') == 0) {
|
|
|
layer.msg('库存数量为空!', {icon: 2});
|
|
|
return;
|
|
|
}
|
|
|
@@ -283,6 +318,10 @@
|
|
|
cpbm: $(row).data('cpbm'),
|
|
|
cpmc: $(row).data('cpmc'),
|
|
|
remaining_quantity: $(row).data('remaining_quantity'),
|
|
|
+ tray_count: 18,
|
|
|
+ layer_height: '1.35',
|
|
|
+ items_per_box: '20', // 默认每箱个数
|
|
|
+ unit: '套', // 默认单位
|
|
|
remark: ''
|
|
|
};
|
|
|
|
|
|
@@ -302,7 +341,30 @@
|
|
|
}
|
|
|
|
|
|
function calculateTotalQuantity() {
|
|
|
- return selectedProducts.reduce((sum, product) => sum + (parseFloat(product.remaining_quantity) || 0), 0);
|
|
|
+ return selectedProducts.reduce((sum, product) => {
|
|
|
+ const quantity = parseFloat(product.actual_quantity);
|
|
|
+ return sum + (isNaN(quantity) ? 0 : quantity);
|
|
|
+ }, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ function validateQuantityInput(input, maxValue) {
|
|
|
+ const value = input.val().trim();
|
|
|
+ const numericValue = parseFloat(value);
|
|
|
+
|
|
|
+ if (value !== '' && isNaN(numericValue)) {
|
|
|
+ input.addClass('invalid');
|
|
|
+ layer.tips('请输入有效数字', input, {tips: [1, '#FF5722']});
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (numericValue > maxValue) {
|
|
|
+ input.addClass('invalid');
|
|
|
+ layer.tips(`不能超过${maxValue}`, input, {tips: [1, '#FF5722']});
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ input.removeClass('invalid');
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
function renderShipmentTable() {
|
|
|
@@ -310,35 +372,114 @@
|
|
|
tbody.empty();
|
|
|
|
|
|
if (selectedProducts.length === 0) {
|
|
|
- tbody.append('<tr><td colspan="5" style="text-align:center;">暂无配货数据</td></tr>');
|
|
|
+ tbody.append('<tr><td colspan="10" style="text-align:center;">暂无配货数据</td></tr>');
|
|
|
$('#tableFooter1').hide();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
selectedProducts.forEach((product, index) => {
|
|
|
+ // 初始化时确保 actual_quantity 有值
|
|
|
+ if (product.actual_quantity === undefined || product.actual_quantity === '') {
|
|
|
+ product.actual_quantity = product.remaining_quantity;
|
|
|
+ }
|
|
|
+
|
|
|
const tr = $(`
|
|
|
- <tr>
|
|
|
- <td>${index + 1}</td>
|
|
|
- <td>${product.cpmc}</td>
|
|
|
- <td>${product.remaining_quantity}</td>
|
|
|
- <td><input type="text" class="quantity-input" data-index="${index}" value="${product.actual_quantity || product.remaining_quantity || ''}" placeholder="" style="width:100%;"></td>
|
|
|
- <td><input type="text" class="remark-input" data-index="${index}" value="${product.remark || ''}" placeholder="请输入备注" style="width:100%;"></td>
|
|
|
- <td><span class="remove-btn" onclick="removeFromShipment(${index})">移除</span></td>
|
|
|
- </tr>
|
|
|
- `);
|
|
|
+ <tr>
|
|
|
+ <td>${index + 1}</td>
|
|
|
+ <td>${product.cpmc}</td>
|
|
|
+ <td>${product.remaining_quantity}</td>
|
|
|
+ <td>
|
|
|
+ <input type="text"
|
|
|
+ class="items-per-box"
|
|
|
+ data-index="${index}"
|
|
|
+ value="${product.items_per_box || '20'}"
|
|
|
+ list="items-per-box-list"
|
|
|
+ style="width:80px">
|
|
|
+ <datalist id="items-per-box-list">
|
|
|
+ <option value="20">
|
|
|
+ <option value="24">
|
|
|
+ <option value="32">
|
|
|
+ <option value="40">
|
|
|
+ <option value="42">
|
|
|
+ <option value="48">
|
|
|
+ <option value="60">
|
|
|
+ <option value="72">
|
|
|
+ <option value="70">
|
|
|
+ <option value="80">
|
|
|
+ <option value="96">
|
|
|
+ <option value="108">
|
|
|
+ <option value="240">
|
|
|
+ </datalist>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <select class="unit-select" data-index="${index}">
|
|
|
+ <option value="套" ${product.unit === '套' ? 'selected' : ''}>套</option>
|
|
|
+ <option value="张" ${product.unit === '张' ? 'selected' : ''}>张</option>
|
|
|
+ <option value="个" ${product.unit === '个' ? 'selected' : ''}>个</option>
|
|
|
+ </select>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <select class="tray-count-select" data-index="${index}">
|
|
|
+ <option value="18" ${product.tray_count == 18 ? 'selected' : ''}>18</option>
|
|
|
+ <option value="24" ${product.tray_count == 24 ? 'selected' : ''}>24</option>
|
|
|
+ </select>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <select class="layer-height-select" data-index="${index}">
|
|
|
+ <option value="1.35" ${product.layer_height == '1.35' ? 'selected' : ''}>1.35</option>
|
|
|
+ <option value="1.05" ${product.layer_height == '1.05' ? 'selected' : ''}>1.05</option>
|
|
|
+ </select>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <input type="text" class="quantity-input" data-index="${index}"
|
|
|
+ value="${product.actual_quantity || ''}"
|
|
|
+ placeholder="" style="width:100%"
|
|
|
+ max="${product.remaining_quantity}">
|
|
|
+ </td>
|
|
|
+ <td><input type="text" class="remark-input" data-index="${index}" value="${product.remark || ''}" placeholder="请输入备注" style="width:100%"></td>
|
|
|
+ <td><span class="remove-btn" onclick="removeFromShipment(${index})">移除</span></td>
|
|
|
+ </tr>
|
|
|
+ `);
|
|
|
tbody.append(tr);
|
|
|
});
|
|
|
|
|
|
$('#tableFooter1').show();
|
|
|
$('#totalQuantity').text(calculateTotalQuantity());
|
|
|
|
|
|
- // 绑定备注输入事件 - 修正后的实现
|
|
|
+ $('.tray-count-select').off('change').on('change', function () {
|
|
|
+ const index = $(this).data('index');
|
|
|
+ selectedProducts[index].tray_count = $(this).val();
|
|
|
+ });
|
|
|
+
|
|
|
+ $('.layer-height-select').off('change').on('change', function () {
|
|
|
+ const index = $(this).data('index');
|
|
|
+ selectedProducts[index].layer_height = $(this).val();
|
|
|
+ });
|
|
|
+
|
|
|
+ $('.items-per-box').off('input').on('input', function () {
|
|
|
+ const index = $(this).data('index');
|
|
|
+ selectedProducts[index].items_per_box = $(this).val();
|
|
|
+ });
|
|
|
+
|
|
|
+ $('.unit-select').off('change').on('change', function () {
|
|
|
+ const index = $(this).data('index');
|
|
|
+ selectedProducts[index].unit = $(this).val();
|
|
|
+ });
|
|
|
+
|
|
|
$('.remark-input').off('input').on('input', function () {
|
|
|
const index = $(this).data('index');
|
|
|
- const remark = $(this).val();
|
|
|
- if (selectedProducts[index]) {
|
|
|
- selectedProducts[index].remark = remark;
|
|
|
- }
|
|
|
+ selectedProducts[index].remark = $(this).val();
|
|
|
+ });
|
|
|
+
|
|
|
+ $('.quantity-input').off('input').on('input', function () {
|
|
|
+ const index = $(this).data('index');
|
|
|
+ const input = $(this);
|
|
|
+ const maxValue = parseFloat(selectedProducts[index].remaining_quantity);
|
|
|
+
|
|
|
+ if (!validateQuantityInput(input, maxValue)) return;
|
|
|
+
|
|
|
+ selectedProducts[index].actual_quantity = input.val().trim() === '' ? '' : parseFloat(input.val());
|
|
|
+ $('#totalQuantity').text(calculateTotalQuantity());
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -419,18 +560,14 @@
|
|
|
$(function () {
|
|
|
loadData();
|
|
|
|
|
|
-
|
|
|
-
|
|
|
$('#searchBtn').on('click', function (e) {
|
|
|
e.preventDefault();
|
|
|
- const keyword = $('#searchInput').val().trim();
|
|
|
- loadData(1, keyword);
|
|
|
+ loadData(1, $('#searchInput').val().trim());
|
|
|
});
|
|
|
|
|
|
$('#searchInput').on('keypress', function (e) {
|
|
|
if (e.which === 13) {
|
|
|
- const keyword = $(this).val().trim();
|
|
|
- loadData(1, keyword);
|
|
|
+ loadData(1, $(this).val().trim());
|
|
|
}
|
|
|
});
|
|
|
|
|
|
@@ -438,24 +575,21 @@
|
|
|
addToShipment(this);
|
|
|
});
|
|
|
|
|
|
- // 修改sadBtn的点击事件处理
|
|
|
$('#sadBtn').on('click', function (e) {
|
|
|
e.preventDefault();
|
|
|
-
|
|
|
- // 生成一行表格的HTML
|
|
|
const generateRowHtml = (index) => `
|
|
|
- <tr data-row="${index}">
|
|
|
- <td><input type="text" name="order_ddbh" class="form-control" required /></td>
|
|
|
- <td><input type="text" name="gdbh" class="form-control" required /></td>
|
|
|
- <td><input type="text" name="cpbm" class="form-control" required /></td>
|
|
|
- <td><input type="text" name="cpmc" class="form-control" required /></td>
|
|
|
- <td><input type="number" name="sl" class="form-control" min="1" required /></td>
|
|
|
- <td>
|
|
|
- <button type="button" class="btn btn-success btn-xs add-row"><i class="fa fa-plus"></i></button>
|
|
|
- <button type="button" class="btn btn-danger btn-xs remove-row"><i class="fa fa-minus"></i></button>
|
|
|
- </td>
|
|
|
- </tr>
|
|
|
- `;
|
|
|
+ <tr data-row="${index}">
|
|
|
+ <td><input type="text" name="order_ddbh" class="form-control" required /></td>
|
|
|
+ <td><input type="text" name="gdbh" class="form-control" required /></td>
|
|
|
+ <td><input type="text" name="cpbm" class="form-control" required /></td>
|
|
|
+ <td><input type="text" name="cpmc" class="form-control" required /></td>
|
|
|
+ <td><input type="number" name="sl" class="form-control" min="1" required /></td>
|
|
|
+ <td>
|
|
|
+ <button type="button" class="btn btn-success btn-xs add-row"><i class="fa fa-plus"></i></button>
|
|
|
+ <button type="button" class="btn btn-danger btn-xs remove-row"><i class="fa fa-minus"></i></button>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ `;
|
|
|
|
|
|
layer.open({
|
|
|
type: 1,
|
|
|
@@ -466,85 +600,72 @@
|
|
|
maxmin: true,
|
|
|
btn: ['加入选品列表', '取消'],
|
|
|
content: `
|
|
|
- <div style="padding: 20px 30px;">
|
|
|
- <table class="table table-bordered" id="productTable">
|
|
|
- <thead>
|
|
|
- <tr>
|
|
|
- <th>销售订单号</th>
|
|
|
- <th>工单编号</th>
|
|
|
- <th>成品编码</th>
|
|
|
- <th>成品名称</th>
|
|
|
- <th>入库数</th>
|
|
|
- <th>操作</th>
|
|
|
- </tr>
|
|
|
- </thead>
|
|
|
- <tbody>
|
|
|
- ${generateRowHtml(0)}
|
|
|
- </tbody>
|
|
|
- </table>
|
|
|
- </div>
|
|
|
- `,
|
|
|
- success: function(layero, index) {
|
|
|
- // 添加行事件
|
|
|
- $(layero).on('click', '.add-row', function() {
|
|
|
- const tbody = $('#productTable tbody');
|
|
|
- const newRowIndex = tbody.find('tr').length;
|
|
|
- tbody.append(generateRowHtml(newRowIndex));
|
|
|
+ <div style="padding:20px 30px">
|
|
|
+ <table class="table table-bordered" id="productTable">
|
|
|
+ <thead>
|
|
|
+ <tr>
|
|
|
+ <th>销售订单号</th>
|
|
|
+ <th>工单编号</th>
|
|
|
+ <th>成品编码</th>
|
|
|
+ <th>成品名称</th>
|
|
|
+ <th>入库数</th>
|
|
|
+ <th>操作</th>
|
|
|
+ </tr>
|
|
|
+ </thead>
|
|
|
+ <tbody>${generateRowHtml(0)}</tbody>
|
|
|
+ </table>
|
|
|
+ </div>
|
|
|
+ `,
|
|
|
+ success: function (layero, index) {
|
|
|
+ $(layero).on('click', '.add-row', function () {
|
|
|
+ $('#productTable tbody').append(generateRowHtml($('#productTable tbody tr').length));
|
|
|
});
|
|
|
|
|
|
- // 删除行事件
|
|
|
- $(layero).on('click', '.remove-row', function() {
|
|
|
- const row = $(this).closest('tr');
|
|
|
+ $(layero).on('click', '.remove-row', function () {
|
|
|
if ($('#productTable tbody tr').length > 1) {
|
|
|
- row.remove();
|
|
|
+ $(this).closest('tr').remove();
|
|
|
} else {
|
|
|
layer.msg('至少保留一行', {icon: 2});
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
- yes: function(index) {
|
|
|
+ yes: function (index) {
|
|
|
const newProducts = [];
|
|
|
let isValid = true;
|
|
|
|
|
|
- $('#productTable tbody tr').each(function() {
|
|
|
+ $('#productTable tbody tr').each(function () {
|
|
|
const rowData = {};
|
|
|
let rowValid = true;
|
|
|
|
|
|
- $(this).find('[required]').each(function() {
|
|
|
- const $input = $(this);
|
|
|
- const val = $input.val().trim();
|
|
|
-
|
|
|
+ $(this).find('[required]').each(function () {
|
|
|
+ const val = $(this).val().trim();
|
|
|
if (!val) {
|
|
|
- layer.tips('此项为必填项', $input, {tips: [1, '#FF5722']});
|
|
|
- isValid = false;
|
|
|
- rowValid = false;
|
|
|
- return false; // 退出当前each循环
|
|
|
+ layer.tips('此项为必填项', $(this), {tips: [1, '#FF5722']});
|
|
|
+ isValid = rowValid = false;
|
|
|
+ return false;
|
|
|
}
|
|
|
-
|
|
|
- rowData[$input.attr('name')] = val;
|
|
|
+ rowData[$(this).attr('name')] = val;
|
|
|
});
|
|
|
|
|
|
if (rowValid) {
|
|
|
- // 设置剩余数量等于入库数量(因为是新增产品)
|
|
|
rowData.remaining_quantity = rowData.sl;
|
|
|
- rowData.total_chu_quantity = 0; // 发货数量初始为0
|
|
|
- rowData.isNew = true; // 标记为新增产品
|
|
|
+ rowData.total_chu_quantity = 0;
|
|
|
+ rowData.tray_count = 18;
|
|
|
+ rowData.layer_height = '1.35';
|
|
|
+ rowData.items_per_box = '20';
|
|
|
+ rowData.unit = '个';
|
|
|
+ rowData.isNew = true;
|
|
|
newProducts.push(rowData);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
if (!isValid || newProducts.length === 0) {
|
|
|
- if (newProducts.length === 0) {
|
|
|
- layer.msg('请至少填写一行有效数据', {icon: 2});
|
|
|
- }
|
|
|
+ if (newProducts.length === 0) layer.msg('请至少填写一行有效数据', {icon: 2});
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 将新产品添加到选品列表
|
|
|
newProducts.forEach(product => {
|
|
|
- // 检查是否已存在相同工单编号的产品
|
|
|
- const exists = selectedProducts.some(item => item.gdbh === product.gdbh);
|
|
|
- if (!exists) {
|
|
|
+ if (!selectedProducts.some(item => item.gdbh === product.gdbh)) {
|
|
|
selectedProducts.push({
|
|
|
gdbh: product.gdbh,
|
|
|
order_ddbh: product.order_ddbh,
|
|
|
@@ -552,7 +673,11 @@
|
|
|
cpmc: product.cpmc,
|
|
|
remaining_quantity: product.remaining_quantity,
|
|
|
total_chu_quantity: product.total_chu_quantity,
|
|
|
- isNew: true, // 标记为新增产品
|
|
|
+ tray_count: product.tray_count,
|
|
|
+ layer_height: product.layer_height,
|
|
|
+ items_per_box: product.items_per_box,
|
|
|
+ unit: product.unit,
|
|
|
+ isNew: true,
|
|
|
remark: ''
|
|
|
});
|
|
|
}
|
|
|
@@ -565,7 +690,6 @@
|
|
|
});
|
|
|
});
|
|
|
|
|
|
-// 修改提交处理逻辑
|
|
|
$('#submit').off('click').on('click', function (e) {
|
|
|
e.preventDefault();
|
|
|
|
|
|
@@ -574,23 +698,40 @@
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- // 确保所有输入数据已更新
|
|
|
- $('.quantity-input').each(function() {
|
|
|
+ let allValid = true;
|
|
|
+ $('.quantity-input').each(function () {
|
|
|
const index = $(this).data('index');
|
|
|
- const value = $(this).val() || $(this).attr('value') || '';
|
|
|
- selectedProducts[index].actual_quantity = value;
|
|
|
+ if (!validateQuantityInput($(this), parseFloat(selectedProducts[index].remaining_quantity))) {
|
|
|
+ allValid = false;
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
- $('.remark-input').each(function() {
|
|
|
+ if (!allValid) {
|
|
|
+ layer.msg('请检查实际发货数量输入是否正确', {icon: 2});
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $('.quantity-input').each(function () {
|
|
|
const index = $(this).data('index');
|
|
|
- const value = $(this).val() || '';
|
|
|
- selectedProducts[index].remark = value;
|
|
|
+ selectedProducts[index].actual_quantity = $(this).val().trim() === '' ? '' : parseFloat($(this).val());
|
|
|
});
|
|
|
|
|
|
- // 分离新增产品和已有产品
|
|
|
- const newProducts = selectedProducts.filter(p => p.isNew);
|
|
|
- const existingProducts = selectedProducts.filter(p => !p.isNew);
|
|
|
+ $('.remark-input').each(function () {
|
|
|
+ const index = $(this).data('index');
|
|
|
+ selectedProducts[index].remark = $(this).val() || '';
|
|
|
+ });
|
|
|
|
|
|
+ $('.items-per-box').each(function () {
|
|
|
+ const index = $(this).data('index');
|
|
|
+ selectedProducts[index].items_per_box = $(this).val() || '20';
|
|
|
+ });
|
|
|
+
|
|
|
+ $('.unit-select').each(function () {
|
|
|
+ const index = $(this).data('index');
|
|
|
+ selectedProducts[index].unit = $(this).val() || '个';
|
|
|
+ });
|
|
|
+
|
|
|
+ const newProducts = selectedProducts.filter(p => p.isNew);
|
|
|
const postData = {
|
|
|
company_name: $('#c-company_name').val(),
|
|
|
postcode: $('#c-postcode').val(),
|
|
|
@@ -600,7 +741,11 @@
|
|
|
products: selectedProducts.map(p => ({
|
|
|
...p,
|
|
|
remark: p.remark || '',
|
|
|
- actual_quantity: p.actual_quantity || p.remaining_quantity
|
|
|
+ actual_quantity: p.actual_quantity || p.remaining_quantity,
|
|
|
+ tray_count: p.tray_count || 18,
|
|
|
+ layer_height: p.layer_height || '1.35',
|
|
|
+ items_per_box: p.items_per_box || '20',
|
|
|
+ unit: p.unit || '套'
|
|
|
})),
|
|
|
newProducts: newProducts.map(p => ({
|
|
|
order_ddbh: p.order_ddbh,
|
|
|
@@ -609,42 +754,40 @@
|
|
|
cpmc: p.cpmc,
|
|
|
sl: p.remaining_quantity,
|
|
|
remark: p.remark || '',
|
|
|
- actual_quantity: p.actual_quantity || p.remaining_quantity
|
|
|
+ actual_quantity: p.actual_quantity || p.remaining_quantity,
|
|
|
+ tray_count: p.tray_count || 18,
|
|
|
+ layer_height: p.layer_height || '1.35',
|
|
|
+ items_per_box: p.items_per_box || '20',
|
|
|
+ unit: p.unit || '个'
|
|
|
}))
|
|
|
};
|
|
|
|
|
|
- // 显示加载中
|
|
|
const loadingIndex = layer.msg('处理中...', {icon: 16, shade: 0.3, time: 0});
|
|
|
|
|
|
- // 先处理新增产品入库
|
|
|
if (newProducts.length > 0) {
|
|
|
$.ajax({
|
|
|
method: "POST",
|
|
|
url: "Finishedproduct/finished",
|
|
|
contentType: "application/json",
|
|
|
- data: JSON.stringify({ data: postData.newProducts }),
|
|
|
- success: function(res) {
|
|
|
+ data: JSON.stringify({data: postData.newProducts}),
|
|
|
+ success: function (res) {
|
|
|
if (res && res.code === 1) {
|
|
|
- // 新增产品入库成功后,提交主表单
|
|
|
submitMainForm(postData, loadingIndex);
|
|
|
} else {
|
|
|
layer.close(loadingIndex);
|
|
|
layer.msg(res?.msg || '新增产品入库失败', {icon: 2});
|
|
|
}
|
|
|
},
|
|
|
- error: function(xhr) {
|
|
|
+ error: function (xhr) {
|
|
|
layer.close(loadingIndex);
|
|
|
- const errorMsg = xhr.responseJSON?.message || xhr.statusText || '请求失败';
|
|
|
- layer.msg('新增产品入库失败: ' + errorMsg, {icon: 2});
|
|
|
+ layer.msg('新增产品入库失败: ' + (xhr.responseJSON?.message || xhr.statusText || '请求失败'), {icon: 2});
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
- // 没有新增产品,直接提交主表单
|
|
|
submitMainForm(postData, loadingIndex);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- // 提交主表单的函数
|
|
|
function submitMainForm(postData, loadingIndex) {
|
|
|
Fast.api.ajax({
|
|
|
url: 'qcode_add/add_bach',
|
|
|
@@ -653,10 +796,10 @@
|
|
|
}, function (data, res) {
|
|
|
layer.close(loadingIndex);
|
|
|
if (res.code == 1) {
|
|
|
- layer.msg('保存成功', {icon: 1});
|
|
|
window.location.reload();
|
|
|
- // 或者跳转到其他页面
|
|
|
- // Backend.api.addtabs('deliver/apply');
|
|
|
+ Backend.api.addtabs('/deliver/index');
|
|
|
+ // layer.msg('保存成功', {icon: 1});
|
|
|
+ // window.location.reload();
|
|
|
} else {
|
|
|
layer.msg(res.msg || '保存失败', {icon: 2});
|
|
|
}
|
|
|
@@ -666,6 +809,4 @@
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
-
|
|
|
</script>
|