index.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>待入库工单列表</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <style>
  8. body {
  9. font-family: "微软雅黑", sans-serif;
  10. padding: 20px;
  11. background: #f9f9f9;
  12. }
  13. h2 {
  14. margin-bottom: 20px;
  15. color: #333;
  16. }
  17. #searchInput {
  18. padding: 8px;
  19. width: 300px;
  20. font-size: 14px;
  21. margin-bottom: 20px;
  22. border: 1px solid #ccc;
  23. border-radius: 4px;
  24. }
  25. #q_btn{
  26. padding: 8px;
  27. font-size: 14px;
  28. margin-bottom: 20px;
  29. border: 1px solid #ccc;
  30. border-radius: 4px;
  31. background-color: #18bc9c;
  32. color: #fff;
  33. }
  34. .scroll-table-wrapper {
  35. max-height: 600px;
  36. overflow-y: auto;
  37. border: 1px solid #ddd;
  38. background: white;
  39. }
  40. table {
  41. width: 100%;
  42. border-collapse: collapse;
  43. table-layout: fixed;
  44. }
  45. th, td {
  46. border: 1px solid #ddd;
  47. text-align: center;
  48. font-size: 14px;
  49. padding: 5px;
  50. word-break: break-word;
  51. }
  52. thead th {
  53. background: #f0f0f0;
  54. position: sticky;
  55. top: 0;
  56. z-index: 2;
  57. }
  58. tbody tr:hover {
  59. background: #f5f5f5;
  60. }
  61. tr.selected {
  62. background-color: yellow !important;
  63. }
  64. #pagination-wrapper {
  65. display: flex;
  66. justify-content: space-between;
  67. align-items: center;
  68. flex-wrap: wrap;
  69. margin-top: 20px;
  70. font-size: 14px;
  71. }
  72. #pagination-controls {
  73. display: flex;
  74. align-items: center;
  75. flex-wrap: wrap;
  76. }
  77. #pagination-controls button {
  78. padding: 6px 10px;
  79. margin: 0 2px;
  80. cursor: pointer;
  81. border: 1px solid #ccc;
  82. background: white;
  83. border-radius: 4px;
  84. }
  85. #pagination-controls button.active {
  86. background: #4CAF50;
  87. color: white;
  88. border-color: #4CAF50;
  89. }
  90. #pagination-controls button:disabled {
  91. background: #eee;
  92. color: #aaa;
  93. cursor: not-allowed;
  94. }
  95. #pageSize {
  96. margin: 0 5px;
  97. padding: 4px 6px;
  98. }
  99. .ellipsis {
  100. padding: 6px 10px;
  101. color: #999;
  102. }
  103. /* 按钮基础样式(可选美化) */
  104. .btn-refresh {
  105. font-size: 18px;
  106. color: #fff;
  107. cursor: pointer;
  108. }
  109. /* 旋转动画类 */
  110. .rotating {
  111. animation: spin 1s linear infinite;
  112. }
  113. @keyframes spin {
  114. 0% { transform: rotate(0deg); }
  115. 100% { transform: rotate(360deg); }
  116. }
  117. </style>
  118. </head>
  119. <body>
  120. <h2>待入库工单列表</h2>
  121. <a href="javascript:;" class="btn btn-primary btn-refresh" title="刷新">
  122. <i class="fas fa-sync-alt"></i> <!-- 这是刷新图标 -->
  123. </a>
  124. <input type="text" id="searchInput" placeholder="搜索产品名称..." />
  125. <button id="q_btn">确认入库</button>
  126. <div class="scroll-table-wrapper">
  127. <table id="productTable">
  128. <thead>
  129. <tr>
  130. <th style="width: 4%"><input type="checkbox" id="checkAll"></th>
  131. <th style="width: 15%">工单编号</th>
  132. <th style="width: 10%">销售订单号</th>
  133. <th style="width: 10%">产品代号</th>
  134. <th style="width: 30%">产品名称</th>
  135. <th style="width: 10%">数量</th>
  136. <th style="width: 10%">入库状态</th>
  137. </tr>
  138. </thead>
  139. <tbody id="tableBody">
  140. <!-- JS 动态渲染数据 -->
  141. </tbody>
  142. </table>
  143. </div>
  144. <div id="pagination-wrapper">
  145. <div id="pagination-info">共 0 条记录,第 1 / 1 页</div>
  146. <div id="pagination-controls">
  147. 每页显示:
  148. <select id="pageSize">
  149. <option value="10">10</option>
  150. <option value="20" selected>20</option>
  151. <option value="50">50</option>
  152. </select> 条
  153. </div>
  154. </div>
  155. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
  156. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  157. <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
  158. <script>
  159. $(document).on('click', '.btn-refresh', function () {
  160. currentPage = 1; // 可选:回到第一页
  161. loadData(currentPage, searchKey); // 带着当前搜索关键字刷新
  162. });
  163. $(document).on('click', '.btn-refresh', function () {
  164. var $icon = $(this).find('i');
  165. // 添加旋转动画
  166. $icon.addClass('rotating');
  167. // 模拟刷新数据(这里调用你的表格刷新函数)
  168. loadData(); // 真实刷新
  169. // 假设刷新完毕后停止旋转(用 AJAX 完成后去除)
  170. setTimeout(function () {
  171. $icon.removeClass('rotating');
  172. }, 1000); // 假设1秒刷新完成
  173. });
  174. let currentPage = 1;
  175. let searchKey = '';
  176. let pageSize = parseInt($('#pageSize').val());
  177. function loadData(page = 1, search = '') {
  178. pageSize = parseInt($('#pageSize').val());
  179. $.ajax({
  180. method: "GET",
  181. url: "Finishedproduct/index",
  182. data: { page: page, search: search, limit: pageSize },
  183. success: function (res) {
  184. const tbody = $('#tableBody');
  185. tbody.empty();
  186. $('#checkAll').prop('checked', false); // 每次刷新取消“全选”
  187. if (res.data && res.data.length > 0) {
  188. res.data.forEach(row => {
  189. tbody.append(`<tr>
  190. <td><input type="checkbox" class="row-check"></td>
  191. <td>${row.order_ddbh}</td>
  192. <td>${row.jjcp_gdbh}</td>
  193. <td>${row.jjcp_cpdh}</td>
  194. <td>${row.jjcp_cpmc}</td>
  195. <td>${row.jjcp_sl}</td>
  196. <td>${row.jjcp_smb}</td>
  197. </tr>`);
  198. });
  199. } else {
  200. tbody.append('<tr><td colspan="5">暂无数据</td></tr>');
  201. }
  202. renderPaginationInfo(res.total, res.page, res.limit);
  203. renderPagination(res.total, res.page, res.limit);
  204. },
  205. error: function () {
  206. console.log("加载数据失败!");
  207. }
  208. });
  209. }
  210. function renderPaginationInfo(total, page, limit) {
  211. const totalPages = Math.ceil(total / limit);
  212. $('#pagination-info').text(`共 ${total} 条记录,第 ${page} / ${totalPages} 页`);
  213. }
  214. function renderPagination(total, current, limit) {
  215. const totalPages = Math.ceil(total / limit);
  216. current = parseInt(current);
  217. const container = $('#pagination-controls');
  218. container.find('button, .ellipsis').remove();
  219. const addButton = (text, pageNum, isActive = false, isDisabled = false) => {
  220. const btn = $('<button>')
  221. .text(text)
  222. .prop('disabled', isDisabled)
  223. .addClass(isActive ? 'active' : '')
  224. .click(() => {
  225. if (!isDisabled && pageNum !== current) {
  226. currentPage = pageNum;
  227. loadData(currentPage, searchKey);
  228. }
  229. });
  230. container.append(btn);
  231. };
  232. addButton('上一页', current - 1, false, current === 1);
  233. const pages = [];
  234. if (totalPages <= 5) {
  235. for (let i = 1; i <= totalPages; i++) pages.push(i);
  236. } else {
  237. if (current <= 3) {
  238. pages.push(1, 2, 3, 4, 5, '...', totalPages);
  239. } else if (current >= totalPages - 2) {
  240. pages.push(1, '...');
  241. for (let i = totalPages - 4; i <= totalPages; i++) pages.push(i);
  242. } else {
  243. pages.push(1, '...', current - 1, current, current + 1, '...', totalPages);
  244. }
  245. }
  246. let prev = null;
  247. pages.forEach(p => {
  248. if (p === '...') {
  249. if (prev !== '...') {
  250. container.append('<span class="ellipsis">...</span>');
  251. prev = '...';
  252. }
  253. } else {
  254. addButton(p, p, p === current);
  255. prev = p;
  256. }
  257. });
  258. addButton('下一页', current + 1, false, current === totalPages);
  259. }
  260. // 行点击切换勾选 + 高亮
  261. $(document).on('click', '#productTable tbody tr', function (e) {
  262. if (!$(e.target).is('input')) {
  263. const checkbox = $(this).find('.row-check');
  264. checkbox.prop('checked', !checkbox.prop('checked'));
  265. }
  266. $(this).toggleClass('selected');
  267. });
  268. // 勾选框勾选联动行背景
  269. $(document).on('change', '.row-check', function () {
  270. const tr = $(this).closest('tr');
  271. tr.toggleClass('selected', $(this).is(':checked'));
  272. });
  273. // 全选/取消全选
  274. $('#checkAll').on('change', function () {
  275. const checked = $(this).is(':checked');
  276. $('.row-check').prop('checked', checked);
  277. $('#productTable tbody tr').each(function () {
  278. $(this).toggleClass('selected', checked);
  279. });
  280. });
  281. $('#searchInput').on('input', function () {
  282. searchKey = $(this).val();
  283. currentPage = 1;
  284. loadData(currentPage, searchKey);
  285. });
  286. $('#pageSize').on('change', function () {
  287. currentPage = 1;
  288. loadData(currentPage, searchKey);
  289. });
  290. // 点击“确认入库”按钮
  291. $('#q_btn').on('click', function () {
  292. const selectedData = [];
  293. $('#productTable tbody tr').each(function () {
  294. const checkbox = $(this).find('.row-check');
  295. if (checkbox.is(':checked')) {
  296. const row = $(this).find('td');
  297. selectedData.push({
  298. order_ddbh: row.eq(1).text().trim(),
  299. jjcp_gdbh: row.eq(2).text().trim(),
  300. jjcp_cpdh: row.eq(3).text().trim(),
  301. jjcp_cpmc: row.eq(4).text().trim(),
  302. jjcp_sl: row.eq(5).text().trim(),
  303. jjcp_smb: row.eq(6).text().trim()
  304. });
  305. }
  306. });
  307. if (selectedData.length === 0) {
  308. alert("请选择要入库的产品!");
  309. return;
  310. }
  311. $.ajax({
  312. method: "POST",
  313. url: "Finishedproduct/finished",
  314. contentType: "application/json",
  315. data: JSON.stringify({ data: selectedData }),
  316. success: function (res) {
  317. Swal.fire({
  318. icon: 'success',
  319. title: '入库成功!',
  320. showConfirmButton: false,
  321. timer: 3000
  322. });
  323. loadData(); // 可选:刷新表格
  324. },
  325. error: function () {
  326. Swal.fire({
  327. icon: 'error',
  328. title: '入库失败!',
  329. showConfirmButton: false,
  330. timer: 3000
  331. });
  332. }
  333. });
  334. });
  335. $(document).ready(function () {
  336. loadData();
  337. });
  338. </script>
  339. </body>
  340. </html>