02-split-panel.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <!doctype html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>02 左右分栏 · 登记未用完 Demo</title>
  7. <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet" />
  8. <link rel="stylesheet" href="_shared.css" />
  9. <style>
  10. .split-layout {
  11. display: grid;
  12. grid-template-columns: 340px 1fr;
  13. gap: 16px;
  14. min-height: 480px;
  15. }
  16. @media (max-width: 900px) {
  17. .split-layout {
  18. grid-template-columns: 1fr;
  19. }
  20. }
  21. .list-panel {
  22. border: 1px solid var(--border);
  23. border-radius: var(--radius-sm);
  24. display: flex;
  25. flex-direction: column;
  26. overflow: hidden;
  27. background: #fafafa;
  28. }
  29. .list-panel__tools {
  30. padding: 10px 12px;
  31. border-bottom: 1px solid var(--border);
  32. background: var(--surface);
  33. display: flex;
  34. gap: 8px;
  35. flex-wrap: wrap;
  36. }
  37. .list-panel__tools .input {
  38. flex: 1;
  39. min-width: 120px;
  40. }
  41. .line-list {
  42. flex: 1;
  43. overflow-y: auto;
  44. max-height: 420px;
  45. }
  46. .line-item {
  47. display: block;
  48. width: 100%;
  49. text-align: left;
  50. padding: 10px 12px;
  51. border: none;
  52. border-bottom: 1px solid var(--border);
  53. background: var(--surface);
  54. cursor: pointer;
  55. transition: background 0.12s;
  56. }
  57. .line-item:hover {
  58. background: var(--row-hover);
  59. }
  60. .line-item.is-active {
  61. background: var(--primary-bg);
  62. border-left: 3px solid var(--primary);
  63. padding-left: 9px;
  64. }
  65. .line-item__top {
  66. display: flex;
  67. align-items: center;
  68. gap: 8px;
  69. margin-bottom: 4px;
  70. }
  71. .line-item__name {
  72. font-size: 13px;
  73. font-weight: 600;
  74. color: var(--text);
  75. flex: 1;
  76. overflow: hidden;
  77. text-overflow: ellipsis;
  78. white-space: nowrap;
  79. }
  80. .line-item__meta {
  81. font-size: 11px;
  82. color: var(--text-muted);
  83. display: flex;
  84. gap: 8px;
  85. flex-wrap: wrap;
  86. }
  87. .detail-panel {
  88. border: 1px solid var(--border);
  89. border-radius: var(--radius-sm);
  90. padding: 16px;
  91. background: var(--surface);
  92. overflow-y: auto;
  93. max-height: 480px;
  94. }
  95. .detail-panel__head {
  96. display: flex;
  97. align-items: center;
  98. justify-content: space-between;
  99. margin-bottom: 16px;
  100. padding-bottom: 12px;
  101. border-bottom: 1px solid var(--border);
  102. }
  103. .detail-panel__title {
  104. font-size: 15px;
  105. font-weight: 600;
  106. }
  107. .detail-panel__sub {
  108. font-size: 12px;
  109. color: var(--text-muted);
  110. margin-top: 2px;
  111. }
  112. .form-grid {
  113. display: grid;
  114. grid-template-columns: repeat(3, minmax(0, 1fr));
  115. gap: 12px 16px;
  116. }
  117. .form-col-span-3 {
  118. grid-column: 1 / -1;
  119. }
  120. .form-col-span-2 {
  121. grid-column: span 2;
  122. }
  123. .field-group-title {
  124. grid-column: 1 / -1;
  125. font-size: 12px;
  126. font-weight: 600;
  127. color: var(--primary-dark);
  128. padding: 8px 0 0;
  129. margin-top: 4px;
  130. border-top: 1px dashed var(--border);
  131. }
  132. .field-group-title:first-child {
  133. border-top: none;
  134. padding-top: 0;
  135. margin-top: 0;
  136. }
  137. .detail-empty {
  138. display: flex;
  139. align-items: center;
  140. justify-content: center;
  141. height: 100%;
  142. min-height: 320px;
  143. color: var(--text-muted);
  144. font-size: 13px;
  145. }
  146. .nav-hint {
  147. font-size: 11px;
  148. color: var(--text-muted);
  149. padding: 8px 12px;
  150. border-top: 1px solid var(--border);
  151. background: var(--surface);
  152. }
  153. kbd {
  154. padding: 1px 5px;
  155. border-radius: 4px;
  156. border: 1px solid var(--border);
  157. background: #f8fafc;
  158. font-size: 10px;
  159. }
  160. </style>
  161. </head>
  162. <body>
  163. <header class="demo-banner">
  164. <div>
  165. <h1><span class="demo-badge">02 左右分栏</span> 登记未用完物料</h1>
  166. <p>左侧列表扫选 · 右侧完整表单 · 支持 ↑↓ 切换当前行</p>
  167. </div>
  168. <div class="demo-banner__actions">
  169. <a href="index.html">← 选型索引</a>
  170. <a class="is-current" href="02-split-panel.html">02 分栏</a>
  171. <a href="01-inline-table.html">01 表格</a>
  172. <a href="03-collapsible.html">03 折叠</a>
  173. </div>
  174. </header>
  175. <div class="page-wrap">
  176. <div class="dialog-backdrop">
  177. <div class="dialog dialog--wide" role="dialog">
  178. <div class="dialog__head">
  179. <h2 class="dialog__title">登记未用完物料</h2>
  180. <button type="button" class="dialog__close">×</button>
  181. </div>
  182. <div class="dialog__body">
  183. <div class="section-head">
  184. <div class="section-head__left">
  185. <div class="section-title">未用完明细</div>
  186. <div class="section-hint">左侧选择要编辑的行;右侧展示完整字段,避免一屏塞满多张卡片。</div>
  187. </div>
  188. <div class="section-tools">
  189. <span class="stat-pill">共 <strong id="line-count">0</strong> 项</span>
  190. <button type="button" class="btn btn-sm">+ 从批次添加</button>
  191. <button type="button" class="btn btn-sm">+ 手工登记</button>
  192. </div>
  193. </div>
  194. <div class="split-layout">
  195. <div class="list-panel">
  196. <div class="list-panel__tools">
  197. <input type="search" class="input" placeholder="搜索物料/批号…" id="filter" />
  198. </div>
  199. <div class="line-list" id="line-list"></div>
  200. <div class="nav-hint"><kbd>↑</kbd> <kbd>↓</kbd> 切换 · 点击左侧行编辑</div>
  201. </div>
  202. <div class="detail-panel" id="detail-panel"></div>
  203. </div>
  204. </div>
  205. <div class="dialog__foot">
  206. <button type="button" class="btn btn-ghost">取消</button>
  207. <button type="button" class="btn btn-primary">保存</button>
  208. </div>
  209. </div>
  210. </div>
  211. <p class="style-note">
  212. <strong>适用场景:</strong>每条都需要核对完整批次信息,或手工登记字段较多。
  213. <ul>
  214. <li>左侧仅展示摘要(名称、批号、数量、持有人),一屏可浏览 8~12 条</li>
  215. <li>右侧 3 列标准表单(label-position top),控件高度 36px,与全站弹窗一致</li>
  216. <li>批次关联字段只读灰底分区;登记字段(数量/持有人/备注)单独成组突出</li>
  217. </ul>
  218. </p>
  219. </div>
  220. <script src="_demo-data.js"></script>
  221. <script>
  222. let rows = [...DEMO_UNUSED_LINES]
  223. let activeId = rows[0]?.id
  224. const lineList = document.getElementById('line-list')
  225. const detailPanel = document.getElementById('detail-panel')
  226. function renderList() {
  227. const kw = (document.getElementById('filter').value || '').trim().toLowerCase()
  228. const filtered = rows.filter((r) => {
  229. if (!kw) return true
  230. return materialSummary(r).toLowerCase().includes(kw)
  231. })
  232. if (!filtered.find((r) => r.id === activeId)) activeId = filtered[0]?.id
  233. lineList.innerHTML = filtered
  234. .map(
  235. (row) => `<button type="button" class="line-item ${row.id === activeId ? 'is-active' : ''}" data-id="${row.id}">
  236. <div class="line-item__top">
  237. <span class="row-index">${rows.indexOf(row) + 1}</span>
  238. <span class="line-item__name">${row.materialName}</span>
  239. <span class="tag ${row.fromBatch ? 'tag--success' : 'tag--warn'}">${row.fromBatch ? '批次' : '手工'}</span>
  240. </div>
  241. <div class="line-item__meta">
  242. <span>${row.unusedQty}${row.unit || ''}</span>
  243. <span>${row.batchNo || '—'}</span>
  244. <span>${row.holder || '未填持有人'}</span>
  245. </div>
  246. </button>`
  247. )
  248. .join('')
  249. document.getElementById('line-count').textContent = rows.length
  250. renderDetail()
  251. }
  252. function renderDetail() {
  253. const row = rows.find((r) => r.id === activeId)
  254. if (!row) {
  255. detailPanel.innerHTML = '<div class="detail-empty">请选择左侧一行,或点击「新增」</div>'
  256. return
  257. }
  258. const readonly = row.fromBatch
  259. detailPanel.innerHTML = `
  260. <div class="detail-panel__head">
  261. <div>
  262. <div class="detail-panel__title">第 ${rows.indexOf(row) + 1} 行 · ${row.materialName}</div>
  263. <div class="detail-panel__sub">${materialSummary(row)}</div>
  264. </div>
  265. <button type="button" class="btn btn-danger-link btn-sm" id="del-current">删除此行</button>
  266. </div>
  267. <div class="form-grid">
  268. <div class="field-group-title">批次检索(可选)</div>
  269. <div class="form-col-span-3">
  270. <label class="field-label">检索批次</label>
  271. <select class="select" ${readonly ? 'disabled' : ''}>
  272. <option>${readonly ? `${row.stockInNo} · ${row.materialName}` : '输入入库编号/物料名检索…'}</option>
  273. </select>
  274. </div>
  275. <div class="field-group-title">批次信息 ${readonly ? '(只读)' : '(可手工填写)'}</div>
  276. ${field('入库编号', row.stockInNo, readonly)}
  277. ${field('入库日期', row.stockInDate, readonly)}
  278. ${field('过期日期', row.expireDate, readonly)}
  279. ${field('物料编码', row.materialCode, readonly)}
  280. ${field('物料名称', row.materialName, readonly && row.fromBatch)}
  281. ${field('规格型号', row.specModel, readonly)}
  282. ${field('单位', row.unit, readonly)}
  283. ${field('货号', row.catalogNo, readonly)}
  284. ${field('批号', row.batchNo, readonly)}
  285. ${field('厂家', row.manufacturer, readonly)}
  286. ${field('单价(元)', formatMoney(row.unitPrice), readonly)}
  287. <div class="field-group-title">登记信息(必填/重点)</div>
  288. <div>
  289. <label class="field-label">未用完数量</label>
  290. <input class="input input-num" type="number" id="f-qty" value="${row.unusedQty}" min="0.01" step="0.01" />
  291. </div>
  292. <div>
  293. <label class="field-label">剩余金额(元)</label>
  294. <input class="input input--readonly" readonly value="${formatMoney(calcAmount(row.unitPrice, row.unusedQty))}" />
  295. </div>
  296. <div>
  297. <label class="field-label">持有人</label>
  298. <input class="input" type="text" id="f-holder" value="${row.holder || ''}" placeholder="可选" />
  299. </div>
  300. <div class="form-col-span-3">
  301. <label class="field-label">备注</label>
  302. <input class="input" type="text" id="f-remark" value="${row.remark || ''}" placeholder="可选" />
  303. </div>
  304. </div>`
  305. document.getElementById('f-qty').addEventListener('input', (e) => {
  306. row.unusedQty = Number(e.target.value) || 0
  307. renderList()
  308. })
  309. document.getElementById('f-holder').addEventListener('input', (e) => {
  310. row.holder = e.target.value
  311. renderList()
  312. })
  313. document.getElementById('f-remark').addEventListener('input', (e) => {
  314. row.remark = e.target.value
  315. })
  316. document.getElementById('del-current').addEventListener('click', () => {
  317. rows = rows.filter((r) => r.id !== activeId)
  318. activeId = rows[0]?.id
  319. renderList()
  320. })
  321. }
  322. function field(label, value, ro) {
  323. return `<div>
  324. <label class="field-label">${label}</label>
  325. <input class="input ${ro ? 'input--readonly' : ''}" ${ro ? 'readonly' : ''} value="${value || ''}" placeholder="${ro ? '—' : '可选'}" />
  326. </div>`
  327. }
  328. lineList.addEventListener('click', (e) => {
  329. const btn = e.target.closest('.line-item')
  330. if (!btn) return
  331. activeId = Number(btn.dataset.id)
  332. renderList()
  333. })
  334. document.getElementById('filter').addEventListener('input', renderList)
  335. document.addEventListener('keydown', (e) => {
  336. if (!['ArrowUp', 'ArrowDown'].includes(e.key)) return
  337. const idx = rows.findIndex((r) => r.id === activeId)
  338. if (idx < 0) return
  339. e.preventDefault()
  340. const next = e.key === 'ArrowUp' ? Math.max(0, idx - 1) : Math.min(rows.length - 1, idx + 1)
  341. activeId = rows[next].id
  342. renderList()
  343. lineList.querySelector('.is-active')?.scrollIntoView({ block: 'nearest' })
  344. })
  345. renderList()
  346. </script>
  347. </body>
  348. </html>