index.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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: 400px;
  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: 10%">产品代号</th>
  132. <th style="width: 30%">产品名称</th>
  133. <th style="width: 10%">数量</th>
  134. <th style="width: 10%">入库状态</th>
  135. </tr>
  136. </thead>
  137. <tbody id="tableBody">
  138. <!-- JS 动态渲染数据 -->
  139. </tbody>
  140. </table>
  141. </div>
  142. <div id="pagination-wrapper">
  143. <div id="pagination-info">共 0 条记录,第 1 / 1 页</div>
  144. <div id="pagination-controls">
  145. 每页显示:
  146. <select id="pageSize">
  147. <option value="10">10</option>
  148. <option value="20" selected>20</option>
  149. <option value="50">50</option>
  150. </select> 条
  151. </div>
  152. </div>
  153. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
  154. <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
  155. <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
  156. <script>
  157. $(document).on('click', '.btn-refresh', function () {
  158. currentPage = 1; // 可选:回到第一页
  159. loadData(currentPage, searchKey); // 带着当前搜索关键字刷新
  160. });
  161. $(document).on('click', '.btn-refresh', function () {
  162. var $icon = $(this).find('i');
  163. // 添加旋转动画
  164. $icon.addClass('rotating');
  165. // 模拟刷新数据(这里调用你的表格刷新函数)
  166. loadData(); // 真实刷新
  167. // 假设刷新完毕后停止旋转(用 AJAX 完成后去除)
  168. setTimeout(function () {
  169. $icon.removeClass('rotating');
  170. }, 1000); // 假设1秒刷新完成
  171. });
  172. let currentPage = 1;
  173. let searchKey = '';
  174. let pageSize = parseInt($('#pageSize').val());
  175. function loadData(page = 1, search = '') {
  176. pageSize = parseInt($('#pageSize').val());
  177. $.ajax({
  178. method: "GET",
  179. url: "Finishedproduct/index",
  180. data: { page: page, search: search, limit: pageSize },
  181. success: function (res) {
  182. const tbody = $('#tableBody');
  183. tbody.empty();
  184. $('#checkAll').prop('checked', false); // 每次刷新取消“全选”
  185. if (res.data && res.data.length > 0) {
  186. res.data.forEach(row => {
  187. tbody.append(`<tr>
  188. <td><input type="checkbox" class="row-check"></td>
  189. <td>${row.jjcp_cpdh}</td>
  190. <td>${row.jjcp_cpmc}</td>
  191. <td>${row.jjcp_sl}</td>
  192. <td>${row.jjcp_smb}</td>
  193. </tr>`);
  194. });
  195. } else {
  196. tbody.append('<tr><td colspan="5">暂无数据</td></tr>');
  197. }
  198. renderPaginationInfo(res.total, res.page, res.limit);
  199. renderPagination(res.total, res.page, res.limit);
  200. },
  201. error: function () {
  202. console.log("加载数据失败!");
  203. }
  204. });
  205. }
  206. function renderPaginationInfo(total, page, limit) {
  207. const totalPages = Math.ceil(total / limit);
  208. $('#pagination-info').text(`共 ${total} 条记录,第 ${page} / ${totalPages} 页`);
  209. }
  210. function renderPagination(total, current, limit) {
  211. const totalPages = Math.ceil(total / limit);
  212. current = parseInt(current);
  213. const container = $('#pagination-controls');
  214. container.find('button, .ellipsis').remove();
  215. const addButton = (text, pageNum, isActive = false, isDisabled = false) => {
  216. const btn = $('<button>')
  217. .text(text)
  218. .prop('disabled', isDisabled)
  219. .addClass(isActive ? 'active' : '')
  220. .click(() => {
  221. if (!isDisabled && pageNum !== current) {
  222. currentPage = pageNum;
  223. loadData(currentPage, searchKey);
  224. }
  225. });
  226. container.append(btn);
  227. };
  228. addButton('上一页', current - 1, false, current === 1);
  229. const pages = [];
  230. if (totalPages <= 5) {
  231. for (let i = 1; i <= totalPages; i++) pages.push(i);
  232. } else {
  233. if (current <= 3) {
  234. pages.push(1, 2, 3, 4, 5, '...', totalPages);
  235. } else if (current >= totalPages - 2) {
  236. pages.push(1, '...');
  237. for (let i = totalPages - 4; i <= totalPages; i++) pages.push(i);
  238. } else {
  239. pages.push(1, '...', current - 1, current, current + 1, '...', totalPages);
  240. }
  241. }
  242. let prev = null;
  243. pages.forEach(p => {
  244. if (p === '...') {
  245. if (prev !== '...') {
  246. container.append('<span class="ellipsis">...</span>');
  247. prev = '...';
  248. }
  249. } else {
  250. addButton(p, p, p === current);
  251. prev = p;
  252. }
  253. });
  254. addButton('下一页', current + 1, false, current === totalPages);
  255. }
  256. // 行点击切换勾选 + 高亮
  257. $(document).on('click', '#productTable tbody tr', function (e) {
  258. if (!$(e.target).is('input')) {
  259. const checkbox = $(this).find('.row-check');
  260. checkbox.prop('checked', !checkbox.prop('checked'));
  261. }
  262. $(this).toggleClass('selected');
  263. });
  264. // 勾选框勾选联动行背景
  265. $(document).on('change', '.row-check', function () {
  266. const tr = $(this).closest('tr');
  267. tr.toggleClass('selected', $(this).is(':checked'));
  268. });
  269. // 全选/取消全选
  270. $('#checkAll').on('change', function () {
  271. const checked = $(this).is(':checked');
  272. $('.row-check').prop('checked', checked);
  273. $('#productTable tbody tr').each(function () {
  274. $(this).toggleClass('selected', checked);
  275. });
  276. });
  277. $('#searchInput').on('input', function () {
  278. searchKey = $(this).val();
  279. currentPage = 1;
  280. loadData(currentPage, searchKey);
  281. });
  282. $('#pageSize').on('change', function () {
  283. currentPage = 1;
  284. loadData(currentPage, searchKey);
  285. });
  286. // 点击“确认入库”按钮
  287. $('#q_btn').on('click', function () {
  288. const selectedData = [];
  289. $('#productTable tbody tr').each(function () {
  290. const checkbox = $(this).find('.row-check');
  291. if (checkbox.is(':checked')) {
  292. const row = $(this).find('td');
  293. selectedData.push({
  294. jjcp_cpdh: row.eq(1).text().trim(),
  295. jjcp_cpmc: row.eq(2).text().trim(),
  296. jjcp_sl: row.eq(3).text().trim(),
  297. jjcp_smb: row.eq(4).text().trim()
  298. });
  299. }
  300. });
  301. if (selectedData.length === 0) {
  302. alert("请选择要入库的产品!");
  303. return;
  304. }
  305. $.ajax({
  306. method: "POST",
  307. url: "Finishedproduct/finished",
  308. contentType: "application/json",
  309. data: JSON.stringify({ data: selectedData }),
  310. success: function (res) {
  311. Swal.fire({
  312. icon: 'success',
  313. title: '入库成功!',
  314. showConfirmButton: false,
  315. timer: 3000
  316. });
  317. loadData(); // 可选:刷新表格
  318. },
  319. error: function () {
  320. Swal.fire({
  321. icon: 'error',
  322. title: '入库失败!',
  323. showConfirmButton: false,
  324. timer: 3000
  325. });
  326. }
  327. });
  328. });
  329. $(document).ready(function () {
  330. loadData();
  331. });
  332. </script>
  333. </body>
  334. </html>