index.html 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  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></td>
  243. <td></td>
  244. <td id="totalQuantity">0</td>
  245. <td colSpan="2"></td>
  246. </tr>
  247. </tfoot>
  248. </table>
  249. </div>
  250. </fieldset>
  251. <div class="form-group layer-footer">
  252. <label class="control-label col-xs-12 col-sm-5"></label>
  253. <div class="col-xs-12 col-sm-5"><br>
  254. <button type="submit" id="submit" class="btn btn-primary btn-embossed">保存</button></div>
  255. </div>
  256. </form>
  257. <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  258. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
  259. <script>
  260. let currentPage = 1;
  261. let limit = 10;
  262. let total = 0;
  263. let selectedRow = null;
  264. let selectedProducts = [];
  265. window.selectRow = function (row) {
  266. if (selectedRow) {
  267. $(selectedRow).removeClass('selected-row');
  268. }
  269. $(row).addClass('selected-row');
  270. selectedRow = row;
  271. };
  272. function addToShipment(row) {
  273. if ($(row).data('remaining_quantity') == 0) {
  274. layer.msg('库存数量为空!', {icon: 2});
  275. return;
  276. }
  277. const rowData = {
  278. gdbh: $(row).data('gdbh'),
  279. order_ddbh: $(row).data('order_ddbh'),
  280. cpbm: $(row).data('cpbm'),
  281. cpmc: $(row).data('cpmc'),
  282. remaining_quantity: $(row).data('remaining_quantity'),
  283. tray_count: 18,
  284. layer_height: '1.35',
  285. items_per_box: '20', // 默认每箱个数
  286. unit: '套', // 默认单位
  287. remark: ''
  288. };
  289. const exists = selectedProducts.some(item => item.gdbh === rowData.gdbh);
  290. if (exists) {
  291. layer.msg('该产品已添加到本次配货中!', {icon: 2});
  292. return;
  293. }
  294. selectedProducts.push(rowData);
  295. renderShipmentTable();
  296. }
  297. function removeFromShipment(index) {
  298. selectedProducts.splice(index, 1);
  299. renderShipmentTable();
  300. }
  301. function calculateTotalQuantity() {
  302. return selectedProducts.reduce((sum, product) => {
  303. const quantity = parseFloat(product.actual_quantity);
  304. return sum + (isNaN(quantity) ? 0 : quantity);
  305. }, 0);
  306. }
  307. function validateQuantityInput(input, maxValue) {
  308. const value = input.val().trim();
  309. const numericValue = parseFloat(value);
  310. if (value !== '' && isNaN(numericValue)) {
  311. input.addClass('invalid');
  312. layer.tips('请输入有效数字', input, {tips: [1, '#FF5722']});
  313. return false;
  314. }
  315. if (numericValue > maxValue) {
  316. input.addClass('invalid');
  317. layer.tips(`不能超过${maxValue}`, input, {tips: [1, '#FF5722']});
  318. return false;
  319. }
  320. input.removeClass('invalid');
  321. return true;
  322. }
  323. function renderShipmentTable() {
  324. const tbody = $('#tableBody1');
  325. tbody.empty();
  326. if (selectedProducts.length === 0) {
  327. tbody.append('<tr><td colspan="10" style="text-align:center;">暂无配货数据</td></tr>');
  328. $('#tableFooter1').hide();
  329. return;
  330. }
  331. selectedProducts.forEach((product, index) => {
  332. // 初始化时确保 actual_quantity 有值
  333. if (product.actual_quantity === undefined || product.actual_quantity === '') {
  334. product.actual_quantity = product.remaining_quantity;
  335. }
  336. const tr = $(`
  337. <tr>
  338. <td>${index + 1}</td>
  339. <td>${product.cpmc}</td>
  340. <td>${product.remaining_quantity}</td>
  341. <td>
  342. <input type="text"
  343. class="items-per-box"
  344. data-index="${index}"
  345. value="${product.items_per_box || '20'}"
  346. list="items-per-box-list"
  347. style="width:80px">
  348. <datalist id="items-per-box-list">
  349. <option value="20">
  350. <option value="24">
  351. <option value="32">
  352. <option value="40">
  353. <option value="42">
  354. <option value="48">
  355. <option value="60">
  356. <option value="72">
  357. <option value="70">
  358. <option value="80">
  359. <option value="96">
  360. <option value="108">
  361. <option value="240">
  362. </datalist>
  363. </td>
  364. <td>
  365. <select class="unit-select" data-index="${index}">
  366. <option value="套" ${product.unit === '套' ? 'selected' : ''}>套</option>
  367. <option value="张" ${product.unit === '张' ? 'selected' : ''}>张</option>
  368. <option value="个" ${product.unit === '个' ? 'selected' : ''}>个</option>
  369. <option value="托" ${product.unit === '托' ? 'selected' : ''}>托</option>
  370. <option value="卷" ${product.unit === '卷' ? 'selected' : ''}>卷</option>
  371. </select>
  372. </td>
  373. <td>
  374. <select class="tray-count-select" data-index="${index}">
  375. <option value="18" ${product.tray_count == 18 ? 'selected' : ''}>18</option>
  376. <option value="24" ${product.tray_count == 24 ? 'selected' : ''}>24</option>
  377. </select>
  378. </td>
  379. <td>
  380. <select class="layer-height-select" data-index="${index}">
  381. <option value="1.35" ${product.layer_height == '1.35' ? 'selected' : ''}>1.35</option>
  382. <option value="1.05" ${product.layer_height == '1.05' ? 'selected' : ''}>1.05</option>
  383. </select>
  384. </td>
  385. <td>
  386. <input type="text" class="quantity-input" data-index="${index}"
  387. value="${product.actual_quantity || ''}"
  388. placeholder="" style="width:100%"
  389. max="${product.remaining_quantity}">
  390. </td>
  391. <td><input type="text" class="remark-input" data-index="${index}" value="${product.remark || ''}" placeholder="请输入备注" style="width:100%"></td>
  392. <td><span class="remove-btn" onclick="removeFromShipment(${index})">移除</span></td>
  393. </tr>
  394. `);
  395. tbody.append(tr);
  396. });
  397. $('#tableFooter1').show();
  398. $('#totalQuantity').text(calculateTotalQuantity());
  399. $('.tray-count-select').off('change').on('change', function () {
  400. const index = $(this).data('index');
  401. selectedProducts[index].tray_count = $(this).val();
  402. });
  403. $('.layer-height-select').off('change').on('change', function () {
  404. const index = $(this).data('index');
  405. selectedProducts[index].layer_height = $(this).val();
  406. });
  407. $('.items-per-box').off('input').on('input', function () {
  408. const index = $(this).data('index');
  409. selectedProducts[index].items_per_box = $(this).val();
  410. });
  411. $('.unit-select').off('change').on('change', function () {
  412. const index = $(this).data('index');
  413. selectedProducts[index].unit = $(this).val();
  414. });
  415. $('.remark-input').off('input').on('input', function () {
  416. const index = $(this).data('index');
  417. selectedProducts[index].remark = $(this).val();
  418. });
  419. $('.quantity-input').off('input').on('input', function () {
  420. const index = $(this).data('index');
  421. const input = $(this);
  422. const maxValue = parseFloat(selectedProducts[index].remaining_quantity);
  423. if (!validateQuantityInput(input, maxValue)) return;
  424. selectedProducts[index].actual_quantity = input.val().trim() === '' ? '' : parseFloat(input.val());
  425. $('#totalQuantity').text(calculateTotalQuantity());
  426. });
  427. }
  428. function loadData(page = 1, keyword = '') {
  429. $.ajax({
  430. method: "GET",
  431. url: "/qcode_add/product",
  432. data: {page, limit, search: keyword},
  433. dataType: "json",
  434. success: function (res) {
  435. const data = res.data || [];
  436. total = res.total || 0;
  437. currentPage = res.page || 1;
  438. limit = res.limit || 10;
  439. const tbody = $('#tableBody');
  440. tbody.empty();
  441. selectedRow = null;
  442. if (data.length === 0) {
  443. tbody.append('<tr><td colspan="7">无数据</td></tr>');
  444. return;
  445. }
  446. data.forEach(item => {
  447. const tr = $(`
  448. <tr onclick="selectRow(this)"
  449. data-order_ddbh="${item.order_ddbh}"
  450. data-gdbh="${item.gdbh}"
  451. data-cpbm="${item.cpbm}"
  452. data-cpmc="${item.cpmc}"
  453. data-sl="${item.sl}"
  454. data-total_chu_quantity="${item.total_chu_quantity}"
  455. data-remaining_quantity="${item.remaining_quantity}">
  456. <td>${item.order_ddbh}</td>
  457. <td>${item.gdbh}</td>
  458. <td>${item.cpbm}</td>
  459. <td>${item.cpmc}</td>
  460. <td>${item.sl}</td>
  461. <td>${item.total_chu_quantity}</td>
  462. <td>${item.remaining_quantity}</td>
  463. </tr>`);
  464. tbody.append(tr);
  465. });
  466. renderPagination();
  467. }
  468. });
  469. }
  470. function renderPagination() {
  471. const pageCount = Math.ceil(total / limit);
  472. const info = $('#pagination-info');
  473. const wrapper = $('#pagination-controls');
  474. const keyword = $('#searchInput').val().trim();
  475. wrapper.empty();
  476. info.text(`共 ${total} 条记录,第 ${currentPage} / ${pageCount} 页`);
  477. const prev = $('<button type="button">上一页</button>').prop('disabled', currentPage <= 1);
  478. prev.on('click', () => loadData(currentPage - 1, keyword));
  479. wrapper.append(prev);
  480. const start = Math.max(1, currentPage - 1);
  481. const end = Math.min(pageCount, currentPage + 1);
  482. for (let i = start; i <= end; i++) {
  483. const btn = $('<button type="button"></button>').text(i);
  484. if (i === currentPage) btn.addClass('active');
  485. btn.on('click', () => loadData(i, keyword));
  486. wrapper.append(btn);
  487. }
  488. const next = $('<button type="button">下一页</button>').prop('disabled', currentPage >= pageCount);
  489. next.on('click', () => loadData(currentPage + 1, keyword));
  490. wrapper.append(next);
  491. }
  492. $(function () {
  493. loadData();
  494. $('#searchBtn').on('click', function (e) {
  495. e.preventDefault();
  496. loadData(1, $('#searchInput').val().trim());
  497. });
  498. $('#searchInput').on('keypress', function (e) {
  499. if (e.which === 13) {
  500. loadData(1, $(this).val().trim());
  501. }
  502. });
  503. $(document).on('click', '#tableBody tr', function () {
  504. addToShipment(this);
  505. });
  506. $('#sadBtn').on('click', function (e) {
  507. e.preventDefault();
  508. const generateRowHtml = (index) => `
  509. <tr data-row="${index}">
  510. <td><input type="text" name="order_ddbh" class="form-control" required /></td>
  511. <td><input type="text" name="gdbh" class="form-control" required /></td>
  512. <td><input type="text" name="cpbm" class="form-control" required /></td>
  513. <td><input type="text" name="cpmc" class="form-control" required /></td>
  514. <td><input type="number" name="sl" class="form-control" min="1" required /></td>
  515. <td>
  516. <select name="unit" class="form-control" required>
  517. <option value="套" selected>套</option>
  518. <option value="张">张</option>
  519. <option value="个">个</option>
  520. <option value="托">托</option>
  521. <option value="卷">卷</option>
  522. </select>
  523. </td>
  524. <td><input type="text" name="remark" class="form-control" /></td>
  525. <td>
  526. <button type="button" class="btn btn-success btn-xs add-row"><i class="fa fa-plus"></i></button>
  527. <button type="button" class="btn btn-danger btn-xs remove-row"><i class="fa fa-minus"></i></button>
  528. </td>
  529. </tr>
  530. `;
  531. layer.open({
  532. type: 1,
  533. title: '新增入库记录',
  534. area: ['90%', '70%'],
  535. shadeClose: true,
  536. resize: true,
  537. maxmin: true,
  538. btn: ['加入选品列表', '取消'],
  539. content: `
  540. <div style="padding:20px 30px">
  541. <table class="table table-bordered" id="productTable">
  542. <thead>
  543. <tr>
  544. <th>销售订单号</th>
  545. <th>工单编号</th>
  546. <th>成品编码</th>
  547. <th>成品名称</th>
  548. <th>入库数</th>
  549. <th>单位</th>
  550. <th>备注</th>
  551. <th>操作</th>
  552. </tr>
  553. </thead>
  554. <tbody>${generateRowHtml(0)}</tbody>
  555. </table>
  556. </div>
  557. `,
  558. success: function (layero, index) {
  559. $(layero).on('click', '.add-row', function () {
  560. $('#productTable tbody').append(generateRowHtml($('#productTable tbody tr').length));
  561. });
  562. $(layero).on('click', '.remove-row', function () {
  563. if ($('#productTable tbody tr').length > 1) {
  564. $(this).closest('tr').remove();
  565. } else {
  566. layer.msg('至少保留一行', {icon: 2});
  567. }
  568. });
  569. },
  570. yes: function (index) {
  571. const newProducts = [];
  572. let isValid = true;
  573. $('#productTable tbody tr').each(function () {
  574. const rowData = {};
  575. let rowValid = true;
  576. // 获取所有输入字段和select字段,包括必填和非必填
  577. $(this).find('input, select').each(function () {
  578. const name = $(this).attr('name');
  579. const val = $(this).val().trim();
  580. // 对必填字段进行验证
  581. if ($(this).prop('required') && !val) {
  582. layer.tips('此项为必填项', $(this), {tips: [1, '#FF5722']});
  583. isValid = rowValid = false;
  584. return false;
  585. }
  586. rowData[name] = val;
  587. });
  588. if (rowValid) {
  589. rowData.remaining_quantity = rowData.sl;
  590. rowData.total_chu_quantity = 0;
  591. rowData.tray_count = 18;
  592. rowData.layer_height = '1.35';
  593. rowData.items_per_box = '20';
  594. rowData.isNew = true;
  595. newProducts.push(rowData);
  596. }
  597. });
  598. if (!isValid || newProducts.length === 0) {
  599. if (newProducts.length === 0) layer.msg('请至少填写一行有效数据', {icon: 2});
  600. return;
  601. }
  602. newProducts.forEach(product => {
  603. if (!selectedProducts.some(item => item.gdbh === product.gdbh)) {
  604. selectedProducts.push({
  605. gdbh: product.gdbh,
  606. order_ddbh: product.order_ddbh,
  607. cpbm: product.cpbm,
  608. cpmc: product.cpmc,
  609. remaining_quantity: product.remaining_quantity,
  610. total_chu_quantity: product.total_chu_quantity,
  611. tray_count: product.tray_count,
  612. layer_height: product.layer_height,
  613. items_per_box: product.items_per_box,
  614. unit: product.unit,
  615. isNew: true,
  616. remark: product.remark || ''
  617. });
  618. }
  619. });
  620. layer.msg(`成功添加 ${newProducts.length} 个产品到选品列表`, {icon: 1});
  621. layer.close(index);
  622. renderShipmentTable();
  623. }
  624. });
  625. });
  626. $('#submit').off('click').on('click', function (e) {
  627. e.preventDefault();
  628. if (selectedProducts.length === 0) {
  629. layer.msg('请至少选择一个产品添加到打托选品列表!', {icon: 2});
  630. return false;
  631. }
  632. let allValid = true;
  633. $('.quantity-input').each(function () {
  634. const index = $(this).data('index');
  635. if (!validateQuantityInput($(this), parseFloat(selectedProducts[index].remaining_quantity))) {
  636. allValid = false;
  637. }
  638. });
  639. if (!allValid) {
  640. layer.msg('请检查实际发货数量输入是否正确', {icon: 2});
  641. return false;
  642. }
  643. $('.quantity-input').each(function () {
  644. const index = $(this).data('index');
  645. selectedProducts[index].actual_quantity = $(this).val().trim() === '' ? '' : parseFloat($(this).val());
  646. });
  647. $('.remark-input').each(function () {
  648. const index = $(this).data('index');
  649. selectedProducts[index].remark = $(this).val() || '';
  650. });
  651. $('.items-per-box').each(function () {
  652. const index = $(this).data('index');
  653. selectedProducts[index].items_per_box = $(this).val() || '20';
  654. });
  655. $('.unit-select').each(function () {
  656. const index = $(this).data('index');
  657. selectedProducts[index].unit = $(this).val() || '个';
  658. });
  659. const newProducts = selectedProducts.filter(p => p.isNew);
  660. const postData = {
  661. company_name: $('#c-company_name').val(),
  662. postcode: $('#c-postcode').val(),
  663. mobile: $('#c-mobile').val(),
  664. company_address: $('#c-company_address').val(),
  665. printer_code: $('#c-printer_code').val(),
  666. products: selectedProducts.map(p => ({
  667. ...p,
  668. remark: p.remark || '',
  669. actual_quantity: p.actual_quantity || p.remaining_quantity,
  670. tray_count: p.tray_count || 18,
  671. layer_height: p.layer_height || '1.35',
  672. items_per_box: p.items_per_box || '20',
  673. unit: p.unit || '套'
  674. })),
  675. newProducts: newProducts.map(p => ({
  676. order_ddbh: p.order_ddbh,
  677. gdbh: p.gdbh,
  678. cpbm: p.cpbm,
  679. cpmc: p.cpmc,
  680. sl: p.remaining_quantity,
  681. remark: p.remark || '',
  682. actual_quantity: p.actual_quantity || p.remaining_quantity,
  683. tray_count: p.tray_count || 18,
  684. layer_height: p.layer_height || '1.35',
  685. items_per_box: p.items_per_box || '20',
  686. unit: p.unit || '个'
  687. }))
  688. };
  689. const loadingIndex = layer.msg('处理中...', {icon: 16, shade: 0.3, time: 0});
  690. if (newProducts.length > 0) {
  691. $.ajax({
  692. method: "POST",
  693. url: "Finishedproduct/finished",
  694. contentType: "application/json",
  695. data: JSON.stringify({data: postData.newProducts}),
  696. success: function (res) {
  697. if (res && res.code === 1) {
  698. submitMainForm(postData, loadingIndex);
  699. } else {
  700. layer.close(loadingIndex);
  701. layer.msg(res?.msg || '新增产品入库失败', {icon: 2});
  702. }
  703. },
  704. error: function (xhr) {
  705. layer.close(loadingIndex);
  706. layer.msg('新增产品入库失败: ' + (xhr.responseJSON?.message || xhr.statusText || '请求失败'), {icon: 2});
  707. }
  708. });
  709. } else {
  710. submitMainForm(postData, loadingIndex);
  711. }
  712. });
  713. function submitMainForm(postData, loadingIndex) {
  714. Fast.api.ajax({
  715. url: 'qcode_add/add_bach',
  716. type: 'POST',
  717. data: {row: JSON.stringify(postData)},
  718. }, function (data, res) {
  719. // layer.close(loadingIndex);
  720. console.log(res.code);
  721. if (res.code == 1) {
  722. window.location.reload();
  723. Backend.api.addtabs('/deliver/index');
  724. } else {
  725. layer.msg(res.msg || '保存失败', {icon: 2});
  726. }
  727. }, function () {
  728. layer.close(loadingIndex);
  729. layer.msg('请求失败', {icon: 2});
  730. });
  731. }
  732. });
  733. </script>