index.html 9.7 KB

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