index.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. .form-group {
  118. margin-bottom: 15px;
  119. }
  120. .form-group label {
  121. display: block;
  122. margin-bottom: 5px;
  123. font-weight: bold;
  124. }
  125. .form-control {
  126. width: 100%;
  127. padding: 6px 10px;
  128. border: 1px solid #ccc;
  129. border-radius: 4px;
  130. }
  131. </style>
  132. </head>
  133. <body>
  134. <h2>入库明细列表</h2>
  135. <a href="javascript:;" class="btn btn-primary btn-refresh" title="刷新">
  136. <i class="fas fa-sync-alt"></i> <!-- 这是刷新图标 -->
  137. </a>
  138. <input type="text" id="searchInput" placeholder="搜索产品名称..." />
  139. <button id="addBtn" class="btn btn-success" style=" height: 40px;">新增产品</button>
  140. <div class="scroll-table-wrapper">
  141. <table id="productTable">
  142. <thead>
  143. <tr>
  144. <th style="width: 4%"><input type="checkbox" id="checkAll"></th>
  145. <th style="width: 15%">工单编号</th>
  146. <th style="width: 10%">销售订单号</th>
  147. <th style="width: 10%">产品代号</th>
  148. <th style="width: 30%">产品名称</th>
  149. <th style="width: 10%">数量</th>
  150. <th style="width: 10%">入库状态</th>
  151. </tr>
  152. </thead>
  153. <tbody id="tableBody">
  154. <!-- JS 动态渲染数据 -->
  155. </tbody>
  156. </table>
  157. </div>
  158. <div id="pagination-wrapper">
  159. <div id="pagination-info">共 0 条记录,第 1 / 1 页</div>
  160. <div id="pagination-controls">
  161. 每页显示:
  162. <select id="pageSize">
  163. <option value="10">10</option>
  164. <option value="20" selected>20</option>
  165. <option value="50">50</option>
  166. </select> 条
  167. </div>
  168. </div>
  169. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
  170. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  171. <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
  172. <!-- 引入 Layer,如果已引入可跳过 -->
  173. <script src="https://cdn.jsdelivr.net/npm/layer/dist/layer.js"></script>
  174. <script>
  175. $(document).on('click', '.btn-refresh', function () {
  176. currentPage = 1; // 可选:回到第一页
  177. loadData(currentPage, searchKey); // 带着当前搜索关键字刷新
  178. });
  179. $(document).on('click', '.btn-refresh', function () {
  180. var $icon = $(this).find('i');
  181. // 添加旋转动画
  182. $icon.addClass('rotating');
  183. // 模拟刷新数据(这里调用你的表格刷新函数)
  184. loadData(); // 真实刷新
  185. // 假设刷新完毕后停止旋转(用 AJAX 完成后去除)
  186. setTimeout(function () {
  187. $icon.removeClass('rotating');
  188. }, 1000); // 假设1秒刷新完成
  189. });
  190. let currentPage = 1;
  191. let searchKey = '';
  192. let pageSize = parseInt($('#pageSize').val());
  193. function loadData(page = 1, search = '') {
  194. pageSize = parseInt($('#pageSize').val());
  195. $.ajax({
  196. method: "GET",
  197. url: "inventorydetails/index",
  198. data: { page: page, search: search, limit: pageSize },
  199. success: function (res) {
  200. const tbody = $('#tableBody');
  201. tbody.empty();
  202. $('#checkAll').prop('checked', false); // 每次刷新取消“全选”
  203. if (res.data && res.data.length > 0) {
  204. res.data.forEach(row => {
  205. tbody.append(`<tr>
  206. <td><input type="checkbox" class="row-check"></td>
  207. <td>${row.order_ddbh}</td>
  208. <td>${row.jjcp_gdbh}</td>
  209. <td>${row.jjcp_cpdh}</td>
  210. <td>${row.jjcp_cpmc}</td>
  211. <td>${row.jjcp_sl}</td>
  212. <td>${row.jjcp_smb}</td>
  213. </tr>`);
  214. });
  215. } else {
  216. tbody.append('<tr><td colspan="5">暂无数据</td></tr>');
  217. }
  218. renderPaginationInfo(res.total, res.page, res.limit);
  219. renderPagination(res.total, res.page, res.limit);
  220. },
  221. error: function () {
  222. console.log("加载数据失败!");
  223. }
  224. });
  225. }
  226. function renderPaginationInfo(total, page, limit) {
  227. const totalPages = Math.ceil(total / limit);
  228. $('#pagination-info').text(`共 ${total} 条记录,第 ${page} / ${totalPages} 页`);
  229. }
  230. function renderPagination(total, current, limit) {
  231. const totalPages = Math.ceil(total / limit);
  232. current = parseInt(current);
  233. const container = $('#pagination-controls');
  234. container.find('button, .ellipsis').remove();
  235. const addButton = (text, pageNum, isActive = false, isDisabled = false) => {
  236. const btn = $('<button>')
  237. .text(text)
  238. .prop('disabled', isDisabled)
  239. .addClass(isActive ? 'active' : '')
  240. .click(() => {
  241. if (!isDisabled && pageNum !== current) {
  242. currentPage = pageNum;
  243. loadData(currentPage, searchKey);
  244. }
  245. });
  246. container.append(btn);
  247. };
  248. addButton('上一页', current - 1, false, current === 1);
  249. const pages = [];
  250. if (totalPages <= 5) {
  251. for (let i = 1; i <= totalPages; i++) pages.push(i);
  252. } else {
  253. if (current <= 3) {
  254. pages.push(1, 2, 3, 4, 5, '...', totalPages);
  255. } else if (current >= totalPages - 2) {
  256. pages.push(1, '...');
  257. for (let i = totalPages - 4; i <= totalPages; i++) pages.push(i);
  258. } else {
  259. pages.push(1, '...', current - 1, current, current + 1, '...', totalPages);
  260. }
  261. }
  262. let prev = null;
  263. pages.forEach(p => {
  264. if (p === '...') {
  265. if (prev !== '...') {
  266. container.append('<span class="ellipsis">...</span>');
  267. prev = '...';
  268. }
  269. } else {
  270. addButton(p, p, p === current);
  271. prev = p;
  272. }
  273. });
  274. addButton('下一页', current + 1, false, current === totalPages);
  275. }
  276. // 行点击切换勾选 + 高亮
  277. $(document).on('click', '#productTable tbody tr', function (e) {
  278. if (!$(e.target).is('input')) {
  279. const checkbox = $(this).find('.row-check');
  280. checkbox.prop('checked', !checkbox.prop('checked'));
  281. }
  282. $(this).toggleClass('selected');
  283. });
  284. // 勾选框勾选联动行背景
  285. $(document).on('change', '.row-check', function () {
  286. const tr = $(this).closest('tr');
  287. tr.toggleClass('selected', $(this).is(':checked'));
  288. });
  289. // 全选/取消全选
  290. $('#checkAll').on('change', function () {
  291. const checked = $(this).is(':checked');
  292. $('.row-check').prop('checked', checked);
  293. $('#productTable tbody tr').each(function () {
  294. $(this).toggleClass('selected', checked);
  295. });
  296. });
  297. $('#searchInput').on('input', function () {
  298. searchKey = $(this).val();
  299. currentPage = 1;
  300. loadData(currentPage, searchKey);
  301. });
  302. $('#pageSize').on('change', function () {
  303. currentPage = 1;
  304. loadData(currentPage, searchKey);
  305. });
  306. $(document).ready(function () {
  307. loadData();
  308. });
  309. $('#addBtn').on('click', function () {
  310. var contentHtml = `
  311. <form id="addForm" style="padding: 20px 30px;" class="form-horizontal">
  312. <div class="form-group" style="display: flex; align-items: center; margin-bottom: 15px;">
  313. <label style="width: 90px;">工单编号</label>
  314. <input type="text" name="order_ddbh" class="form-control" style="flex:1;" required />
  315. </div>
  316. <div class="form-group" style="display: flex; align-items: center; margin-bottom: 15px;">
  317. <label style="width: 90px;">销售订单号</label>
  318. <input type="text" name="jjcp_gdbh" class="form-control" style="flex:1;" required />
  319. </div>
  320. <div class="form-group" style="display: flex; align-items: center; margin-bottom: 15px;">
  321. <label style="width: 90px;">产品代号</label>
  322. <input type="text" name="jjcp_cpdh" class="form-control" style="flex:1;" required />
  323. </div>
  324. <div class="form-group" style="display: flex; align-items: center; margin-bottom: 15px;">
  325. <label style="width: 90px;">产品名称</label>
  326. <input type="text" name="jjcp_cpmc" class="form-control" style="flex:1;" required />
  327. </div>
  328. <div class="form-group" style="display: flex; align-items: center;">
  329. <label style="width: 90px;">数量</label>
  330. <input type="number" name="jjcp_sl" class="form-control" style="flex:1;" required />
  331. </div>
  332. </form>`;
  333. layer.open({
  334. type: 1,
  335. title: '新增入库记录',
  336. area: ['50%', '50%'], // 初始窗口大小
  337. shadeClose: true, // 点击遮罩关闭
  338. resize: true, // 允许拉伸
  339. maxmin: true, // 显示最大化/最小化按钮
  340. btn: ['入库', '取消'],
  341. content: contentHtml,
  342. yes: function (index) {
  343. var formData = {};
  344. $('#addForm').serializeArray().forEach(function (item) {
  345. formData[item.name] = item.value.trim();
  346. });
  347. // 简单校验
  348. if (!formData.order_ddbh || !formData.jjcp_gdbh || !formData.jjcp_cpdh || !formData.jjcp_cpmc || !formData.jjcp_sl) {
  349. layer.msg('请填写所有字段');
  350. return;
  351. }
  352. $.ajax({
  353. method: "POST",
  354. url: "Finishedproduct/finished",
  355. contentType: "application/json",
  356. data: JSON.stringify({ data: [formData] }), // 注意:加了中括号 []
  357. success: function () {
  358. layer.msg('入库成功!');
  359. layer.close(index);
  360. loadData();
  361. },
  362. error: function () {
  363. layer.msg('入库失败!');
  364. }
  365. });
  366. }
  367. });
  368. });
  369. </script>
  370. </body>
  371. </html>