demo-pl-vehicle-inline-personnel-create.html 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  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>Demo · 三方车辆 · 关联人员快速新建</title>
  7. <link rel="preconnect" href="https://fonts.googleapis.com" />
  8. <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
  9. <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet" />
  10. <style>
  11. :root {
  12. --primary: #10b981;
  13. --primary-dark: #059669;
  14. --primary-bg: #ecfdf5;
  15. --text: #1e293b;
  16. --text-muted: #64748b;
  17. --border: #d9e8e2;
  18. --bg-page: #fefefe;
  19. --surface: #ffffff;
  20. --table-head: #f8fafc;
  21. --row-alt: #fafafa;
  22. --row-hover: #f1f5f9;
  23. --shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  24. --radius: 10px;
  25. --content-padding: 24px;
  26. --warning: #d97706;
  27. --danger: #dc2626;
  28. }
  29. * { box-sizing: border-box; }
  30. body {
  31. margin: 0;
  32. min-height: 100vh;
  33. font-family: Inter, -apple-system, sans-serif;
  34. font-size: 14px;
  35. line-height: 1.5;
  36. color: var(--text);
  37. background: var(--bg-page);
  38. }
  39. .demo-banner {
  40. background: linear-gradient(90deg, #ecfdf5, #fff);
  41. border-bottom: 1px solid var(--border);
  42. padding: 12px 24px;
  43. display: flex;
  44. align-items: center;
  45. justify-content: space-between;
  46. gap: 16px;
  47. flex-wrap: wrap;
  48. }
  49. .demo-banner h1 {
  50. margin: 0;
  51. font-size: 15px;
  52. font-weight: 600;
  53. }
  54. .demo-banner p {
  55. margin: 4px 0 0;
  56. font-size: 12px;
  57. color: var(--text-muted);
  58. }
  59. .demo-actions {
  60. display: flex;
  61. gap: 8px;
  62. flex-wrap: wrap;
  63. }
  64. .page-container {
  65. padding: var(--content-padding);
  66. max-width: 1440px;
  67. margin: 0 auto;
  68. }
  69. .panel {
  70. background: var(--surface);
  71. border: 1px solid var(--border);
  72. border-radius: var(--radius);
  73. box-shadow: var(--shadow);
  74. overflow: hidden;
  75. }
  76. .panel-top {
  77. padding: 16px 20px;
  78. border-bottom: 1px solid var(--border);
  79. }
  80. .title-bar-heading {
  81. margin: 0;
  82. font-size: 16px;
  83. font-weight: 600;
  84. display: flex;
  85. align-items: center;
  86. gap: 8px;
  87. }
  88. .title-bar-heading::before {
  89. content: '';
  90. width: 4px;
  91. height: 18px;
  92. border-radius: 2px;
  93. background: var(--primary);
  94. }
  95. .list-toolbar {
  96. padding: 12px 20px;
  97. background: var(--table-head);
  98. border-bottom: 1px solid var(--border);
  99. }
  100. .list-toolbar-row {
  101. display: flex;
  102. align-items: center;
  103. gap: 8px;
  104. flex-wrap: wrap;
  105. }
  106. .btn {
  107. display: inline-flex;
  108. align-items: center;
  109. gap: 6px;
  110. height: 36px;
  111. padding: 0 14px;
  112. border-radius: 8px;
  113. border: 1px solid var(--border);
  114. background: var(--surface);
  115. color: var(--text);
  116. font-size: 14px;
  117. font-family: inherit;
  118. cursor: pointer;
  119. transition: all 0.15s ease;
  120. white-space: nowrap;
  121. }
  122. .btn:hover { background: var(--row-hover); }
  123. .btn-main {
  124. background: var(--primary);
  125. border-color: var(--primary);
  126. color: #fff;
  127. }
  128. .btn-main:hover {
  129. background: var(--primary-dark);
  130. border-color: var(--primary-dark);
  131. }
  132. .btn-ghost {
  133. background: var(--surface);
  134. }
  135. .btn-sm {
  136. height: 32px;
  137. padding: 0 12px;
  138. font-size: 13px;
  139. }
  140. .btn-link {
  141. border: none;
  142. background: none;
  143. color: var(--primary-dark);
  144. padding: 0 4px;
  145. height: auto;
  146. }
  147. .btn-link:hover { text-decoration: underline; background: none; }
  148. .btn-danger {
  149. color: var(--danger);
  150. border-color: rgba(220, 38, 38, 0.25);
  151. }
  152. .list-body { padding: 0; }
  153. table.list-table {
  154. width: 100%;
  155. border-collapse: collapse;
  156. }
  157. .list-table th,
  158. .list-table td {
  159. padding: 12px 16px;
  160. text-align: center;
  161. border-bottom: 1px solid var(--border);
  162. }
  163. .list-table th {
  164. background: var(--table-head);
  165. color: var(--text-muted);
  166. font-size: 12px;
  167. font-weight: 600;
  168. }
  169. .list-table tbody tr:nth-child(even) { background: var(--row-alt); }
  170. .list-table tbody tr:hover { background: var(--row-hover); }
  171. .link-primary {
  172. color: var(--primary-dark);
  173. text-decoration: none;
  174. cursor: pointer;
  175. font-weight: 500;
  176. }
  177. .link-primary:hover { text-decoration: underline; }
  178. .tag {
  179. display: inline-block;
  180. padding: 2px 8px;
  181. border-radius: 6px;
  182. font-size: 12px;
  183. font-weight: 500;
  184. color: #fff;
  185. }
  186. .tag.success { background: var(--primary-dark); }
  187. .tag.warning { background: var(--warning); }
  188. /* Dialog */
  189. .backdrop {
  190. position: fixed;
  191. inset: 0;
  192. background: rgba(15, 23, 42, 0.35);
  193. backdrop-filter: none;
  194. display: none;
  195. align-items: center;
  196. justify-content: center;
  197. z-index: 1000;
  198. padding: 24px;
  199. }
  200. .backdrop.is-open { display: flex; }
  201. .dialog {
  202. background: var(--surface);
  203. border-radius: var(--radius);
  204. box-shadow: 0 20px 60px rgba(15, 23, 42, 0.18);
  205. width: min(1360px, 100%);
  206. max-height: calc(100vh - 48px);
  207. display: flex;
  208. flex-direction: column;
  209. overflow: hidden;
  210. }
  211. .dialog.dialog-sm { width: min(720px, 100%); }
  212. .dialog-header {
  213. padding: 16px 20px;
  214. border-bottom: 1px solid var(--border);
  215. display: flex;
  216. align-items: center;
  217. justify-content: space-between;
  218. }
  219. .dialog-header h2 {
  220. margin: 0;
  221. font-size: 16px;
  222. font-weight: 600;
  223. }
  224. .dialog-close {
  225. width: 32px;
  226. height: 32px;
  227. border: none;
  228. background: none;
  229. border-radius: 8px;
  230. cursor: pointer;
  231. color: var(--text-muted);
  232. font-size: 20px;
  233. line-height: 1;
  234. }
  235. .dialog-close:hover { background: var(--row-hover); color: var(--text); }
  236. .dialog-body {
  237. padding: 20px;
  238. overflow-y: auto;
  239. flex: 1;
  240. }
  241. .dialog-footer {
  242. padding: 12px 20px;
  243. border-top: 1px solid var(--border);
  244. background: var(--table-head);
  245. display: flex;
  246. justify-content: flex-end;
  247. gap: 8px;
  248. }
  249. .form-grid-3 {
  250. display: grid;
  251. grid-template-columns: repeat(3, 1fr);
  252. gap: 16px 20px;
  253. }
  254. .form-grid-2 {
  255. display: grid;
  256. grid-template-columns: repeat(2, 1fr);
  257. gap: 16px 20px;
  258. }
  259. @media (max-width: 900px) {
  260. .form-grid-3, .form-grid-2 { grid-template-columns: 1fr; }
  261. }
  262. .form-item label {
  263. display: block;
  264. font-size: 13px;
  265. font-weight: 500;
  266. margin-bottom: 6px;
  267. color: var(--text);
  268. }
  269. .form-item .form-label-tip {
  270. font-size: 12px;
  271. font-weight: 400;
  272. color: var(--text-muted);
  273. margin-left: 4px;
  274. }
  275. .form-item input,
  276. .form-item select,
  277. .form-item textarea {
  278. width: 100%;
  279. height: 36px;
  280. padding: 0 12px;
  281. border: 1px solid var(--border);
  282. border-radius: 8px;
  283. font-family: inherit;
  284. font-size: 14px;
  285. color: var(--text);
  286. background: var(--surface);
  287. }
  288. .form-item textarea {
  289. height: auto;
  290. min-height: 72px;
  291. padding: 8px 12px;
  292. resize: vertical;
  293. }
  294. .form-item input:focus,
  295. .form-item select:focus,
  296. .form-item textarea:focus {
  297. outline: none;
  298. border-color: var(--primary);
  299. box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
  300. }
  301. .form-col-span-full { grid-column: 1 / -1; }
  302. .sub-table-section {
  303. margin-top: 20px;
  304. padding-top: 16px;
  305. border-top: 1px dashed var(--border);
  306. }
  307. .sub-table-header {
  308. display: flex;
  309. align-items: center;
  310. justify-content: space-between;
  311. margin-bottom: 10px;
  312. }
  313. .sub-table-title {
  314. font-size: 14px;
  315. font-weight: 600;
  316. }
  317. .sub-table-actions {
  318. display: flex;
  319. gap: 8px;
  320. }
  321. .sub-table .list-table td { text-align: left; }
  322. .sub-table .list-table th:first-child,
  323. .sub-table .list-table td:first-child { text-align: center; }
  324. .select-with-action {
  325. display: flex;
  326. gap: 6px;
  327. align-items: center;
  328. }
  329. .select-with-action select { flex: 1; min-width: 0; }
  330. .toast {
  331. position: fixed;
  332. top: 20px;
  333. left: 50%;
  334. transform: translateX(-50%) translateY(-20px);
  335. background: var(--primary-dark);
  336. color: #fff;
  337. padding: 10px 18px;
  338. border-radius: 8px;
  339. font-size: 14px;
  340. opacity: 0;
  341. pointer-events: none;
  342. transition: all 0.25s ease;
  343. z-index: 2000;
  344. box-shadow: 0 8px 24px rgba(5, 150, 105, 0.35);
  345. }
  346. .toast.is-show {
  347. opacity: 1;
  348. transform: translateX(-50%) translateY(0);
  349. }
  350. .hint-box {
  351. margin-top: 16px;
  352. padding: 12px 14px;
  353. border-radius: 8px;
  354. background: var(--primary-bg);
  355. border: 1px solid rgba(16, 185, 129, 0.25);
  356. font-size: 13px;
  357. color: var(--text-muted);
  358. }
  359. .hint-box strong { color: var(--primary-dark); }
  360. .flow-steps {
  361. display: flex;
  362. gap: 8px;
  363. flex-wrap: wrap;
  364. margin-top: 8px;
  365. }
  366. .flow-step {
  367. display: inline-flex;
  368. align-items: center;
  369. gap: 6px;
  370. padding: 4px 10px;
  371. border-radius: 999px;
  372. background: var(--surface);
  373. border: 1px solid var(--border);
  374. font-size: 12px;
  375. color: var(--text-muted);
  376. }
  377. .flow-step.active {
  378. border-color: var(--primary);
  379. background: var(--primary-bg);
  380. color: var(--primary-dark);
  381. font-weight: 600;
  382. }
  383. .flow-step .num {
  384. width: 18px;
  385. height: 18px;
  386. border-radius: 50%;
  387. background: var(--border);
  388. color: var(--text-muted);
  389. display: inline-flex;
  390. align-items: center;
  391. justify-content: center;
  392. font-size: 11px;
  393. font-weight: 700;
  394. }
  395. .flow-step.active .num {
  396. background: var(--primary);
  397. color: #fff;
  398. }
  399. .badge-new {
  400. display: inline-block;
  401. margin-left: 6px;
  402. padding: 1px 6px;
  403. border-radius: 4px;
  404. background: var(--primary-bg);
  405. color: var(--primary-dark);
  406. font-size: 11px;
  407. font-weight: 600;
  408. }
  409. .icon { width: 16px; height: 16px; display: inline-block; vertical-align: -3px; }
  410. </style>
  411. </head>
  412. <body>
  413. <div class="demo-banner">
  414. <div>
  415. <h1>Demo · 三方车辆 · 编辑时快速新建并绑定人员</h1>
  416. <p>交互原型(Fresh Mint)— 点击下方按钮体验完整流程</p>
  417. <div class="flow-steps" id="flowSteps">
  418. <span class="flow-step active" data-step="1"><span class="num">1</span>编辑车辆</span>
  419. <span class="flow-step" data-step="2"><span class="num">2</span>添加人员行</span>
  420. <span class="flow-step" data-step="3"><span class="num">3</span>快速新建人员</span>
  421. <span class="flow-step" data-step="4"><span class="num">4</span>自动选中并绑定</span>
  422. </div>
  423. </div>
  424. <div class="demo-actions">
  425. <button class="btn btn-ghost" type="button" onclick="openVehicleDialog()">打开「编辑车辆」弹窗</button>
  426. <button class="btn btn-main" type="button" onclick="runFullDemo()">▶ 自动演示完整流程</button>
  427. </div>
  428. </div>
  429. <div class="page-container">
  430. <section class="panel">
  431. <div class="panel-top">
  432. <h2 class="title-bar-heading">三方车辆</h2>
  433. </div>
  434. <div class="list-toolbar">
  435. <div class="list-toolbar-row">
  436. <button class="btn btn-ghost" type="button">快速识别创建</button>
  437. <button class="btn btn-main" type="button">新增车辆</button>
  438. <button class="btn btn-ghost" type="button" onclick="openVehicleDialog()">编辑</button>
  439. </div>
  440. </div>
  441. <div class="list-body">
  442. <table class="list-table">
  443. <thead>
  444. <tr>
  445. <th style="width:48px">序号</th>
  446. <th>车牌号</th>
  447. <th>车辆状态</th>
  448. <th>承运商</th>
  449. <th>关联人员</th>
  450. </tr>
  451. </thead>
  452. <tbody>
  453. <tr>
  454. <td>1</td>
  455. <td><a class="link-primary" href="#" onclick="openVehicleDialog(); return false;">皖A12345 / 皖A67890挂</a></td>
  456. <td><span class="tag success">可用</span></td>
  457. <td>某某物流</td>
  458. <td id="listPersonnelSummary">—</td>
  459. </tr>
  460. <tr>
  461. <td>2</td>
  462. <td><a class="link-primary" href="#">苏B88888</a></td>
  463. <td><span class="tag success">可用</span></td>
  464. <td>华东运输</td>
  465. <td>王师傅(司机)</td>
  466. </tr>
  467. </tbody>
  468. </table>
  469. </div>
  470. </section>
  471. <div class="hint-box">
  472. <strong>设计要点</strong>:在「关联人员」子表每行的姓名下拉旁增加「新建」入口;新建成功后自动回填当前行并刷新下拉选项,无需切页到「三方驾押人员」。
  473. </div>
  474. </div>
  475. <!-- 编辑车辆弹窗 -->
  476. <div class="backdrop" id="vehicleBackdrop">
  477. <div class="dialog" role="dialog" aria-labelledby="vehicleDialogTitle">
  478. <div class="dialog-header">
  479. <h2 id="vehicleDialogTitle">编辑车辆</h2>
  480. <button class="dialog-close" type="button" aria-label="关闭" onclick="closeVehicleDialog()">×</button>
  481. </div>
  482. <div class="dialog-body">
  483. <div class="form-grid-3">
  484. <div class="form-item">
  485. <label>车牌号</label>
  486. <input type="text" value="皖A12345" readonly />
  487. </div>
  488. <div class="form-item">
  489. <label>挂车号</label>
  490. <input type="text" value="皖A67890挂" readonly />
  491. </div>
  492. <div class="form-item">
  493. <label>载重(吨)</label>
  494. <input type="text" value="34" readonly />
  495. </div>
  496. <div class="form-item">
  497. <label>承运商</label>
  498. <input type="text" value="某某物流" readonly />
  499. </div>
  500. <div class="form-item">
  501. <label>车辆状态</label>
  502. <input type="text" value="可用" readonly />
  503. </div>
  504. <div class="form-item">
  505. <label>备注</label>
  506. <input type="text" placeholder="请输入备注" />
  507. </div>
  508. </div>
  509. <div class="sub-table-section">
  510. <div class="sub-table-header">
  511. <span class="sub-table-title">关联人员</span>
  512. <div class="sub-table-actions">
  513. <button class="btn btn-sm btn-ghost" type="button" id="btnAddPersonnel" onclick="addPersonnelRow()">
  514. <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 5v14M5 12h14"/></svg>
  515. 添加人员
  516. </button>
  517. </div>
  518. </div>
  519. <table class="list-table sub-table" id="personnelTable">
  520. <thead>
  521. <tr>
  522. <th style="width:56px">序号</th>
  523. <th style="min-width:220px">姓名</th>
  524. <th style="width:120px">手机号</th>
  525. <th style="width:80px">年龄</th>
  526. <th style="width:110px">人员类型</th>
  527. <th style="width:100px">备注</th>
  528. <th style="width:60px">操作</th>
  529. </tr>
  530. </thead>
  531. <tbody id="personnelTbody">
  532. <!-- rows injected -->
  533. </tbody>
  534. </table>
  535. </div>
  536. </div>
  537. <div class="dialog-footer">
  538. <button class="btn btn-ghost" type="button" onclick="closeVehicleDialog()">取消</button>
  539. <button class="btn btn-main" type="button" onclick="saveVehicle()">确定</button>
  540. </div>
  541. </div>
  542. </div>
  543. <!-- 快速新建人员弹窗 -->
  544. <div class="backdrop" id="personnelBackdrop" style="z-index:1100">
  545. <div class="dialog dialog-sm" role="dialog" aria-labelledby="personnelDialogTitle">
  546. <div class="dialog-header">
  547. <h2 id="personnelDialogTitle">快速新建三方人员</h2>
  548. <button class="dialog-close" type="button" aria-label="关闭" onclick="closePersonnelDialog()">×</button>
  549. </div>
  550. <div class="dialog-body">
  551. <div class="form-grid-2">
  552. <div class="form-item">
  553. <label>姓名 <span style="color:var(--danger)">*</span></label>
  554. <input type="text" id="newName" placeholder="请输入姓名" maxlength="100" />
  555. </div>
  556. <div class="form-item">
  557. <label>人员类型 <span style="color:var(--danger)">*</span></label>
  558. <select id="newType">
  559. <option value="driver">司机</option>
  560. <option value="escort">押运员</option>
  561. </select>
  562. </div>
  563. <div class="form-item">
  564. <label>手机号</label>
  565. <input type="text" id="newPhone" placeholder="13800000000" maxlength="32" />
  566. </div>
  567. <div class="form-item">
  568. <label>身份证号</label>
  569. <input type="text" id="newIdCard" placeholder="340000199001010000" maxlength="32" />
  570. </div>
  571. <div class="form-item form-col-span-full">
  572. <label>备注</label>
  573. <textarea id="newRemark" placeholder="可选"></textarea>
  574. </div>
  575. </div>
  576. <div class="hint-box" style="margin-top:12px">
  577. 保存后将<strong>自动选中到当前关联行</strong>,并同步写入「三方驾押人员」主数据。
  578. </div>
  579. </div>
  580. <div class="dialog-footer">
  581. <button class="btn btn-ghost" type="button" onclick="closePersonnelDialog()">取消</button>
  582. <button class="btn btn-main" type="button" id="btnSavePersonnel" onclick="saveNewPersonnel()">保存并关联</button>
  583. </div>
  584. </div>
  585. </div>
  586. <div class="toast" id="toast"></div>
  587. <script>
  588. /** @type {{id:string,name:string,phone:string,age:number|null,type:string,remark:string,isNew?:boolean}[]} */
  589. let personnelPool = [
  590. { id: 'p1', name: '王师傅', phone: '13800001111', age: 42, type: 'driver', remark: '' }
  591. ]
  592. /** @type {{personnelId:string,role:string,remark:string}[]} */
  593. let personnelRows = []
  594. let activeRowIndex = -1
  595. let rowKey = 0
  596. function setFlowStep(step) {
  597. document.querySelectorAll('.flow-step').forEach(el => {
  598. el.classList.toggle('active', Number(el.dataset.step) <= step)
  599. })
  600. }
  601. function showToast(msg) {
  602. const t = document.getElementById('toast')
  603. t.textContent = msg
  604. t.classList.add('is-show')
  605. setTimeout(() => t.classList.remove('is-show'), 2400)
  606. }
  607. function openVehicleDialog() {
  608. document.getElementById('vehicleBackdrop').classList.add('is-open')
  609. if (personnelRows.length === 0) {
  610. addPersonnelRow()
  611. }
  612. renderPersonnelRows()
  613. setFlowStep(1)
  614. }
  615. function closeVehicleDialog() {
  616. document.getElementById('vehicleBackdrop').classList.remove('is-open')
  617. }
  618. function addPersonnelRow() {
  619. personnelRows.push({ personnelId: '', role: 'driver', remark: '' })
  620. renderPersonnelRows()
  621. setFlowStep(2)
  622. }
  623. function removePersonnelRow(index) {
  624. personnelRows.splice(index, 1)
  625. renderPersonnelRows()
  626. }
  627. function getPersonnelLabel(p) {
  628. return p.phone ? `${p.name}(${p.phone})` : p.name
  629. }
  630. function renderPersonnelRows() {
  631. const tbody = document.getElementById('personnelTbody')
  632. tbody.innerHTML = personnelRows.map((row, index) => {
  633. const options = personnelPool.map(p =>
  634. `<option value="${p.id}" ${row.personnelId === p.id ? 'selected' : ''}>${getPersonnelLabel(p)}${p.isNew ? ' ★' : ''}</option>`
  635. ).join('')
  636. const selected = personnelPool.find(p => p.id === row.personnelId)
  637. return `
  638. <tr data-index="${index}">
  639. <td>${index + 1}</td>
  640. <td>
  641. <div class="select-with-action">
  642. <select onchange="onPersonnelChange(${index}, this.value)">
  643. <option value="">请选择人员</option>
  644. ${options}
  645. </select>
  646. <button class="btn btn-sm btn-link" type="button" onclick="openPersonnelDialog(${index})">新建</button>
  647. </div>
  648. ${selected?.isNew ? '<span class="badge-new">刚创建</span>' : ''}
  649. </td>
  650. <td>${selected?.phone || '—'}</td>
  651. <td style="text-align:center">${selected?.age ?? '—'}</td>
  652. <td>
  653. <select onchange="onRoleChange(${index}, this.value)">
  654. <option value="driver" ${row.role === 'driver' ? 'selected' : ''}>司机</option>
  655. <option value="escort" ${row.role === 'escort' ? 'selected' : ''}>押运员</option>
  656. </select>
  657. </td>
  658. <td><input type="text" value="${row.remark || ''}" placeholder="备注" oninput="personnelRows[${index}].remark=this.value" style="height:32px" /></td>
  659. <td style="text-align:center">
  660. <button class="btn btn-sm btn-danger" type="button" onclick="removePersonnelRow(${index})" title="删除">✕</button>
  661. </td>
  662. </tr>
  663. `
  664. }).join('')
  665. }
  666. function onPersonnelChange(index, id) {
  667. personnelRows[index].personnelId = id
  668. const p = personnelPool.find(x => x.id === id)
  669. if (p) {
  670. personnelRows[index].role = p.type === 'escort' ? 'escort' : 'driver'
  671. }
  672. renderPersonnelRows()
  673. }
  674. function onRoleChange(index, role) {
  675. personnelRows[index].role = role
  676. }
  677. function openPersonnelDialog(rowIndex) {
  678. activeRowIndex = rowIndex
  679. document.getElementById('newName').value = ''
  680. document.getElementById('newPhone').value = ''
  681. document.getElementById('newIdCard').value = ''
  682. document.getElementById('newRemark').value = ''
  683. document.getElementById('newType').value = personnelRows[rowIndex]?.role || 'driver'
  684. document.getElementById('personnelBackdrop').classList.add('is-open')
  685. setFlowStep(3)
  686. setTimeout(() => document.getElementById('newName').focus(), 200)
  687. }
  688. function closePersonnelDialog() {
  689. document.getElementById('personnelBackdrop').classList.remove('is-open')
  690. activeRowIndex = -1
  691. }
  692. function calcAgeFromIdCard(idCard) {
  693. if (!idCard || idCard.length < 14) return null
  694. const y = parseInt(idCard.slice(6, 10), 10)
  695. if (!y) return null
  696. return new Date().getFullYear() - y
  697. }
  698. function saveNewPersonnel() {
  699. const name = document.getElementById('newName').value.trim()
  700. const phone = document.getElementById('newPhone').value.trim()
  701. const idCard = document.getElementById('newIdCard').value.trim()
  702. const type = document.getElementById('newType').value
  703. const remark = document.getElementById('newRemark').value.trim()
  704. if (!name) {
  705. showToast('请填写姓名')
  706. document.getElementById('newName').focus()
  707. return
  708. }
  709. rowKey += 1
  710. const newPerson = {
  711. id: `new-${rowKey}`,
  712. name,
  713. phone,
  714. age: calcAgeFromIdCard(idCard),
  715. type,
  716. remark,
  717. isNew: true
  718. }
  719. personnelPool.unshift(newPerson)
  720. if (activeRowIndex >= 0) {
  721. personnelRows[activeRowIndex].personnelId = newPerson.id
  722. personnelRows[activeRowIndex].role = type
  723. personnelRows[activeRowIndex].remark = remark
  724. }
  725. closePersonnelDialog()
  726. renderPersonnelRows()
  727. setFlowStep(4)
  728. showToast(`已创建「${name}」并自动关联到当前行`)
  729. }
  730. function saveVehicle() {
  731. const bound = personnelRows
  732. .filter(r => r.personnelId)
  733. .map(r => {
  734. const p = personnelPool.find(x => x.id === r.personnelId)
  735. const roleLabel = r.role === 'driver' ? '司机' : '押运员'
  736. return `${p?.name || '未知'}(${roleLabel})`
  737. })
  738. const summary = bound.length ? bound.join('、') : '—'
  739. document.getElementById('listPersonnelSummary').textContent = summary
  740. closeVehicleDialog()
  741. showToast('车辆保存成功,关联人员已更新')
  742. }
  743. async function runFullDemo() {
  744. personnelRows = []
  745. openVehicleDialog()
  746. await wait(600)
  747. addPersonnelRow()
  748. await wait(500)
  749. openPersonnelDialog(0)
  750. await wait(400)
  751. document.getElementById('newName').value = '张师傅'
  752. document.getElementById('newPhone').value = '13812345678'
  753. document.getElementById('newIdCard').value = '340000199001010000'
  754. document.getElementById('newType').value = 'driver'
  755. await wait(800)
  756. saveNewPersonnel()
  757. await wait(1000)
  758. saveVehicle()
  759. }
  760. function wait(ms) {
  761. return new Promise(resolve => setTimeout(resolve, ms))
  762. }
  763. // init
  764. renderPersonnelRows()
  765. </script>
  766. </body>
  767. </html>