index.html 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. <style>
  2. table tr th, table tr td {
  3. border: thin #ddd dashed;
  4. padding: 5px;
  5. }
  6. .select2-container {
  7. width: 400px !important;
  8. }
  9. .select2-dropdown {
  10. width: 400px !important;
  11. }
  12. .select2-results__options {
  13. max-height: 200px;
  14. overflow-y: auto;
  15. }
  16. .select2-container--default .select2-selection--single .select2-selection__clear {
  17. margin-top: -6px;
  18. }
  19. .select2-container--default .select2-selection--single .select2-selection__rendered {
  20. line-height: 35px;
  21. }
  22. .select2-container--default .select2-selection--single {
  23. width: 470px !important;
  24. height: 35px !important;
  25. line-height: 38px;
  26. padding: 4px 10px;
  27. font-size: 14px;
  28. border: 1px solid #ccc;
  29. border-radius: 4px;
  30. box-sizing: border-box;
  31. }
  32. .select2-container--open .select2-dropdown--below {
  33. margin-top: -13px;
  34. }
  35. .selection {
  36. top: -13px;
  37. }
  38. .selected-row {
  39. background-color: #ddefeb !important;
  40. }
  41. #pagination-wrapper {
  42. margin-top: 20px;
  43. font-family: Arial, sans-serif;
  44. text-align: center;
  45. }
  46. #pagination-bar {
  47. display: flex;
  48. justify-content: center;
  49. align-items: center;
  50. flex-wrap: nowrap;
  51. gap: 16px;
  52. white-space: nowrap;
  53. overflow-x: auto;
  54. }
  55. #pagination-info {
  56. color: #444;
  57. }
  58. #pagination-controls {
  59. display: inline-flex;
  60. gap: 8px;
  61. flex-wrap: nowrap;
  62. }
  63. #pagination-controls button {
  64. padding: 6px 12px;
  65. border: 1px solid #ccc;
  66. background-color: #f8f8f8;
  67. cursor: pointer;
  68. border-radius: 4px;
  69. transition: all 0.2s ease;
  70. }
  71. #pagination-controls button:hover:not(:disabled) {
  72. background-color: #e0e0e0;
  73. }
  74. #pagination-controls button:disabled {
  75. background-color: #f0f0f0;
  76. cursor: not-allowed;
  77. color: #aaa;
  78. }
  79. #pagination-controls button.active {
  80. background-color: #007bff;
  81. color: white;
  82. font-weight: bold;
  83. border-color: #007bff;
  84. }
  85. #table-container {
  86. height: 200px;
  87. overflow-y: auto;
  88. border: 1px solid #ccc;
  89. margin-bottom: 10px;
  90. }
  91. #table thead th {
  92. position: sticky;
  93. top: 0;
  94. background-color: #f5f5f5;
  95. z-index: 1;
  96. }
  97. .tray-btn {
  98. padding: 5px 10px;
  99. margin-right: 8px;
  100. border: 1px solid #ccc;
  101. background-color: white;
  102. color: #000;
  103. cursor: pointer;
  104. border-radius: 4px;
  105. }
  106. .tray-btn.active {
  107. background-color: #007bff;
  108. color: white;
  109. border-color: #007bff;
  110. }
  111. .remove-btn {
  112. color: red;
  113. cursor: pointer;
  114. margin-left: 10px;
  115. }
  116. #tableBody tr {
  117. cursor: pointer;
  118. }
  119. #tableBody tr:hover {
  120. background-color: #f0f0f0;
  121. }
  122. #tableBody1 tr td {
  123. padding: 8px;
  124. }
  125. .total-row {
  126. font-weight: bold;
  127. background-color: #f5f5f5;
  128. }
  129. .tray-count-select {
  130. width: 80px;
  131. padding: 5px;
  132. border: 1px solid #ccc;
  133. border-radius: 4px;
  134. }
  135. .layer-height-select {
  136. width: 80px;
  137. padding: 5px;
  138. border: 1px solid #ccc;
  139. border-radius: 4px;
  140. }
  141. .quantity-input.invalid {
  142. border-color: red;
  143. background-color: #ffeeee;
  144. }
  145. .items-per-box {
  146. width: 80px;
  147. padding: 5px;
  148. border: 1px solid #ccc;
  149. border-radius: 4px;
  150. }
  151. .unit-select {
  152. width: 80px;
  153. padding: 5px;
  154. border: 1px solid #ccc;
  155. border-radius: 4px;
  156. }
  157. </style>
  158. <form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
  159. <fieldset style="width: 1280px;margin:10px 10px 0px 10px ;padding: 10px 10px 0px 10px ;border:solid thin #c0c0c0">
  160. <legend style="padding: 0px;margin: 0px">生成厂商信息</legend>
  161. <div class="form-group">
  162. <label class="control-label col-xs-2 col-sm-1">生产厂商:</label>
  163. <div class="col-xs-2 col-sm-3">
  164. <input id="c-company_name" data-rule="required" disabled class="form-control" value="{$row['nickname']}" name="company_name" type="text">
  165. </div>
  166. <label class="control-label col-xs-2 col-sm-1">邮政编码:</label>
  167. <div class="col-xs-2 col-sm-3">
  168. <input id="c-postcode" data-rule="required" disabled class="form-control" value="{$row['postcode']}" name="postcode" type="text">
  169. </div>
  170. <label class="control-label col-xs-2 col-sm-1">电&nbsp;&nbsp;话:</label>
  171. <div class="col-xs-2 col-sm-3">
  172. <input id="c-mobile" data-rule="required;mobile" disabled class="form-control" value="{$row['mobile']}" name="mobile" type="text">
  173. </div>
  174. </div>
  175. <div class="form-group">
  176. <label class="control-label col-xs-2 col-sm-1">地&nbsp;&nbsp;&nbsp;&nbsp;址:</label>
  177. <div class="col-xs-2 col-sm-7">
  178. <input id="c-company_address" data-rule="required" disabled class="form-control" value="{$row['company_address']}" name="company_address" type="text">
  179. </div>
  180. <label class="control-label col-xs-2 col-sm-1">厂家编码:</label>
  181. <div class="col-xs-2 col-sm-3">
  182. <input id="c-printer_code" data-rule="required" disabled class="form-control" value="{$row['printer_code']}" name="company_address" type="text">
  183. </div>
  184. </div>
  185. </fieldset>
  186. <fieldset style="width:1280px;margin:10px 10px 0;padding:10px;border:solid thin #c0c0c0">
  187. <legend style="padding:0;margin:0">打托选择列表</legend>
  188. <div style="margin-bottom:10px">
  189. <input type="text" id="searchInput" placeholder="请输入关键字搜索..." style="width:300px;height:35px">
  190. <button type="button" id="searchBtn" className="btn btn-primary" style="height:34px">查询</button>
  191. <button id="sadBtn" class="btn btn-success">
  192. <i class="fas fa-plus"></i> 新增产品
  193. </button>
  194. </div>
  195. <div id="table-container">
  196. <table id="table" style="width:100%;border-collapse:collapse">
  197. <thead>
  198. <tr>
  199. <th>销售订单号</th>
  200. <th>工单编号</th>
  201. <th>成品编码</th>
  202. <th>成品名称</th>
  203. <th>入库数</th>
  204. <th>发货数</th>
  205. <th>剩余数</th>
  206. </tr>
  207. </thead>
  208. <tbody id="tableBody"></tbody>
  209. </table>
  210. </div>
  211. <div id="pagination-wrapper">
  212. <div id="pagination-bar">
  213. <div id="pagination-info">共 0 条记录,第 1 / 1 页</div>
  214. <div id="pagination-controls"></div>
  215. </div>
  216. </div>
  217. </fieldset>
  218. <fieldset style="width:1280px;margin:10px 10px 0;padding:10px;border:solid thin #c0c0c0">
  219. <legend style="padding:0;margin:0">打托选品列表</legend>
  220. <div id="table-container1">
  221. <table id="table1" style="width:100%;border-collapse:collapse">
  222. <thead>
  223. <tr>
  224. <th style="width: 3%">序号</th>
  225. <th style="width: 15%">产品名称</th>
  226. <th style="width: 7%">可发数量</th>
  227. <th style="width: 4%">每箱个数</th>
  228. <th style="width: 4%">单位</th>
  229. <th style="width: 4%">打托数</th>
  230. <th style="width: 4%">层高</th>
  231. <th style="width: 9%">实际发货数量</th>
  232. <th style="width: 15%">备注</th>
  233. <th style="width: 4%">操作</th>
  234. </tr>
  235. </thead>
  236. <tbody id="tableBody1"></tbody>
  237. <tfoot id="tableFooter1" style="display:none">
  238. <tr className="total-row">
  239. <td colSpan="3">合计</td>
  240. <td></td>
  241. <td></td>
  242. <td id="totalQuantity">0</td>
  243. <td colSpan="2"></td>
  244. </tr>
  245. </tfoot>
  246. </table>
  247. </div>
  248. </fieldset>
  249. <div class="form-group layer-footer">
  250. <label class="control-label col-xs-12 col-sm-5"></label>
  251. <div class="col-xs-12 col-sm-5"><br>
  252. <button type="submit" id="submit" class="btn btn-primary btn-embossed">保存</button></div>
  253. </div>
  254. </form>
  255. <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  256. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
  257. <script>
  258. let currentPage = 1;
  259. let limit = 10;
  260. let total = 0;
  261. let selectedRow = null;
  262. let selectedProducts = [];
  263. window.selectRow = function (row) {
  264. if (selectedRow) {
  265. $(selectedRow).removeClass('selected-row');
  266. }
  267. $(row).addClass('selected-row');
  268. selectedRow = row;
  269. };
  270. function addToShipment(row) {
  271. if ($(row).data('remaining_quantity') == 0) {
  272. layer.msg('库存数量为空!', {icon: 2});
  273. return;
  274. }
  275. const rowData = {
  276. gdbh: $(row).data('gdbh'),
  277. order_ddbh: $(row).data('order_ddbh'),
  278. cpbm: $(row).data('cpbm'),
  279. cpmc: $(row).data('cpmc'),
  280. remaining_quantity: $(row).data('remaining_quantity'),
  281. tray_count: 18,
  282. layer_height: '1.35',
  283. items_per_box: '20', // 默认每箱个数
  284. unit: '套', // 默认单位
  285. remark: ''
  286. };
  287. const exists = selectedProducts.some(item => item.gdbh === rowData.gdbh);
  288. if (exists) {
  289. layer.msg('该产品已添加到本次配货中!', {icon: 2});
  290. return;
  291. }
  292. selectedProducts.push(rowData);
  293. renderShipmentTable();
  294. }
  295. function removeFromShipment(index) {
  296. selectedProducts.splice(index, 1);
  297. renderShipmentTable();
  298. }
  299. function calculateTotalQuantity() {
  300. return selectedProducts.reduce((sum, product) => {
  301. const quantity = parseFloat(product.actual_quantity);
  302. return sum + (isNaN(quantity) ? 0 : quantity);
  303. }, 0);
  304. }
  305. function validateQuantityInput(input, maxValue) {
  306. const value = input.val().trim();
  307. const numericValue = parseFloat(value);
  308. if (value !== '' && isNaN(numericValue)) {
  309. input.addClass('invalid');
  310. layer.tips('请输入有效数字', input, {tips: [1, '#FF5722']});
  311. return false;
  312. }
  313. if (numericValue > maxValue) {
  314. input.addClass('invalid');
  315. layer.tips(`不能超过${maxValue}`, input, {tips: [1, '#FF5722']});
  316. return false;
  317. }
  318. input.removeClass('invalid');
  319. return true;
  320. }
  321. function renderShipmentTable() {
  322. const tbody = $('#tableBody1');
  323. tbody.empty();
  324. if (selectedProducts.length === 0) {
  325. tbody.append('<tr><td colspan="10" style="text-align:center;">暂无配货数据</td></tr>');
  326. $('#tableFooter1').hide();
  327. return;
  328. }
  329. selectedProducts.forEach((product, index) => {
  330. // 初始化时确保 actual_quantity 有值
  331. if (product.actual_quantity === undefined || product.actual_quantity === '') {
  332. product.actual_quantity = product.remaining_quantity;
  333. }
  334. const tr = $(`
  335. <tr>
  336. <td>${index + 1}</td>
  337. <td>${product.cpmc}</td>
  338. <td>${product.remaining_quantity}</td>
  339. <td>
  340. <input type="text"
  341. class="items-per-box"
  342. data-index="${index}"
  343. value="${product.items_per_box || '20'}"
  344. list="items-per-box-list"
  345. style="width:80px">
  346. <datalist id="items-per-box-list">
  347. <option value="20">
  348. <option value="24">
  349. <option value="32">
  350. <option value="40">
  351. <option value="42">
  352. <option value="48">
  353. <option value="60">
  354. <option value="72">
  355. <option value="70">
  356. <option value="80">
  357. <option value="96">
  358. <option value="108">
  359. <option value="240">
  360. </datalist>
  361. </td>
  362. <td>
  363. <select class="unit-select" data-index="${index}">
  364. <option value="套" ${product.unit === '套' ? 'selected' : ''}>套</option>
  365. <option value="张" ${product.unit === '张' ? 'selected' : ''}>张</option>
  366. <option value="个" ${product.unit === '个' ? 'selected' : ''}>个</option>
  367. </select>
  368. </td>
  369. <td>
  370. <select class="tray-count-select" data-index="${index}">
  371. <option value="18" ${product.tray_count == 18 ? 'selected' : ''}>18</option>
  372. <option value="24" ${product.tray_count == 24 ? 'selected' : ''}>24</option>
  373. </select>
  374. </td>
  375. <td>
  376. <select class="layer-height-select" data-index="${index}">
  377. <option value="1.35" ${product.layer_height == '1.35' ? 'selected' : ''}>1.35</option>
  378. <option value="1.05" ${product.layer_height == '1.05' ? 'selected' : ''}>1.05</option>
  379. </select>
  380. </td>
  381. <td>
  382. <input type="text" class="quantity-input" data-index="${index}"
  383. value="${product.actual_quantity || ''}"
  384. placeholder="" style="width:100%"
  385. max="${product.remaining_quantity}">
  386. </td>
  387. <td><input type="text" class="remark-input" data-index="${index}" value="${product.remark || ''}" placeholder="请输入备注" style="width:100%"></td>
  388. <td><span class="remove-btn" onclick="removeFromShipment(${index})">移除</span></td>
  389. </tr>
  390. `);
  391. tbody.append(tr);
  392. });
  393. $('#tableFooter1').show();
  394. $('#totalQuantity').text(calculateTotalQuantity());
  395. $('.tray-count-select').off('change').on('change', function () {
  396. const index = $(this).data('index');
  397. selectedProducts[index].tray_count = $(this).val();
  398. });
  399. $('.layer-height-select').off('change').on('change', function () {
  400. const index = $(this).data('index');
  401. selectedProducts[index].layer_height = $(this).val();
  402. });
  403. $('.items-per-box').off('input').on('input', function () {
  404. const index = $(this).data('index');
  405. selectedProducts[index].items_per_box = $(this).val();
  406. });
  407. $('.unit-select').off('change').on('change', function () {
  408. const index = $(this).data('index');
  409. selectedProducts[index].unit = $(this).val();
  410. });
  411. $('.remark-input').off('input').on('input', function () {
  412. const index = $(this).data('index');
  413. selectedProducts[index].remark = $(this).val();
  414. });
  415. $('.quantity-input').off('input').on('input', function () {
  416. const index = $(this).data('index');
  417. const input = $(this);
  418. const maxValue = parseFloat(selectedProducts[index].remaining_quantity);
  419. if (!validateQuantityInput(input, maxValue)) return;
  420. selectedProducts[index].actual_quantity = input.val().trim() === '' ? '' : parseFloat(input.val());
  421. $('#totalQuantity').text(calculateTotalQuantity());
  422. });
  423. }
  424. function loadData(page = 1, keyword = '') {
  425. $.ajax({
  426. method: "GET",
  427. url: "/qcode_add/product",
  428. data: {page, limit, search: keyword},
  429. dataType: "json",
  430. success: function (res) {
  431. const data = res.data || [];
  432. total = res.total || 0;
  433. currentPage = res.page || 1;
  434. limit = res.limit || 10;
  435. const tbody = $('#tableBody');
  436. tbody.empty();
  437. selectedRow = null;
  438. if (data.length === 0) {
  439. tbody.append('<tr><td colspan="7">无数据</td></tr>');
  440. return;
  441. }
  442. data.forEach(item => {
  443. const tr = $(`
  444. <tr onclick="selectRow(this)"
  445. data-order_ddbh="${item.order_ddbh}"
  446. data-gdbh="${item.gdbh}"
  447. data-cpbm="${item.cpbm}"
  448. data-cpmc="${item.cpmc}"
  449. data-sl="${item.sl}"
  450. data-total_chu_quantity="${item.total_chu_quantity}"
  451. data-remaining_quantity="${item.remaining_quantity}">
  452. <td>${item.order_ddbh}</td>
  453. <td>${item.gdbh}</td>
  454. <td>${item.cpbm}</td>
  455. <td>${item.cpmc}</td>
  456. <td>${item.sl}</td>
  457. <td>${item.total_chu_quantity}</td>
  458. <td>${item.remaining_quantity}</td>
  459. </tr>`);
  460. tbody.append(tr);
  461. });
  462. renderPagination();
  463. }
  464. });
  465. }
  466. function renderPagination() {
  467. const pageCount = Math.ceil(total / limit);
  468. const info = $('#pagination-info');
  469. const wrapper = $('#pagination-controls');
  470. const keyword = $('#searchInput').val().trim();
  471. wrapper.empty();
  472. info.text(`共 ${total} 条记录,第 ${currentPage} / ${pageCount} 页`);
  473. const prev = $('<button type="button">上一页</button>').prop('disabled', currentPage <= 1);
  474. prev.on('click', () => loadData(currentPage - 1, keyword));
  475. wrapper.append(prev);
  476. const start = Math.max(1, currentPage - 1);
  477. const end = Math.min(pageCount, currentPage + 1);
  478. for (let i = start; i <= end; i++) {
  479. const btn = $('<button type="button"></button>').text(i);
  480. if (i === currentPage) btn.addClass('active');
  481. btn.on('click', () => loadData(i, keyword));
  482. wrapper.append(btn);
  483. }
  484. const next = $('<button type="button">下一页</button>').prop('disabled', currentPage >= pageCount);
  485. next.on('click', () => loadData(currentPage + 1, keyword));
  486. wrapper.append(next);
  487. }
  488. $(function () {
  489. loadData();
  490. $('#searchBtn').on('click', function (e) {
  491. e.preventDefault();
  492. loadData(1, $('#searchInput').val().trim());
  493. });
  494. $('#searchInput').on('keypress', function (e) {
  495. if (e.which === 13) {
  496. loadData(1, $(this).val().trim());
  497. }
  498. });
  499. $(document).on('click', '#tableBody tr', function () {
  500. addToShipment(this);
  501. });
  502. $('#sadBtn').on('click', function (e) {
  503. e.preventDefault();
  504. const generateRowHtml = (index) => `
  505. <tr data-row="${index}">
  506. <td><input type="text" name="order_ddbh" class="form-control" required /></td>
  507. <td><input type="text" name="gdbh" class="form-control" required /></td>
  508. <td><input type="text" name="cpbm" class="form-control" required /></td>
  509. <td><input type="text" name="cpmc" class="form-control" required /></td>
  510. <td><input type="number" name="sl" class="form-control" min="1" required /></td>
  511. <td>
  512. <button type="button" class="btn btn-success btn-xs add-row"><i class="fa fa-plus"></i></button>
  513. <button type="button" class="btn btn-danger btn-xs remove-row"><i class="fa fa-minus"></i></button>
  514. </td>
  515. </tr>
  516. `;
  517. layer.open({
  518. type: 1,
  519. title: '新增入库记录',
  520. area: ['90%', '70%'],
  521. shadeClose: true,
  522. resize: true,
  523. maxmin: true,
  524. btn: ['加入选品列表', '取消'],
  525. content: `
  526. <div style="padding:20px 30px">
  527. <table class="table table-bordered" id="productTable">
  528. <thead>
  529. <tr>
  530. <th>销售订单号</th>
  531. <th>工单编号</th>
  532. <th>成品编码</th>
  533. <th>成品名称</th>
  534. <th>入库数</th>
  535. <th>操作</th>
  536. </tr>
  537. </thead>
  538. <tbody>${generateRowHtml(0)}</tbody>
  539. </table>
  540. </div>
  541. `,
  542. success: function (layero, index) {
  543. $(layero).on('click', '.add-row', function () {
  544. $('#productTable tbody').append(generateRowHtml($('#productTable tbody tr').length));
  545. });
  546. $(layero).on('click', '.remove-row', function () {
  547. if ($('#productTable tbody tr').length > 1) {
  548. $(this).closest('tr').remove();
  549. } else {
  550. layer.msg('至少保留一行', {icon: 2});
  551. }
  552. });
  553. },
  554. yes: function (index) {
  555. const newProducts = [];
  556. let isValid = true;
  557. $('#productTable tbody tr').each(function () {
  558. const rowData = {};
  559. let rowValid = true;
  560. $(this).find('[required]').each(function () {
  561. const val = $(this).val().trim();
  562. if (!val) {
  563. layer.tips('此项为必填项', $(this), {tips: [1, '#FF5722']});
  564. isValid = rowValid = false;
  565. return false;
  566. }
  567. rowData[$(this).attr('name')] = val;
  568. });
  569. if (rowValid) {
  570. rowData.remaining_quantity = rowData.sl;
  571. rowData.total_chu_quantity = 0;
  572. rowData.tray_count = 18;
  573. rowData.layer_height = '1.35';
  574. rowData.items_per_box = '20';
  575. rowData.unit = '个';
  576. rowData.isNew = true;
  577. newProducts.push(rowData);
  578. }
  579. });
  580. if (!isValid || newProducts.length === 0) {
  581. if (newProducts.length === 0) layer.msg('请至少填写一行有效数据', {icon: 2});
  582. return;
  583. }
  584. newProducts.forEach(product => {
  585. if (!selectedProducts.some(item => item.gdbh === product.gdbh)) {
  586. selectedProducts.push({
  587. gdbh: product.gdbh,
  588. order_ddbh: product.order_ddbh,
  589. cpbm: product.cpbm,
  590. cpmc: product.cpmc,
  591. remaining_quantity: product.remaining_quantity,
  592. total_chu_quantity: product.total_chu_quantity,
  593. tray_count: product.tray_count,
  594. layer_height: product.layer_height,
  595. items_per_box: product.items_per_box,
  596. unit: product.unit,
  597. isNew: true,
  598. remark: ''
  599. });
  600. }
  601. });
  602. layer.msg(`成功添加 ${newProducts.length} 个产品到选品列表`, {icon: 1});
  603. layer.close(index);
  604. renderShipmentTable();
  605. }
  606. });
  607. });
  608. $('#submit').off('click').on('click', function (e) {
  609. e.preventDefault();
  610. if (selectedProducts.length === 0) {
  611. layer.msg('请至少选择一个产品添加到打托选品列表!', {icon: 2});
  612. return false;
  613. }
  614. let allValid = true;
  615. $('.quantity-input').each(function () {
  616. const index = $(this).data('index');
  617. if (!validateQuantityInput($(this), parseFloat(selectedProducts[index].remaining_quantity))) {
  618. allValid = false;
  619. }
  620. });
  621. if (!allValid) {
  622. layer.msg('请检查实际发货数量输入是否正确', {icon: 2});
  623. return false;
  624. }
  625. $('.quantity-input').each(function () {
  626. const index = $(this).data('index');
  627. selectedProducts[index].actual_quantity = $(this).val().trim() === '' ? '' : parseFloat($(this).val());
  628. });
  629. $('.remark-input').each(function () {
  630. const index = $(this).data('index');
  631. selectedProducts[index].remark = $(this).val() || '';
  632. });
  633. $('.items-per-box').each(function () {
  634. const index = $(this).data('index');
  635. selectedProducts[index].items_per_box = $(this).val() || '20';
  636. });
  637. $('.unit-select').each(function () {
  638. const index = $(this).data('index');
  639. selectedProducts[index].unit = $(this).val() || '个';
  640. });
  641. const newProducts = selectedProducts.filter(p => p.isNew);
  642. const postData = {
  643. company_name: $('#c-company_name').val(),
  644. postcode: $('#c-postcode').val(),
  645. mobile: $('#c-mobile').val(),
  646. company_address: $('#c-company_address').val(),
  647. printer_code: $('#c-printer_code').val(),
  648. products: selectedProducts.map(p => ({
  649. ...p,
  650. remark: p.remark || '',
  651. actual_quantity: p.actual_quantity || p.remaining_quantity,
  652. tray_count: p.tray_count || 18,
  653. layer_height: p.layer_height || '1.35',
  654. items_per_box: p.items_per_box || '20',
  655. unit: p.unit || '套'
  656. })),
  657. newProducts: newProducts.map(p => ({
  658. order_ddbh: p.order_ddbh,
  659. gdbh: p.gdbh,
  660. cpbm: p.cpbm,
  661. cpmc: p.cpmc,
  662. sl: p.remaining_quantity,
  663. remark: p.remark || '',
  664. actual_quantity: p.actual_quantity || p.remaining_quantity,
  665. tray_count: p.tray_count || 18,
  666. layer_height: p.layer_height || '1.35',
  667. items_per_box: p.items_per_box || '20',
  668. unit: p.unit || '个'
  669. }))
  670. };
  671. const loadingIndex = layer.msg('处理中...', {icon: 16, shade: 0.3, time: 0});
  672. if (newProducts.length > 0) {
  673. $.ajax({
  674. method: "POST",
  675. url: "Finishedproduct/finished",
  676. contentType: "application/json",
  677. data: JSON.stringify({data: postData.newProducts}),
  678. success: function (res) {
  679. if (res && res.code === 1) {
  680. submitMainForm(postData, loadingIndex);
  681. } else {
  682. layer.close(loadingIndex);
  683. layer.msg(res?.msg || '新增产品入库失败', {icon: 2});
  684. }
  685. },
  686. error: function (xhr) {
  687. layer.close(loadingIndex);
  688. layer.msg('新增产品入库失败: ' + (xhr.responseJSON?.message || xhr.statusText || '请求失败'), {icon: 2});
  689. }
  690. });
  691. } else {
  692. submitMainForm(postData, loadingIndex);
  693. }
  694. });
  695. function submitMainForm(postData, loadingIndex) {
  696. Fast.api.ajax({
  697. url: 'qcode_add/add_bach',
  698. type: 'POST',
  699. data: {row: JSON.stringify(postData)},
  700. }, function (data, res) {
  701. layer.close(loadingIndex);
  702. if (res.code == 1) {
  703. window.location.reload();
  704. Backend.api.addtabs('/deliver/index');
  705. // layer.msg('保存成功', {icon: 1});
  706. // window.location.reload();
  707. } else {
  708. layer.msg(res.msg || '保存失败', {icon: 2});
  709. }
  710. }, function () {
  711. layer.close(loadingIndex);
  712. layer.msg('请求失败', {icon: 2});
  713. });
  714. }
  715. });
  716. </script>