index.html 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. <style>
  2. table tr th,table tr td {border: thin #ddd dashed;padding: 5px }
  3. .select2-container {
  4. width: 400px !important;
  5. }
  6. .select2-dropdown {
  7. width: 400px !important;
  8. }
  9. .select2-results__options {
  10. max-height: 200px; /* 固定高度 */
  11. overflow-y: auto; /* 超出时出现滚动条 */
  12. }
  13. .select2-container--default .select2-selection--single .select2-selection__clear{
  14. margin-top: -6px;
  15. }
  16. .select2-container--default .select2-selection--single .select2-selection__rendered{
  17. line-height: 35px;
  18. }
  19. .select2-container--default .select2-selection--single{
  20. width: 470px !important;
  21. height: 35px !important;
  22. line-height: 38px;
  23. padding: 4px 10px;
  24. font-size: 14px;
  25. border: 1px solid #ccc;
  26. border-radius: 4px;
  27. box-sizing: border-box;
  28. }
  29. .select2-container--open .select2-dropdown--below{
  30. margin-top: -13px;
  31. }
  32. .selection{
  33. top: -13px;
  34. }
  35. /*table部分*/
  36. .selected-row {
  37. /*background-color: yellow !important;*/
  38. background-color: #ddefeb !important;
  39. }
  40. #pagination-wrapper {
  41. margin-top: 20px;
  42. font-family: Arial, sans-serif;
  43. text-align: center;
  44. }
  45. #pagination-bar {
  46. display: flex;
  47. justify-content: center;
  48. align-items: center;
  49. flex-wrap: nowrap;
  50. gap: 16px; /* 控制 info 和按钮间距 */
  51. white-space: nowrap;
  52. overflow-x: auto; /* 小屏幕自动横向滚动,防止换行 */
  53. }
  54. #pagination-info {
  55. color: #444;
  56. }
  57. #pagination-controls {
  58. display: inline-flex;
  59. gap: 8px;
  60. flex-wrap: nowrap;
  61. }
  62. #pagination-controls button {
  63. padding: 6px 12px;
  64. border: 1px solid #ccc;
  65. background-color: #f8f8f8;
  66. cursor: pointer;
  67. border-radius: 4px;
  68. transition: all 0.2s ease;
  69. }
  70. #pagination-controls button:hover:not(:disabled) {
  71. background-color: #e0e0e0;
  72. }
  73. #pagination-controls button:disabled {
  74. background-color: #f0f0f0;
  75. cursor: not-allowed;
  76. color: #aaa;
  77. }
  78. #pagination-controls button.active {
  79. background-color: #007bff;
  80. color: white;
  81. font-weight: bold;
  82. border-color: #007bff;
  83. }
  84. #table-container {
  85. height: 300px; /* 你可以按需调整高度 */
  86. overflow-y: auto;
  87. border: 1px solid #ccc;
  88. margin-bottom: 10px;
  89. }
  90. /* 让表头固定,表体滚动(可选进阶) */
  91. #table thead th {
  92. position: sticky;
  93. top: 0;
  94. background-color: #f5f5f5;
  95. z-index: 1;
  96. }
  97. </style>
  98. <form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
  99. <fieldset style="width: 1200px;margin:10px 10px 0px 10px ;padding: 10px 10px 0px 10px ;border:solid thin #c0c0c0">
  100. <legend style="padding: 0px;margin: 0px">生成厂商信息</legend>
  101. <div class="form-group">
  102. <label class="control-label col-xs-2 col-sm-1">生产厂商:</label>
  103. <div class="col-xs-2 col-sm-3">
  104. <input id="c-company_name" data-rule="required" disabled class="form-control" value="{$row['nickname']}" name="company_name" type="text">
  105. </div>
  106. <label class="control-label col-xs-2 col-sm-1">邮政编码:</label>
  107. <div class="col-xs-2 col-sm-3">
  108. <input id="c-postcode" data-rule="required" disabled class="form-control" value="{$row['postcode']}" name="postcode" type="text">
  109. </div>
  110. <label class="control-label col-xs-2 col-sm-1">电&nbsp;&nbsp;话:</label>
  111. <div class="col-xs-2 col-sm-3">
  112. <input id="c-mobile" data-rule="required;mobile" disabled class="form-control" value="{$row['mobile']}" name="mobile" type="text">
  113. </div>
  114. </div>
  115. <div class="form-group">
  116. <label class="control-label col-xs-2 col-sm-1">地&nbsp;&nbsp;&nbsp;&nbsp;址:</label>
  117. <div class="col-xs-2 col-sm-7">
  118. <input id="c-company_address" data-rule="required" disabled class="form-control" value="{$row['company_address']}" name="company_address" type="text">
  119. </div>
  120. <label class="control-label col-xs-2 col-sm-1">厂家编码:</label>
  121. <div class="col-xs-2 col-sm-3">
  122. <input id="c-printer_code" data-rule="required" disabled class="form-control" value="{$row['printer_code']}" name="company_address" type="text">
  123. </div>
  124. </div>
  125. </fieldset>
  126. <fieldset style="width: 1200px;margin:10px 10px 0px 10px ;padding: 10px 10px 0px 10px ;border: solid thin #c0c0c0">
  127. <legend style="padding: 0px;margin: 0px">产品信息</legend>
  128. <!-- 搜索栏 -->
  129. <div style="margin-bottom: 10px;">
  130. <input type="text" id="searchInput" placeholder="请输入关键字搜索..." style="width: 300px;height: 35px; " />
  131. <button id="searchBtn" class="btn btn-primary">搜索</button>
  132. </div>
  133. <!-- 表格容器 -->
  134. <div id="table-container">
  135. <table id="table" border="1" cellpadding="8" cellspacing="0" style="width: 100%;border-collapse: collapse;">
  136. <thead>
  137. <tr>
  138. <th>销售订单号</th>
  139. <th>工单编号</th>
  140. <th>成品编码</th>
  141. <th>成品名称</th>
  142. <th>入库数</th>
  143. <th>发货数</th>
  144. <th>剩余数</th>
  145. </tr>
  146. </thead>
  147. <tbody id="tableBody">
  148. </tbody>
  149. </table>
  150. </div>
  151. <!-- 分页控件 -->
  152. <div id="pagination-wrapper">
  153. <div id="pagination-bar">
  154. <div id="pagination-info">共 0 条记录,第 1 / 1 页</div>
  155. <div id="pagination-controls"></div>
  156. </div>
  157. </div>
  158. </fieldset>
  159. <fieldset style="width: 1200px;margin:10px 10px 0px 10px ;padding: 10px 10px 0px 10px ;border: solid thin #c0c0c0">
  160. <!-- <legend style="padding: 0px;margin: 0px">托盘参数</legend>-->
  161. <table style="width: 100%;border: thin #ddd dashed;">
  162. <!-- <caption style="padding: 0px;margin: 0px">标签序列配置</caption>-->
  163. <!-- <tr>-->
  164. <!-- <th style="width: 40%">字段</th>-->
  165. <!-- <th>值</th>-->
  166. <!-- </tr>-->
  167. <tr>
  168. <td><span>生产批次号/工单编号</span></td>
  169. <td style="padding: 5px 0px 0px 5px"><input type="text" disabled class="form-control" placeholder="选择产品信息获取" id="c-batch" name="batch" style="width: 360px;"></td>
  170. </tr>
  171. <tr>
  172. <td><span>销售订单号</span></td>
  173. <td style="padding: 5px 0px 0px 5px"><input type="text" disabled class="form-control" placeholder="选择产品信息获取" id="c-order_ddbh" name="order_ddbh" style="width: 360px;"></td>
  174. </tr>
  175. <tr>
  176. <td><span>成品编码</span></td>
  177. <td style="padding: 5px 0px 0px 5px"><input type="text" disabled class="form-control" placeholder="选择产品信息获取" id="c-cpbm" name="cpbm" style="width: 360px;"></td>
  178. </tr>
  179. <tr>
  180. <td><span>成品名称</span></td>
  181. <td style="padding: 5px 0px 0px 5px"><input type="text" disabled class="form-control" placeholder="选择产品信息获取" id="c-cpmc" name="cpmc" style="width: 360px;"></td>
  182. </tr>
  183. <tr style="display: none">
  184. <td><span>入库数</span></td>
  185. <td style="padding: 5px 0px 0px 5px"><input type="text" disabled class="form-control" placeholder="选择产品信息获取" id="c-sl" name="sl" style="width: 360px;"></td>
  186. </tr>
  187. <tr style="display: none">
  188. <td><span>发货数</span></td>
  189. <td style="padding: 5px 0px 0px 5px"><input type="text" disabled class="form-control" placeholder="选择产品信息获取" id="c-total_chu_quantity" name="total_chu_quantity" style="width: 360px;"></td>
  190. </tr>
  191. <tr>
  192. <td><span>剩余数</span></td>
  193. <td style="padding: 5px 0px 0px 5px"><input type="text" disabled class="form-control" placeholder="选择产品信息获取" id="c-remaining_quantity" name="remaining_quantity" style="width: 360px;"></td>
  194. </tr>
  195. <tr class="xiang">
  196. <td><span>本次打包数</span></td>
  197. <td style="padding: 5px 0px 0px 5px"><input type="text" oninput="validateAndCalculate()" name="number" id="c-number" data-rule="required"></td>
  198. </tr>
  199. <tr>
  200. <td><span>选择单位(个/套/张)</span></td>
  201. <td style="padding: 5px 0px 0px 5px">
  202. <select id="danwei" name="danwei" style="width: 200px;padding: 5px;">
  203. <option value="1">个</option>
  204. <option value="2">套</option>
  205. <option value="3">张</option>
  206. </select>
  207. </td>
  208. </tr>
  209. <tr class="xiang">
  210. <td><span>每一箱数量</span></td>
  211. <td style="padding: 5px 0px 0px 5px">
  212. <select name="box_number" id="box_number" oninput="calculateTotalBoxes()" style="width:200px;padding: 5px">
  213. <option value="1">========选择=========</option>
  214. <option value="20">========20========</option>
  215. <option value="25">========25========</option>
  216. <option value="25">========40========</option>
  217. <option value="50">========50========</option>
  218. <option value="250">========250========</option>
  219. <option value="500">========500========</option>
  220. <option value="1000">=======1000========</option>
  221. <option value="2000">=======2000========</option>
  222. <option value="2500">=======2500========</option>
  223. <option value="3000">=======3000========</option>
  224. <option value="4000">=======4000========</option>
  225. <option value="5000">=======5000========</option>
  226. <option value="8000">=======8000========</option>
  227. <option value="10000">=======10000========</option>
  228. <option value="24000">=======24000========</option>
  229. </select>
  230. </td>
  231. </tr>
  232. <tr class="xiang">
  233. <td><span>一托盘多少箱(箱*层)</span></td>
  234. <td style="padding: 5px 0px 0px 5px">
  235. <input type="text" id="tray_num" oninput="calculateTotalBoxes()" style="width: 100px;" min="1" step="1" > 箱/层 ×
  236. <input type="text" id="tray_number" oninput="calculateTotalBoxes()" style="width: 100px;" min="1" step="1" > 层/托 =
  237. <input type="text" id="total_boxes" style="width: 100px;" disabled> 箱/托
  238. <span style="color: red;font-size: 23px;"> *</span>
  239. </td>
  240. </tr>
  241. <tr>
  242. <td><span>本次打包托盘数(大件数)</span></td>
  243. <td style="padding: 5px 0px 0px 5px"><input type="text" id="c-box_num" disabled name="box_num" ></td>
  244. </tr>
  245. <tr>
  246. <td><span>总箱数</span></td>
  247. <td style="padding: 5px 0px 0px 5px"><input type="text" id="c-small_num" disabled name="small_num" data-rule="required"></td>
  248. </tr>
  249. <tr>
  250. <td><span>每托高度(米/m)</span></td>
  251. <td style="padding: 5px 0px 0px 5px; position: relative;">
  252. <input type="text" id="pallet_height" name="pallet_height"
  253. style="width: 160px;" placeholder="" autocomplete="off">
  254. <ul id="height-suggestions" style=" position: absolute;
  255. top: 33px; left: 5px; width: 160px;
  256. border: 1px solid #ccc; background: #fff; list-style: none;
  257. margin: 0; padding: 0; display: none; z-index: 1000;">
  258. <li style="padding: 5px; cursor: pointer;">0.995</li>
  259. <li style="padding: 5px; cursor: pointer;">1.05</li>
  260. <li style="padding: 5px; cursor: pointer;">1.35</li>
  261. </ul>
  262. <span style="color: red; font-size: 23px;"> *</span>
  263. </td>
  264. </tr>
  265. <tr>
  266. <td><span>托盘规格(例如:0.9 * 1.2)</span></td>
  267. <td style="padding: 5px 0px 0px 5px; position: relative;">
  268. <div style="display: inline-block; position: relative;">
  269. <input type="text" id="pallet_length" name="pallet_length" style="width:80px;" autocomplete="off">
  270. <ul id="length-suggestions" style="
  271. position: absolute;
  272. top: 28px;
  273. left: 0;
  274. width: 80px;
  275. border: 1px solid #ccc;
  276. background: #fff;
  277. list-style: none;
  278. margin: 0;
  279. padding: 0;
  280. display: none;
  281. z-index: 1000;">
  282. <li style="padding: 5px; cursor: pointer;">0.9</li>
  283. <li style="padding: 5px; cursor: pointer;">1.0</li>
  284. <li style="padding: 5px; cursor: pointer;">1.1</li>
  285. </ul>
  286. </div>
  287. &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  288. *
  289. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  290. <div style="display: inline-block; position: relative;">
  291. <input type="text" id="pallet_width" name="pallet_width" style="width:80px;" autocomplete="off">
  292. <ul id="width-suggestions" style="
  293. position: absolute;
  294. top: 28px;
  295. left: 0;
  296. width: 80px;
  297. border: 1px solid #ccc;
  298. background: #fff;
  299. list-style: none;
  300. margin: 0;
  301. padding: 0;
  302. display: none;
  303. z-index: 1000;">
  304. <li style="padding: 5px; cursor: pointer;">1.1</li>
  305. <li style="padding: 5px; cursor: pointer;">1.2</li>
  306. <li style="padding: 5px; cursor: pointer;">1.3</li>
  307. </ul>
  308. </div>
  309. <span style="color: red;font-size: 23px;"> *</span>
  310. </td>
  311. </tr>
  312. <tr>
  313. <td><span>生产日期</span></td>
  314. <td style="padding: 5px 0px 0px 5px">
  315. <input class="" id="c-manufacture_date" value="{:date('Y-m-d')}" style="width: 180px;" name="manufacture_date" type="date" >
  316. </td>
  317. </tr>
  318. <tr>
  319. <td><span>打码日期</span></td>
  320. <td style="padding: 5px 0px 0px 5px">
  321. <input class="" type="date" id="c-print_date" style="width: 180px" name="print_date" value="{:date('Y-m-d')}">
  322. </td>
  323. </tr>
  324. <tr>
  325. <td><span>大件开始流水号</span></td>
  326. <td>
  327. <div style="display: flex; align-items: center;">
  328. <input type="text" name="big_liushui" id="c-big_liushui" disabled>
  329. <button type="button" id="reset_liushui" style="margin-left: 10px;">重置流水号</button>
  330. </div>
  331. </td>
  332. </tr>
  333. <tr>
  334. <td><span>大件重量(单位千克数值)有小数时保留2位小数</span></td>
  335. <td style="padding: 5px 0px 0px 5px"><input type="text" id="c-big_weight" name="big_weight" data-rule="required"><span style="color: red;font-size: 23px;"> *</span></td>
  336. </tr>
  337. <tr>
  338. <td><span>小件开始流水号</span></td>
  339. <td style="padding: 5px 0px 0px 5px"><input type="text" id="c-small_start_liushui" name="small_start_liushui" value="1" ></td>
  340. </tr>
  341. <tr>
  342. <td><span>小件重量(单位克 数值)</span></td>
  343. <td style="padding: 5px 0px 0px 5px"><input type="text" id="c-small_weight" name="small_weight" data-rule="required"><span style="color: red;font-size: 23px;"> *</span></td>
  344. </tr>
  345. </table>
  346. </fieldset>
  347. <div class="form-group layer-footer">
  348. <label class="control-label col-xs-12 col-sm-5"></label>
  349. <div class="col-xs-12 col-sm-5"><br>
  350. <button type="submit" id="submit" class="btn btn-primary btn-embossed">保存</button></div>
  351. </div>
  352. </form>
  353. <!-- 引入 select2 样式 -->
  354. <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
  355. <!-- 引入 jQuery -->
  356. <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
  357. <!-- 引入 select2 JS -->
  358. <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
  359. <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  360. <script>
  361. $(function() {
  362. const $input = $('#pallet_height');
  363. const $list = $('#height-suggestions');
  364. // 显示下拉菜单
  365. $input.on('focus click', function () {
  366. $list.show();
  367. });
  368. // 点击选项
  369. $list.on('click', 'li', function () {
  370. $input.val($(this).text());
  371. $list.hide();
  372. });
  373. // 失焦隐藏
  374. $input.on('blur', function () {
  375. setTimeout(() => $list.hide(), 100); // 延迟防止刚点 li 时被关闭
  376. });
  377. });
  378. let currentPage = 1;
  379. let limit = 10;
  380. let total = 0;
  381. let selectedRow = null;
  382. // 绑定全局选择函数
  383. window.selectRow = function (row) {
  384. console.log('行数据:', row);
  385. if (selectedRow) {
  386. $(selectedRow).removeClass('selected-row');
  387. }
  388. $(row).addClass('selected-row');
  389. selectedRow = row;
  390. const rowData = {
  391. gdbh: $(row).data('gdbh'),
  392. order_ddbh: $(row).data('order_ddbh'),
  393. cpbm: $(row).data('cpbm'),
  394. cpmc: $(row).data('cpmc'),
  395. sl: $(row).data('sl'),
  396. total_chu_quantity: $(row).data('total_chu_quantity'),
  397. remaining_quantity: $(row).data('remaining_quantity')
  398. };
  399. console.log('选中的行数据:', rowData);
  400. $('#c-batch').val(rowData['gdbh']);
  401. $('#c-order_ddbh').val(rowData['order_ddbh']);
  402. $('#c-cpbm').val(rowData['cpbm']);
  403. $('#c-cpmc').val(rowData['cpmc']);
  404. $('#c-sl').val(rowData['sl']);
  405. $('#c-total_chu_quantity').val(rowData['total_chu_quantity']);
  406. // 新增这段判断
  407. if (parseFloat(rowData['remaining_quantity']) >= 0) {
  408. $('#c-remaining_quantity').val(rowData['remaining_quantity']);
  409. } else {
  410. $('#c-remaining_quantity').val('');
  411. }
  412. };
  413. function loadData(page = 1, keyword = '') {
  414. $.ajax({
  415. method: "GET",
  416. url: "/qcode_add/product", // 替换成你的接口路径
  417. data: {
  418. page: page,
  419. limit: limit,
  420. search: keyword
  421. },
  422. dataType: "json",
  423. success: function (res) {
  424. const data = res.data || [];
  425. total = res.total || 0;
  426. currentPage = res.page || 1;
  427. limit = res.limit || 10;
  428. const tbody = $('#tableBody');
  429. tbody.empty();
  430. selectedRow = null;
  431. if (!Array.isArray(data) || data.length === 0) {
  432. tbody.append('<tr><td colspan="5">无数据</td></tr>');
  433. return;
  434. }
  435. $('#c-big_liushui').val(1)
  436. data.forEach(item => {
  437. const tr = $(`
  438. <tr onclick="selectRow(this)"
  439. data-order_ddbh="${item.order_ddbh}"
  440. data-gdbh="${item.gdbh}"
  441. data-cpbm="${item.cpbm}"
  442. data-cpmc="${item.cpmc}"
  443. data-sl="${item.sl}"
  444. data-total_chu_quantity="${item.total_chu_quantity}"
  445. data-remaining_quantity="${item.remaining_quantity}">
  446. <td>${item.order_ddbh}</td>
  447. <td>${item.gdbh}</td>
  448. <td>${item.cpbm}</td>
  449. <td>${item.cpmc}</td>
  450. <td>${item.sl}</td>
  451. <td>${item.total_chu_quantity}</td>
  452. <td>${item.remaining_quantity}</td>
  453. </tr>`);
  454. tbody.append(tr);
  455. });
  456. renderPagination();
  457. }
  458. });
  459. }
  460. function renderPagination() {
  461. const pageCount = Math.ceil(total / limit);
  462. const info = $('#pagination-info');
  463. const wrapper = $('#pagination-controls');
  464. const keyword = $('#searchInput').val().trim();
  465. wrapper.empty();
  466. info.text(`共 ${total} 条记录,第 ${currentPage} / ${pageCount} 页`);
  467. // 上一页按钮
  468. const prev = $('<button type="button">上一页</button>').prop('disabled', currentPage <= 1);
  469. prev.on('click', (e) => {
  470. e.preventDefault();
  471. e.stopPropagation(); // 防止事件冒泡
  472. loadData(currentPage - 1, keyword);
  473. });
  474. wrapper.append(prev);
  475. // 页码按钮
  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', (e) => {
  482. e.preventDefault();
  483. e.stopPropagation();
  484. loadData(i, keyword);
  485. });
  486. wrapper.append(btn);
  487. }
  488. // 下一页按钮
  489. const next = $('<button type="button">下一页</button>').prop('disabled', currentPage >= pageCount);
  490. next.on('click', (e) => {
  491. e.preventDefault();
  492. e.stopPropagation();
  493. loadData(currentPage + 1, keyword);
  494. });
  495. wrapper.append(next);
  496. }
  497. //搜索按钮
  498. $('#searchBtn').on('click', function (e) {
  499. e.preventDefault();
  500. const keyword = $('#searchInput').val().trim();
  501. loadData(1, keyword);
  502. });
  503. //搜索input框
  504. $('#searchInput').on('keypress', function (e) {
  505. if (e.which === 13) {
  506. const keyword = $('#searchInput').val().trim();
  507. loadData(1, keyword);
  508. }
  509. });
  510. $(function () {
  511. loadData(1);
  512. });
  513. function allowNumberAndDot(input) {
  514. input.value = input.value.replace(/[^\d.]/g, '') // 只保留数字和小数点
  515. .replace(/^\./g, '') // 开头不能是小数点
  516. .replace(/\.{2,}/g, '.') // 不能连续两个点
  517. .replace(/(\.\d*)\./g, '$1'); // 只允许一个小数点
  518. }
  519. //托盘规格
  520. $('#pallet_length, #pallet_width').on('input', function() {
  521. allowNumberAndDot(this);
  522. });
  523. // 绑定 pallet_length 的下拉选择
  524. $('#pallet_length').on('focus input', function () {
  525. $('#length-suggestions').show();
  526. });
  527. $('#length-suggestions li').on('click', function () {
  528. $('#pallet_length').val($(this).text());
  529. $('#length-suggestions').hide();
  530. });
  531. // 绑定 pallet_width 的下拉选择
  532. $('#pallet_width').on('focus input', function () {
  533. $('#width-suggestions').show();
  534. });
  535. $('#width-suggestions li').on('click', function () {
  536. $('#pallet_width').val($(this).text());
  537. $('#width-suggestions').hide();
  538. });
  539. // 点击空白区域时隐藏建议框
  540. $(document).on('click', function (e) {
  541. if (!$(e.target).closest('#pallet_length, #length-suggestions').length) {
  542. $('#length-suggestions').hide();
  543. }
  544. if (!$(e.target).closest('#pallet_width, #width-suggestions').length) {
  545. $('#width-suggestions').hide();
  546. }
  547. });
  548. function validateAndCalculate() {
  549. let input = document.getElementById('c-number');
  550. let remainingInput = document.getElementById('c-remaining_quantity');
  551. let max = parseInt(remainingInput.value, 10);
  552. // 判断库存是否为空或非法
  553. if (!remainingInput.value || isNaN(max)) {
  554. input.value = '';
  555. layer.msg('库存数量为空,无法输入!', {icon: 2});
  556. return;
  557. }
  558. // 只允许输入数字(去除字母、负号、小数点等)
  559. input.value = input.value.replace(/[^\d]/g, '');
  560. let val = parseInt(input.value, 10);
  561. // 判断是否超出库存
  562. if (!isNaN(val) && val > max) {
  563. layer.msg('输入值不能超过库存数量!', {icon: 0});
  564. input.value = max;
  565. }
  566. // 调用原始计算逻辑
  567. calculateTotalBoxes();
  568. }
  569. //一托盘多少箱
  570. function calculateTotalBoxes() {
  571. // 获取用户输入
  572. const number = parseInt(document.getElementById("c-number").value || 0); // 本次打包数
  573. const box_number = parseInt(document.getElementById("box_number").value || 0); // 每一箱数量(个)
  574. const tray_num = parseInt(document.getElementById("tray_num").value || 0); // 每层的箱数(箱/层)
  575. const tray_layer = parseInt(document.getElementById("tray_number").value || 0); // 层数(层/托)
  576. // 计算每托盘能放多少箱
  577. const boxes_per_tray = tray_num * tray_layer;
  578. document.getElementById("total_boxes").value = boxes_per_tray; // 自动填充 total_boxes(箱/托)字段
  579. // 计算总箱数(向上取整)
  580. // const totalBoxCount = Math.ceil(number / box_number);
  581. const totalBoxCount = Math.ceil(number / box_number);
  582. // 计算托盘数(向上取整)
  583. const trayCount = Math.ceil(totalBoxCount / boxes_per_tray);
  584. console.log("本次打包数:", number);
  585. console.log("每箱数量:", box_number);
  586. console.log("总箱数:", totalBoxCount);
  587. console.log("每托盘箱数:", boxes_per_tray);
  588. console.log("本次托盘数:", trayCount);
  589. if(trayCount == 'Infinity'){
  590. document.getElementById("c-box_num").value = 0;
  591. }else{
  592. document.getElementById("c-box_num").value = trayCount;
  593. document.getElementById("c-small_num").value = totalBoxCount;
  594. }
  595. // 填入最终托盘数(大件数)
  596. // $('#c-box_num').val(trayCount);
  597. }
  598. </script>