@skillre/dsh-plugin-work-dashboard 0.13.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.en.md +6 -9
  2. package/README.md +9 -12
  3. package/lib/client/api.d.ts +3 -3
  4. package/lib/client/api.js +1 -3
  5. package/lib/client/text.js +5 -5
  6. package/lib/client.js +37 -30
  7. package/lib/index.js +56 -8
  8. package/lib/report-contract.d.ts +132 -2
  9. package/lib/report-contract.js +127 -1
  10. package/lib/report-form.d.ts +33 -2
  11. package/lib/report-form.js +79 -6
  12. package/lib/report-page.js +2093 -1481
  13. package/lib/report-style.d.ts +24 -12
  14. package/lib/report-style.js +368 -447
  15. package/lib/transport.d.ts +5 -5
  16. package/lib/transport.js +4 -3
  17. package/lib/types.d.ts +25 -10
  18. package/package.json +9 -16
  19. package/skills/poc-export/SKILL.md +3 -3
  20. package/skills/poc-export/scripts/export-form.mjs +24 -5
  21. package/skills/poc-submit/SKILL.md +2 -2
  22. package/compatibility.json +0 -240
  23. package/docs/DESIGN-0.3.md +0 -122
  24. package/docs/DESIGN-1.0-/344/274/230/345/214/226/346/226/271/346/241/210.md +0 -212
  25. package/docs/DESIGN-/344/274/232/350/257/235/344/272/214-SuperAgent/344/270/216/344/273/223/345/272/223/346/224/271/351/200/240.md +0 -275
  26. package/docs/DESIGN-/345/257/274/345/207/272/350/241/250/345/215/225/351/207/215/350/256/276/350/256/241.md +0 -330
  27. package/docs/DESIGN-/346/217/220/351/206/222/344/270/216Gate/350/257/204/345/256/241.md +0 -518
  28. package/docs/DESIGN-/346/226/207/346/234/254/346/210/252/346/226/255.md +0 -565
  29. package/docs/DESIGN-/350/241/250/345/215/225/345/210/206/351/230/266/346/256/265.md +0 -420
  30. package/docs/LEDGER-REQUIREMENTS-v3.1.md +0 -367
  31. package/docs/PLAN-0.7-0.9.md +0 -230
  32. package/docs/PLAN-v3.1-adaptation.md +0 -237
  33. package/docs/POC-3.2-/350/277/233/345/261/225/345/245/221/347/272/246.md +0 -21
  34. package/docs/Super-Agent-3.2-/350/201/224/350/260/203/346/211/213/345/206/214.md +0 -38
  35. package/docs/TARGET-/345/217/260/350/264/246/344/273/223/345/272/223v3.1.md +0 -500
  36. package/docs//350/200/201Mac-SuperAgent/346/224/271/351/200/240/350/256/260/345/275/225-/347/254/254/344/272/214/346/255/245.md +0 -233
  37. package/lib/form.d.ts +0 -597
  38. package/lib/form.js +0 -3211
@@ -235,7 +235,13 @@ function reportPage() {
235
235
  var enums = {};
236
236
  var projectInputs = [];
237
237
  var bases = [];
238
- var state = { active: 0, workspaces: [] };
238
+ /** The parsed `poc-report-input` block, kept so a save can embed it again. */
239
+ var inputRaw = null;
240
+ var state = { active: 0, workspaces: [], screen: 1 };
241
+ /** The project's read-only second screen, or `null` when the Host had none. */
242
+ var dossier = null;
243
+ /** `2026-12-03 22:41`, the moment the snapshot was taken. */
244
+ var exportedAt = '';
239
245
  var app = null;
240
246
  var fieldRefs = {};
241
247
  var notices = [];
@@ -325,10 +331,143 @@ function reportPage() {
325
331
  }
326
332
  return parsed;
327
333
  }
334
+ /**
335
+ * Coerce the Host's dossier into the shape the second screen renders.
336
+ *
337
+ * Returns `null` for anything unusable rather than throwing: the dossier is
338
+ * context, and a malformed one must not stop the colleague from recording this
339
+ * round. An `undefined` dossier (a new-project form) is the normal case, not an
340
+ * error.
341
+ *
342
+ * Every string is length-capped so a corrupted payload cannot bloat the page,
343
+ * and every list is bounded so one enormous project cannot make the file slow
344
+ * to open.
345
+ */
346
+ function normalizeDossier(raw) {
347
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
348
+ return null;
349
+ function strList(value, max) {
350
+ var source = Array.isArray(value) ? value : [];
351
+ var out = [];
352
+ for (var i = 0; i < source.length && out.length < max; i += 1) {
353
+ var item = str(at(source, i), 200);
354
+ if (item !== '')
355
+ out.push(item);
356
+ }
357
+ return out;
358
+ }
359
+ var g0 = raw.gate0 && typeof raw.gate0 === 'object' ? raw.gate0 : {};
360
+ var plan = raw.plan && typeof raw.plan === 'object' ? raw.plan : {};
361
+ var outcome = raw.outcome && typeof raw.outcome === 'object' ? raw.outcome : {};
362
+ var gaps = raw.gaps && typeof raw.gaps === 'object' ? raw.gaps : {};
363
+ function refs(source, max, build) {
364
+ var list = Array.isArray(source) ? source : [];
365
+ var out = [];
366
+ for (var i = 0; i < list.length && out.length < max; i += 1) {
367
+ var item = at(list, i);
368
+ if (!item || typeof item !== 'object')
369
+ continue;
370
+ out.push(build(item));
371
+ }
372
+ return out;
373
+ }
374
+ var rounds = [];
375
+ var roundSource = Array.isArray(raw.rounds) ? raw.rounds : [];
376
+ for (var r = 0; r < roundSource.length && rounds.length < 10; r += 1) {
377
+ var round = at(roundSource, r);
378
+ if (!round || typeof round !== 'object')
379
+ continue;
380
+ var lines = [];
381
+ var lineSource = Array.isArray(round.lines) ? round.lines : [];
382
+ for (var l = 0; l < lineSource.length && lines.length < 100; l += 1) {
383
+ var line = at(lineSource, l);
384
+ if (!line || typeof line !== 'object')
385
+ continue;
386
+ lines.push({ title: str(line.title, 500), status: str(line.status, 30), actual: str(line.actual, 4000) });
387
+ }
388
+ rounds.push({
389
+ seq: str(round.seq, 20),
390
+ date: str(round.date, 20),
391
+ type: str(round.type, 40),
392
+ change: str(round.change, 40),
393
+ actual: str(round.actual, 12_000),
394
+ lines: lines,
395
+ completion: str(round.completion, 10),
396
+ evidenceCount: typeof round.evidenceCount === 'number' && round.evidenceCount >= 0 ? round.evidenceCount : 0,
397
+ ids: str(round.ids, 400),
398
+ customer: str(round.customer, 1000),
399
+ });
400
+ }
401
+ var total = Number(raw.roundTotal);
402
+ return {
403
+ pocId: str(raw.pocId, 120),
404
+ name: str(raw.name, 500),
405
+ stage: str(raw.stage, 60),
406
+ status: str(raw.status, 60),
407
+ owner: str(raw.owner, 120),
408
+ company: str(raw.company, 200),
409
+ department: str(raw.department, 200),
410
+ system: str(raw.system, 40),
411
+ sales: str(raw.sales, 120),
412
+ techOwner: str(raw.techOwner, 120),
413
+ execSponsor: str(raw.execSponsor, 120),
414
+ amountWan: str(raw.amountWan, 30),
415
+ pocType: str(raw.pocType, 40),
416
+ daysInStage: typeof raw.daysInStage === 'number' && Number.isFinite(raw.daysInStage) ? raw.daysInStage : null,
417
+ stageSince: str(raw.stageSince, 20),
418
+ g0Conclusion: str(raw.g0Conclusion, 60),
419
+ g0Complete: raw.g0Complete === true,
420
+ gate0: {
421
+ whyCustomer: str(g0.whyCustomer, 12_000),
422
+ whyUs: str(g0.whyUs, 12_000),
423
+ decisionChain: str(g0.decisionChain, 12_000),
424
+ postPocDecision: str(g0.postPocDecision, 12_000),
425
+ competitor: str(g0.competitor, 1000),
426
+ missing: strList(g0.missing, 20),
427
+ },
428
+ plan: {
429
+ customerPain: str(plan.customerPain, 4000),
430
+ expectedRecognition: str(plan.expectedRecognition, 4000),
431
+ ourEdge: str(plan.ourEdge, 4000),
432
+ timelineStart: str(plan.timelineStart, 20),
433
+ timelineEnd: str(plan.timelineEnd, 20),
434
+ criteria: refs(plan.criteria, 100, function (item) {
435
+ return { id: str(item.id, 40), name: str(item.name, 500), metric: str(item.metric, 1000), status: str(item.status, 40) };
436
+ }),
437
+ scenarios: refs(plan.scenarios, 100, function (item) {
438
+ return {
439
+ id: str(item.id, 40), name: str(item.name, 500), goal: str(item.goal, 2000), status: str(item.status, 40),
440
+ evidenceCount: typeof item.evidenceCount === 'number' && item.evidenceCount >= 0 ? item.evidenceCount : 0,
441
+ };
442
+ }),
443
+ risks: refs(plan.risks, 50, function (item) {
444
+ return { name: str(item.name, 500), level: str(item.level, 20), mitigation: str(item.mitigation, 2000) };
445
+ }),
446
+ },
447
+ rounds: rounds,
448
+ roundTotal: Number.isFinite(total) && total >= 0 ? total : rounds.length,
449
+ outcome: {
450
+ achievement: str(outcome.achievement, 2000),
451
+ proved: str(outcome.proved, 4000),
452
+ recognized: str(outcome.recognized, 4000),
453
+ nextBusiness: str(outcome.nextBusiness, 4000),
454
+ overall: str(outcome.overall, 4000),
455
+ },
456
+ gaps: {
457
+ stalled: gaps.stalled === true,
458
+ stalledDays: typeof gaps.stalledDays === 'number' && Number.isFinite(gaps.stalledDays) ? gaps.stalledDays : null,
459
+ unverifiedCriteria: typeof gaps.unverifiedCriteria === 'number' && gaps.unverifiedCriteria >= 0 ? gaps.unverifiedCriteria : 0,
460
+ g0Missing: typeof gaps.g0Missing === 'number' && gaps.g0Missing >= 0 ? gaps.g0Missing : 0,
461
+ pendingPlans: typeof gaps.pendingPlans === 'number' && gaps.pendingPlans >= 0 ? gaps.pendingPlans : 0,
462
+ },
463
+ };
464
+ }
328
465
  function normalizeData(raw) {
329
466
  intent = raw.intent === 'progress' ? 'progress' : 'new';
330
467
  today = isCalendarDate(txt(raw.today)) ? txt(raw.today) : localToday();
331
468
  formId = trim(raw.form_id) || 'draft-' + today;
469
+ exportedAt = trim(raw.exported_at);
470
+ dossier = normalizeDossier(raw.dossier);
332
471
  enums = normalizeEnums(raw.enums);
333
472
  projectInputs = [];
334
473
  if (intent === 'progress') {
@@ -407,6 +546,9 @@ function reportPage() {
407
546
  plans: [],
408
547
  noProgress: false,
409
548
  stageNotes: blankStageNotes(),
549
+ openLines: {},
550
+ stageTab: 'G0',
551
+ stageOpen: true,
410
552
  submissionId: '',
411
553
  lastSignature: '',
412
554
  lineSeq: 0,
@@ -429,6 +571,9 @@ function reportPage() {
429
571
  plans: [],
430
572
  noProgress: false,
431
573
  stageNotes: blankStageNotes(),
574
+ openLines: {},
575
+ stageTab: 'G0',
576
+ stageOpen: true,
432
577
  submissionId: '',
433
578
  lastSignature: '',
434
579
  lineSeq: 0,
@@ -543,7 +688,7 @@ function reportPage() {
543
688
  }
544
689
  catch (error) {
545
690
  storageOk = false;
546
- pushNotice('storage', '浏览器没有可用的本地存储,草稿无法自动保存;请填完后及时生成回传文件。', true);
691
+ pushNotice('storage', '浏览器没有可用的本地存储,草稿无法自动保存;请填完后及时点「保存」。', true);
547
692
  }
548
693
  }
549
694
  function scheduleSave() {
@@ -717,6 +862,21 @@ function reportPage() {
717
862
  state.active = active;
718
863
  return true;
719
864
  }
865
+ /** Apply the snapshot embedded in a saved form file (no localStorage needed). */
866
+ function loadSavedDraft(saved) {
867
+ if (!saved || saved.v !== 1)
868
+ return false;
869
+ var workspaces = Array.isArray(saved.workspaces) ? saved.workspaces : [];
870
+ if (workspaces.length !== state.workspaces.length)
871
+ return false;
872
+ for (var i = 0; i < workspaces.length; i += 1) {
873
+ restoreWorkspace(at(state.workspaces, i), at(workspaces, i));
874
+ }
875
+ var active = Number(saved.active);
876
+ if (Number.isInteger(active) && active >= 0 && active < state.workspaces.length)
877
+ state.active = active;
878
+ return true;
879
+ }
720
880
  function resetDraft() {
721
881
  var confirmed = true;
722
882
  if (typeof win.confirm === 'function') {
@@ -812,76 +972,105 @@ function reportPage() {
812
972
  var modalCancel = null;
813
973
  var pendingConfirm = null;
814
974
  var lastFocus = null;
975
+ /** Build the toast and the one modal both flows share. */
815
976
  function ensureChrome() {
816
977
  toastNode = el('div', 'rp-toast');
817
978
  toastNode.hidden = true;
818
979
  toastNode.setAttribute('role', 'status');
819
980
  toastNode.setAttribute('aria-live', 'polite');
981
+ var iconSpan = svgIcon('check', 14);
982
+ toastNode.appendChild(iconSpan);
983
+ var toastText = el('span', '');
984
+ toastText.id = 'rp-toast-text';
985
+ toastNode.appendChild(toastText);
820
986
  doc.body.appendChild(toastNode);
821
- modalNode = el('div', 'rp-modal');
822
- modalNode.hidden = true;
823
- var card = el('div', 'rp-modal-card');
987
+ modalNode = el('div', 'rp-overlay');
988
+ var card = el('div', 'rp-modalcard');
824
989
  card.setAttribute('role', 'dialog');
825
990
  card.setAttribute('aria-modal', 'true');
826
991
  card.setAttribute('aria-labelledby', 'rp-modal-title');
827
992
  var title = el('h2', '');
828
993
  title.id = 'rp-modal-title';
829
- setText(title, '还有项目没有填写');
830
- var body = el('p', '');
831
- setText(body, '下面这些项目本次没有任何填写,不会包含在回传文件里。你可以返回补填,或确认跳过。');
832
- modalList = el('ul', 'rp-modal-list');
833
- var actions = el('div', 'rp-modal-actions');
834
- modalCancel = el('button', 'rp-btn');
994
+ card.appendChild(title);
995
+ var sub = el('p', 'rp-msub');
996
+ sub.id = 'rp-modal-sub';
997
+ card.appendChild(sub);
998
+ modalList = el('div', '');
999
+ modalList.id = 'rp-modal-body';
1000
+ card.appendChild(modalList);
1001
+ var actions = el('div', 'rp-modalactions');
1002
+ modalCancel = el('button', 'rp-btn is-plain');
835
1003
  modalCancel.type = 'button';
836
- setText(modalCancel, '返回填写');
837
- modalConfirm = el('button', 'rp-btn rp-btn-primary');
1004
+ setText(modalCancel, '继续填写');
1005
+ modalConfirm = el('button', 'rp-btn is-dark');
838
1006
  modalConfirm.type = 'button';
839
- setText(modalConfirm, '跳过这些项目,继续');
1007
+ setText(modalConfirm, '确认保存');
840
1008
  actions.appendChild(modalCancel);
841
1009
  actions.appendChild(modalConfirm);
842
- card.appendChild(title);
843
- card.appendChild(body);
844
- card.appendChild(modalList);
845
1010
  card.appendChild(actions);
846
1011
  modalNode.appendChild(card);
847
1012
  doc.body.appendChild(modalNode);
848
1013
  modalCancel.addEventListener('click', function () {
849
- var skipped = pendingConfirm ? pendingConfirm.skipped : [];
850
1014
  closeModal();
851
- if (skipped.length) {
852
- state.active = at(skipped, 0).index;
853
- renderPage();
854
- toast('已切换到未填写的项目。');
855
- }
856
1015
  });
857
1016
  modalConfirm.addEventListener('click', function () {
858
1017
  var run = pendingConfirm ? pendingConfirm.run : null;
1018
+ var skipped = pendingConfirm ? pendingConfirm.skipped : [];
859
1019
  closeModal();
860
1020
  if (typeof run === 'function')
861
- run();
1021
+ run(skipped);
1022
+ });
1023
+ modalNode.addEventListener('click', function (event) {
1024
+ if (event.target === modalNode)
1025
+ closeModal();
862
1026
  });
863
1027
  }
864
- function openModal(skipped, run) {
1028
+ /**
1029
+ * Show the modal in one of its two modes.
1030
+ *
1031
+ * `preview` lists what a save would write, so the colleague can check before
1032
+ * committing. `confirm-skip` is the batch case: some selected project was never
1033
+ * touched and would be left out of the download.
1034
+ */
1035
+ function openModal(mode, body, skipped, run) {
865
1036
  if (!modalNode)
866
1037
  return;
1038
+ var title = doc.getElementById('rp-modal-title');
1039
+ var sub = doc.getElementById('rp-modal-sub');
867
1040
  clearNode(modalList);
868
- for (var i = 0; i < skipped.length; i += 1) {
869
- var item = el('li', '');
870
- var skippedWs = at(skipped, i);
871
- var skippedInput = skippedWs.input;
872
- var name = skippedInput ? (skippedInput.name || skippedInput.pocId) : '';
873
- setText(item, name || '未命名项目');
874
- modalList.appendChild(item);
1041
+ if (mode === 'preview') {
1042
+ setText(title, '保存后写进文件的内容');
1043
+ setText(sub, '这份快照会嵌进同一个 HTML 文件,不写入台账。DSH 校验后才会准备待审差异。');
1044
+ setText(modalCancel, '继续填写');
1045
+ setText(modalConfirm, '确认保存');
1046
+ modalList.appendChild(body);
1047
+ }
1048
+ else {
1049
+ setText(title, '还有项目没有填写');
1050
+ setText(sub, '下面这些项目本次没有任何填写,不会包含在保存的文件里。');
1051
+ setText(modalCancel, '返回填写');
1052
+ setText(modalConfirm, '跳过这些项目,继续');
1053
+ var list = el('ul', '');
1054
+ for (var i = 0; i < skipped.length; i += 1) {
1055
+ var item = el('li', '');
1056
+ var k = el('span', 'rp-k');
1057
+ setText(k, at(skipped, i).input.pocId);
1058
+ var v = el('span', 'rp-v');
1059
+ setText(v, at(skipped, i).input.name || '未命名项目');
1060
+ item.appendChild(k);
1061
+ item.appendChild(v);
1062
+ list.appendChild(item);
1063
+ }
1064
+ modalList.appendChild(list);
875
1065
  }
876
1066
  pendingConfirm = { skipped: skipped, run: run };
877
1067
  lastFocus = doc.activeElement;
878
- modalNode.hidden = false;
879
- modalCancel.focus();
1068
+ modalNode.className = 'rp-overlay is-on';
880
1069
  }
881
1070
  function closeModal() {
882
1071
  if (!modalNode)
883
1072
  return;
884
- modalNode.hidden = true;
1073
+ modalNode.className = 'rp-overlay';
885
1074
  pendingConfirm = null;
886
1075
  if (lastFocus && typeof lastFocus.focus === 'function')
887
1076
  lastFocus.focus();
@@ -1074,30 +1263,115 @@ function reportPage() {
1074
1263
  registerRef(path, wrap);
1075
1264
  return wrap;
1076
1265
  }
1077
- function sectionShell(num, title, count) {
1078
- var sec = el('section', 'rp-sec');
1079
- var head = el('div', 'rp-sec-head');
1266
+ // -------------------------------------------------------------------------
1267
+ // Small DOM builders shared by both screens
1268
+ // -------------------------------------------------------------------------
1269
+ function svgIcon(name, size) {
1270
+ var paths = {
1271
+ pen: 'M12 20h9|M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z',
1272
+ arrow: 'M5 12h14|m12 5 7 7-7 7',
1273
+ chevron: 'm6 9 6 6 6-6',
1274
+ chevronUp: 'm18 15-6-6-6 6',
1275
+ file: 'M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z|M14 2v6h6',
1276
+ x: 'M18 6 6 18|m6 6 12 12',
1277
+ plus: 'M12 5v14|M5 12h14',
1278
+ check: 'M20 6 9 17l-5-5',
1279
+ square: 'M3 3h18v18H3z',
1280
+ chat: 'M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z',
1281
+ list: 'm3 6 2 2 4-4|m3 14 2 2 4-4|M13 8h8|M13 16h8',
1282
+ info: 'M12 12v5|M12 7h.01',
1283
+ warn: 'M12 8v4|M12 16h.01',
1284
+ minus: 'M5 12h14',
1285
+ circle: 'M12 12m-10 0a10 10 0 1 0 20 0a10 10 0 1 0 -20 0',
1286
+ target: 'M12 12m-10 0a10 10 0 1 0 20 0a10 10 0 1 0 -20 0|M12 12m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0',
1287
+ shield: 'M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z',
1288
+ };
1289
+ var parts = txt(at(paths, name)).split('|');
1290
+ var markup = '';
1291
+ for (var i = 0; i < parts.length; i += 1) {
1292
+ var d = at(parts, i);
1293
+ if (d === '')
1294
+ continue;
1295
+ if (d.indexOf('m-') === 0)
1296
+ markup += '<circle cx="12" cy="12" r="10"/>';
1297
+ else if (d.indexOf('M3 3h18v18H3z') === 0)
1298
+ markup += '<rect x="3" y="3" width="18" height="18" rx="2"/>';
1299
+ else
1300
+ markup += '<path d="' + d + '"/>';
1301
+ }
1302
+ var node = el('span', '');
1303
+ node.innerHTML = '<svg width="' + size + '" height="' + size + '" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">' + markup + '</svg>';
1304
+ return node.firstChild;
1305
+ }
1306
+ function mono(text) {
1307
+ var node = el('span', '');
1308
+ setText(node, text);
1309
+ node.style.fontFamily = 'var(--mono)';
1310
+ return node;
1311
+ }
1312
+ /** One labelled field: label row, control box, inline error slot. */
1313
+ function fieldWrap(path, label, required, control, hint, boxClass) {
1314
+ var wrap = el('div', 'rp-f');
1315
+ var lab = el('label', 'rp-label');
1316
+ setText(lab, label);
1317
+ if (required) {
1318
+ var req = el('span', 'rp-req');
1319
+ setText(req, '*');
1320
+ lab.appendChild(req);
1321
+ }
1322
+ if (hint !== '') {
1323
+ var h = el('span', 'rp-hint');
1324
+ setText(h, hint);
1325
+ lab.appendChild(h);
1326
+ }
1327
+ var box = el('div', 'rp-box' + (boxClass === '' ? '' : ' ' + boxClass));
1328
+ box.appendChild(control);
1329
+ var err = el('span', 'rp-err');
1330
+ lab.setAttribute('for', '');
1331
+ wrap.appendChild(lab);
1332
+ wrap.appendChild(box);
1333
+ wrap.appendChild(err);
1334
+ registerRef(path, wrap);
1335
+ return wrap;
1336
+ }
1337
+ /** A section head: numbered badge, title, one-line lead, right-hand note. */
1338
+ function sectionShell(num, title, sub, note) {
1339
+ var head = el('div', 'rp-sechead');
1340
+ var left = el('div', 'rp-secl');
1341
+ // An empty `num` means this block is a continuation of the section above it,
1342
+ // so it gets no badge at all — an empty circle reads as a broken number.
1080
1343
  if (num !== '') {
1081
- var badge = el('span', 'rp-sec-num');
1344
+ var badge = el('span', 'rp-secnum');
1082
1345
  setText(badge, num);
1083
- head.appendChild(badge);
1346
+ left.appendChild(badge);
1347
+ }
1348
+ var titles = el('div', '');
1349
+ var t = el('div', 'rp-sectitle');
1350
+ setText(t, title);
1351
+ titles.appendChild(t);
1352
+ if (sub !== '') {
1353
+ var s = el('div', 'rp-secsub');
1354
+ setText(s, sub);
1355
+ titles.appendChild(s);
1356
+ }
1357
+ left.appendChild(titles);
1358
+ head.appendChild(left);
1359
+ if (note !== '') {
1360
+ var n = el('span', 'rp-secnote');
1361
+ setText(n, note);
1362
+ head.appendChild(n);
1084
1363
  }
1085
- var heading = el('h2', 'rp-sec-title');
1086
- setText(heading, title);
1087
- head.appendChild(heading);
1088
- if (count) {
1089
- var counter = el('span', 'rp-sec-count');
1090
- setText(counter, count);
1091
- head.appendChild(counter);
1092
- }
1093
- sec.appendChild(head);
1094
- return sec;
1364
+ return head;
1095
1365
  }
1096
1366
  function sectionNote(sec, text) {
1097
- var note = el('p', 'rp-sec-note');
1098
- addText(note, text);
1099
- sec.appendChild(note);
1367
+ var p = el('p', 'rp-secsub');
1368
+ p.style.padding = '0 0 10px 35px';
1369
+ setText(p, text);
1370
+ sec.appendChild(p);
1100
1371
  }
1372
+ // -------------------------------------------------------------------------
1373
+ // Screen 1: the worksheet
1374
+ // -------------------------------------------------------------------------
1101
1375
  function renderNoticesBox() {
1102
1376
  var box = el('div', '');
1103
1377
  box.id = 'rp-notices';
@@ -1121,800 +1395,1226 @@ function reportPage() {
1121
1395
  setText(dismiss, '知道了');
1122
1396
  card.appendChild(dismiss);
1123
1397
  box.appendChild(card);
1398
+ noticesRendered[notice.id] = true;
1124
1399
  }
1125
1400
  return box;
1126
1401
  }
1127
- function renderHeader(ws) {
1128
- var head = el('header', 'rp-head');
1129
- var main = el('div', 'rp-head-main');
1130
- var eyebrow = el('div', 'rp-eyebrow');
1131
- var title = el('h1', 'rp-title');
1132
- var meta = el('div', 'rp-meta');
1133
- var round = el('div', 'rp-head-round');
1134
- var big = el('div', 'rp-big');
1135
- var small = el('div', 'rp-small');
1136
- if (ws.isNew) {
1137
- setText(eyebrow, '新建项目');
1138
- setText(title, '登记一个 POC 项目');
1139
- var metaToday = el('span', '');
1140
- addText(metaToday, '今天 ');
1141
- var metaDate = el('b', '');
1142
- setText(metaDate, today);
1143
- metaToday.appendChild(metaDate);
1144
- var metaHint = el('span', '');
1145
- setText(metaHint, '带 * 的为立项必填');
1146
- meta.appendChild(metaToday);
1147
- meta.appendChild(metaHint);
1148
- setText(big, 'G0');
1149
- setText(small, '立项登记');
1402
+ /** The dark bar with the project id, the save state and the two screen tabs. */
1403
+ function renderTopBar(ws) {
1404
+ var bar = el('header', 'rp-top');
1405
+ var left = el('div', 'rp-top-l');
1406
+ left.appendChild(el('i', 'rp-dot'));
1407
+ var idNode = el('span', 'rp-id');
1408
+ setText(idNode, ws.isNew ? '新建项目' : ws.input.pocId);
1409
+ left.appendChild(idNode);
1410
+ left.appendChild(el('span', 'rp-vsep'));
1411
+ var act = el('span', 'rp-act');
1412
+ setText(act, state.screen === 1 ? (ws.isNew ? '登记立项' : '记录进展') : '项目档案');
1413
+ left.appendChild(act);
1414
+ bar.appendChild(left);
1415
+ var right = el('div', 'rp-top-r');
1416
+ var save = el('span', 'rp-savestate');
1417
+ save.id = 'rp-savestate';
1418
+ setText(save, storageOk ? '草稿已存本机' : '草稿不会自动保存');
1419
+ right.appendChild(save);
1420
+ var tabs = el('div', 'rp-tabs');
1421
+ tabs.setAttribute('role', 'tablist');
1422
+ tabs.setAttribute('aria-label', '切换页面');
1423
+ var names = ['1 填写', '2 项目档案'];
1424
+ for (var i = 0; i < 2; i += 1) {
1425
+ var tab = el('button', 'rp-tab');
1426
+ tab.type = 'button';
1427
+ tab.setAttribute('role', 'tab');
1428
+ tab.setAttribute('data-act', 'screen');
1429
+ tab.setAttribute('data-n', String(i + 1));
1430
+ tab.setAttribute('aria-selected', state.screen === i + 1 ? 'true' : 'false');
1431
+ setText(tab, at(names, i));
1432
+ // A new-project form has no ledger record to describe, so the dossier tab
1433
+ // is disabled rather than opening an empty page.
1434
+ if (i === 1 && dossier === null) {
1435
+ tab.disabled = true;
1436
+ tab.style.opacity = '0.45';
1437
+ tab.style.cursor = 'not-allowed';
1438
+ }
1439
+ tabs.appendChild(tab);
1440
+ }
1441
+ right.appendChild(tabs);
1442
+ bar.appendChild(right);
1443
+ return bar;
1444
+ }
1445
+ function eyebrowLine(tagText, when, pages) {
1446
+ var row = el('div', 'rp-eyebrow');
1447
+ var left = el('div', 'rp-eyebrow-l');
1448
+ var tag = el('span', 'rp-tagline');
1449
+ setText(tag, tagText);
1450
+ left.appendChild(tag);
1451
+ left.appendChild(el('i', 'rp-rule'));
1452
+ var whenNode = el('span', 'rp-when');
1453
+ setText(whenNode, when);
1454
+ left.appendChild(whenNode);
1455
+ row.appendChild(left);
1456
+ var p = el('span', 'rp-pages');
1457
+ setText(p, pages);
1458
+ row.appendChild(p);
1459
+ return row;
1460
+ }
1461
+ function factRow(label, value) {
1462
+ var cell = el('div', 'rp-fact');
1463
+ var dt = el('dt', '');
1464
+ setText(dt, label);
1465
+ var dd = el('dd', value === '' ? 'is-empty' : '');
1466
+ setText(dd, value === '' ? '—' : value);
1467
+ cell.appendChild(dt);
1468
+ cell.appendChild(dd);
1469
+ return cell;
1470
+ }
1471
+ /** Screen 1 head: who the project is, plus the plain-language ground rules. */
1472
+ function renderWorksheetHead(ws) {
1473
+ var head = el('div', '');
1474
+ var rounds = ws.isNew ? 1 : (Number.isFinite(ws.input.roundCount) ? ws.input.roundCount : 0) + 1;
1475
+ var when = exportedAt === '' ? '' : '数据截至 ' + exportedAt;
1476
+ head.appendChild(eyebrowLine(ws.isNew ? '立项登记' : '第 ' + rounds + ' 次进展', when, '01 / 02'));
1477
+ var h1 = el('h1', 'rp-h1');
1478
+ setText(h1, ws.isNew ? '登记一个 POC 项目' : (ws.input.name || ws.input.pocId));
1479
+ head.appendChild(h1);
1480
+ var sub = el('div', 'rp-subline');
1481
+ if (!ws.isNew) {
1482
+ var input = ws.input;
1483
+ var chip = el('span', 'rp-chip-stage');
1484
+ chip.appendChild(el('i', ''));
1485
+ var b = el('b', '');
1486
+ setText(b, input.stage || '阶段未填');
1487
+ chip.appendChild(b);
1488
+ sub.appendChild(chip);
1489
+ if (dossier && dossier.daysInStage !== null) {
1490
+ var days = el('span', 'rp-muted');
1491
+ setText(days, '已在本阶段 ' + dossier.daysInStage + ' 天');
1492
+ sub.appendChild(days);
1493
+ }
1494
+ sub.appendChild(el('i', 'rp-vsep2'));
1495
+ var st = el('span', 'rp-st');
1496
+ setText(st, input.status || '状态未填');
1497
+ sub.appendChild(st);
1150
1498
  }
1151
1499
  else {
1152
- var input = ws.input;
1153
- setText(eyebrow, '记录进展');
1154
- setText(title, input.name || input.pocId || '未命名项目');
1155
- var metaId = el('span', '');
1156
- var idNode = el('b', '');
1157
- setText(idNode, input.pocId || '—');
1158
- metaId.appendChild(idNode);
1159
- meta.appendChild(metaId);
1160
- if (input.company) {
1161
- var metaCompany = el('span', '');
1162
- setText(metaCompany, input.company);
1163
- meta.appendChild(metaCompany);
1164
- }
1165
- var metaStage = el('span', '');
1166
- var stageNode = el('b', '');
1167
- setText(stageNode, input.stage || '阶段未填');
1168
- metaStage.appendChild(stageNode);
1169
- addText(metaStage, ' · ' + (input.status || '状态未填'));
1170
- meta.appendChild(metaStage);
1171
- var metaOwner = el('span', '');
1172
- addText(metaOwner, '负责人 ');
1173
- var ownerNode = el('b', '');
1174
- setText(ownerNode, input.owner || '—');
1175
- metaOwner.appendChild(ownerNode);
1176
- meta.appendChild(metaOwner);
1177
- if (input.previousDate) {
1178
- var metaPrev = el('span', '');
1179
- setText(metaPrev, '上次进展 ' + input.previousDate);
1180
- meta.appendChild(metaPrev);
1181
- }
1182
- var nextRound = (Number.isFinite(input.roundCount) ? input.roundCount : 0) + 1;
1183
- setText(big, String(nextRound));
1184
- setText(small, '第几次进展');
1185
- }
1186
- main.appendChild(eyebrow);
1187
- main.appendChild(title);
1188
- main.appendChild(meta);
1189
- round.appendChild(big);
1190
- round.appendChild(small);
1191
- head.appendChild(main);
1192
- head.appendChild(round);
1500
+ var tip = el('span', 'rp-muted');
1501
+ setText(tip, '带 * 的为立项必填;其余由台账维护');
1502
+ sub.appendChild(tip);
1503
+ }
1504
+ head.appendChild(sub);
1505
+ // A new form gets no summary strip: it would restate the fields sitting a few
1506
+ // centimetres below it, and it could only ever update on a re-render.
1507
+ if (ws.isNew)
1508
+ return head;
1509
+ var facts = el('dl', 'rp-facts');
1510
+ if (dossier) {
1511
+ var where = [dossier.company, dossier.department].filter(function (part) { return part !== ''; }).join(' · ');
1512
+ facts.appendChild(factRow('客户', where));
1513
+ facts.appendChild(factRow('项目负责人', dossier.owner));
1514
+ facts.appendChild(factRow('客户技术责任人', dossier.techOwner));
1515
+ facts.appendChild(factRow('合同金额', dossier.amountWan === '' ? '' : dossier.amountWan + ' 万元'));
1516
+ facts.appendChild(factRow('项目类型', dossier.pocType));
1517
+ }
1518
+ else {
1519
+ var input2 = ws.input;
1520
+ facts.appendChild(factRow('客户', input2.company));
1521
+ facts.appendChild(factRow('项目负责人', input2.owner));
1522
+ }
1523
+ head.appendChild(facts);
1524
+ head.appendChild(el('div', 'rp-hairline'));
1525
+ var guide = el('div', 'rp-guide');
1526
+ guide.appendChild(svgIcon('pen', 14));
1527
+ var gp = el('p', '');
1528
+ setText(gp, ws.isNew
1529
+ ? '这一页只填立项信息。填完保存,把文件发回即可。'
1530
+ : '这一页只填本轮进展。项目的完整背景在第二页,随时可翻回去看。');
1531
+ guide.appendChild(gp);
1532
+ if (dossier !== null) {
1533
+ var link = el('a', '');
1534
+ link.setAttribute('data-act', 'screen');
1535
+ link.setAttribute('data-n', '2');
1536
+ setText(link, '查看项目档案');
1537
+ link.appendChild(svgIcon('arrow', 13));
1538
+ guide.appendChild(link);
1539
+ }
1540
+ head.appendChild(guide);
1193
1541
  return head;
1194
1542
  }
1195
- function renderTabs() {
1196
- var nav = el('nav', 'rp-tabs');
1197
- nav.setAttribute('role', 'tablist');
1198
- nav.setAttribute('aria-label', '选择要填写的项目');
1199
- for (var i = 0; i < state.workspaces.length; i += 1) {
1200
- var ws = at(state.workspaces, i);
1201
- var button = el('button', 'rp-tab');
1202
- button.type = 'button';
1203
- button.setAttribute('role', 'tab');
1204
- button.setAttribute('data-tab', String(i));
1205
- button.setAttribute('aria-selected', i === state.active ? 'true' : 'false');
1206
- button.id = 'rp-tab-' + i;
1207
- var name = el('span', '');
1208
- var input = ws.input;
1209
- setText(name, input.name || input.pocId || '未命名');
1210
- var idNode = el('span', 'rp-tab-id');
1211
- setText(idNode, input.pocId || '');
1212
- var dot = el('span', 'rp-tab-dot');
1213
- dot.setAttribute('data-filled', touched(ws) ? 'true' : 'false');
1214
- button.appendChild(dot);
1215
- button.appendChild(name);
1216
- button.appendChild(idNode);
1217
- nav.appendChild(button);
1218
- }
1219
- return nav;
1220
- }
1221
- function renderRoundStrip(ws) {
1222
- var box = el('div', 'rp-roundbar');
1223
- var grid = el('div', 'rp-grid-3');
1224
- var dateInput = mkDate(ws.roundDate);
1225
- dateInput.setAttribute('data-role', 'round');
1226
- dateInput.setAttribute('data-field', 'date');
1227
- grid.appendChild(wrapField('round:date', '本轮日期', true, dateInput, ''));
1228
- var typeSelect = mkSelect(enums.type, ws.roundType, '— 未选 —');
1229
- typeSelect.setAttribute('data-role', 'round');
1230
- typeSelect.setAttribute('data-field', 'type');
1231
- grid.appendChild(wrapField('round:type', '类型', true, typeSelect, ''));
1232
- var changeSelect = mkSelect(enums.change, ws.noProgress ? '无实质进展' : ws.roundChange, '— 未选 —');
1233
- changeSelect.setAttribute('data-role', 'round');
1234
- changeSelect.setAttribute('data-field', 'change');
1235
- if (ws.noProgress)
1236
- changeSelect.disabled = true;
1237
- grid.appendChild(wrapField('round:change', '这一次什么变了', true, changeSelect, ''));
1238
- box.appendChild(grid);
1239
- return box;
1240
- }
1241
- function renderStatusField(ws, line, visibleLabel) {
1242
- var wrap = el('div', 'rp-f rp-statusf');
1243
- var id = idFor('line:' + line.key + ':status');
1244
- var label = el('span', visibleLabel ? 'rp-mini-label' : 'rp-sr');
1245
- label.id = id + '-label';
1246
- addText(label, '完成情况');
1247
- if (visibleLabel) {
1248
- var req = el('span', 'rp-req');
1249
- setText(req, '*');
1250
- label.appendChild(req);
1251
- }
1543
+ /** The segmented five-way status control. */
1544
+ function renderStatusField(ws, line) {
1252
1545
  var seg = el('div', 'rp-seg');
1253
1546
  seg.setAttribute('role', 'group');
1254
- seg.setAttribute('aria-labelledby', id + '-label');
1255
- seg.setAttribute('aria-describedby', id + '-err');
1547
+ seg.setAttribute('aria-label', '完成情况');
1548
+ seg.setAttribute('data-line', line.key);
1256
1549
  for (var i = 0; i < enums.status.length; i += 1) {
1257
1550
  var value = at(enums.status, i);
1258
1551
  var button = el('button', '');
1259
1552
  button.type = 'button';
1260
1553
  button.setAttribute('data-role', 'line-status');
1261
- button.setAttribute('data-line', line.key);
1262
1554
  button.setAttribute('data-value', value);
1263
- button.setAttribute('data-k', statusTone(value));
1555
+ button.setAttribute('data-line', line.key);
1264
1556
  button.setAttribute('aria-pressed', line.status === value ? 'true' : 'false');
1265
1557
  setText(button, value);
1266
1558
  seg.appendChild(button);
1267
1559
  }
1268
- wrap.appendChild(label);
1269
- wrap.appendChild(seg);
1270
- var err = el('p', 'rp-err');
1271
- err.id = id + '-err';
1272
- wrap.appendChild(err);
1273
- registerRef('line:' + line.key + ':status', wrap);
1274
- return wrap;
1560
+ return seg;
1275
1561
  }
1276
1562
  function renderEvidenceRow(ws, line, ev) {
1277
- var field = el('div', 'rp-f rp-ev-field');
1278
- var row = el('div', 'rp-ev-row');
1279
- var title = mkInput(ev.title, '证据名称,如「压测报告」', 500);
1563
+ var row = el('div', 'rp-evrow');
1564
+ row.setAttribute('data-ev', ev.key);
1565
+ row.appendChild(svgIcon('file', 13));
1566
+ var title = mkInput(ev.title, '证据名称,如「客户签字版清单」', 500);
1280
1567
  title.setAttribute('data-role', 'ev-title');
1281
1568
  title.setAttribute('data-line', line.key);
1282
1569
  title.setAttribute('data-ev', ev.key);
1283
- title.setAttribute('aria-label', '证据名称');
1284
1570
  row.appendChild(title);
1285
- var link = mkInput(ev.link, '链接(可空)', 1000);
1286
- link.setAttribute('data-role', 'ev-link');
1287
- link.setAttribute('data-line', line.key);
1288
- link.setAttribute('data-ev', ev.key);
1289
- link.setAttribute('aria-label', '证据链接(可空)');
1290
- row.appendChild(link);
1291
- var type = mkSelect(enums.evidence, ev.type, '类型');
1292
- type.className = 'rp-select rp-ev-type';
1571
+ var type = el('select', 'rp-evtype');
1293
1572
  type.setAttribute('data-role', 'ev-type');
1294
1573
  type.setAttribute('data-line', line.key);
1295
1574
  type.setAttribute('data-ev', ev.key);
1296
- type.setAttribute('aria-label', '证据类型(可空)');
1575
+ type.setAttribute('aria-label', '证据类型');
1576
+ var blank = el('option', '');
1577
+ blank.value = '';
1578
+ blank.textContent = '类型';
1579
+ type.appendChild(blank);
1580
+ for (var i = 0; i < enums.evidence.length; i += 1) {
1581
+ var option = el('option', '');
1582
+ option.value = at(enums.evidence, i);
1583
+ option.textContent = at(enums.evidence, i);
1584
+ if (ev.type === at(enums.evidence, i))
1585
+ option.selected = true;
1586
+ type.appendChild(option);
1587
+ }
1297
1588
  row.appendChild(type);
1298
- var remove = el('button', 'rp-del');
1299
- remove.type = 'button';
1300
- remove.setAttribute('data-act', 'ev-remove');
1301
- remove.setAttribute('data-line', line.key);
1302
- remove.setAttribute('data-ev', ev.key);
1303
- remove.setAttribute('aria-label', '删除这条证据');
1304
- setText(remove, '×');
1305
- row.appendChild(remove);
1306
- field.appendChild(row);
1307
- var err = el('p', 'rp-err');
1308
- err.id = idFor('line:' + line.key + ':evidence:' + ev.key + ':title') + '-err';
1309
- field.appendChild(err);
1310
- registerRef('line:' + line.key + ':evidence:' + ev.key + ':title', field);
1311
- return field;
1589
+ var link = mkInput(ev.link, '链接(选填)', 1000);
1590
+ link.style.display = 'none';
1591
+ link.setAttribute('data-role', 'ev-link');
1592
+ link.setAttribute('data-line', line.key);
1593
+ link.setAttribute('data-ev', ev.key);
1594
+ row.appendChild(link);
1595
+ var del = el('button', 'rp-icobtn');
1596
+ del.type = 'button';
1597
+ del.setAttribute('data-act', 'ev-del');
1598
+ del.setAttribute('data-line', line.key);
1599
+ del.setAttribute('data-ev', ev.key);
1600
+ del.setAttribute('aria-label', '删除这条证据');
1601
+ del.appendChild(svgIcon('x', 12));
1602
+ row.appendChild(del);
1603
+ return row;
1312
1604
  }
1313
1605
  function renderEvidenceSection(ws, line) {
1314
- var box = el('div', 'rp-ev');
1315
- var bar = el('div', 'rp-ev-bar');
1316
- var count = el('span', 'rp-ev-count');
1317
- count.setAttribute('data-ev-count', '');
1318
- bar.appendChild(count);
1319
- var toggle = el('button', 'rp-ev-toggle');
1320
- toggle.type = 'button';
1321
- toggle.setAttribute('data-act', 'ev-toggle');
1322
- toggle.setAttribute('data-line', line.key);
1323
- toggle.setAttribute('aria-expanded', 'false');
1324
- bar.appendChild(toggle);
1325
- box.appendChild(bar);
1326
- var list = el('div', 'rp-ev-list');
1327
- list.setAttribute('data-open', 'false');
1328
- list.setAttribute('data-ev-list', '');
1606
+ var wrap = el('div', 'rp-f');
1607
+ var lab = el('div', 'rp-label');
1608
+ setText(lab, '证据');
1609
+ var hint = el('span', 'rp-hint');
1610
+ setText(hint, '每条单独记,不借用别项');
1611
+ lab.appendChild(hint);
1612
+ wrap.appendChild(lab);
1329
1613
  for (var i = 0; i < line.evidence.length; i += 1) {
1330
- list.appendChild(renderEvidenceRow(ws, line, at(line.evidence, i)));
1614
+ wrap.appendChild(renderEvidenceRow(ws, line, at(line.evidence, i)));
1331
1615
  }
1332
- var add = el('button', 'rp-ev-add');
1616
+ wrap.appendChild(renderAddEvidence(line.key));
1617
+ return wrap;
1618
+ }
1619
+ function renderAddEvidence(lineKey) {
1620
+ var add = el('button', 'rp-addline');
1333
1621
  add.type = 'button';
1334
1622
  add.setAttribute('data-act', 'ev-add');
1335
- add.setAttribute('data-line', line.key);
1336
- setText(add, '+ 再加一条证据');
1337
- list.appendChild(add);
1338
- box.appendChild(list);
1339
- updateEvidenceUI(line, box);
1340
- return box;
1341
- }
1342
- function updateEvidenceUI(line, box) {
1343
- if (!box)
1344
- return;
1345
- var count = box.querySelector('[data-ev-count]');
1346
- var toggle = box.querySelector('[data-act="ev-toggle"]');
1347
- var filled = 0;
1348
- for (var i = 0; i < line.evidence.length; i += 1) {
1349
- if (evidenceHasContent(at(line.evidence, i)))
1350
- filled += 1;
1351
- }
1352
- if (count) {
1353
- setText(count, filled ? '证据 ' + filled + ' 条' : '还没有证据');
1354
- count.className = 'rp-ev-count' + (filled ? ' has' : '');
1355
- }
1356
- if (toggle)
1357
- setText(toggle, filled ? '查看 / 编辑' : '+ 添加证据');
1358
- }
1359
- function renderLineExtras(ws, line) {
1360
- var details = el('details', 'rp-more');
1361
- var summary = el('summary', '');
1362
- setText(summary, '可选:客户反馈 / 场景与指标 / 完成度');
1363
- details.appendChild(summary);
1364
- var body = el('div', 'rp-more-body');
1365
- var grid = el('div', 'rp-grid-2');
1366
- var synced = mkInput(line.customerSynced, '和谁同步的', 500);
1367
- synced.setAttribute('data-role', 'line-customer');
1368
- synced.setAttribute('data-field', 'synced');
1369
- synced.setAttribute('data-line', line.key);
1370
- grid.appendChild(wrapField('line:' + line.key + ':customerSynced', '同步对象', false, synced, ''));
1371
- var completion = mkSelect(enums.completion, line.completion, '— 未填 —');
1372
- completion.setAttribute('data-role', 'line-completion');
1373
- completion.setAttribute('data-line', line.key);
1374
- grid.appendChild(wrapField('line:' + line.key + ':completion', '完成度', false, completion, ''));
1375
- body.appendChild(grid);
1376
- var feedback = mkArea(line.customerFeedback, '照原样记,不要替他判断认可不认可', 2);
1377
- feedback.setAttribute('data-role', 'line-customer');
1378
- feedback.setAttribute('data-field', 'feedback');
1379
- feedback.setAttribute('data-line', line.key);
1380
- body.appendChild(wrapField('line:' + line.key + ':customerFeedback', '客户原话 / 反馈', false, feedback, ''));
1381
- if (ws.input && ws.input.scenarios.length) {
1382
- body.appendChild(renderIdChecks('推进了哪些场景', 'line-scenario', line.key, ws.input.scenarios, line.scenarioIds, '勾选这一轮实际验证过的场景。'));
1383
- }
1384
- if (ws.input && ws.input.criteria.length) {
1385
- body.appendChild(renderIdChecks('验证了哪些指标', 'line-criteria', line.key, ws.input.criteria, line.criteriaIds, '与场景相互独立:一条指标可以被验证而没有推进任何场景。'));
1386
- }
1387
- details.appendChild(body);
1388
- return details;
1623
+ add.setAttribute('data-line', lineKey);
1624
+ add.appendChild(svgIcon('plus', 12));
1625
+ addText(add, '加一条证据');
1626
+ return add;
1389
1627
  }
1390
- function renderIdChecks(title, role, lineKey, values, selected, help) {
1628
+ function renderIdChecks(ws, line) {
1629
+ var input = ws.input;
1391
1630
  var wrap = el('div', 'rp-f');
1392
- var label = el('span', 'rp-mini-label');
1393
- addText(label, title);
1394
- wrap.appendChild(label);
1395
- if (help) {
1396
- var hint = el('p', 'rp-help');
1397
- addText(hint, help);
1398
- wrap.appendChild(hint);
1631
+ var lab = el('div', 'rp-label');
1632
+ setText(lab, '推进了哪些场景 / 验证了哪些指标');
1633
+ wrap.appendChild(lab);
1634
+ var chips = el('div', 'rp-chips');
1635
+ function addChip(kind, id, selected) {
1636
+ var chip = el('button', 'rp-chip');
1637
+ chip.type = 'button';
1638
+ chip.setAttribute('data-act', 'pick');
1639
+ chip.setAttribute('data-kind', kind);
1640
+ chip.setAttribute('data-id', id);
1641
+ chip.setAttribute('data-line', line.key);
1642
+ chip.setAttribute('aria-pressed', selected ? 'true' : 'false');
1643
+ chip.setAttribute('title', kind === 'scn' ? '场景 ' + id : '指标 ' + id);
1644
+ chip.appendChild(svgIcon(selected ? 'check' : 'square', 11));
1645
+ addText(chip, id);
1646
+ chips.appendChild(chip);
1647
+ }
1648
+ for (var s = 0; s < input.scenarios.length; s += 1) {
1649
+ var scn = at(input.scenarios, s);
1650
+ if (scn.id === '')
1651
+ continue;
1652
+ addChip('scn', scn.id, line.scenarioIds.indexOf(scn.id) >= 0);
1399
1653
  }
1400
- var box = el('div', 'rp-checks');
1401
- for (var i = 0; i < values.length; i += 1) {
1402
- var value = at(values, i);
1403
- var item = el('label', 'rp-check');
1404
- var input = el('input', '');
1405
- input.type = 'checkbox';
1406
- input.setAttribute('data-role', role);
1407
- input.setAttribute('data-line', lineKey);
1408
- input.setAttribute('data-id', value.id);
1409
- input.checked = selected.indexOf(value.id) >= 0;
1410
- if (input.checked)
1411
- item.className = 'rp-check is-on';
1412
- item.appendChild(input);
1413
- var text = el('span', '');
1414
- addText(text, value.name || value.id);
1415
- item.appendChild(text);
1416
- if (value.id) {
1417
- var idNode = el('span', 'rp-check-id');
1418
- setText(idNode, value.id);
1419
- item.appendChild(idNode);
1420
- }
1421
- box.appendChild(item);
1654
+ for (var c = 0; c < input.criteria.length; c += 1) {
1655
+ var cri = at(input.criteria, c);
1656
+ if (cri.id === '')
1657
+ continue;
1658
+ addChip('cri', cri.id, line.criteriaIds.indexOf(cri.id) >= 0);
1422
1659
  }
1423
- wrap.appendChild(box);
1424
- return wrap;
1425
- }
1426
- function updateLineIndexes() {
1427
- var ws = activeWorkspace();
1428
- var nodes = app.querySelectorAll('[data-idx]');
1429
- for (var i = 0; i < nodes.length; i += 1) {
1430
- var number = i + 1;
1431
- setText(at(nodes, i), (number < 10 ? '0' : '') + number);
1660
+ if (!chips.childNodes.length) {
1661
+ var none = el('p', 'rp-hint');
1662
+ setText(none, '这个项目的方案里还没有场景或指标,无可勾选。');
1663
+ chips.appendChild(none);
1432
1664
  }
1665
+ wrap.appendChild(chips);
1666
+ return wrap;
1433
1667
  }
1434
- function renderLineTitleField(ws, line) {
1668
+ function renderCustomerFields(ws, line) {
1435
1669
  var wrap = el('div', 'rp-f');
1436
- var label = el('label', 'rp-sr');
1437
- var id = idFor('line:' + line.key + ':title');
1438
- label.setAttribute('for', id);
1439
- label.id = id + '-label';
1440
- addText(label, '计划外的工作');
1441
- wrap.appendChild(label);
1442
- var input = mkInput(line.title, '计划外做了什么,如「临时支持客户压测」', 500);
1443
- input.id = id;
1444
- input.setAttribute('data-role', 'line-title');
1445
- input.setAttribute('data-line', line.key);
1446
- input.setAttribute('aria-describedby', id + '-err');
1447
- wrap.appendChild(input);
1448
- var err = el('p', 'rp-err');
1449
- err.id = id + '-err';
1450
- wrap.appendChild(err);
1451
- registerRef('line:' + line.key + ':title', wrap);
1670
+ var lab = el('div', 'rp-label');
1671
+ setText(lab, '客户反馈');
1672
+ var hint = el('span', 'rp-hint');
1673
+ setText(hint, '和谁同步、客户说了什么');
1674
+ lab.appendChild(hint);
1675
+ wrap.appendChild(lab);
1676
+ var synced = mkInput(line.customerSynced, '与谁同步', 500);
1677
+ synced.setAttribute('data-role', 'customer-synced');
1678
+ synced.setAttribute('data-line', line.key);
1679
+ var syncedBox = el('div', 'rp-box');
1680
+ syncedBox.style.marginBottom = '8px';
1681
+ syncedBox.appendChild(synced);
1682
+ wrap.appendChild(syncedBox);
1683
+ var feedback = mkArea(line.customerFeedback, '客户的原话,别转述成「客户认可」', 2);
1684
+ feedback.setAttribute('data-role', 'customer-feedback');
1685
+ feedback.setAttribute('data-line', line.key);
1686
+ var fbBox = el('div', 'rp-box');
1687
+ fbBox.appendChild(feedback);
1688
+ wrap.appendChild(fbBox);
1452
1689
  return wrap;
1453
1690
  }
1691
+ function renderLineTitleField(ws, line) {
1692
+ var title = mkInput(line.title, '例:受邀参加客户年度安全峰会', 500);
1693
+ title.setAttribute('data-role', 'line-title');
1694
+ title.setAttribute('data-line', line.key);
1695
+ return fieldWrap('line:' + line.key + ':title', '做了什么(自拟标题)', true, title, '', '');
1696
+ }
1697
+ function renderActualField(line, rows) {
1698
+ var area = mkArea(line.actual, '写清楚做到哪一步、结果是什么、还差什么…', rows);
1699
+ area.setAttribute('data-role', 'line-actual');
1700
+ area.setAttribute('data-line', line.key);
1701
+ return fieldWrap('line:' + line.key + ':actual', '实际做了什么', true, area, '', '');
1702
+ }
1703
+ /** The readable head of a plan id: `plan-7f2a` rather than the whole UUID. */
1704
+ function shortPlanId(id) {
1705
+ var text = trim(id);
1706
+ if (text.indexOf('plan-') === 0)
1707
+ text = text.slice(5);
1708
+ if (text.indexOf('legacy-') === 0)
1709
+ return text;
1710
+ var cut = text.indexOf('-');
1711
+ return 'plan-' + (cut > 0 ? text.slice(0, cut) : text);
1712
+ }
1713
+ /** One work item.
1714
+ *
1715
+ * Collapsed is the default and is not a dead end: the collapsed row carries a
1716
+ * single-line `actual` input, so the common case — three plans, three
1717
+ * outcomes — is filled without opening anything. Expanding is for the extras
1718
+ * only: evidence, customer feedback, scenario/criteria picks.
1719
+ */
1454
1720
  function renderLineCard(ws, line, position, extra) {
1455
- var article = el('article', 'rp-item');
1456
- article.setAttribute('data-line', line.key);
1457
- article.setAttribute('data-status', statusTone(line.status));
1458
- var top = el('div', 'rp-item-top');
1459
- var index = el('span', 'rp-idx');
1460
- index.setAttribute('data-idx', '');
1461
- setText(index, (position < 10 ? '0' : '') + position);
1462
- top.appendChild(index);
1463
- var titleBlock = el('div', 'rp-item-title');
1464
- if (extra) {
1465
- titleBlock.appendChild(renderLineTitleField(ws, line));
1466
- var remove = el('button', 'rp-del');
1467
- remove.type = 'button';
1468
- remove.setAttribute('data-act', 'line-remove');
1469
- remove.setAttribute('data-line', line.key);
1470
- remove.setAttribute('aria-label', '删除这条计划外的工作');
1471
- setText(remove, '×');
1472
- top.appendChild(titleBlock);
1473
- top.appendChild(remove);
1474
- }
1475
- else {
1476
- var planText = el('div', 'rp-plan-text');
1477
- addText(planText, line.title);
1478
- var tag = el('span', 'rp-tag rp-tag-plan');
1479
- setText(tag, '上轮计划');
1480
- planText.appendChild(tag);
1481
- titleBlock.appendChild(planText);
1482
- var sub = el('div', 'rp-item-sub');
1483
- var input = ws.input;
1484
- var owner = '';
1485
- var deadline = '';
1486
- for (var i = 0; i < input.previousPlans.length; i += 1) {
1487
- if (at(input.previousPlans, i).id === line.planId) {
1488
- owner = at(input.previousPlans, i).owner;
1489
- deadline = at(input.previousPlans, i).deadline;
1490
- break;
1491
- }
1492
- }
1493
- if (owner)
1494
- addText(sub, owner + ' · ');
1495
- else
1496
- addText(sub, '负责人未填 · ');
1497
- addText(sub, '截止 ');
1498
- var deadlineNode = el('b', '');
1499
- setText(deadlineNode, deadline || '未填');
1500
- sub.appendChild(deadlineNode);
1501
- titleBlock.appendChild(sub);
1502
- top.appendChild(titleBlock);
1503
- top.appendChild(renderStatusField(ws, line, false));
1504
- }
1505
- article.appendChild(top);
1506
- var body = el('div', 'rp-item-body');
1507
- if (extra) {
1508
- body.appendChild(renderStatusField(ws, line, true));
1509
- }
1510
- var actual = mkArea(line.actual, '做到了哪一步,卡在哪;没做完就写没做完。', 3);
1511
- actual.setAttribute('data-role', 'line-actual');
1512
- actual.setAttribute('data-line', line.key);
1513
- body.appendChild(wrapField('line:' + line.key + ':actual', '实际做到什么', true, actual, ''));
1721
+ var open = ws.openLines[line.key] === true;
1722
+ var wrap = el('div', 'rp-plan' + (open ? ' is-open' : ''));
1723
+ wrap.setAttribute('data-line', line.key);
1724
+ wrap.className += ' rp-item';
1725
+ var head = el('div', 'rp-planhead');
1726
+ if (line.planId !== '') {
1727
+ var idNode = el('span', 'rp-planid');
1728
+ // `plan-<uuid>` is 41 characters and would push the goal off the row. The
1729
+ // first segment is enough to tell two plans apart on screen, and the title
1730
+ // attribute carries the full id for anyone who needs to quote it.
1731
+ setText(idNode, shortPlanId(line.planId));
1732
+ idNode.setAttribute('title', line.planId);
1733
+ head.appendChild(idNode);
1734
+ }
1735
+ var goal = el('span', 'rp-plangoal');
1736
+ setText(goal, line.title === '' ? '(未命名)' : line.title);
1737
+ head.appendChild(goal);
1738
+ head.appendChild(renderStatusField(ws, line));
1739
+ wrap.appendChild(head);
1740
+ if (!open) {
1741
+ var row = el('div', 'rp-collapsed');
1742
+ var actual = mkInput(line.actual, '填写实际结果…', 5000);
1743
+ actual.setAttribute('data-role', 'line-actual');
1744
+ actual.setAttribute('data-line', line.key);
1745
+ var box = el('div', 'rp-box is-quiet');
1746
+ box.appendChild(actual);
1747
+ row.appendChild(box);
1748
+ var counts = [
1749
+ ['evidence', 'file', '证据', line.evidence.length, line.evidence.length > 0],
1750
+ ['customer', 'chat', '反馈', 0, trim(line.customerSynced) !== '' || trim(line.customerFeedback) !== ''],
1751
+ ['ids', 'list', '场景', 0, line.scenarioIds.length + line.criteriaIds.length > 0],
1752
+ ];
1753
+ for (var i = 0; i < counts.length; i += 1) {
1754
+ var spec = at(counts, i);
1755
+ var button = el('button', 'rp-mini');
1756
+ button.type = 'button';
1757
+ button.setAttribute('data-act', 'open-line');
1758
+ button.setAttribute('data-part', at(spec, 0));
1759
+ button.setAttribute('data-line', line.key);
1760
+ button.setAttribute('data-n', at(spec, 4) ? '1' : '0');
1761
+ button.appendChild(svgIcon(at(spec, 1), 11));
1762
+ addText(button, at(spec, 2) + (at(spec, 3) > 0 ? ' ' + at(spec, 3) : ''));
1763
+ row.appendChild(button);
1764
+ }
1765
+ wrap.appendChild(row);
1766
+ return wrap;
1767
+ }
1768
+ var body = el('div', 'rp-planbody');
1769
+ if (extra)
1770
+ body.appendChild(renderLineTitleField(ws, line));
1771
+ body.appendChild(renderActualField(line, 2));
1514
1772
  body.appendChild(renderEvidenceSection(ws, line));
1515
- body.appendChild(renderLineExtras(ws, line));
1516
- article.appendChild(body);
1517
- return article;
1518
- }
1519
- function renderAddLineButton(label) {
1520
- var button = el('button', 'rp-add');
1521
- button.type = 'button';
1522
- button.setAttribute('data-act', 'add-line');
1523
- button.setAttribute('data-add-line', '');
1524
- setText(button, label);
1525
- return button;
1526
- }
1527
- function renderNoPlansBlock(ws) {
1528
- var box = el('div', 'rp-roundbar');
1529
- var note = el('p', 'rp-help');
1530
- addText(note, '上一轮没有约定计划,所以没有需要逐项对照的承诺。可以登记这轮实际做的事,或勾选下面的「本轮无实质进展」。');
1531
- box.appendChild(note);
1532
- var label = el('label', 'rp-check');
1533
- var input = el('input', '');
1534
- input.type = 'checkbox';
1535
- input.setAttribute('data-role', 'no-progress');
1536
- input.checked = ws.noProgress;
1537
- if (ws.noProgress)
1538
- label.className = 'rp-check is-on';
1539
- label.appendChild(input);
1540
- var text = el('span', '');
1541
- setText(text, '本轮无实质进展(明确记录)');
1542
- label.appendChild(text);
1543
- box.appendChild(label);
1544
- return box;
1545
- }
1546
- function renderLinesBlock(ws, addLabel) {
1547
- var box = el('div', '');
1548
- var list = el('div', '');
1549
- list.id = 'rp-lines';
1550
- for (var i = 0; i < ws.lines.length; i += 1) {
1551
- var line = at(ws.lines, i);
1552
- list.appendChild(renderLineCard(ws, line, i + 1, line.editableTitle));
1553
- }
1554
- box.appendChild(list);
1555
- box.appendChild(renderAddLineButton(addLabel));
1556
- return box;
1773
+ var two = el('div', 'rp-two');
1774
+ two.appendChild(renderCustomerFields(ws, line));
1775
+ two.appendChild(renderIdChecks(ws, line));
1776
+ body.appendChild(two);
1777
+ var close = el('button', 'rp-addline');
1778
+ close.type = 'button';
1779
+ close.setAttribute('data-act', 'close-line');
1780
+ close.setAttribute('data-line', line.key);
1781
+ close.style.paddingTop = '14px';
1782
+ close.style.color = 'var(--ink3)';
1783
+ close.appendChild(svgIcon('chevronUp', 12));
1784
+ addText(close, '收起这一项');
1785
+ body.appendChild(close);
1786
+ if (extra) {
1787
+ var del = el('button', 'rp-addline');
1788
+ del.type = 'button';
1789
+ del.setAttribute('data-act', 'line-del');
1790
+ del.setAttribute('data-line', line.key);
1791
+ del.style.paddingLeft = '14px';
1792
+ del.style.color = 'var(--ink3)';
1793
+ del.appendChild(svgIcon('x', 12));
1794
+ addText(del, '删除这条');
1795
+ body.appendChild(del);
1796
+ }
1797
+ wrap.appendChild(body);
1798
+ return wrap;
1557
1799
  }
1558
1800
  function renderProgressSection(ws) {
1559
1801
  var input = ws.input;
1560
- var sec = sectionShell('1', '上次定的计划,做到什么程度了', input.previousPlans.length ? input.previousPlans.length + ' 项' : '无计划');
1561
- sectionNote(sec, '逐项对照。没做完就写没做完,比写成「推进中」有用。');
1802
+ var sec = el('section', '');
1803
+ var planned = input.previousPlans.length;
1804
+ sec.appendChild(sectionShell('1', '上次定的计划,做到什么程度了', '逐项反馈。没做完就写没做完,比写成「推进中」有用。', planned ? planned + ' 项' : '无计划'));
1562
1805
  var general = el('p', 'rp-err rp-err-general');
1563
1806
  general.id = 'rp-round-error';
1564
1807
  sec.appendChild(general);
1565
1808
  registerRef('round:missing', general);
1566
- sec.appendChild(renderRoundStrip(ws));
1567
- if (!input.previousPlans.length)
1568
- sec.appendChild(renderNoPlansBlock(ws));
1569
- sec.appendChild(renderLinesBlock(ws, input.previousPlans.length ? '+ 添加一条计划外的进展' : '+ 添加一条进展'));
1809
+ if (!planned) {
1810
+ var box = el('div', '');
1811
+ var note = el('p', 'rp-hint');
1812
+ setText(note, '上一轮没有约定计划,所以没有需要逐项对照的承诺。可以登记这轮实际做的事,或勾选下面的「本轮无实质进展」。');
1813
+ box.appendChild(note);
1814
+ var label = el('label', 'rp-mini');
1815
+ label.style.marginTop = '12px';
1816
+ var checkbox = el('input', '');
1817
+ checkbox.type = 'checkbox';
1818
+ checkbox.setAttribute('data-role', 'no-progress');
1819
+ checkbox.checked = ws.noProgress;
1820
+ label.appendChild(checkbox);
1821
+ var span = el('span', '');
1822
+ setText(span, '本轮无实质进展(明确记录)');
1823
+ label.appendChild(span);
1824
+ if (ws.noProgress)
1825
+ label.setAttribute('data-n', '1');
1826
+ box.appendChild(label);
1827
+ sec.appendChild(box);
1828
+ }
1829
+ var list = el('div', '');
1830
+ for (var i = 0; i < ws.lines.length; i += 1) {
1831
+ var line = at(ws.lines, i);
1832
+ list.appendChild(renderLineCard(ws, line, i + 1, line.editableTitle));
1833
+ }
1834
+ sec.appendChild(list);
1835
+ var add = el('button', 'rp-addline');
1836
+ add.type = 'button';
1837
+ add.setAttribute('data-act', 'add-line');
1838
+ add.style.paddingTop = '10px';
1839
+ add.appendChild(svgIcon('plus', 12));
1840
+ addText(add, planned ? '添加一条计划外的进展' : '添加一条进展');
1841
+ sec.appendChild(add);
1842
+ return sec;
1843
+ }
1844
+ function renderPlansSection(ws, num = '4') {
1845
+ var sec = el('section', '');
1846
+ sec.appendChild(sectionShell(num, '下一轮打算做什么', '这里写的,下次就是对照项。', '必选其一'));
1847
+ var choice = el('div', 'rp-choice' + (ws.plansChoice === '' ? ' is-error' : ''));
1848
+ choice.setAttribute('role', 'group');
1849
+ choice.setAttribute('aria-label', '下轮计划');
1850
+ var options = [
1851
+ ['has', '安排下一步计划'],
1852
+ ['none', '明确暂无下一步'],
1853
+ ];
1854
+ for (var i = 0; i < options.length; i += 1) {
1855
+ var value = at(at(options, i), 0);
1856
+ var button = el('button', '');
1857
+ button.type = 'button';
1858
+ button.setAttribute('data-role', 'plans-choice');
1859
+ button.setAttribute('data-value', value);
1860
+ button.setAttribute('aria-pressed', ws.plansChoice === value ? 'true' : 'false');
1861
+ button.appendChild(svgIcon(ws.plansChoice === value ? 'target' : 'circle', 13));
1862
+ addText(button, at(at(options, i), 1));
1863
+ choice.appendChild(button);
1864
+ }
1865
+ registerRef('plans:choice', choice);
1866
+ sec.appendChild(choice);
1867
+ var list = el('div', '');
1868
+ list.id = 'rp-plans';
1869
+ list.hidden = ws.plansChoice !== 'has';
1870
+ for (var p = 0; p < ws.plans.length; p += 1) {
1871
+ list.appendChild(renderPlanRow(ws, at(ws.plans, p)));
1872
+ }
1873
+ if (!ws.plans.length && ws.plansChoice === 'has') {
1874
+ var empty = el('p', 'rp-hint');
1875
+ setText(empty, '还没有计划。点下面的「加一条下轮计划」。');
1876
+ list.appendChild(empty);
1877
+ }
1878
+ sec.appendChild(list);
1879
+ var noneNote = el('p', 'rp-hint');
1880
+ noneNote.id = 'rp-plans-none';
1881
+ noneNote.hidden = ws.plansChoice !== 'none';
1882
+ noneNote.style.paddingBottom = '12px';
1883
+ setText(noneNote, '已明确暂无下一步。下次不会拿计划对账。');
1884
+ sec.appendChild(noneNote);
1885
+ var addPlan = el('button', 'rp-addline');
1886
+ addPlan.type = 'button';
1887
+ addPlan.setAttribute('data-act', 'add-plan');
1888
+ addPlan.hidden = ws.plansChoice !== 'has';
1889
+ addPlan.appendChild(svgIcon('plus', 12));
1890
+ addText(addPlan, '再加一条下轮计划');
1891
+ sec.appendChild(addPlan);
1570
1892
  return sec;
1571
1893
  }
1572
1894
  function renderPlanRow(ws, plan) {
1573
- var row = el('div', 'rp-plan-row');
1574
- var goal = mkInput(plan.goal, '要做什么', 500);
1575
- goal.className = 'rp-input rp-plan-goal';
1895
+ var row = el('div', 'rp-prow');
1896
+ row.setAttribute('data-plan', plan.key);
1897
+ var goal = mkInput(plan.goal, '下一轮要达成什么', 500);
1576
1898
  goal.setAttribute('data-role', 'plan-goal');
1577
1899
  goal.setAttribute('data-plan', plan.key);
1578
- row.appendChild(wrapField('plan:' + plan.key + ':goal', '要做什么', true, goal, ''));
1900
+ var goalField = fieldWrap('plan:' + plan.key + ':goal', '要做什么', true, goal, '', 'is-quiet');
1901
+ goalField.className += ' rp-grow';
1902
+ row.appendChild(goalField);
1579
1903
  var owner = mkInput(plan.owner, '负责人', 120);
1580
1904
  owner.setAttribute('data-role', 'plan-owner');
1581
1905
  owner.setAttribute('data-plan', plan.key);
1582
- row.appendChild(wrapField('plan:' + plan.key + ':owner', '负责人', true, owner, ''));
1906
+ var ownerField = fieldWrap('plan:' + plan.key + ':owner', '负责人', true, owner, '', 'is-quiet');
1907
+ ownerField.className += ' rp-w180';
1908
+ row.appendChild(ownerField);
1583
1909
  var deadline = mkDate(plan.deadline);
1584
1910
  deadline.setAttribute('data-role', 'plan-deadline');
1585
1911
  deadline.setAttribute('data-plan', plan.key);
1586
- row.appendChild(wrapField('plan:' + plan.key + ':deadline', '截止日期', true, deadline, ''));
1587
- var remove = el('button', 'rp-del');
1588
- remove.type = 'button';
1589
- remove.setAttribute('data-act', 'plan-remove');
1590
- remove.setAttribute('data-plan', plan.key);
1591
- remove.setAttribute('aria-label', '删除这条计划');
1592
- setText(remove, '×');
1593
- row.appendChild(remove);
1912
+ var deadlineField = fieldWrap('plan:' + plan.key + ':deadline', '截止日期', true, deadline, '', 'is-quiet');
1913
+ deadlineField.className += ' rp-w160';
1914
+ row.appendChild(deadlineField);
1915
+ if (ws.plans.length > 1) {
1916
+ var del = el('button', 'rp-delbtn');
1917
+ del.type = 'button';
1918
+ del.setAttribute('data-act', 'plan-remove');
1919
+ del.setAttribute('data-plan', plan.key);
1920
+ del.setAttribute('aria-label', '删除这条计划');
1921
+ del.appendChild(svgIcon('x', 13));
1922
+ row.appendChild(del);
1923
+ }
1594
1924
  return row;
1595
1925
  }
1596
- function renderPlansSection(ws, asSubsection) {
1597
- var sec = sectionShell(asSubsection ? '' : '2', '下一步计划', '会成为下次的对照项');
1598
- sectionNote(sec, '写清楚要做什么、谁负责、什么时候交。下次会原样成为对照项。');
1599
- var choice = el('div', 'rp-choice');
1600
- choice.setAttribute('role', 'radiogroup');
1601
- var options = [
1602
- { value: 'has', title: '安排下一步计划', hint: '写清楚做什么、谁负责、什么时候交' },
1603
- { value: 'none', title: '明确暂无下一步', hint: '不写计划也可以,下次不会拿计划对账' },
1604
- ];
1605
- for (var i = 0; i < options.length; i += 1) {
1606
- var opt = at(options, i);
1607
- var label = el('label', 'rp-choice-opt' + (ws.plansChoice === opt.value ? ' is-on' : ''));
1608
- var input = el('input', '');
1609
- input.type = 'radio';
1610
- input.name = 'rp-plans-' + ws.index;
1611
- input.value = opt.value;
1612
- input.setAttribute('data-role', 'plans-choice');
1613
- input.checked = ws.plansChoice === opt.value;
1614
- label.appendChild(input);
1615
- var title = el('span', 'rp-choice-title');
1616
- setText(title, opt.title);
1617
- label.appendChild(title);
1618
- var hint = el('span', 'rp-choice-hint');
1619
- setText(hint, opt.hint);
1620
- label.appendChild(hint);
1621
- choice.appendChild(label);
1622
- }
1623
- sec.appendChild(wrapGroup('plans:choice', '下一步计划(必选一项)', true, choice, ''));
1624
- var list = el('div', 'rp-plan-list');
1625
- list.id = 'rp-plans';
1626
- for (var j = 0; j < ws.plans.length; j += 1) {
1627
- list.appendChild(renderPlanRow(ws, at(ws.plans, j)));
1926
+ /** The round's own metadata: date, type, what changed. */
1927
+ function renderRoundStrip(ws, num = '2') {
1928
+ var sec = el('section', '');
1929
+ sec.appendChild(sectionShell(num, '这一轮本身', '日期、类型、以及和上一轮相比什么变了', '三项都必填'));
1930
+ var grid = el('div', 'rp-three');
1931
+ var date = mkDate(ws.roundDate);
1932
+ date.setAttribute('data-role', 'round');
1933
+ date.setAttribute('data-field', 'date');
1934
+ grid.appendChild(fieldWrap('round:date', '本轮日期', true, date, '', 'is-quiet'));
1935
+ var type = mkSelect(enums.type, ws.roundType, '— 未选 —');
1936
+ type.setAttribute('data-role', 'round');
1937
+ type.setAttribute('data-field', 'type');
1938
+ grid.appendChild(fieldWrap('round:type', '类型', true, type, '', 'is-quiet'));
1939
+ var change = mkSelect(enums.change, ws.noProgress ? '无实质进展' : ws.roundChange, '— 未选 —');
1940
+ change.setAttribute('data-role', 'round');
1941
+ change.setAttribute('data-field', 'change');
1942
+ if (ws.noProgress)
1943
+ change.disabled = true;
1944
+ grid.appendChild(fieldWrap('round:change', '这一次什么变了', true, change, '', 'is-quiet'));
1945
+ sec.appendChild(grid);
1946
+ return sec;
1947
+ }
1948
+ function renderExtraSection(ws) {
1949
+ var sec = el('section', '');
1950
+ sec.appendChild(sectionShell('3', '计划之外还做了什么', '临时插入的事也算进展,别让它只活在聊天记录里。', '没有就留空'));
1951
+ var list = el('div', '');
1952
+ list.id = 'rp-extras';
1953
+ for (var i = 0; i < ws.lines.length; i += 1) {
1954
+ var line = at(ws.lines, i);
1955
+ if (!line.editableTitle)
1956
+ continue;
1957
+ list.appendChild(renderLineCard(ws, line, i + 1, true));
1628
1958
  }
1629
1959
  sec.appendChild(list);
1630
- var empty = el('p', 'rp-plans-empty');
1631
- empty.setAttribute('data-plans-empty', '');
1632
- setText(empty, '还没有计划,点下面的按钮添加一条。');
1633
- sec.appendChild(empty);
1634
- var add = el('button', 'rp-add');
1960
+ // The plan_id note only matters once there is something to explain; above an
1961
+ // empty section it would be a second line of small print next to the first.
1962
+ if (list.childNodes.length) {
1963
+ var note = el('div', 'rp-bullets');
1964
+ var item = el('div', 'rp-bullet');
1965
+ item.appendChild(svgIcon('info', 12));
1966
+ var text = el('span', '');
1967
+ setText(text, '计划外条目没有 plan_id,导入时不与任何上轮承诺对账。');
1968
+ item.appendChild(text);
1969
+ note.appendChild(item);
1970
+ sec.appendChild(note);
1971
+ }
1972
+ if (!list.childNodes.length) {
1973
+ var emptyNote = el('p', 'rp-hint');
1974
+ emptyNote.style.padding = '2px 0 6px';
1975
+ setText(emptyNote, '这一轮没有计划之外的事,留空即可。');
1976
+ sec.appendChild(emptyNote);
1977
+ }
1978
+ var add = el('button', 'rp-addline');
1635
1979
  add.type = 'button';
1636
- add.setAttribute('data-act', 'add-plan');
1637
- setText(add, '+ 再加一条计划');
1980
+ add.setAttribute('data-act', 'add-line');
1981
+ add.style.paddingTop = '14px';
1982
+ add.appendChild(svgIcon('plus', 12));
1983
+ addText(add, '再加一条计划外进展');
1638
1984
  sec.appendChild(add);
1639
- var noneNote = el('p', 'rp-help');
1640
- noneNote.setAttribute('data-plans-none', '');
1641
- setText(noneNote, '已明确:本次不安排下一步计划。');
1642
- sec.appendChild(noneNote);
1643
- var hasChoice = ws.plansChoice === 'has';
1644
- list.hidden = !hasChoice;
1645
- add.hidden = !hasChoice;
1646
- empty.hidden = !hasChoice || ws.plans.length > 0;
1647
- noneNote.hidden = ws.plansChoice !== 'none';
1648
1985
  return sec;
1649
1986
  }
1987
+ /**
1988
+ * The optional other-stage facts.
1989
+ *
1990
+ * Four stage tabs, each with its own text, held separately so switching tabs
1991
+ * never moves one stage's words into another's. The panel spells out that this
1992
+ * text does not change the stage and does not write a Gate verdict, because the
1993
+ * colleague is otherwise being asked for material that gets reviewed.
1994
+ */
1650
1995
  function renderStageNotes(ws) {
1651
- var details = el('details', 'rp-opt');
1652
- var summary = el('summary', '');
1653
- setText(summary, '其他阶段的补充事实(选填)');
1654
- details.appendChild(summary);
1655
- var note = el('p', 'rp-opt-note');
1656
- addText(note, '只记录事实,作为待审补充;不改变项目阶段,也不写 Gate 判定。所有阶段都可以按需展开。');
1657
- details.appendChild(note);
1658
- var body = el('div', 'rp-opt-body');
1659
- var current = ws.input ? ws.input.stage : 'G0';
1996
+ var acc = el('div', 'rp-acc' + (ws.stageOpen ? '' : ' is-closed'));
1997
+ acc.setAttribute('data-open', ws.stageOpen ? '1' : '0');
1998
+ acc.id = 'rp-stage-acc';
1999
+ var head = el('button', 'rp-acchead');
2000
+ head.type = 'button';
2001
+ head.setAttribute('data-act', 'stage-toggle');
2002
+ head.setAttribute('aria-expanded', ws.stageOpen ? 'true' : 'false');
2003
+ var left = el('span', 'rp-accl');
2004
+ left.appendChild(svgIcon('chevron', 15));
2005
+ // The title and its one-line explanation stack: inline they run together
2006
+ // into one unreadable sentence.
2007
+ var titles = el('span', '');
2008
+ titles.style.display = 'flex';
2009
+ titles.style.flexDirection = 'column';
2010
+ titles.style.minWidth = '0';
2011
+ var t = el('span', 'rp-acctitle');
2012
+ setText(t, '其他阶段的补充事实');
2013
+ titles.appendChild(t);
2014
+ var s = el('span', 'rp-accsub');
2015
+ setText(s, '只记录事实,作为待审补充;不改变项目阶段,也不写 Gate 判定');
2016
+ titles.appendChild(s);
2017
+ left.appendChild(titles);
2018
+ head.appendChild(left);
2019
+ var opt = el('span', 'rp-accopt');
2020
+ setText(opt, '选填');
2021
+ head.appendChild(opt);
2022
+ acc.appendChild(head);
2023
+ var body = el('div', 'rp-accbody');
2024
+ var tabs = el('div', 'rp-stagetabs');
2025
+ tabs.setAttribute('role', 'tablist');
1660
2026
  for (var i = 0; i < STAGES.length; i += 1) {
1661
2027
  var stage = at(STAGES, i);
1662
- var stageBox = el('details', 'rp-stage');
1663
- var stageSummary = el('summary', '');
1664
- addText(stageSummary, at(STAGE_LABELS, stage));
1665
- if (current && current.indexOf(stage) === 0) {
1666
- var badge = el('span', 'rp-stage-badge');
1667
- setText(badge, '当前阶段');
1668
- stageSummary.appendChild(badge);
1669
- }
1670
- stageBox.appendChild(stageSummary);
1671
- var stageBody = el('div', 'rp-stage-body');
1672
- var area = mkArea(at(ws.stageNotes, stage), stagePlaceholder(stage), 3);
1673
- area.setAttribute('data-role', 'stage');
1674
- area.setAttribute('data-stage', stage);
1675
- area.setAttribute('aria-label', at(STAGE_LABELS, stage) + '的补充事实');
1676
- stageBody.appendChild(area);
1677
- stageBox.appendChild(stageBody);
1678
- body.appendChild(stageBox);
1679
- }
1680
- details.appendChild(body);
1681
- return details;
2028
+ var tab = el('button', '');
2029
+ tab.type = 'button';
2030
+ tab.setAttribute('role', 'tab');
2031
+ tab.setAttribute('data-act', 'stage-tab');
2032
+ tab.setAttribute('data-stage', stage);
2033
+ tab.setAttribute('aria-selected', ws.stageTab === stage ? 'true' : 'false');
2034
+ var code = el('span', 'rp-code');
2035
+ setText(code, stage);
2036
+ tab.appendChild(code);
2037
+ addText(tab, ' ' + at(STAGE_LABELS, stage).replace(stage + ' · ', ''));
2038
+ var hasFacts = trim(ws.stageNotes[stage]) !== '';
2039
+ if (hasFacts)
2040
+ tab.appendChild(el('i', 'rp-pip'));
2041
+ tabs.appendChild(tab);
2042
+ }
2043
+ body.appendChild(tabs);
2044
+ var panel = el('div', 'rp-panel');
2045
+ var top = el('div', 'rp-panelhead');
2046
+ var l = el('div', 'rp-l');
2047
+ var code2 = el('span', 'rp-stagecode');
2048
+ setText(code2, at(STAGE_LABELS, ws.stageTab));
2049
+ l.appendChild(code2);
2050
+ var note = el('span', 'rp-note');
2051
+ setText(note, '补的是事实,不是评价');
2052
+ l.appendChild(note);
2053
+ top.appendChild(l);
2054
+ var count = el('span', 'rp-count');
2055
+ count.id = 'rp-stage-count';
2056
+ setText(count, ws.stageNotes[ws.stageTab].length + ' / 2000 字');
2057
+ top.appendChild(count);
2058
+ panel.appendChild(top);
2059
+ var area = mkArea(ws.stageNotes[ws.stageTab], stagePlaceholder(ws.stageTab), 3);
2060
+ area.setAttribute('data-role', 'stage');
2061
+ area.setAttribute('data-stage', ws.stageTab);
2062
+ area.setAttribute('maxlength', '2000');
2063
+ area.setAttribute('aria-label', at(STAGE_LABELS, ws.stageTab) + '的补充事实');
2064
+ var box = el('div', 'rp-box');
2065
+ box.appendChild(area);
2066
+ panel.appendChild(box);
2067
+ var bullets = el('div', 'rp-bullets');
2068
+ var lines = [
2069
+ '不会改变项目阶段——阶段推进走 Gate 评审',
2070
+ '不会写入 Gate 判定,只作为待审补充材料',
2071
+ '留空表示这一阶段没有要补的事实',
2072
+ ];
2073
+ for (var b = 0; b < lines.length; b += 1) {
2074
+ var row = el('div', 'rp-bullet');
2075
+ row.appendChild(svgIcon('minus', 11));
2076
+ var span = el('span', '');
2077
+ setText(span, at(lines, b));
2078
+ row.appendChild(span);
2079
+ bullets.appendChild(row);
2080
+ }
2081
+ panel.appendChild(bullets);
2082
+ body.appendChild(panel);
2083
+ acc.appendChild(body);
2084
+ return acc;
1682
2085
  }
1683
2086
  function stagePlaceholder(stage) {
1684
2087
  if (stage === 'G0')
1685
- return '客户痛点、决策链、预算、竞争等事实';
2088
+ return '客户痛点、决策链、预算、竞争等事实。写清楚是谁说的、什么时候说的——评审时要能追溯到来源。';
1686
2089
  if (stage === 'G1')
1687
- return '方案范围、指标口径、验证场景、风险等事实';
2090
+ return '方案范围、指标口径、验证场景、风险等事实。';
1688
2091
  if (stage === 'G2')
1689
- return '验证环境、前置条件、准备情况等事实';
1690
- return '客户结论、后续动作、里程碑等事实';
1691
- }
1692
- function renderOptionalRound(ws) {
1693
- var details = el('details', 'rp-opt');
1694
- var summary = el('summary', '');
1695
- setText(summary, '可选:第一轮进展与下一步计划(不填也能提交)');
1696
- details.appendChild(summary);
1697
- var note = el('p', 'rp-opt-note');
1698
- addText(note, '已经有客户动作就登记首轮事实;如果只是先定计划,只填下面的「下一步计划」也可以。');
1699
- details.appendChild(note);
1700
- var body = el('div', 'rp-opt-body');
1701
- body.appendChild(renderRoundStrip(ws));
1702
- body.appendChild(renderLinesBlock(ws, '+ 添加一条工作记录'));
1703
- body.appendChild(renderPlansSection(ws, true));
1704
- details.appendChild(body);
1705
- return details;
1706
- }
1707
- function renderIdentitySection(ws) {
1708
- var sec = sectionShell('1', '项目身份', '');
1709
- sectionNote(sec, '请填写立项基本信息。阶段和状态由台账维护。');
1710
- var grid = el('div', 'rp-grid-2');
1711
- var pocId = mkInput(ws.identity.pocId, '如 POC-2026-007', 64);
1712
- pocId.setAttribute('data-role', 'identity');
1713
- pocId.setAttribute('data-field', 'pocId');
1714
- grid.appendChild(wrapField('identity:pocId', '项目编号', true, pocId, ''));
1715
- var name = mkInput(ws.identity.name, '项目名称', 500);
1716
- name.setAttribute('data-role', 'identity');
1717
- name.setAttribute('data-field', 'name');
1718
- grid.appendChild(wrapField('identity:name', '项目名称', true, name, ''));
1719
- var owner = mkInput(ws.identity.owner, '我方负责人', 120);
1720
- owner.setAttribute('data-role', 'identity');
1721
- owner.setAttribute('data-field', 'owner');
1722
- grid.appendChild(wrapField('identity:owner', '负责人(我方)', true, owner, ''));
1723
- var company = mkInput(ws.identity.company, '客户公司', 200);
1724
- company.setAttribute('data-role', 'identity');
1725
- company.setAttribute('data-field', 'company');
1726
- grid.appendChild(wrapField('identity:company', '客户公司', true, company, ''));
1727
- var optional = el('details', 'rp-opt');
2092
+ return '验证环境、前置条件、准备情况等事实。';
2093
+ return '客户结论、后续动作、里程碑等事实。';
2094
+ }
2095
+ /** The new-project worksheet: identity + Gate 0, no round required. */
2096
+ function renderNewProject(ws) {
2097
+ var wrap = el('div', '');
2098
+ var identity = el('section', '');
2099
+ identity.appendChild(sectionShell('1', '项目身份', '谁、哪家、谁负责。阶段和状态由台账维护。', '带 * 必填'));
2100
+ var grid = el('div', 'rp-two');
2101
+ var col1 = el('div', 'rp-f');
2102
+ var col2 = el('div', 'rp-f');
2103
+ function addInput(field, label, placeholder, required, value, max, target) {
2104
+ var control = mkInput(value, placeholder, max);
2105
+ control.setAttribute('data-role', 'identity');
2106
+ control.setAttribute('data-field', field);
2107
+ target.appendChild(fieldWrap('identity:' + field, label, required, control, '', ''));
2108
+ }
2109
+ addInput('pocId', '项目编号', '如 POC-2026-007', true, ws.identity.pocId, 64, col1);
2110
+ addInput('name', '项目名称', '项目名称', true, ws.identity.name, 500, col1);
2111
+ addInput('owner', '负责人(我方)', '我方负责人', true, ws.identity.owner, 120, col1);
2112
+ addInput('company', '客户公司', '客户公司', true, ws.identity.company, 200, col2);
2113
+ // `tech_owner` is one of the five G0 prerequisites even though it lives in
2114
+ // the identity block of the schema, so it carries the gate0 role: that is
2115
+ // what the G0 validation and its error path expect.
2116
+ var techOwner = mkInput(ws.identity.techOwner, '客户侧能推动技术验证的人', 120);
2117
+ techOwner.setAttribute('data-role', 'gate0');
2118
+ techOwner.setAttribute('data-field', 'techOwner');
2119
+ col2.appendChild(fieldWrap('gate0:techOwner', '客户技术责任人', true, techOwner, 'G0 五项之一', ''));
2120
+ var amount = mkNumber(ws.identity.amountWan);
2121
+ amount.setAttribute('data-role', 'identity');
2122
+ amount.setAttribute('data-field', 'amountWan');
2123
+ amount.placeholder = '只填数字,如 120';
2124
+ col2.appendChild(fieldWrap('identity:amountWan', '预计金额(万元)', false, amount, '', ''));
2125
+ grid.appendChild(col1);
2126
+ grid.appendChild(col2);
2127
+ identity.appendChild(grid);
2128
+ var optional = el('details', '');
2129
+ optional.style.paddingTop = '16px';
1728
2130
  var summary = el('summary', '');
2131
+ summary.style.cursor = 'pointer';
2132
+ summary.style.fontSize = '11.5px';
2133
+ summary.style.color = 'var(--ink3)';
1729
2134
  setText(summary, '更多项目信息(选填)');
1730
2135
  optional.appendChild(summary);
1731
- sec.appendChild(grid);
1732
- grid = el('div', 'rp-grid-2');
2136
+ var grid2 = el('div', 'rp-two');
2137
+ grid2.style.paddingTop = '12px';
2138
+ var c3 = el('div', 'rp-f');
2139
+ var c4 = el('div', 'rp-f');
1733
2140
  var system = mkSelect(enums.system, ws.identity.system, '— 未选 —');
1734
2141
  system.setAttribute('data-role', 'identity');
1735
2142
  system.setAttribute('data-field', 'system');
1736
- grid.appendChild(wrapField('identity:system', '体系', false, system, ''));
1737
- var department = mkInput(ws.identity.department, '客户部门', 200);
1738
- department.setAttribute('data-role', 'identity');
1739
- department.setAttribute('data-field', 'department');
1740
- grid.appendChild(wrapField('identity:department', '部门', false, department, ''));
2143
+ c3.appendChild(fieldWrap('identity:system', '体系', false, system, '', ''));
2144
+ var dept = mkInput(ws.identity.department, '客户部门', 200);
2145
+ dept.setAttribute('data-role', 'identity');
2146
+ dept.setAttribute('data-field', 'department');
2147
+ c3.appendChild(fieldWrap('identity:department', '部门', false, dept, '', ''));
1741
2148
  var sales = mkInput(ws.identity.sales, '销售', 120);
1742
2149
  sales.setAttribute('data-role', 'identity');
1743
2150
  sales.setAttribute('data-field', 'sales');
1744
- grid.appendChild(wrapField('identity:sales', '销售', false, sales, ''));
1745
- var amount = mkNumber(ws.identity.amountWan);
1746
- amount.setAttribute('data-role', 'identity');
1747
- amount.setAttribute('data-field', 'amountWan');
1748
- amount.placeholder = '预计金额';
1749
- grid.appendChild(wrapField('identity:amountWan', '预计金额(万元)', false, amount, '只填数字,如 120'));
2151
+ c4.appendChild(fieldWrap('identity:sales', '销售', false, sales, '', ''));
1750
2152
  var pocType = mkSelect(enums.poc_type, ws.identity.pocType, '— 未选 —');
1751
2153
  pocType.setAttribute('data-role', 'identity');
1752
2154
  pocType.setAttribute('data-field', 'pocType');
1753
- grid.appendChild(wrapField('identity:pocType', '项目类型', false, pocType, ''));
1754
- var execSponsor = mkInput(ws.identity.execSponsor, '客户业务决策人', 120);
1755
- execSponsor.setAttribute('data-role', 'identity');
1756
- execSponsor.setAttribute('data-field', 'execSponsor');
1757
- grid.appendChild(wrapField('identity:execSponsor', '客户业务决策人', false, execSponsor, ''));
1758
- optional.appendChild(grid);
1759
- sec.appendChild(optional);
1760
- return sec;
1761
- }
1762
- function renderGate0Section(ws) {
1763
- var sec = sectionShell('2', 'Gate 0 · 值不值得做', '五项必填');
1764
- sectionNote(sec, '这五项齐了,G0 评审才有意义。评审结论不在这里填。');
1765
- var grid = el('div', 'rp-grid-2');
1766
- function addArea(field, label, value, placeholder) {
1767
- var area = mkArea(value, placeholder, 3);
2155
+ c4.appendChild(fieldWrap('identity:pocType', '项目类型', false, pocType, '', ''));
2156
+ var sponsor = mkInput(ws.identity.execSponsor, '客户业务决策人', 120);
2157
+ sponsor.setAttribute('data-role', 'identity');
2158
+ sponsor.setAttribute('data-field', 'execSponsor');
2159
+ c4.appendChild(fieldWrap('identity:execSponsor', '客户业务决策人', false, sponsor, '', ''));
2160
+ grid2.appendChild(c3);
2161
+ grid2.appendChild(c4);
2162
+ optional.appendChild(grid2);
2163
+ identity.appendChild(optional);
2164
+ wrap.appendChild(identity);
2165
+ var gate = el('section', '');
2166
+ gate.appendChild(sectionShell('2', 'Gate 0 · 值不值得做', '这五项齐了,G0 评审才有意义。评审结论不在这里填。', '五项必填'));
2167
+ var areas = [
2168
+ ['whyCustomer', '客户为什么要测', ws.gate0.whyCustomer, '客户自己的痛点与压力,不是我们的卖点'],
2169
+ ['whyUs', '我们为什么测', ws.gate0.whyUs, '对我们的价值:突破点、可复制的样板、后续生意'],
2170
+ ['decisionChain', '项目流程 / 决策链', ws.gate0.decisionChain, '谁提需求、谁评审、谁签字、按什么流程走'],
2171
+ ['postPocDecision', '测完之后客户会做什么决定', ws.gate0.postPocDecision, '采购、扩容、试点转正,还是就此结束'],
2172
+ ];
2173
+ for (var a = 0; a < areas.length; a += 1) {
2174
+ var spec = at(areas, a);
2175
+ var area = mkArea(at(spec, 2), at(spec, 3), 3);
1768
2176
  area.setAttribute('data-role', 'gate0');
1769
- area.setAttribute('data-field', field);
1770
- grid.appendChild(wrapField('gate0:' + field, label, true, area, ''));
2177
+ area.setAttribute('data-field', at(spec, 0));
2178
+ gate.appendChild(fieldWrap('gate0:' + at(spec, 0), at(spec, 1), true, area, '', ''));
1771
2179
  }
1772
- addArea('whyCustomer', '客户为什么要测', ws.gate0.whyCustomer, '客户自己的痛点与压力,不是我们的卖点');
1773
- addArea('whyUs', '我们为什么测', ws.gate0.whyUs, '对我们的价值:突破点、可复制的样板、后续生意');
1774
- addArea('decisionChain', '项目流程 / 决策链', ws.gate0.decisionChain, '谁提需求、谁评审、谁签字、按什么流程走');
1775
- addArea('postPocDecision', '测完之后客户会做什么决定', ws.gate0.postPocDecision, '采购、扩容、试点转正,还是就此结束');
1776
- sec.appendChild(grid);
1777
- var second = el('div', 'rp-grid-2');
1778
- var techOwner = mkInput(ws.identity.techOwner, '客户技术责任人', 120);
1779
- techOwner.setAttribute('data-role', 'gate0');
1780
- techOwner.setAttribute('data-field', 'techOwner');
1781
- second.appendChild(wrapField('gate0:techOwner', '客户技术责任人', true, techOwner, 'G0 五项之一:客户侧能推动技术验证的人'));
1782
2180
  var competitor = mkInput(ws.gate0.competitor, '主要竞争对手', 500);
1783
2181
  competitor.setAttribute('data-role', 'gate0');
1784
2182
  competitor.setAttribute('data-field', 'competitor');
1785
- second.appendChild(wrapField('gate0:competitor', '主要竞争对手', false, competitor, ''));
1786
- sec.appendChild(second);
1787
- return sec;
1788
- }
1789
- function renderWorkspace(ws) {
1790
- var container = el('div', '');
1791
- container.id = 'rp-project';
1792
- if (ws.isNew) {
1793
- container.appendChild(renderIdentitySection(ws));
1794
- container.appendChild(renderGate0Section(ws));
1795
- container.appendChild(renderOptionalRound(ws));
2183
+ gate.appendChild(fieldWrap('gate0:competitor', '主要竞争对手', false, competitor, '选填', ''));
2184
+ wrap.appendChild(gate);
2185
+ // Section 3 owns the whole optional first round, in the order the facts are
2186
+ // asked for: the round's own metadata, then what was done, then next steps.
2187
+ var extra = el('section', '');
2188
+ extra.appendChild(sectionShell('3', '第一轮进展与下一步计划', '不填也能保存。填了就是第一轮记录。', '选填'));
2189
+ extra.appendChild(renderRoundStrip(ws, ''));
2190
+ var list = el('div', '');
2191
+ for (var i = 0; i < ws.lines.length; i += 1) {
2192
+ list.appendChild(renderLineCard(ws, at(ws.lines, i), i + 1, at(ws.lines, i).editableTitle));
1796
2193
  }
1797
- else {
1798
- container.appendChild(renderProgressSection(ws));
1799
- container.appendChild(renderPlansSection(ws, false));
1800
- }
1801
- container.appendChild(renderStageNotes(ws));
1802
- return container;
2194
+ extra.appendChild(list);
2195
+ var add = el('button', 'rp-addline');
2196
+ add.type = 'button';
2197
+ add.setAttribute('data-act', 'add-line');
2198
+ add.style.paddingTop = '10px';
2199
+ add.style.paddingBottom = '18px';
2200
+ add.appendChild(svgIcon('plus', 12));
2201
+ addText(add, '添加第一轮的进展');
2202
+ extra.appendChild(add);
2203
+ extra.appendChild(renderPlansSection(ws, ''));
2204
+ wrap.appendChild(extra);
2205
+ wrap.appendChild(renderStageNotes(ws));
2206
+ return wrap;
1803
2207
  }
1804
- function renderPreview() {
1805
- var details = el('details', 'rp-preview');
1806
- details.id = 'rp-preview';
1807
- var summary = el('summary', '');
1808
- setText(summary, '预览本次回传内容');
1809
- details.appendChild(summary);
1810
- var body = el('div', 'rp-preview-body');
1811
- body.id = 'rp-preview-body';
1812
- details.appendChild(body);
1813
- details.addEventListener('toggle', function () {
1814
- if (details.open)
1815
- buildPreview();
1816
- });
1817
- return details;
2208
+ // -------------------------------------------------------------------------
2209
+ // Screen 2: the read-only dossier
2210
+ // -------------------------------------------------------------------------
2211
+ function dossierHead() {
2212
+ var d = dossier;
2213
+ var head = el('div', '');
2214
+ var when = exportedAt === '' ? '整份档案为导出时刻的快照' : '整份档案截至 ' + exportedAt + ' 导出时刻';
2215
+ head.appendChild(eyebrowLine('项目档案', when, '02 / 02'));
2216
+ var h1 = el('h1', 'rp-h1');
2217
+ h1.style.fontSize = '34px';
2218
+ setText(h1, d.name || d.pocId);
2219
+ head.appendChild(h1);
2220
+ var lead = el('p', 'rp-lead');
2221
+ setText(lead, '这一页是台账的完整快照,用于对照第一页要填的内容。这里没有任何可编辑的格子——所有修改都发生在第一页。');
2222
+ head.appendChild(lead);
2223
+ var stats = el('dl', 'rp-stats');
2224
+ var achieved = 0;
2225
+ for (var c = 0; c < d.plan.criteria.length; c += 1) {
2226
+ if (at(d.plan.criteria, c).status === '已达成')
2227
+ achieved += 1;
2228
+ }
2229
+ var evidenceTotal = 0;
2230
+ for (var r = 0; r < d.rounds.length; r += 1)
2231
+ evidenceTotal += at(d.rounds, r).evidenceCount;
2232
+ var cells = [
2233
+ ['进展轮次', d.roundTotal + ' 轮'],
2234
+ ['验证场景', d.plan.scenarios.length + ' 个'],
2235
+ ['成功指标', d.plan.criteria.length + ' 条'],
2236
+ ['已挂证据', evidenceTotal + ' 条'],
2237
+ ['阶段停留', d.daysInStage === null ? '未知' : d.daysInStage + ' 天'],
2238
+ ];
2239
+ for (var i = 0; i < cells.length; i += 1) {
2240
+ var cell = el('div', 'rp-stat');
2241
+ var dt = el('dt', '');
2242
+ setText(dt, at(at(cells, i), 0));
2243
+ var dd = el('dd', '');
2244
+ setText(dd, at(at(cells, i), 1));
2245
+ cell.appendChild(dt);
2246
+ cell.appendChild(dd);
2247
+ stats.appendChild(cell);
2248
+ }
2249
+ head.appendChild(stats);
2250
+ head.appendChild(el('div', 'rp-hairline2'));
2251
+ return head;
1818
2252
  }
1819
- function buildPreview() {
1820
- var body = app.querySelector('#rp-preview-body');
1821
- if (!body)
1822
- return;
1823
- clearNode(body);
1824
- var included = [];
1825
- var skipped = [];
1826
- for (var i = 0; i < state.workspaces.length; i += 1) {
1827
- if (intent === 'new' || touched(at(state.workspaces, i)))
1828
- included.push(at(state.workspaces, i));
1829
- else
1830
- skipped.push(at(state.workspaces, i));
2253
+ function dossierSectionHead(num, title, note) {
2254
+ var head = el('div', 'rp-dsechead');
2255
+ var left = el('div', 'rp-dsecl');
2256
+ var n = el('span', 'rp-dsecnum');
2257
+ setText(n, num);
2258
+ left.appendChild(n);
2259
+ var t = el('h2', 'rp-dsectitle');
2260
+ setText(t, title);
2261
+ left.appendChild(t);
2262
+ head.appendChild(left);
2263
+ var noteNode = el('span', 'rp-dsecnote');
2264
+ setText(noteNode, note);
2265
+ head.appendChild(noteNode);
2266
+ return head;
2267
+ }
2268
+ /** One Gate 0 argument; an empty one says so instead of vanishing. */
2269
+ function dossierArg(label, value) {
2270
+ var row = el('div', 'rp-arg');
2271
+ var dt = el('dt', '');
2272
+ setText(dt, label);
2273
+ var dd = el('dd', value === '' ? 'is-empty' : '');
2274
+ setText(dd, value === '' ? '台账未填写' : value);
2275
+ row.appendChild(dt);
2276
+ row.appendChild(dd);
2277
+ return row;
2278
+ }
2279
+ function renderDossierG0() {
2280
+ var d = dossier;
2281
+ var sec = el('section', '');
2282
+ sec.appendChild(dossierSectionHead('01', '这个项目为什么做', d.g0Complete ? 'Gate 0 · 已完整' : 'Gate 0 · 立项论证'));
2283
+ var dl = el('dl', '');
2284
+ dl.appendChild(dossierArg('客户为什么要测', d.gate0.whyCustomer));
2285
+ dl.appendChild(dossierArg('我们为什么测', d.gate0.whyUs));
2286
+ dl.appendChild(dossierArg('项目流程 / 决策链', d.gate0.decisionChain));
2287
+ dl.appendChild(dossierArg('测完之后客户会做什么决定', d.gate0.postPocDecision));
2288
+ if (d.gate0.competitor !== '')
2289
+ dl.appendChild(dossierArg('主要竞争对手', d.gate0.competitor));
2290
+ sec.appendChild(dl);
2291
+ var missing = d.gate0.missing.length;
2292
+ if (missing) {
2293
+ var warn = el('div', 'rp-warn');
2294
+ warn.appendChild(svgIcon('warn', 13));
2295
+ var text = el('span', '');
2296
+ setText(text, '立项论证缺 ' + missing + ' 项。这些由项目负责人在台账里补,不在导出表单里填。');
2297
+ warn.appendChild(text);
2298
+ sec.appendChild(warn);
1831
2299
  }
1832
- var heading = el('h3', '');
1833
- setText(heading, intent === 'new' ? '新建项目' : '记录进展 · 会包含 ' + included.length + ' 个项目');
1834
- body.appendChild(heading);
1835
- var list = el('ul', 'rp-preview-list');
1836
- for (var j = 0; j < included.length; j += 1) {
1837
- var ws = at(included, j);
1838
- var item = el('li', '');
1839
- var label = el('b', '');
1840
- if (ws.isNew)
1841
- setText(label, ws.identity.name || ws.identity.pocId || '新建项目');
1842
- else
1843
- setText(label, ws.input.name || ws.input.pocId);
1844
- item.appendChild(label);
1845
- var bits = [];
1846
- if (intent === 'new') {
1847
- bits.push(ws.identity.pocId || '编号未填');
1848
- bits.push(ws.gate0.whyCustomer ? 'G0 已填' : 'G0 未填');
1849
- if (newRoundPresent(ws))
1850
- bits.push('含第一轮进展');
1851
- }
1852
- else {
1853
- var roundLines = 0;
1854
- for (var k = 0; k < ws.lines.length; k += 1)
1855
- if (lineHasContent(at(ws.lines, k)))
1856
- roundLines += 1;
1857
- bits.push(ws.noProgress ? '本轮无实质进展' : '工作项 ' + roundLines + ' 条');
1858
- bits.push(ws.plansChoice === 'none' ? '已明确暂无下一步' : '计划 ' + ws.plans.length + ' 条');
1859
- }
1860
- var dim = el('span', 'rp-preview-dim');
1861
- addText(dim, ' ' + bits.join(' · '));
1862
- item.appendChild(dim);
1863
- list.appendChild(item);
2300
+ return sec;
2301
+ }
2302
+ function renderDossierPlan() {
2303
+ var d = dossier;
2304
+ var sec = el('section', '');
2305
+ sec.appendChild(dossierSectionHead('02', '打算怎么验证', 'Gate 1 · 方案设计与验证口径'));
2306
+ var cols = el('dl', 'rp-cols');
2307
+ var specs = [
2308
+ ['客户痛点', d.plan.customerPain],
2309
+ ['我们的优势', d.plan.ourEdge],
2310
+ ['预期认可', d.plan.expectedRecognition],
2311
+ ['时间线', [d.plan.timelineStart, d.plan.timelineEnd].filter(function (part) { return part !== ''; }).join(' → ')],
2312
+ ];
2313
+ for (var i = 0; i < specs.length; i += 1) {
2314
+ var value = at(at(specs, i), 1);
2315
+ if (value === '')
2316
+ continue;
2317
+ var col = el('div', 'rp-col');
2318
+ var dt = el('dt', '');
2319
+ setText(dt, at(at(specs, i), 0));
2320
+ var dd = el('dd', '');
2321
+ setText(dd, value);
2322
+ col.appendChild(dt);
2323
+ col.appendChild(dd);
2324
+ cols.appendChild(col);
2325
+ }
2326
+ if (cols.childNodes.length)
2327
+ sec.appendChild(cols);
2328
+ if (d.plan.criteria.length) {
2329
+ var hrow = el('div', 'rp-hrow');
2330
+ var b = el('b', '');
2331
+ setText(b, '成功指标');
2332
+ hrow.appendChild(b);
2333
+ var note = el('span', '');
2334
+ setText(note, '状态由台账派生,不能在这里改');
2335
+ hrow.appendChild(note);
2336
+ sec.appendChild(hrow);
2337
+ for (var c = 0; c < d.plan.criteria.length; c += 1) {
2338
+ var cri = at(d.plan.criteria, c);
2339
+ var row = el('div', 'rp-row');
2340
+ var rid = el('span', 'rp-rid');
2341
+ setText(rid, cri.id);
2342
+ row.appendChild(rid);
2343
+ var rt = el('span', 'rp-rt');
2344
+ setText(rt, cri.name);
2345
+ row.appendChild(rt);
2346
+ var rd = el('span', 'rp-rd');
2347
+ setText(rd, cri.metric);
2348
+ row.appendChild(rd);
2349
+ var chip = el('span', 'rp-tagchip');
2350
+ if (cri.status === '已达成')
2351
+ chip.className += ' is-ok';
2352
+ else if (cri.status === '部分达成')
2353
+ chip.className += ' is-warn';
2354
+ else
2355
+ chip.className += ' is-mute';
2356
+ setText(chip, cri.status === '' ? '未验证' : cri.status);
2357
+ row.appendChild(chip);
2358
+ sec.appendChild(row);
2359
+ }
2360
+ }
2361
+ if (d.plan.scenarios.length) {
2362
+ var hrow2 = el('div', 'rp-hrow');
2363
+ hrow2.style.paddingTop = '20px';
2364
+ var b2 = el('b', '');
2365
+ setText(b2, '验证场景');
2366
+ hrow2.appendChild(b2);
2367
+ var note2 = el('span', '');
2368
+ setText(note2, '证据按 id 挂靠,第一页勾选的就是这些');
2369
+ hrow2.appendChild(note2);
2370
+ sec.appendChild(hrow2);
2371
+ for (var s = 0; s < d.plan.scenarios.length; s += 1) {
2372
+ var scn = at(d.plan.scenarios, s);
2373
+ var r2 = el('div', 'rp-row');
2374
+ var sid = el('span', 'rp-rid');
2375
+ setText(sid, scn.id);
2376
+ r2.appendChild(sid);
2377
+ var mid = el('div', 'rp-rw');
2378
+ var sn = el('div', '');
2379
+ setText(sn, scn.name);
2380
+ mid.appendChild(sn);
2381
+ if (scn.goal !== '') {
2382
+ var sg = el('div', 'rp-rsub');
2383
+ setText(sg, scn.goal);
2384
+ mid.appendChild(sg);
2385
+ }
2386
+ r2.appendChild(mid);
2387
+ var right = el('div', 'rp-rright');
2388
+ var st = el('div', 'rp-st');
2389
+ setText(st, scn.status === '' ? '未开始' : scn.status);
2390
+ if (scn.status === '待客户确认')
2391
+ st.style.color = 'var(--flag)';
2392
+ else if (scn.status === '无证据')
2393
+ st.style.color = 'var(--ink3)';
2394
+ right.appendChild(st);
2395
+ var ev = el('div', 'rp-ev');
2396
+ setText(ev, scn.evidenceCount + ' 条证据');
2397
+ right.appendChild(ev);
2398
+ r2.appendChild(right);
2399
+ sec.appendChild(r2);
2400
+ }
2401
+ }
2402
+ if (d.plan.risks.length) {
2403
+ var hrow3 = el('div', 'rp-hrow');
2404
+ hrow3.style.paddingTop = '20px';
2405
+ var b3 = el('b', '');
2406
+ setText(b3, '最大风险');
2407
+ hrow3.appendChild(b3);
2408
+ sec.appendChild(hrow3);
2409
+ for (var k = 0; k < d.plan.risks.length; k += 1) {
2410
+ var risk = at(d.plan.risks, k);
2411
+ var rr = el('div', 'rp-row');
2412
+ var rn = el('span', 'rp-rt');
2413
+ rn.style.width = 'auto';
2414
+ setText(rn, risk.name);
2415
+ rr.appendChild(rn);
2416
+ var rd2 = el('span', 'rp-rd');
2417
+ setText(rd2, risk.mitigation === '' ? '未写应对' : risk.mitigation);
2418
+ rr.appendChild(rd2);
2419
+ if (risk.level !== '') {
2420
+ var lv = el('span', 'rp-tagchip is-mute');
2421
+ setText(lv, risk.level === 'high' ? '高' : risk.level === 'medium' ? '中' : risk.level === 'low' ? '低' : risk.level);
2422
+ rr.appendChild(lv);
2423
+ }
2424
+ sec.appendChild(rr);
2425
+ }
1864
2426
  }
1865
- if (!included.length) {
1866
- var none = el('li', '');
1867
- setText(none, '还没有填写任何项目。');
1868
- list.appendChild(none);
2427
+ return sec;
2428
+ }
2429
+ function renderDossierRounds() {
2430
+ var d = dossier;
2431
+ var sec = el('section', '');
2432
+ var note = d.roundTotal > d.rounds.length
2433
+ ? '最近 ' + d.rounds.length + ' 轮 · 共 ' + d.roundTotal + ' 轮'
2434
+ : '共 ' + d.roundTotal + ' 轮';
2435
+ sec.appendChild(dossierSectionHead('03', '已经发生过什么', note));
2436
+ if (!d.rounds.length) {
2437
+ sec.appendChild(emptyBox('还没有任何进展记录', '这一轮是第一轮。填完之后,下次导出会在这里看到它。'));
2438
+ return sec;
2439
+ }
2440
+ for (var i = 0; i < d.rounds.length; i += 1) {
2441
+ var round = at(d.rounds, i);
2442
+ var row = el('div', 'rp-round');
2443
+ var gut = el('div', 'rp-roundgut');
2444
+ var seq = el('div', 'rp-seq');
2445
+ setText(seq, round.seq === '' ? '—' : '#' + round.seq);
2446
+ gut.appendChild(seq);
2447
+ if (round.date !== '') {
2448
+ var date = el('div', 'rp-date');
2449
+ setText(date, round.date);
2450
+ gut.appendChild(date);
2451
+ }
2452
+ row.appendChild(gut);
2453
+ var content = el('div', 'rp-roundc');
2454
+ var tagrow = el('div', 'rp-tagrow');
2455
+ if (round.type !== '') {
2456
+ var t = el('span', 'rp-tag');
2457
+ setText(t, round.type);
2458
+ tagrow.appendChild(t);
2459
+ }
2460
+ if (round.change !== '') {
2461
+ var c = el('span', 'rp-tag is-acc');
2462
+ setText(c, round.change);
2463
+ tagrow.appendChild(c);
2464
+ }
2465
+ tagrow.appendChild(el('i', 'rp-fill'));
2466
+ if (round.completion !== '') {
2467
+ var pct = el('span', 'rp-pct');
2468
+ setText(pct, '完成度 ' + round.completion);
2469
+ tagrow.appendChild(pct);
2470
+ }
2471
+ content.appendChild(tagrow);
2472
+ if (round.actual !== '') {
2473
+ var p = el('p', '');
2474
+ setText(p, round.actual);
2475
+ content.appendChild(p);
2476
+ }
2477
+ var foot = el('div', 'rp-roundf');
2478
+ var bits = [];
2479
+ if (round.ids !== '')
2480
+ bits.push(['ids', round.ids]);
2481
+ if (round.evidenceCount > 0)
2482
+ bits.push(['', '证据 ' + round.evidenceCount + ' 条']);
2483
+ if (round.customer !== '')
2484
+ bits.push(['', round.customer]);
2485
+ for (var b = 0; b < bits.length; b += 1) {
2486
+ if (b > 0)
2487
+ foot.appendChild(el('i', ''));
2488
+ var node = el('span', at(bits, b)[0] === 'ids' ? 'rp-ids' : '');
2489
+ setText(node, at(bits, b)[1]);
2490
+ foot.appendChild(node);
2491
+ }
2492
+ if (foot.childNodes.length)
2493
+ content.appendChild(foot);
2494
+ row.appendChild(content);
2495
+ sec.appendChild(row);
1869
2496
  }
1870
- body.appendChild(list);
1871
- if (skipped.length) {
1872
- var skipHeading = el('h3', '');
1873
- setText(skipHeading, '未填写、不会包含');
1874
- body.appendChild(skipHeading);
1875
- var skipList = el('ul', 'rp-preview-list');
1876
- for (var s = 0; s < skipped.length; s += 1) {
1877
- var skipItem = el('li', '');
1878
- var skipName = at(skipped, s).input ? (at(skipped, s).input.name || at(skipped, s).input.pocId) : '未命名项目';
1879
- setText(skipItem, skipName || '未命名项目');
1880
- skipList.appendChild(skipItem);
1881
- }
1882
- body.appendChild(skipList);
1883
- }
1884
- var noteHeading = el('h3', '');
1885
- setText(noteHeading, '怎么交回');
1886
- var note = el('p', 'rp-preview-dim');
1887
- addText(note, '点「生成回传文件」下载一个只读 HTML,通过企业微信发给发起人。文件里的数据只用于 DSH 校验后合并,不会执行任何代码。');
1888
- body.appendChild(noteHeading);
1889
- body.appendChild(note);
2497
+ return sec;
2498
+ }
2499
+ function renderDossierGaps() {
2500
+ var d = dossier;
2501
+ var sec = el('section', '');
2502
+ sec.appendChild(dossierSectionHead('04', '现在卡在哪', '台账派生 · 只读'));
2503
+ var row = el('div', 'rp-cards4');
2504
+ var gaps = d.gaps;
2505
+ var skills = [
2506
+ ['阶段停留', gaps.stalledDays === null ? '—' : String(gaps.stalledDays), '天', gaps.stalled ? '超过 14 天提醒线' : '正常', gaps.stalled ? 'rp-t-flag' : 'rp-t-mute'],
2507
+ ['立项缺口', String(gaps.g0Missing), '项', gaps.g0Missing ? 'G0 论证还有空项' : '五项已齐', gaps.g0Missing ? 'rp-t-flag' : 'rp-t-mute'],
2508
+ ['未验证指标', String(gaps.unverifiedCriteria), '条', gaps.unverifiedCriteria ? '尚无证据支撑' : '全部已有结论', gaps.unverifiedCriteria ? 'rp-t-stop' : 'rp-t-mute'],
2509
+ ['下轮计划', String(gaps.pendingPlans), '条', gaps.pendingPlans ? '下次会逐项对照' : '暂无待办', 'rp-t-mute'],
2510
+ ];
2511
+ for (var i = 0; i < skills.length; i += 1) {
2512
+ var spec = at(skills, i);
2513
+ var card = el('div', 'rp-card4');
2514
+ var dt = el('dt', '');
2515
+ setText(dt, at(spec, 0));
2516
+ card.appendChild(dt);
2517
+ var v = el('div', 'rp-v');
2518
+ var b = el('b', at(spec, 4));
2519
+ setText(b, at(spec, 1));
2520
+ v.appendChild(b);
2521
+ var unit = el('span', '');
2522
+ setText(unit, at(spec, 2));
2523
+ v.appendChild(unit);
2524
+ card.appendChild(v);
2525
+ var n = el('div', 'rp-n');
2526
+ setText(n, at(spec, 3));
2527
+ card.appendChild(n);
2528
+ row.appendChild(card);
2529
+ }
2530
+ sec.appendChild(row);
2531
+ return sec;
2532
+ }
2533
+ function renderDossierOutcome() {
2534
+ var d = dossier;
2535
+ var sec = el('section', '');
2536
+ var entered = d.outcome.achievement !== '' || d.outcome.overall !== '' || d.outcome.proved !== '';
2537
+ sec.appendChild(dossierSectionHead('05', '结果与结论', entered ? 'G4 · 已记录' : 'G4 · 尚未进入'));
2538
+ if (!entered) {
2539
+ sec.appendChild(emptyBox('项目尚未进入结果转化阶段', '证明了什么、客户认可什么、下一步生意动作,都在 G4 才产生。'));
2540
+ return sec;
2541
+ }
2542
+ var dl = el('dl', '');
2543
+ dl.appendChild(dossierArg('我们证明了什么', d.outcome.proved));
2544
+ dl.appendChild(dossierArg('客户认可什么', d.outcome.recognized));
2545
+ dl.appendChild(dossierArg('下一步生意动作', d.outcome.nextBusiness));
2546
+ dl.appendChild(dossierArg('整体结论', d.outcome.overall === '' ? d.outcome.achievement : d.outcome.overall));
2547
+ sec.appendChild(dl);
2548
+ return sec;
1890
2549
  }
2550
+ function emptyBox(title, sub) {
2551
+ var box = el('div', 'rp-emptybox');
2552
+ box.appendChild(svgIcon('target', 20));
2553
+ var b = el('b', '');
2554
+ setText(b, title);
2555
+ box.appendChild(b);
2556
+ var s = el('span', '');
2557
+ setText(s, sub);
2558
+ box.appendChild(s);
2559
+ return box;
2560
+ }
2561
+ function renderDossier() {
2562
+ var wrap = el('div', '');
2563
+ wrap.appendChild(dossierHead());
2564
+ wrap.appendChild(renderDossierG0());
2565
+ wrap.appendChild(renderDossierPlan());
2566
+ wrap.appendChild(renderDossierRounds());
2567
+ wrap.appendChild(renderDossierGaps());
2568
+ wrap.appendChild(renderDossierOutcome());
2569
+ var foot = el('p', 'rp-pfoot');
2570
+ setText(foot, '档案是快照,不会随你的填写改变。要修改项目事实,请回第一页填写,或在台账里补。');
2571
+ wrap.appendChild(foot);
2572
+ return wrap;
2573
+ }
2574
+ // -------------------------------------------------------------------------
2575
+ // Footer bar
2576
+ // -------------------------------------------------------------------------
1891
2577
  function renderBar() {
1892
2578
  var bar = el('footer', 'rp-bar');
1893
- var inner = el('div', 'rp-bar-in');
1894
- var status = el('span', 'rp-state');
1895
- status.id = 'rp-state';
1896
- status.setAttribute('role', 'status');
1897
- status.setAttribute('aria-live', 'polite');
1898
- inner.appendChild(status);
1899
- var actions = el('div', 'rp-bar-actions');
1900
- var preview = el('button', 'rp-btn');
2579
+ var left = el('div', 'rp-bar-l');
2580
+ var ring = el('div', 'rp-ring');
2581
+ ring.id = 'rp-ring';
2582
+ var num = el('i', '');
2583
+ num.id = 'rp-ringnum';
2584
+ ring.appendChild(num);
2585
+ left.appendChild(ring);
2586
+ var texts = el('div', 'rp-bartxt');
2587
+ var main = el('div', 'rp-barmain');
2588
+ main.id = 'rp-barmain';
2589
+ texts.appendChild(main);
2590
+ var sub = el('div', 'rp-barsub');
2591
+ sub.id = 'rp-barsub';
2592
+ texts.appendChild(sub);
2593
+ left.appendChild(texts);
2594
+ bar.appendChild(left);
2595
+ var right = el('div', 'rp-bar-r');
2596
+ var back = el('button', 'rp-btn is-ghost');
2597
+ back.type = 'button';
2598
+ back.setAttribute('data-act', 'screen');
2599
+ back.setAttribute('data-n', '1');
2600
+ back.id = 'rp-back';
2601
+ back.hidden = true;
2602
+ setText(back, '回到第 1 页填写');
2603
+ right.appendChild(back);
2604
+ var preview = el('button', 'rp-btn is-ghost');
1901
2605
  preview.type = 'button';
1902
2606
  preview.setAttribute('data-act', 'preview');
2607
+ preview.id = 'rp-preview-btn';
1903
2608
  setText(preview, '预览');
1904
- var json = el('button', 'rp-linkbtn');
1905
- json.type = 'button';
1906
- json.setAttribute('data-act', 'json');
1907
- setText(json, '下载 JSON(备用)');
1908
- var primary = el('button', 'rp-btn rp-btn-primary');
1909
- primary.type = 'button';
1910
- primary.setAttribute('data-act', 'export');
1911
- setText(primary, '生成回传文件');
1912
- actions.appendChild(preview);
1913
- actions.appendChild(json);
1914
- actions.appendChild(primary);
1915
- inner.appendChild(actions);
1916
- bar.appendChild(inner);
1917
- app.appendChild(bar);
2609
+ right.appendChild(preview);
2610
+ var save = el('button', 'rp-btn is-solid');
2611
+ save.type = 'button';
2612
+ save.setAttribute('data-act', 'save');
2613
+ save.id = 'rp-save-btn';
2614
+ setText(save, '保存这份文件');
2615
+ right.appendChild(save);
2616
+ bar.appendChild(right);
2617
+ return bar;
1918
2618
  }
1919
2619
  function renderPage() {
1920
2620
  if (!app)
@@ -1925,127 +2625,180 @@ function reportPage() {
1925
2625
  if (notices.length)
1926
2626
  app.appendChild(renderNoticesBox());
1927
2627
  var ws = activeWorkspace();
1928
- app.appendChild(renderHeader(ws));
1929
- if (state.workspaces.length > 1)
1930
- app.appendChild(renderTabs());
1931
- app.appendChild(renderWorkspace(ws));
1932
- app.appendChild(renderPreview());
1933
- renderBar();
1934
- syncPlansUI(ws);
1935
- syncNoProgressUI(ws);
2628
+ app.appendChild(renderTopBar(ws));
2629
+ var worksheet = el('main', 'rp-screen' + (state.screen === 1 ? ' is-on' : ''));
2630
+ worksheet.id = 'rp-screen-1';
2631
+ var paper1 = el('div', 'rp-paper');
2632
+ paper1.appendChild(renderWorksheetHead(ws));
2633
+ if (ws.isNew)
2634
+ paper1.appendChild(renderNewProject(ws));
2635
+ else {
2636
+ paper1.appendChild(renderProgressSection(ws));
2637
+ paper1.appendChild(renderRoundStrip(ws));
2638
+ paper1.appendChild(renderExtraSection(ws));
2639
+ paper1.appendChild(renderPlansSection(ws, '4'));
2640
+ paper1.appendChild(renderStageNotes(ws));
2641
+ }
2642
+ worksheet.appendChild(paper1);
2643
+ app.appendChild(worksheet);
2644
+ var dossierScreen = el('main', 'rp-screen' + (state.screen === 2 ? ' is-on' : ''));
2645
+ dossierScreen.id = 'rp-screen-2';
2646
+ if (dossier !== null) {
2647
+ var paper2 = el('div', 'rp-paper');
2648
+ paper2.appendChild(renderDossier());
2649
+ dossierScreen.appendChild(paper2);
2650
+ }
2651
+ app.appendChild(dossierScreen);
2652
+ app.appendChild(renderBar());
1936
2653
  updateBar();
1937
2654
  }
1938
- // -------------------------------------------------------------------------
1939
- // UI sync helpers
1940
- // -------------------------------------------------------------------------
1941
- function syncPlansUI(ws) {
1942
- var list = app.querySelector('#rp-plans');
1943
- var addButton = app.querySelector('[data-act="add-plan"]');
1944
- var empty = app.querySelector('[data-plans-empty]');
1945
- var noneNote = app.querySelector('[data-plans-none]');
1946
- var radios = app.querySelectorAll('[data-role="plans-choice"]');
1947
- for (var i = 0; i < radios.length; i += 1) {
1948
- at(radios, i).checked = at(radios, i).value === ws.plansChoice;
1949
- var label = at(radios, i).parentNode;
1950
- if (label) {
1951
- if (at(radios, i).value === ws.plansChoice)
1952
- label.className = 'rp-choice-opt is-on';
1953
- else
1954
- label.className = 'rp-choice-opt';
1955
- }
1956
- }
1957
- var has = ws.plansChoice === 'has';
1958
- var none = ws.plansChoice === 'none';
1959
- if (list)
1960
- list.hidden = !has;
1961
- if (addButton)
1962
- addButton.hidden = !has;
1963
- if (empty)
1964
- empty.hidden = !has || ws.plans.length > 0;
1965
- if (noneNote)
1966
- noneNote.hidden = !none;
1967
- }
1968
- function syncNoProgressUI(ws) {
1969
- var checkbox = app.querySelector('[data-role="no-progress"]');
1970
- if (checkbox) {
1971
- checkbox.checked = ws.noProgress;
1972
- var label = checkbox.parentNode;
1973
- if (label)
1974
- label.className = ws.noProgress ? 'rp-check is-on' : 'rp-check';
1975
- }
1976
- var change = app.querySelector('[data-role="round"][data-field="change"]');
1977
- if (change) {
1978
- change.disabled = ws.noProgress;
1979
- change.value = ws.noProgress ? '无实质进展' : ws.roundChange;
1980
- }
1981
- }
1982
- function updateTabsUI() {
1983
- for (var i = 0; i < state.workspaces.length; i += 1) {
1984
- var tab = app.querySelector('[data-tab="' + i + '"]');
1985
- if (!tab)
1986
- continue;
1987
- var dot = tab.querySelector('.rp-tab-dot');
1988
- if (dot)
1989
- dot.setAttribute('data-filled', touched(at(state.workspaces, i)) ? 'true' : 'false');
1990
- }
1991
- }
1992
- function barMessage() {
2655
+ function setScreen(next) {
2656
+ if (next === state.screen)
2657
+ return;
2658
+ if (next === 2 && dossier === null)
2659
+ return;
2660
+ state.screen = next;
2661
+ var s1 = app.querySelector('#rp-screen-1');
2662
+ var s2 = app.querySelector('#rp-screen-2');
2663
+ if (s1)
2664
+ s1.className = 'rp-screen' + (next === 1 ? ' is-on' : '');
2665
+ if (s2)
2666
+ s2.className = 'rp-screen' + (next === 2 ? ' is-on' : '');
2667
+ var tabs = app.querySelectorAll('[data-act="screen"][role="tab"]');
2668
+ for (var i = 0; i < tabs.length; i += 1) {
2669
+ at(tabs, i).setAttribute('aria-selected', String(Number(at(tabs, i).getAttribute('data-n')) === next));
2670
+ }
2671
+ var act = app.querySelector('.rp-act');
1993
2672
  var ws = activeWorkspace();
1994
- if (!ws)
1995
- return { count: 0, first: '', special: 'empty' };
1996
- if (intent === 'progress' && !touched(ws))
1997
- return { count: 0, first: '', special: 'empty' };
1998
- var issues = validateWorkspace(ws);
1999
- if (issues.length)
2000
- return { count: issues.length, first: at(issues, 0).message, special: '' };
2001
- return { count: 0, first: '', special: 'ready' };
2673
+ setText(act, next === 1 ? (ws.isNew ? '登记立项' : '记录进展') : '项目档案');
2674
+ updateBar();
2675
+ if (typeof win.scrollTo === 'function') {
2676
+ try {
2677
+ win.scrollTo({ top: 0, behavior: 'smooth' });
2678
+ }
2679
+ catch (error) {
2680
+ win.scrollTo(0, 0);
2681
+ }
2682
+ }
2002
2683
  }
2684
+ // -------------------------------------------------------------------------
2685
+ // Bar state
2686
+ // -------------------------------------------------------------------------
2003
2687
  function updateBar() {
2004
- var node = app ? app.querySelector('#rp-state') : null;
2005
- if (!node)
2688
+ var ring = app ? app.querySelector('#rp-ring') : null;
2689
+ var main = app ? app.querySelector('#rp-barmain') : null;
2690
+ var sub = app ? app.querySelector('#rp-barsub') : null;
2691
+ if (!ring || !main || !sub)
2006
2692
  return;
2007
- clearNode(node);
2008
- var ready = barMessage();
2009
- if (justExported) {
2010
- var ok = el('span', 'rp-ok');
2011
- setText(ok, '已生成回传文件;再次下载内容相同');
2012
- node.appendChild(ok);
2693
+ var ws = activeWorkspace();
2694
+ var onDossier = state.screen === 2;
2695
+ var back = app.querySelector('#rp-back');
2696
+ var previewBtn = app.querySelector('#rp-preview-btn');
2697
+ var saveBtn = app.querySelector('#rp-save-btn');
2698
+ if (back)
2699
+ back.hidden = !onDossier;
2700
+ if (previewBtn)
2701
+ previewBtn.hidden = onDossier;
2702
+ if (saveBtn)
2703
+ saveBtn.hidden = onDossier;
2704
+ var issues = validateWorkspace(ws);
2705
+ // `validateWorkspace` returns no issues for an untouched progress form: it
2706
+ // has nothing to complain about yet. That is right for validation and wrong
2707
+ // for the ring, which would then read 100% on an empty page. An untouched
2708
+ // form counts as zero progress.
2709
+ var untouched = intent === 'progress' && !ws.isNew && !touched(ws);
2710
+ var total = requiredCount(ws);
2711
+ var filled = untouched ? 0 : Math.max(0, total - issues.length);
2712
+ var complete = total > 0 ? filled >= total : true;
2713
+ var pct = untouched || total === 0 ? (untouched ? 0 : 100) : Math.round((filled / total) * 100);
2714
+ ring.style.setProperty('--p', String(pct));
2715
+ ring.className = 'rp-ring' + (complete && !untouched ? ' is-done' : '');
2716
+ var num = app.querySelector('#rp-ringnum');
2717
+ setText(num, complete && !untouched ? '✓' : String(filled));
2718
+ if (onDossier) {
2719
+ setText(main, '正在查看项目档案(只读)');
2720
+ main.style.color = '#F2F6F3';
2721
+ setText(sub, '所有修改都在第 1 页;这一页的内容不会随填写改变');
2013
2722
  return;
2014
2723
  }
2015
- if (ready.special === 'empty') {
2016
- setText(node, '请先填写本轮事实,或明确标记本轮无实质进展。');
2724
+ // An untouched progress form is valid but empty: saying "可以保存了" there
2725
+ // would be true of the validator and false of the situation.
2726
+ if (untouched) {
2727
+ setText(main, '请先填写本轮进展');
2728
+ main.style.color = '#F2F6F3';
2729
+ setText(sub, '至少填一条实际结果;什么也没发生就勾选「本轮无实质进展」');
2017
2730
  return;
2018
2731
  }
2019
- if (ready.count) {
2020
- var strong = el('b', '');
2021
- setText(strong, ready.count + ' 项待补');
2022
- node.appendChild(strong);
2023
- addText(node, ':' + ready.first);
2732
+ if (issues.length === 0) {
2733
+ setText(main, '可以保存了');
2734
+ main.style.color = '#8EE2B8';
2735
+ setText(sub, justExported ? '已保存;把这份文件发回即可' : '保存后这份文件就带着本轮内容,发回即可');
2024
2736
  return;
2025
2737
  }
2026
- var okNode = el('span', 'rp-ok');
2027
- setText(okNode, intent === 'new' ? '必填项已齐,可以生成回传文件(第一轮进展为选填)' : '可以生成回传文件');
2028
- node.appendChild(okNode);
2738
+ setText(main, '还差 ' + issues.length + ' 项才能保存');
2739
+ main.style.color = '#F2F6F3';
2740
+ var parts = [];
2741
+ for (var i = 0; i < issues.length && parts.length < 2; i += 1)
2742
+ parts.push(at(issues, i).message);
2743
+ setText(sub, parts.join(' · ') + (issues.length > 2 ? ' 等' : ''));
2744
+ }
2745
+ /**
2746
+ * How many required facts this workspace has.
2747
+ *
2748
+ * Used only for the progress ring. It mirrors `validateWorkspace`: the ring is
2749
+ * "how much of what must be filled is filled", so it counts the same fields the
2750
+ * validator checks rather than every input on the page.
2751
+ */
2752
+ function requiredCount(ws) {
2753
+ // The denominator has to be the number of facts the validator will demand, or
2754
+ // the ring and the "还差 N 项" message disagree. Every term here has exactly
2755
+ // one matching issue in `validateWorkspace`.
2756
+ if (ws.isNew) {
2757
+ var n = 4; // pocId, name, owner, company
2758
+ n += 1; // techOwner, one of the five G0 prerequisites
2759
+ var g0 = ['whyCustomer', 'whyUs', 'decisionChain', 'postPocDecision'];
2760
+ for (var i = 0; i < g0.length; i += 1)
2761
+ n += 1;
2762
+ if (newRoundPresent(ws)) {
2763
+ n += 3; // date, type, change
2764
+ n += 1; // the plan choice
2765
+ if (ws.plansChoice === 'has')
2766
+ n += ws.plans.length * 3;
2767
+ }
2768
+ return Math.max(n, 1);
2769
+ }
2770
+ // One line per previous plan, plus date / type / change, plus the choice.
2771
+ var total = ws.lines.length + 3 + 1;
2772
+ if (ws.plansChoice === 'has')
2773
+ total += ws.plans.length * 3;
2774
+ return Math.max(total, 1);
2029
2775
  }
2030
2776
  function updateBarSoon() {
2031
2777
  if (barTimer)
2032
2778
  win.clearTimeout(barTimer);
2033
2779
  barTimer = win.setTimeout(updateBar, 120);
2034
2780
  }
2781
+ // -------------------------------------------------------------------------
2782
+ // Error marking
2783
+ // -------------------------------------------------------------------------
2784
+ /** Clear one field's error state, by the wrapper the issue path registered. */
2035
2785
  function clearFieldError(target) {
2036
- var field = target;
2037
- while (field && field !== app) {
2038
- if (field.nodeType === 1 && field.className && String(field.className).indexOf('rp-f') >= 0) {
2039
- field.className = String(field.className).replace(/\s*is-error\b/g, '');
2040
- var invalid = field.querySelectorAll('input,textarea,select');
2786
+ if (!target)
2787
+ return;
2788
+ var node = target;
2789
+ while (node && node !== app) {
2790
+ var cls = String(node.className || '');
2791
+ if (cls.indexOf('rp-f') >= 0 || cls.indexOf('rp-box') >= 0 || cls.indexOf('rp-select') >= 0) {
2792
+ node.className = cls.replace(/\s*is-error\b/g, '');
2793
+ var invalid = node.querySelectorAll('input,textarea,select');
2041
2794
  for (var i = 0; i < invalid.length; i += 1)
2042
2795
  at(invalid, i).removeAttribute('aria-invalid');
2043
- var err = field.querySelector('.rp-err');
2796
+ var err = node.querySelector('.rp-err');
2044
2797
  if (err)
2045
2798
  err.textContent = '';
2046
- break;
2799
+ return;
2047
2800
  }
2048
- field = field.parentNode;
2801
+ node = node.parentNode;
2049
2802
  }
2050
2803
  }
2051
2804
  function clearAllErrors() {
@@ -2054,9 +2807,7 @@ function reportPage() {
2054
2807
  var marked = app.querySelectorAll('.is-error');
2055
2808
  for (var i = 0; i < marked.length; i += 1) {
2056
2809
  var node = at(marked, i);
2057
- node.className = String(node.className).replace(/\s*is-error\b/g, '');
2058
- if (node.className === '')
2059
- node.removeAttribute('class');
2810
+ node.className = String(node.className).replace(/\s*is-error\b/g, '').trim();
2060
2811
  }
2061
2812
  var invalid = app.querySelectorAll('[aria-invalid]');
2062
2813
  for (var j = 0; j < invalid.length; j += 1)
@@ -2064,49 +2815,63 @@ function reportPage() {
2064
2815
  var errors = app.querySelectorAll('.rp-err');
2065
2816
  for (var k = 0; k < errors.length; k += 1)
2066
2817
  at(errors, k).textContent = '';
2067
- var planList = app.querySelector('#rp-plans');
2068
- if (planList)
2069
- planList.className = 'rp-plan-list';
2070
2818
  }
2819
+ /** Paint one issue onto its field, opening whatever hides it. */
2071
2820
  function markIssue(issue) {
2072
2821
  var ref = at(fieldRefs, issue.path);
2073
2822
  if (!ref)
2074
2823
  return;
2075
- var isField = ref.className && String(ref.className).indexOf('rp-f') >= 0;
2076
- if (isField) {
2824
+ var cls = String(ref.className || '');
2825
+ var box = ref.querySelector('.rp-box') || ref;
2826
+ if (cls.indexOf('rp-choice') >= 0) {
2077
2827
  ref.className = String(ref.className) + ' is-error';
2078
- var inputs = ref.querySelectorAll('input,textarea,select');
2079
- for (var i = 0; i < inputs.length; i += 1)
2080
- at(inputs, i).setAttribute('aria-invalid', 'true');
2081
- var err = ref.querySelector('.rp-err');
2082
- if (err)
2083
- err.textContent = issue.message;
2084
- var details = ref.parentNode;
2085
- while (details && details !== app) {
2086
- if (details.tagName === 'DETAILS') {
2087
- details.open = true;
2088
- break;
2089
- }
2090
- details = details.parentNode;
2091
- }
2092
- var evList = ref.parentNode && ref.parentNode.className && String(ref.parentNode.className).indexOf('rp-ev-list') >= 0 ? ref.parentNode : null;
2093
- if (evList) {
2094
- evList.setAttribute('data-open', 'true');
2095
- var evToggle = evList.previousSibling ? evList.previousSibling.querySelector('[data-act="ev-toggle"]') : null;
2096
- if (evToggle)
2097
- evToggle.setAttribute('aria-expanded', 'true');
2098
- }
2828
+ return;
2829
+ }
2830
+ if (cls.indexOf('rp-select') >= 0) {
2831
+ box.className = String(box.className) + ' is-error';
2832
+ }
2833
+ else if (box !== ref) {
2834
+ box.className = String(box.className) + ' is-error';
2099
2835
  }
2100
2836
  else {
2101
2837
  ref.className = String(ref.className) + ' is-error';
2102
- ref.textContent = issue.message;
2103
2838
  }
2839
+ var inputs = ref.querySelectorAll('input,textarea,select');
2840
+ for (var i = 0; i < inputs.length; i += 1)
2841
+ at(inputs, i).setAttribute('aria-invalid', 'true');
2842
+ var err = ref.querySelector('.rp-err');
2843
+ if (err)
2844
+ err.textContent = issue.message;
2104
2845
  }
2846
+ /**
2847
+ * Mark every issue, open the accordions that hide them, and scroll to the first.
2848
+ *
2849
+ * A collapsed line hides its own `actual` field, so a failure there would be
2850
+ * reported on a field the colleague cannot see. Expanding the container is part
2851
+ * of showing the error, not a nicety.
2852
+ */
2105
2853
  function applyIssues(issues) {
2106
2854
  clearAllErrors();
2107
- for (var i = 0; i < issues.length; i += 1)
2855
+ var ws = activeWorkspace();
2856
+ var expanded = false;
2857
+ for (var i = 0; i < issues.length; i += 1) {
2858
+ var path = at(issues, i).path;
2859
+ if (path.indexOf('line:') === 0) {
2860
+ var pieces = path.split(':');
2861
+ var key = at(pieces, 1);
2862
+ if (key && ws.openLines[key] !== true) {
2863
+ ws.openLines[key] = true;
2864
+ expanded = true;
2865
+ }
2866
+ }
2108
2867
  markIssue(at(issues, i));
2109
- var first = app.querySelector('.rp-f.is-error') || app.querySelector('.rp-err.is-error');
2868
+ }
2869
+ if (expanded) {
2870
+ renderPage();
2871
+ for (var j = 0; j < issues.length; j += 1)
2872
+ markIssue(at(issues, j));
2873
+ }
2874
+ var first = app.querySelector('.is-error');
2110
2875
  if (first) {
2111
2876
  if (typeof first.scrollIntoView === 'function') {
2112
2877
  try {
@@ -2165,22 +2930,25 @@ function reportPage() {
2165
2930
  function validateLines(ws, issues) {
2166
2931
  for (var i = 0; i < ws.lines.length; i += 1) {
2167
2932
  var line = at(ws.lines, i);
2168
- var number = i + 1;
2933
+ // Name the item by its own goal rather than by an array position: the
2934
+ // screen shows a plan's title, not "第 2 项", so an index would send the
2935
+ // reader counting rows to find the field the message is about.
2936
+ var label = trim(line.title) === '' ? '这条计划外进展' : '「' + trim(line.title) + '」';
2169
2937
  if (line.editableTitle && trim(line.title) === '') {
2170
- issues.push({ path: 'line:' + line.key + ':title', message: '第 ' + number + ' 项:请填写计划外工作的名称' });
2938
+ issues.push({ path: 'line:' + line.key + ':title', message: '计划外进展:请填写它做了什么' });
2171
2939
  }
2172
2940
  if (trim(line.status) === '') {
2173
- issues.push({ path: 'line:' + line.key + ':status', message: '第 ' + number + ' 项:请选择完成情况' });
2941
+ issues.push({ path: 'line:' + line.key + ':status', message: label + ':请选择完成情况' });
2174
2942
  }
2175
2943
  if (trim(line.actual) === '') {
2176
- issues.push({ path: 'line:' + line.key + ':actual', message: '第 ' + number + ' 项:请填写实际做到什么' });
2944
+ issues.push({ path: 'line:' + line.key + ':actual', message: label + ':请填写实际做到什么' });
2177
2945
  }
2178
2946
  for (var e = 0; e < line.evidence.length; e += 1) {
2179
2947
  var ev = at(line.evidence, e);
2180
2948
  if (evidenceHasContent(ev) && trim(ev.title) === '') {
2181
2949
  issues.push({
2182
2950
  path: 'line:' + line.key + ':evidence:' + ev.key + ':title',
2183
- message: '第 ' + number + ' 项第 ' + (e + 1) + ' 条证据:请填写证据名称',
2951
+ message: label + ':第 ' + (e + 1) + ' 条证据还没填名称',
2184
2952
  });
2185
2953
  }
2186
2954
  }
@@ -2199,21 +2967,22 @@ function reportPage() {
2199
2967
  }
2200
2968
  for (var i = 0; i < ws.plans.length; i += 1) {
2201
2969
  var plan = at(ws.plans, i);
2202
- var number = i + 1;
2203
- if (trim(plan.goal) === '') {
2204
- issues.push({ path: 'plan:' + plan.key + ':goal', message: '第 ' + number + ' 条计划:请填写要做什么' });
2970
+ var goal = trim(plan.goal);
2971
+ var name = goal === '' ? '下轮计划第 ' + (i + 1) + ' 条' : '「' + goal + '」';
2972
+ if (goal === '') {
2973
+ issues.push({ path: 'plan:' + plan.key + ':goal', message: '下轮计划第 ' + (i + 1) + ' 条:请填写要做什么' });
2205
2974
  }
2206
- else if (trim(plan.goal).length > 500) {
2207
- issues.push({ path: 'plan:' + plan.key + ':goal', message: '第 ' + number + ' 条计划:目标不能超过 500 字' });
2975
+ else if (goal.length > 500) {
2976
+ issues.push({ path: 'plan:' + plan.key + ':goal', message: '下轮计划目标不能超过 500 字' });
2208
2977
  }
2209
2978
  if (trim(plan.owner) === '') {
2210
- issues.push({ path: 'plan:' + plan.key + ':owner', message: '第 ' + number + ' 条计划:请填写负责人' });
2979
+ issues.push({ path: 'plan:' + plan.key + ':owner', message: name + ':请填写负责人' });
2211
2980
  }
2212
2981
  if (trim(plan.deadline) === '') {
2213
- issues.push({ path: 'plan:' + plan.key + ':deadline', message: '第 ' + number + ' 条计划:请选择截止日期' });
2982
+ issues.push({ path: 'plan:' + plan.key + ':deadline', message: name + ':请选择截止日期' });
2214
2983
  }
2215
2984
  else if (!isCalendarDate(trim(plan.deadline))) {
2216
- issues.push({ path: 'plan:' + plan.key + ':deadline', message: '第 ' + number + ' 条计划:截止日期格式不对' });
2985
+ issues.push({ path: 'plan:' + plan.key + ':deadline', message: name + ':截止日期格式不对' });
2217
2986
  }
2218
2987
  }
2219
2988
  }
@@ -2512,295 +3281,99 @@ function reportPage() {
2512
3281
  css += txt(at(styles, i).textContent);
2513
3282
  return css;
2514
3283
  }
2515
- /** A tiny fallback so the receipt stays legible even if the page carried no stylesheet. */
2516
- var FALLBACK_RECEIPT_CSS = 'body{font-family:-apple-system,"PingFang SC",sans-serif;line-height:1.6;margin:0;padding:24px;background:#f5f7fb;color:#192638}.rp-rec-shell{max-width:820px;margin:0 auto}.rp-rec-card{background:#fff;border:1px solid #e6ebf2;border-radius:10px;padding:18px 20px;margin:14px 0}.rp-rec-pair{display:grid;grid-template-columns:132px 1fr;gap:12px;padding:6px 0;border-top:1px dashed #e6ebf2}.rp-rec-pair dt{color:#7a8aa0}.rp-rec-pair dd{margin:0;white-space:pre-wrap}.rp-rec-note{background:#eef3ff;padding:10px 14px;border-radius:8px;margin-bottom:14px}.rp-rec-lines{list-style:none;padding:0}.rp-rec-lines>li{background:#f7f9fc;padding:9px 11px;border-radius:8px;margin:8px 0}.rp-rec-status{font-size:12px;background:#eef;padding:1px 7px;border-radius:4px;margin-left:8px}.rp-rec-plans{list-style:none;padding:0}.rp-rec-more,.rp-rec-dim{color:#7a8aa0;font-size:12px}';
2517
- function rawFor(pocId) {
2518
- for (var i = 0; i < projectInputs.length; i += 1) {
2519
- if (at(projectInputs, i).pocId === pocId)
2520
- return at(projectInputs, i);
2521
- }
2522
- return null;
2523
- }
2524
- function scenarioNames(raw, ids) {
2525
- var names = [];
2526
- for (var i = 0; i < ids.length; i += 1) {
2527
- var found = '';
2528
- if (raw) {
2529
- for (var j = 0; j < raw.scenarios.length; j += 1) {
2530
- if (at(raw.scenarios, j).id === at(ids, i)) {
2531
- found = at(raw.scenarios, j).name;
2532
- break;
2533
- }
2534
- }
2535
- }
2536
- names.push(found || at(ids, i));
2537
- }
2538
- return names.join('、');
2539
- }
2540
- function criteriaNames(raw, ids) {
2541
- var names = [];
2542
- for (var i = 0; i < ids.length; i += 1) {
2543
- var found = '';
2544
- if (raw) {
2545
- for (var j = 0; j < raw.criteria.length; j += 1) {
2546
- if (at(raw.criteria, j).id === at(ids, i)) {
2547
- found = at(raw.criteria, j).name;
2548
- break;
2549
- }
2550
- }
2551
- }
2552
- names.push(found || at(ids, i));
2553
- }
2554
- return names.join('、');
2555
- }
2556
- function recPairs(pairs) {
2557
- var out = '';
2558
- for (var i = 0; i < pairs.length; i += 1) {
2559
- var label = at(pairs, i)[0];
2560
- var value = at(pairs, i)[1];
2561
- if (value === null || value === undefined || txt(value) === '')
2562
- continue;
2563
- out += '<div class="rp-rec-pair"><dt>' + escapeHtml(label) + '</dt><dd>' + escapeHtml(value) + '</dd></div>';
2564
- }
2565
- if (out === '')
2566
- return '';
2567
- return '<dl>' + out + '</dl>';
2568
- }
2569
- function recSection(title, pairs) {
2570
- var body = recPairs(pairs);
2571
- if (body === '')
2572
- return '';
2573
- return '<div class="rp-rec-sec"><h2>' + escapeHtml(title) + '</h2>' + body + '</div>';
3284
+ // -------------------------------------------------------------------------
3285
+ // Export flow
3286
+ // -------------------------------------------------------------------------
3287
+ function setExporting(active) {
3288
+ exporting = active;
3289
+ var button = app ? app.querySelector('[data-act="save"]') : null;
3290
+ if (!button)
3291
+ return;
3292
+ button.disabled = active;
3293
+ setText(button, active ? '保存中…' : '保存');
2574
3294
  }
2575
- function recRoundBlock(round, raw, heading, isNew) {
2576
- if (!round)
2577
- return '';
2578
- var out = '';
2579
- out += '<div class="rp-rec-sec rp-rec-new"><h2>' + escapeHtml(heading) + '<span class="rp-rec-tag">新</span></h2>';
2580
- out += recPairs([
2581
- ['日期', round.date],
2582
- ['类型', round.type],
2583
- ['这一次什么变了', round.change],
2584
- ]);
2585
- var lines = Array.isArray(round.lines) ? round.lines : [];
2586
- if (lines.length) {
2587
- out += '<h3>本轮工作项</h3><ul class="rp-rec-lines">';
2588
- for (var i = 0; i < lines.length; i += 1) {
2589
- var line = at(lines, i);
2590
- out += '<li>';
2591
- out += '<div class="rp-rec-line-head"><span class="rp-rec-line-title">' + escapeHtml(line.title) + '</span>';
2592
- out += '<span class="rp-rec-status" data-status="' + escapeHtml(statusTone(txt(line.status))) + '">' + escapeHtml(line.status) + '</span></div>';
2593
- out += '<p class="rp-rec-actual">' + escapeHtml(line.actual) + '</p>';
2594
- var evidence = Array.isArray(line.evidence) ? line.evidence : [];
2595
- if (evidence.length) {
2596
- var pieces = [];
2597
- for (var e = 0; e < evidence.length; e += 1) {
2598
- var piece = txt(at(evidence, e).title);
2599
- if (txt(at(evidence, e).type) !== '')
2600
- piece += '(' + txt(at(evidence, e).type) + ')';
2601
- if (txt(at(evidence, e).link) !== '')
2602
- piece += ' · ' + txt(at(evidence, e).link);
2603
- pieces.push(piece);
2604
- }
2605
- out += '<p class="rp-rec-more">证据:' + escapeHtml(pieces.join(';')) + '</p>';
2606
- }
2607
- var customer = line.customer || {};
2608
- var customerBits = [];
2609
- if (txt(customer.synced_with) !== '')
2610
- customerBits.push('同步对象:' + txt(customer.synced_with));
2611
- if (txt(customer.feedback) !== '')
2612
- customerBits.push('客户反馈:' + txt(customer.feedback));
2613
- if (customerBits.length)
2614
- out += '<p class="rp-rec-more">' + escapeHtml(customerBits.join(';')) + '</p>';
2615
- var refBits = [];
2616
- if (Array.isArray(line.scenario_ids) && line.scenario_ids.length)
2617
- refBits.push('场景:' + scenarioNames(raw, line.scenario_ids));
2618
- if (Array.isArray(line.criteria_ids) && line.criteria_ids.length)
2619
- refBits.push('指标:' + criteriaNames(raw, line.criteria_ids));
2620
- if (txt(line.completion) !== '')
2621
- refBits.push('完成度:' + txt(line.completion));
2622
- if (refBits.length)
2623
- out += '<p class="rp-rec-more">' + escapeHtml(refBits.join(' · ')) + '</p>';
2624
- out += '</li>';
2625
- }
2626
- out += '</ul>';
2627
- }
2628
- else if (txt(round.change) === '无实质进展') {
2629
- out += '<p class="rp-rec-dim">本轮已明确:没有实质进展。</p>';
2630
- }
2631
- else {
2632
- out += '<p class="rp-rec-dim">本轮只登记了下一步计划,没有逐项反馈的工作项。</p>';
2633
- }
2634
- var plans = Array.isArray(round.next_plans) ? round.next_plans : [];
2635
- out += '<h3>下一步计划</h3>';
2636
- if (plans.length) {
2637
- out += '<ul class="rp-rec-plans">';
2638
- for (var p = 0; p < plans.length; p += 1) {
2639
- var plan = at(plans, p);
2640
- var meta = [];
2641
- if (txt(plan.owner) !== '')
2642
- meta.push(txt(plan.owner));
2643
- if (txt(plan.deadline) !== '')
2644
- meta.push('截止 ' + txt(plan.deadline));
2645
- out += '<li>' + escapeHtml(plan.goal);
2646
- if (meta.length)
2647
- out += '<span>' + escapeHtml(meta.join(' · ')) + '</span>';
2648
- out += '</li>';
2649
- }
2650
- out += '</ul>';
2651
- }
2652
- else {
2653
- out += '<p class="rp-rec-dim">已明确:暂无下一步计划。</p>';
2654
- }
2655
- var notes = Array.isArray(round.stage_notes) ? round.stage_notes : [];
2656
- if (notes.length) {
2657
- out += '<h3>其他阶段的补充事实</h3>' + recPairs(stageNotePairs(notes));
2658
- }
2659
- out += '</div>';
2660
- return out;
2661
- }
2662
- function stageNotePairs(notes) {
2663
- var pairs = [];
2664
- for (var i = 0; i < notes.length; i += 1) {
2665
- var note = at(notes, i);
2666
- pairs.push([at(STAGE_LABELS, txt(note.stage)) || txt(note.stage), note.text]);
2667
- }
2668
- return pairs;
2669
- }
2670
- function receiptChangeCard(change) {
2671
- var raw = rawFor(txt(change.poc_id));
2672
- var identity = change.identity || null;
2673
- var title = identity ? (txt(identity.name) || txt(change.poc_id)) : raw ? (raw.name || raw.pocId) : txt(change.poc_id);
2674
- var metaBits = [txt(change.poc_id)];
2675
- if (identity) {
2676
- if (txt(identity.company) !== '')
2677
- metaBits.push(txt(identity.company));
2678
- if (txt(identity.system) !== '')
2679
- metaBits.push(txt(identity.system));
2680
- if (txt(identity.owner) !== '')
2681
- metaBits.push('负责人 ' + txt(identity.owner));
2682
- }
2683
- else if (raw) {
2684
- if (raw.company !== '')
2685
- metaBits.push(raw.company);
2686
- if (raw.stage !== '')
2687
- metaBits.push(raw.stage);
2688
- if (raw.status !== '')
2689
- metaBits.push(raw.status);
2690
- if (raw.owner !== '')
2691
- metaBits.push('负责人 ' + raw.owner);
2692
- }
2693
- var out = '<article class="rp-rec-card">';
2694
- out += '<header class="rp-rec-head"><h1>' + escapeHtml(title) + '</h1>';
2695
- out += '<div class="rp-rec-meta">' + escapeHtml(metaBits.filter(function (v) { return v !== ''; }).join(' · ')) + '</div></header>';
2696
- if (identity) {
2697
- out += recSection('项目身份', [
2698
- ['项目名称', identity.name],
2699
- ['负责人(我方)', identity.owner],
2700
- ['体系', identity.system],
2701
- ['客户公司', identity.company],
2702
- ['部门', identity.department],
2703
- ['销售', identity.sales],
2704
- ['预计金额(万元)', identity.amount_wan],
2705
- ['项目类型', identity.poc_type],
2706
- ['客户技术责任人', identity.tech_owner],
2707
- ['客户业务决策人', identity.exec_sponsor],
2708
- ]);
2709
- var gate0 = change.gate0 || {};
2710
- out += recSection('Gate 0 · 值不值得做', [
2711
- ['客户为什么要测', gate0.why_customer],
2712
- ['我们为什么测', gate0.why_us],
2713
- ['项目流程 / 决策链', gate0.decision_chain],
2714
- ['测完之后客户会做什么决定', gate0.post_poc_decision],
2715
- ['主要竞争对手', gate0.competitor],
2716
- ]);
2717
- if (change.round) {
2718
- out += recRoundBlock(change.round, raw, '第一轮进展', true);
2719
- }
2720
- else {
2721
- out += '<p class="rp-rec-dim">本次为新建登记,未填写第一轮进展。</p>';
2722
- }
2723
- if (!change.round && Array.isArray(change.stage_notes) && change.stage_notes.length) {
2724
- out += '<div class="rp-rec-sec"><h2>其他阶段的补充事实</h2>' + recPairs(stageNotePairs(change.stage_notes)) + '</div>';
2725
- }
2726
- }
2727
- else {
2728
- if (change.round) {
2729
- out += recRoundBlock(change.round, raw, '本轮事实', false);
2730
- }
2731
- if (Array.isArray(change.stage_notes) && change.stage_notes.length) {
2732
- out += '<div class="rp-rec-sec"><h2>其他阶段的补充事实</h2>' + recPairs(stageNotePairs(change.stage_notes)) + '</div>';
2733
- }
2734
- }
2735
- out += '</article>';
2736
- return out;
3295
+ /** A readable file-name part; Chinese names are kept, path characters are not. */
3296
+ function safeFilePart(value) {
3297
+ var part = trim(value)
3298
+ .replace(/[\u0000-\u001f\u007f\\/:*?"<>|]/g, ' ')
3299
+ .replace(/\s+/g, ' ')
3300
+ .trim()
3301
+ .replace(/^\.+/, '')
3302
+ .trim()
3303
+ .slice(0, 32);
3304
+ return part;
3305
+ }
3306
+ /** 项目名称_负责人: the part the recipient reads in a chat list of files. */
3307
+ function fileSubject(ws) {
3308
+ var name = trim(ws.isNew ? ws.identity.name : (ws.input ? ws.input.name : ''));
3309
+ var owner = trim(ws.isNew ? ws.identity.owner : (ws.input ? ws.input.owner : ''));
3310
+ var pocId = trim(ws.isNew ? ws.identity.pocId : (ws.input ? ws.input.pocId : ''));
3311
+ var subjectName = safeFilePart(name) || safeFilePart(pocId) || '未命名项目';
3312
+ var subjectOwner = safeFilePart(owner) || '未填负责人';
3313
+ return subjectName + '_' + subjectOwner;
3314
+ }
3315
+ function savedFileName(ws) {
3316
+ var label = intent === 'new' ? '新建项目' : '记录进展';
3317
+ return fileSubject(ws) + '_' + label + '_' + today + '.html';
2737
3318
  }
2738
3319
  /**
2739
- * The closing script tag for the receipt's inert JSON block.
3320
+ * The closing script tag, built from a char code on purpose.
2740
3321
  *
2741
- * Built from a char code on purpose: bundlers constant-fold adjacent string
2742
- * literals, which would produce a literal closing script tag in THIS script and make
2743
- * the Host's own script element terminate early. Splitting it at runtime keeps
2744
- * the source of the embedded page safe no matter how the module is bundled.
3322
+ * Bundlers constant-fold adjacent string literals, which would put a literal
3323
+ * closing tag in THIS script and end the Host's own script element early.
2745
3324
  */
2746
3325
  var CLOSE_SCRIPT_TAG = '<' + String.fromCharCode(47) + 'script>';
2747
- function buildReceiptHtml(payload, included, skipped) {
3326
+ /**
3327
+ * The file handed back, which is the SAME form filled in.
3328
+ *
3329
+ * It carries three things: the stylesheet and the page script (so it opens as
3330
+ * an editable form again), the display input plus a `draft` snapshot (so the
3331
+ * colleague's own answers come back), and the inert `poc-return-data` block
3332
+ * the submission skill reads. One file replaces the earlier form + receipt
3333
+ * pair: forwarding a saved form is the whole workflow.
3334
+ */
3335
+ function buildSavedFormHtml(payload) {
2748
3336
  var css = collectCss();
2749
- if (trim(css) === '')
2750
- css = FALLBACK_RECEIPT_CSS;
2751
- var intentLabel = intent === 'new' ? '新建项目' : '记录进展';
2752
- var cards = '';
2753
- for (var i = 0; i < payload.changes.length; i += 1)
2754
- cards += receiptChangeCard(at(payload.changes, i));
2755
- var skippedNote = '';
2756
- if (skipped.length) {
2757
- var names = [];
2758
- for (var s = 0; s < skipped.length; s += 1) {
2759
- var ws = at(skipped, s);
2760
- var name = ws.input ? (ws.input.name || ws.input.pocId) : '未命名项目';
2761
- names.push(name);
2762
- }
2763
- skippedNote = '<p class="rp-rec-skip">本次未填写、未包含的项目:' + escapeHtml(names.join('、')) + '。</p>';
2764
- }
2765
- var json = scriptSafe(JSON.stringify(payload));
3337
+ var scriptNode = doc.getElementById('poc-form-script');
3338
+ var source = scriptNode ? txt(scriptNode.textContent) : '';
3339
+ if (trim(source) === '')
3340
+ throw new Error('页面里缺少表单脚本,无法保存;请重新导出表单。');
3341
+ var subject = state.workspaces.length === 1 ? fileSubject(activeWorkspace()) : '';
3342
+ var title = subject === '' ? (intent === 'new' ? '新建项目' : '记录进展') : subject;
3343
+ var input = {
3344
+ intent: intent,
3345
+ today: today,
3346
+ form_id: formId,
3347
+ exported_at: exportedAt,
3348
+ projects: inputRaw && Array.isArray(inputRaw.projects) ? inputRaw.projects : [],
3349
+ // The dossier travels with the saved file. Without it, re-opening a saved
3350
+ // form would show an empty second page — the colleague would lose the
3351
+ // project context exactly when they are correcting what they wrote.
3352
+ dossier: dossier,
3353
+ enums: inputRaw && inputRaw.enums ? inputRaw.enums : enums,
3354
+ draft: serializeState(),
3355
+ };
2766
3356
  var parts = [];
2767
3357
  parts.push('<!DOCTYPE html>');
2768
3358
  parts.push('<html lang="zh-CN">');
2769
3359
  parts.push('<head>');
2770
3360
  parts.push('<meta charset="UTF-8">');
2771
3361
  parts.push('<meta name="viewport" content="width=device-width, initial-scale=1">');
2772
- parts.push('<meta http-equiv="Content-Security-Policy" content="default-src \'none\'; style-src \'unsafe-inline\'; base-uri \'none\'">');
2773
- parts.push('<title>' + escapeHtml('POC 回传 · ' + intentLabel) + '</title>');
3362
+ parts.push('<meta http-equiv="Content-Security-Policy" content="default-src \'none\'; script-src \'unsafe-inline\'; style-src \'unsafe-inline\'; form-action \'none\'; base-uri \'none\'">');
3363
+ parts.push('<title>' + escapeHtml(title) + '</title>');
2774
3364
  parts.push('<style>' + css + '</style>');
2775
3365
  parts.push('</head>');
2776
- parts.push('<body class="rp-rec-body">');
2777
- parts.push('<div class="rp-rec-shell">');
2778
- parts.push('<div class="rp-rec-note">这是组员填写的 POC 回传文件,内容只读。把整个文件(或附带的 .json)通过企业微信发给发起人,由 DSH 校验后合并进台账;文件里的数据只用于读取,不会执行任何代码。</div>');
2779
- parts.push('<div class="rp-rec-bar"><span>' + escapeHtml(intentLabel + ' · ' + payload.changes.length + ' 个项目') + '</span><span class="rp-rec-dim">生成于 ' + escapeHtml(today) + '</span></div>');
2780
- parts.push(cards);
2781
- parts.push(skippedNote);
2782
- parts.push('</div>');
2783
- parts.push('<' + 'script type="application/json" id="poc-return-data">' + json + CLOSE_SCRIPT_TAG);
3366
+ parts.push('<body>');
3367
+ parts.push('<main id="app" class="rp-app"></main>');
3368
+ parts.push('<noscript>请用启用了 JavaScript 的浏览器打开这份文件。无需联网。</noscript>');
3369
+ parts.push('<script type="application/json" id="poc-report-input">' + scriptSafe(JSON.stringify(input)) + CLOSE_SCRIPT_TAG);
3370
+ parts.push('<' + 'script id="poc-form-script">' + source.split('</' + 'script').join('<\\/' + 'script') + CLOSE_SCRIPT_TAG);
3371
+ parts.push('<' + 'script type="application/json" id="poc-return-data">' + scriptSafe(JSON.stringify(payload)) + CLOSE_SCRIPT_TAG);
2784
3372
  parts.push('</body>');
2785
3373
  parts.push('</html>');
2786
3374
  return parts.join('\n');
2787
3375
  }
2788
- // -------------------------------------------------------------------------
2789
- // Export flow
2790
- // -------------------------------------------------------------------------
2791
- function setExporting(active) {
2792
- exporting = active;
2793
- var button = app ? app.querySelector('[data-act="export"]') : null;
2794
- if (!button)
2795
- return;
2796
- button.disabled = active;
2797
- setText(button, active ? '生成中…' : '生成回传文件');
2798
- }
2799
- function safeFilePart(value) {
2800
- var part = trim(value).replace(/[^A-Za-z0-9._-]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 60);
2801
- return part || 'poc';
2802
- }
2803
- function doExport(included, skipped, mode) {
3376
+ function doExport(included, skipped) {
2804
3377
  if (exporting)
2805
3378
  return;
2806
3379
  setExporting(true);
@@ -2808,28 +3381,11 @@ function reportPage() {
2808
3381
  for (var i = 0; i < included.length; i += 1)
2809
3382
  rotateIdsIfChanged(at(included, i));
2810
3383
  var payload = buildPayload(included);
2811
- var stamp = today.replace(/-/g, '');
2812
- var baseName = 'poc-report';
2813
- if (included.length === 1) {
2814
- var only = at(included, 0);
2815
- var label = only.isNew ? only.identity.pocId : only.input.pocId;
2816
- if (trim(label) !== '')
2817
- baseName = 'poc-return-' + safeFilePart(label);
2818
- else
2819
- baseName = 'poc-return-new';
2820
- }
2821
- else {
2822
- baseName = 'poc-return-' + included.length;
2823
- }
2824
- if (mode === 'json') {
2825
- downloadFile('poc-report-' + included.length + '-' + stamp + '.json', JSON.stringify(payload, null, 2), 'application/json');
2826
- toast('已下载 JSON(备用);转发给发起人时优先用回传文件。');
2827
- }
2828
- else {
2829
- var html = buildReceiptHtml(payload, included, skipped);
2830
- downloadFile(baseName + '-' + stamp + '.html', html, 'text/html');
2831
- toast('已生成回传文件,请通过企业微信发给发起人。');
2832
- }
3384
+ var html = buildSavedFormHtml(payload);
3385
+ var target = included.length === 1 ? at(included, 0) : activeWorkspace();
3386
+ var name = included.length === 1 ? savedFileName(target) : '记录进展_' + included.length + '个项目_' + today + '.html';
3387
+ downloadFile(name, html, 'text/html');
3388
+ toast('已保存到表单文件;把这份文件发回即可。');
2833
3389
  saveDraftNow();
2834
3390
  justExported = true;
2835
3391
  updateBar();
@@ -2839,7 +3395,7 @@ function reportPage() {
2839
3395
  updateBar();
2840
3396
  }, 900);
2841
3397
  }
2842
- function runExport(mode) {
3398
+ function runExport() {
2843
3399
  if (exporting)
2844
3400
  return;
2845
3401
  var included = [];
@@ -2851,7 +3407,7 @@ function reportPage() {
2851
3407
  skipped.push(at(state.workspaces, i));
2852
3408
  }
2853
3409
  if (!included.length) {
2854
- toast('还没有填写任何项目,先填写后再生成回传文件。');
3410
+ toast('还没有填写任何内容,先填写后再保存。');
2855
3411
  return;
2856
3412
  }
2857
3413
  var invalid = null;
@@ -2863,22 +3419,114 @@ function reportPage() {
2863
3419
  }
2864
3420
  }
2865
3421
  if (invalid) {
3422
+ // Jump to the first gap instead of showing the preview: a modal would cover
3423
+ // the field the colleague has to fill in.
2866
3424
  if (invalid.ws.index !== state.active) {
2867
3425
  state.active = invalid.ws.index;
2868
3426
  renderPage();
2869
3427
  }
2870
3428
  applyIssues(invalid.issues);
2871
3429
  updateBar();
2872
- toast('还有 ' + invalid.issues.length + ' 项待补:' + at(invalid.issues, 0).message);
3430
+ toast('还差 ' + invalid.issues.length + ' 项:' + at(invalid.issues, 0).message);
2873
3431
  return;
2874
3432
  }
2875
3433
  if (skipped.length) {
2876
- openModal(skipped, function () {
2877
- doExport(included, skipped, mode);
3434
+ openModal('confirm-skip', null, skipped, function (confirmed) {
3435
+ doExport(included, confirmed);
2878
3436
  });
2879
3437
  return;
2880
3438
  }
2881
- doExport(included, [], mode);
3439
+ doExport(included, []);
3440
+ }
3441
+ /**
3442
+ * The pre-save check: what this round will write, in words.
3443
+ *
3444
+ * The colleague is about to forward a file that becomes ledger facts, so the
3445
+ * last thing before saving is a readback rather than another form.
3446
+ */
3447
+ function openPreview() {
3448
+ var ws = activeWorkspace();
3449
+ if (!ws)
3450
+ return;
3451
+ var body = el('div', '');
3452
+ function heading(text) {
3453
+ var h = el('h3', '');
3454
+ setText(h, text);
3455
+ body.appendChild(h);
3456
+ }
3457
+ function list(rows) {
3458
+ var ul = el('ul', '');
3459
+ for (var i = 0; i < rows.length; i += 1) {
3460
+ var li = el('li', '');
3461
+ var k = el('span', 'rp-k');
3462
+ setText(k, at(rows, i)[0]);
3463
+ var v = el('span', 'rp-v');
3464
+ setText(v, at(rows, i)[1]);
3465
+ li.appendChild(k);
3466
+ li.appendChild(v);
3467
+ ul.appendChild(li);
3468
+ }
3469
+ body.appendChild(ul);
3470
+ }
3471
+ heading('本轮概况');
3472
+ list([
3473
+ ['日期', trim(ws.roundDate) || '—'],
3474
+ ['类型', trim(ws.roundType) || '—'],
3475
+ ['这一次什么变了', roundChangeOf(ws) || '—'],
3476
+ ]);
3477
+ heading(ws.isNew ? '立项信息' : '上轮计划反馈');
3478
+ if (ws.isNew) {
3479
+ list([
3480
+ ['项目编号', trim(ws.identity.pocId) || '—'],
3481
+ ['项目名称', trim(ws.identity.name) || '—'],
3482
+ ['客户公司', trim(ws.identity.company) || '—'],
3483
+ ['负责人', trim(ws.identity.owner) || '—'],
3484
+ ]);
3485
+ }
3486
+ else {
3487
+ var rows2 = [];
3488
+ for (var i = 0; i < ws.lines.length; i += 1) {
3489
+ var line = at(ws.lines, i);
3490
+ var detail = trim(line.actual) === '' ? '(未填实际结果)' : trim(line.actual);
3491
+ rows2.push([line.planId || '计划外', (line.title || '(未命名)') + ' — ' + (trim(line.status) || '未选状态') + '\n' + detail]);
3492
+ }
3493
+ if (!rows2.length)
3494
+ rows2.push(['—', '(还没有填写任何工作项)']);
3495
+ list(rows2);
3496
+ }
3497
+ heading('下一轮计划');
3498
+ if (ws.plansChoice === 'none')
3499
+ list([['—', '已明确:暂无下一步']]);
3500
+ else if (!ws.plans.length)
3501
+ list([['—', '(还没有安排计划)']]);
3502
+ else {
3503
+ var rows3 = [];
3504
+ for (var p = 0; p < ws.plans.length; p += 1) {
3505
+ var plan = at(ws.plans, p);
3506
+ rows3.push([trim(plan.owner) || '—', (trim(plan.goal) || '(未填)') + ' · 截止 ' + (trim(plan.deadline) || '—')]);
3507
+ }
3508
+ list(rows3);
3509
+ }
3510
+ var notes = [];
3511
+ for (var s = 0; s < STAGES.length; s += 1) {
3512
+ var stage = at(STAGES, s);
3513
+ var value = trim(ws.stageNotes[stage]);
3514
+ if (value !== '')
3515
+ notes.push([stage, value.slice(0, 80) + (value.length > 80 ? '…' : '')]);
3516
+ }
3517
+ if (notes.length) {
3518
+ heading('其他阶段补充事实');
3519
+ list(notes);
3520
+ }
3521
+ openModal('preview', body, [], null);
3522
+ }
3523
+ function removePlan(ws, key) {
3524
+ for (var i = 0; i < ws.plans.length; i += 1) {
3525
+ if (at(ws.plans, i).key === key) {
3526
+ ws.plans.splice(i, 1);
3527
+ return;
3528
+ }
3529
+ }
2882
3530
  }
2883
3531
  // -------------------------------------------------------------------------
2884
3532
  // Event handling
@@ -2893,13 +3541,11 @@ function reportPage() {
2893
3541
  var ws = activeWorkspace();
2894
3542
  if (!ws)
2895
3543
  return;
2896
- var handled = false;
2897
3544
  var lineKey = dataOf(target, 'line');
2898
3545
  var planKey = dataOf(target, 'plan');
2899
3546
  if (role === 'identity') {
2900
3547
  var identityField = dataOf(target, 'field');
2901
3548
  ws.identity[identityField] = target.value;
2902
- handled = true;
2903
3549
  }
2904
3550
  else if (role === 'gate0') {
2905
3551
  var gateField = dataOf(target, 'field');
@@ -2907,7 +3553,6 @@ function reportPage() {
2907
3553
  ws.identity.techOwner = target.value;
2908
3554
  else
2909
3555
  ws.gate0[gateField] = target.value;
2910
- handled = true;
2911
3556
  }
2912
3557
  else if (role === 'round') {
2913
3558
  var roundField = dataOf(target, 'field');
@@ -2917,77 +3562,62 @@ function reportPage() {
2917
3562
  ws.roundType = target.value;
2918
3563
  else if (roundField === 'change')
2919
3564
  ws.roundChange = target.value;
2920
- handled = true;
2921
3565
  }
2922
3566
  else if (role === 'stage') {
2923
3567
  var stage = dataOf(target, 'stage');
2924
- if (stage === 'G0' || stage === 'G1' || stage === 'G2' || stage === 'G4')
3568
+ if (stage === 'G0' || stage === 'G1' || stage === 'G2' || stage === 'G4') {
3569
+ ;
2925
3570
  ws.stageNotes[stage] = target.value;
2926
- handled = true;
3571
+ var counter = app.querySelector('#rp-stage-count');
3572
+ setText(counter, target.value.length + ' / 2000 字');
3573
+ autosizeBox(target);
3574
+ }
2927
3575
  }
2928
3576
  else if (role === 'line-title') {
2929
3577
  var titleLine = findLine(ws, lineKey);
2930
3578
  if (titleLine)
2931
3579
  titleLine.title = target.value;
2932
- handled = true;
2933
3580
  }
2934
3581
  else if (role === 'line-actual') {
2935
3582
  var actualLine = findLine(ws, lineKey);
2936
3583
  if (actualLine)
2937
3584
  actualLine.actual = target.value;
2938
- handled = true;
3585
+ autosizeBox(target);
2939
3586
  }
2940
- else if (role === 'line-customer') {
2941
- var customerLine = findLine(ws, lineKey);
2942
- if (customerLine) {
2943
- if (dataOf(target, 'field') === 'feedback')
2944
- customerLine.customerFeedback = target.value;
2945
- else
2946
- customerLine.customerSynced = target.value;
2947
- }
2948
- handled = true;
2949
- }
2950
- else if (role === 'line-completion') {
2951
- var completionLine = findLine(ws, lineKey);
2952
- if (completionLine)
2953
- completionLine.completion = target.value;
2954
- handled = true;
2955
- }
2956
- else if (role === 'line-scenario' || role === 'line-criteria') {
2957
- var refLine = findLine(ws, lineKey);
2958
- if (refLine) {
2959
- var id = dataOf(target, 'id');
2960
- var list = role === 'line-scenario' ? refLine.scenarioIds : refLine.criteriaIds;
2961
- var position = list.indexOf(id);
2962
- if (target.checked && position < 0)
2963
- list.push(id);
2964
- if (!target.checked && position >= 0)
2965
- list.splice(position, 1);
2966
- var label = target.parentNode;
2967
- if (label && label.className && String(label.className).indexOf('rp-check') >= 0) {
2968
- label.className = target.checked ? 'rp-check is-on' : 'rp-check';
2969
- }
2970
- }
2971
- handled = true;
3587
+ else if (role === 'customer-synced') {
3588
+ var syncedLine = findLine(ws, lineKey);
3589
+ if (syncedLine)
3590
+ syncedLine.customerSynced = target.value;
2972
3591
  }
2973
- else if (role === 'ev-title' || role === 'ev-link' || role === 'ev-type') {
3592
+ else if (role === 'customer-feedback') {
3593
+ var feedbackLine = findLine(ws, lineKey);
3594
+ if (feedbackLine)
3595
+ feedbackLine.customerFeedback = target.value;
3596
+ autosizeBox(target);
3597
+ }
3598
+ else if (role === 'ev-title') {
2974
3599
  var evLine = findLine(ws, lineKey);
2975
3600
  if (evLine) {
2976
3601
  var ev = findEvidence(evLine, dataOf(target, 'ev'));
2977
- if (ev) {
2978
- if (role === 'ev-title')
2979
- ev.title = target.value;
2980
- else if (role === 'ev-link')
2981
- ev.link = target.value;
2982
- else
2983
- ev.type = target.value;
2984
- var box = target;
2985
- while (box && box !== app && !(box.classList && box.classList.contains('rp-ev')))
2986
- box = box.parentNode;
2987
- updateEvidenceUI(evLine, box);
2988
- }
3602
+ if (ev)
3603
+ ev.title = target.value;
3604
+ }
3605
+ }
3606
+ else if (role === 'ev-link') {
3607
+ var linkLine = findLine(ws, lineKey);
3608
+ if (linkLine) {
3609
+ var linkEv = findEvidence(linkLine, dataOf(target, 'ev'));
3610
+ if (linkEv)
3611
+ linkEv.link = target.value;
3612
+ }
3613
+ }
3614
+ else if (role === 'ev-type') {
3615
+ var typeLine = findLine(ws, lineKey);
3616
+ if (typeLine) {
3617
+ var typeEv = findEvidence(typeLine, dataOf(target, 'ev'));
3618
+ if (typeEv)
3619
+ typeEv.type = target.value;
2989
3620
  }
2990
- handled = true;
2991
3621
  }
2992
3622
  else if (role === 'plan-goal' || role === 'plan-owner' || role === 'plan-deadline') {
2993
3623
  var plan = findPlan(ws, planKey);
@@ -2999,306 +3629,285 @@ function reportPage() {
2999
3629
  else
3000
3630
  plan.deadline = target.value;
3001
3631
  }
3002
- handled = true;
3003
- }
3004
- else if (role === 'plans-choice') {
3005
- ws.plansChoice = target.value === 'has' ? 'has' : 'none';
3006
- if (ws.plansChoice === 'has' && !ws.plans.length)
3007
- addPlanRow(ws, false);
3008
- syncPlansUI(ws);
3009
- handled = true;
3010
3632
  }
3011
3633
  else if (role === 'no-progress') {
3012
- if (target.checked) {
3013
- var hasExtra = false;
3014
- for (var i = 0; i < ws.lines.length; i += 1) {
3015
- if (lineHasContent(at(ws.lines, i)))
3016
- hasExtra = true;
3017
- }
3018
- if (hasExtra) {
3019
- target.checked = false;
3020
- toast('已经填写了工作项,不能同时标记「无实质进展」;请先清空工作项。');
3021
- return;
3022
- }
3023
- ws.noProgress = true;
3024
- }
3025
- else {
3026
- ws.noProgress = false;
3634
+ ws.noProgress = target.checked === true;
3635
+ var change = app.querySelector('[data-role="round"][data-field="change"]');
3636
+ if (change) {
3637
+ change.disabled = ws.noProgress;
3638
+ change.value = ws.noProgress ? '无实质进展' : ws.roundChange;
3027
3639
  }
3028
- syncNoProgressUI(ws);
3029
- handled = true;
3030
3640
  }
3031
- if (!handled)
3641
+ else {
3032
3642
  return;
3033
- justExported = false;
3034
- clearFieldError(target);
3035
- updateBarSoon();
3036
- updateTabsUI();
3037
- scheduleSave();
3038
- }
3039
- function addPlanRow(ws, focus) {
3040
- var plan = makePlan(ws);
3041
- ws.plans.push(plan);
3042
- var list = app.querySelector('#rp-plans');
3043
- if (list)
3044
- list.appendChild(renderPlanRow(ws, plan));
3045
- syncPlansUI(ws);
3046
- if (focus) {
3047
- var input = app.querySelector('[data-plan="' + plan.key + '"]');
3048
- if (input && typeof input.focus === 'function')
3049
- input.focus();
3050
- }
3051
- }
3052
- function addLine(ws) {
3053
- if (ws.noProgress) {
3054
- ws.noProgress = false;
3055
- syncNoProgressUI(ws);
3056
- }
3057
- var line = makeExtraLine(ws);
3058
- ws.lines.push(line);
3059
- var list = app.querySelector('#rp-lines');
3060
- if (list)
3061
- list.appendChild(renderLineCard(ws, line, ws.lines.length, true));
3062
- updateLineIndexes();
3063
- var input = app.querySelector('[data-line="' + line.key + '"][data-role="line-title"]');
3064
- if (input && typeof input.focus === 'function') {
3065
- input.focus();
3066
- if (typeof input.scrollIntoView === 'function')
3067
- input.scrollIntoView({ block: 'center' });
3068
3643
  }
3069
- justExported = false;
3070
- updateBarSoon();
3071
- updateTabsUI();
3072
- scheduleSave();
3073
- }
3074
- function removeLine(ws, key) {
3075
- var position = -1;
3076
- for (var i = 0; i < ws.lines.length; i += 1) {
3077
- if (at(ws.lines, i).key === key)
3078
- position = i;
3644
+ var box = target;
3645
+ while (box && box !== app) {
3646
+ var cls = String(box.className || '');
3647
+ if (cls.indexOf('rp-f') >= 0 || cls.indexOf('rp-box') >= 0 || cls.indexOf('rp-select') >= 0)
3648
+ break;
3649
+ box = box.parentNode;
3079
3650
  }
3080
- if (position < 0)
3081
- return;
3082
- if (!at(ws.lines, position).editableTitle)
3083
- return;
3084
- ws.lines.splice(position, 1);
3085
- var article = app.querySelector('[data-line="' + key + '"]');
3086
- if (article && article.parentNode)
3087
- article.parentNode.removeChild(article);
3088
- updateLineIndexes();
3089
- var addButton = app.querySelector('[data-add-line]');
3090
- if (addButton && typeof addButton.focus === 'function')
3091
- addButton.focus();
3092
- justExported = false;
3093
- updateBarSoon();
3094
- updateTabsUI();
3651
+ clearFieldError(box);
3095
3652
  scheduleSave();
3096
- }
3097
- function addEvidence(ws, lineKey) {
3098
- var line = findLine(ws, lineKey);
3099
- if (!line)
3100
- return;
3101
- var ev = makeEvidence(ws);
3102
- line.evidence.push(ev);
3103
- var article = app.querySelector('[data-line="' + lineKey + '"]');
3104
- var list = article ? article.querySelector('[data-ev-list]') : null;
3105
- if (list) {
3106
- list.setAttribute('data-open', 'true');
3107
- var addButton = list.querySelector('[data-act="ev-add"]');
3108
- var row = renderEvidenceRow(ws, line, ev);
3109
- if (addButton)
3110
- list.insertBefore(row, addButton);
3111
- else
3112
- list.appendChild(row);
3113
- }
3114
- var toggle = article ? article.querySelector('[data-act="ev-toggle"]') : null;
3115
- if (toggle)
3116
- toggle.setAttribute('aria-expanded', 'true');
3117
- updateEvidenceUI(line, article ? article.querySelector('.rp-ev') : null);
3118
- var input = article ? article.querySelector('[data-ev="' + ev.key + '"][data-role="ev-title"]') : null;
3119
- if (input && typeof input.focus === 'function')
3120
- input.focus();
3121
- justExported = false;
3122
3653
  updateBarSoon();
3123
- scheduleSave();
3124
3654
  }
3125
- function removeEvidence(ws, lineKey, evKey) {
3126
- var line = findLine(ws, lineKey);
3127
- if (!line)
3655
+ /** Grow a textarea to its content; the page never scrolls inside one. */
3656
+ function autosizeBox(target) {
3657
+ if (!target || target.tagName !== 'TEXTAREA')
3128
3658
  return;
3129
- for (var i = 0; i < line.evidence.length; i += 1) {
3130
- if (at(line.evidence, i).key !== evKey)
3131
- continue;
3132
- line.evidence.splice(i, 1);
3133
- break;
3134
- }
3135
- var article = app.querySelector('[data-line="' + lineKey + '"]');
3136
- var row = article ? article.querySelector('[data-ev="' + evKey + '"]') : null;
3137
- var field = row;
3138
- while (field && field !== article && !(field.className && String(field.className).indexOf('rp-ev-field') >= 0))
3139
- field = field.parentNode;
3140
- if (field && field.parentNode)
3141
- field.parentNode.removeChild(field);
3142
- updateEvidenceUI(line, article ? article.querySelector('.rp-ev') : null);
3143
- var addButton = article ? article.querySelector('[data-act="ev-add"]') : null;
3144
- if (addButton && typeof addButton.focus === 'function')
3145
- addButton.focus();
3146
- justExported = false;
3147
- updateBarSoon();
3148
- scheduleSave();
3659
+ target.style.height = 'auto';
3660
+ target.style.height = Math.max(24, target.scrollHeight) + 'px';
3149
3661
  }
3150
- function removePlan(ws, planKey) {
3151
- for (var i = 0; i < ws.plans.length; i += 1) {
3152
- if (at(ws.plans, i).key !== planKey)
3153
- continue;
3154
- ws.plans.splice(i, 1);
3155
- break;
3156
- }
3157
- var list = app.querySelector('#rp-plans');
3158
- var rows = list ? list.querySelectorAll('.rp-plan-row') : [];
3159
- for (var j = 0; j < rows.length; j += 1) {
3160
- var input = at(rows, j).querySelector('[data-plan="' + planKey + '"]');
3161
- if (input) {
3162
- list.removeChild(at(rows, j));
3163
- break;
3662
+ function autosizeAll() {
3663
+ var areas = app.querySelectorAll('textarea');
3664
+ for (var i = 0; i < areas.length; i += 1)
3665
+ autosizeBox(at(areas, i));
3666
+ }
3667
+ function onClick(event) {
3668
+ var actionNode = event.target;
3669
+ while (actionNode && actionNode !== app) {
3670
+ if (actionNode.nodeType === 1 && actionNode.getAttribute) {
3671
+ var act = actionNode.getAttribute('data-act');
3672
+ if (act)
3673
+ break;
3674
+ var role = actionNode.getAttribute('data-role');
3675
+ if (role === 'line-status' || role === 'plans-choice' || role === 'no-progress')
3676
+ break;
3164
3677
  }
3678
+ actionNode = actionNode.parentNode;
3165
3679
  }
3166
- syncPlansUI(ws);
3167
- var addButton = app.querySelector('[data-act="add-plan"]');
3168
- if (addButton && typeof addButton.focus === 'function')
3169
- addButton.focus();
3170
- justExported = false;
3171
- updateBarSoon();
3172
- updateTabsUI();
3173
- scheduleSave();
3174
- }
3175
- function onStatusClick(target) {
3176
- var ws = activeWorkspace();
3177
- var lineKey = dataOf(target, 'line');
3178
- var value = dataOf(target, 'value');
3179
- var line = findLine(ws, lineKey);
3180
- if (!line)
3680
+ if (!actionNode || actionNode === app)
3181
3681
  return;
3182
- line.status = value;
3183
- var group = target.parentNode;
3184
- if (group) {
3185
- var buttons = group.querySelectorAll('button');
3186
- for (var i = 0; i < buttons.length; i += 1) {
3187
- at(buttons, i).setAttribute('aria-pressed', at(buttons, i).getAttribute('data-value') === value ? 'true' : 'false');
3188
- }
3189
- }
3190
- var article = target;
3191
- while (article && article !== app && !(article.tagName === 'ARTICLE' && article.getAttribute('data-line')))
3192
- article = article.parentNode;
3193
- if (article && article.tagName === 'ARTICLE')
3194
- article.setAttribute('data-status', statusTone(value));
3195
- clearFieldError(target);
3196
- justExported = false;
3197
- updateBarSoon();
3198
- updateTabsUI();
3199
- scheduleSave();
3200
- }
3201
- function openPreview() {
3202
- var details = app.querySelector('#rp-preview');
3203
- if (!details)
3682
+ var ws = activeWorkspace();
3683
+ if (!ws)
3204
3684
  return;
3205
- details.open = true;
3206
- buildPreview();
3207
- if (typeof details.scrollIntoView === 'function')
3208
- details.scrollIntoView({ behavior: 'smooth', block: 'start' });
3209
- }
3210
- function onClick(event) {
3211
- var target = event.target;
3212
- if (!target)
3685
+ var actRole = dataOf(actionNode, 'role');
3686
+ if (actRole === 'line-status') {
3687
+ event.preventDefault();
3688
+ var statusLine = findLine(ws, dataOf(actionNode, 'line'));
3689
+ if (!statusLine)
3690
+ return;
3691
+ statusLine.status = dataOf(actionNode, 'value');
3692
+ var seg = actionNode.parentNode;
3693
+ if (seg) {
3694
+ var siblings = seg.querySelectorAll('button');
3695
+ for (var i = 0; i < siblings.length; i += 1) {
3696
+ at(siblings, i).setAttribute('aria-pressed', dataOf(at(siblings, i), 'value') === statusLine.status ? 'true' : 'false');
3697
+ }
3698
+ }
3699
+ clearFieldError(seg);
3700
+ scheduleSave();
3701
+ updateBarSoon();
3213
3702
  return;
3214
- var statusButton = closestAttr(target, 'data-role');
3215
- if (statusButton && dataOf(statusButton, 'role') === 'line-status') {
3216
- onStatusClick(statusButton);
3703
+ }
3704
+ if (actRole === 'plans-choice') {
3705
+ event.preventDefault();
3706
+ var choice = dataOf(actionNode, 'value');
3707
+ var nextChoice = choice === 'has' ? 'has' : 'none';
3708
+ // Re-clicking the active choice must not add a row: the buttons are a
3709
+ // radio group, and a stray extra plan would arrive as a required field the
3710
+ // colleague never asked for.
3711
+ if (ws.plansChoice === nextChoice)
3712
+ return;
3713
+ ws.plansChoice = nextChoice;
3714
+ if (nextChoice === 'has' && ws.plans.length === 0)
3715
+ ws.plans.push(makePlan(ws));
3716
+ renderPage();
3717
+ scheduleSave();
3217
3718
  return;
3218
3719
  }
3219
- var actionNode = closestAttr(target, 'data-act');
3220
- if (!actionNode)
3720
+ if (actRole === 'no-progress') {
3721
+ // The change event handles the checkbox itself.
3221
3722
  return;
3723
+ }
3222
3724
  var action = dataOf(actionNode, 'act');
3223
- var ws = activeWorkspace();
3224
- if (action === 'tab') {
3225
- var index = Number(dataOf(actionNode, 'tab'));
3226
- if (!Number.isInteger(index) || index < 0 || index >= state.workspaces.length)
3227
- return;
3228
- if (index === state.active)
3725
+ if (action === 'screen') {
3726
+ event.preventDefault();
3727
+ var target = Number(dataOf(actionNode, 'n'));
3728
+ if (target === 1 || target === 2)
3729
+ setScreen(target);
3730
+ return;
3731
+ }
3732
+ if (action === 'stage-toggle') {
3733
+ event.preventDefault();
3734
+ ws.stageOpen = !ws.stageOpen;
3735
+ var acc = app.querySelector('#rp-stage-acc');
3736
+ if (acc) {
3737
+ acc.setAttribute('data-open', ws.stageOpen ? '1' : '0');
3738
+ actionNode.setAttribute('aria-expanded', ws.stageOpen ? 'true' : 'false');
3739
+ }
3740
+ scheduleSave();
3741
+ return;
3742
+ }
3743
+ if (action === 'stage-tab') {
3744
+ event.preventDefault();
3745
+ var next = dataOf(actionNode, 'stage');
3746
+ if (next !== 'G0' && next !== 'G1' && next !== 'G2' && next !== 'G4')
3229
3747
  return;
3230
- saveDraftNow();
3231
- state.active = index;
3748
+ ws.stageTab = next;
3232
3749
  renderPage();
3233
- if (typeof win.scrollTo === 'function')
3234
- win.scrollTo(0, 0);
3750
+ scheduleSave();
3751
+ return;
3752
+ }
3753
+ if (action === 'open-line') {
3754
+ event.preventDefault();
3755
+ var openKey = dataOf(actionNode, 'line');
3756
+ ws.openLines[openKey] = true;
3757
+ var openLine = findLine(ws, openKey);
3758
+ // Opening a line with no evidence row yet gives it one, so the first input
3759
+ // the colleague sees is a place to type rather than an empty list.
3760
+ if (openLine && dataOf(actionNode, 'part') === 'evidence' && !openLine.evidence.length) {
3761
+ openLine.evidence.push(makeEvidence(ws));
3762
+ }
3763
+ renderPage();
3764
+ var focusTarget = app.querySelector('[data-line="' + openKey + '"] textarea');
3765
+ if (focusTarget && typeof focusTarget.focus === 'function')
3766
+ focusTarget.focus();
3767
+ scheduleSave();
3768
+ return;
3769
+ }
3770
+ if (action === 'close-line') {
3771
+ event.preventDefault();
3772
+ ws.openLines[dataOf(actionNode, 'line')] = false;
3773
+ renderPage();
3774
+ scheduleSave();
3235
3775
  return;
3236
3776
  }
3237
3777
  if (action === 'add-line') {
3238
- addLine(ws);
3778
+ event.preventDefault();
3779
+ var extra = makeExtraLine(ws);
3780
+ ws.openLines[extra.key] = true;
3781
+ ws.lines.push(extra);
3782
+ renderPage();
3783
+ var areas = app.querySelectorAll('[data-line="' + extra.key + '"] textarea');
3784
+ if (areas.length) {
3785
+ var first = at(areas, 0);
3786
+ if (typeof first.scrollIntoView === 'function')
3787
+ first.scrollIntoView({ behavior: 'smooth', block: 'center' });
3788
+ if (typeof first.focus === 'function')
3789
+ first.focus();
3790
+ }
3791
+ scheduleSave();
3239
3792
  return;
3240
3793
  }
3241
- if (action === 'line-remove') {
3242
- removeLine(ws, dataOf(actionNode, 'line'));
3794
+ if (action === 'line-del') {
3795
+ event.preventDefault();
3796
+ var delKey = dataOf(actionNode, 'line');
3797
+ for (var i = 0; i < ws.lines.length; i += 1) {
3798
+ if (at(ws.lines, i).key === delKey && at(ws.lines, i).editableTitle) {
3799
+ ws.lines.splice(i, 1);
3800
+ break;
3801
+ }
3802
+ }
3803
+ delete ws.openLines[delKey];
3804
+ renderPage();
3805
+ scheduleSave();
3243
3806
  return;
3244
3807
  }
3245
- if (action === 'add-plan') {
3246
- addPlanRow(ws, true);
3247
- justExported = false;
3248
- updateBarSoon();
3808
+ if (action === 'ev-add') {
3809
+ event.preventDefault();
3810
+ var evLine2 = findLine(ws, dataOf(actionNode, 'line'));
3811
+ if (!evLine2)
3812
+ return;
3813
+ evLine2.evidence.push(makeEvidence(ws));
3814
+ renderPage();
3815
+ var inputs = app.querySelectorAll('[data-line="' + evLine2.key + '"] .rp-evrow input');
3816
+ if (inputs.length) {
3817
+ var last = at(inputs, inputs.length - 1);
3818
+ if (typeof last.focus === 'function')
3819
+ last.focus();
3820
+ }
3249
3821
  scheduleSave();
3250
3822
  return;
3251
3823
  }
3252
- if (action === 'plan-remove') {
3253
- removePlan(ws, dataOf(actionNode, 'plan'));
3824
+ if (action === 'ev-del') {
3825
+ event.preventDefault();
3826
+ var evLine3 = findLine(ws, dataOf(actionNode, 'line'));
3827
+ if (!evLine3)
3828
+ return;
3829
+ var evKey = dataOf(actionNode, 'ev');
3830
+ for (var j = 0; j < evLine3.evidence.length; j += 1) {
3831
+ if (at(evLine3.evidence, j).key === evKey) {
3832
+ evLine3.evidence.splice(j, 1);
3833
+ break;
3834
+ }
3835
+ }
3836
+ if (!evLine3.evidence.length)
3837
+ evLine3.evidence.push(makeEvidence(ws));
3838
+ renderPage();
3839
+ scheduleSave();
3254
3840
  return;
3255
3841
  }
3256
- if (action === 'ev-toggle') {
3257
- var lineKey = dataOf(actionNode, 'line');
3258
- var line = findLine(ws, lineKey);
3259
- var article = actionNode;
3260
- while (article && article !== app && !(article.tagName === 'ARTICLE' && article.getAttribute('data-line')))
3261
- article = article.parentNode;
3262
- var list = article ? article.querySelector('[data-ev-list]') : null;
3263
- if (!list)
3842
+ if (action === 'pick') {
3843
+ event.preventDefault();
3844
+ var pickLine = findLine(ws, dataOf(actionNode, 'line'));
3845
+ if (!pickLine)
3264
3846
  return;
3265
- var open = list.getAttribute('data-open') === 'true';
3266
- list.setAttribute('data-open', open ? 'false' : 'true');
3267
- actionNode.setAttribute('aria-expanded', open ? 'false' : 'true');
3268
- if (!open && line && !line.evidence.length)
3269
- addEvidence(ws, lineKey);
3847
+ var kind = dataOf(actionNode, 'kind');
3848
+ var id = dataOf(actionNode, 'id');
3849
+ var list = kind === 'scn' ? pickLine.scenarioIds : pickLine.criteriaIds;
3850
+ var position = list.indexOf(id);
3851
+ if (position >= 0)
3852
+ list.splice(position, 1);
3853
+ else
3854
+ list.push(id);
3855
+ actionNode.setAttribute('aria-pressed', position >= 0 ? 'false' : 'true');
3856
+ var chosen = position < 0;
3857
+ var kids = actionNode.childNodes;
3858
+ for (var k = 0; k < kids.length; k += 1) {
3859
+ if (kids[k].nodeType === 1 && kids[k].tagName === 'svg') {
3860
+ actionNode.replaceChild(svgIcon(chosen ? 'check' : 'square', 11), kids[k]);
3861
+ break;
3862
+ }
3863
+ }
3864
+ var mini = app.querySelector('[data-line="' + pickLine.key + '"] .rp-mini');
3865
+ scheduleSave();
3866
+ updateBarSoon();
3270
3867
  return;
3271
3868
  }
3272
- if (action === 'ev-add') {
3273
- addEvidence(ws, dataOf(actionNode, 'line'));
3869
+ if (action === 'add-plan') {
3870
+ event.preventDefault();
3871
+ ws.plans.push(makePlan(ws));
3872
+ renderPage();
3873
+ var goals = app.querySelectorAll('[data-role="plan-goal"]');
3874
+ if (goals.length) {
3875
+ var lastGoal = at(goals, goals.length - 1);
3876
+ if (typeof lastGoal.focus === 'function')
3877
+ lastGoal.focus();
3878
+ }
3879
+ scheduleSave();
3274
3880
  return;
3275
3881
  }
3276
- if (action === 'ev-remove') {
3277
- removeEvidence(ws, dataOf(actionNode, 'line'), dataOf(actionNode, 'ev'));
3882
+ if (action === 'plan-remove') {
3883
+ event.preventDefault();
3884
+ removePlan(ws, dataOf(actionNode, 'plan'));
3885
+ renderPage();
3886
+ scheduleSave();
3278
3887
  return;
3279
3888
  }
3280
3889
  if (action === 'preview') {
3890
+ event.preventDefault();
3281
3891
  openPreview();
3282
3892
  return;
3283
3893
  }
3284
- if (action === 'export') {
3285
- runExport('html');
3286
- return;
3287
- }
3288
- if (action === 'json') {
3289
- runExport('json');
3894
+ if (action === 'save') {
3895
+ event.preventDefault();
3896
+ runExport();
3290
3897
  return;
3291
3898
  }
3292
3899
  if (action === 'reset-draft') {
3900
+ event.preventDefault();
3293
3901
  resetDraft();
3294
3902
  return;
3295
3903
  }
3296
3904
  if (action === 'dismiss-notice') {
3297
- var id = dataOf(actionNode, 'id');
3905
+ event.preventDefault();
3906
+ var id2 = dataOf(actionNode, 'id');
3298
3907
  var kept = [];
3299
- for (var i = 0; i < notices.length; i += 1) {
3300
- if (at(notices, i).id !== id)
3301
- kept.push(at(notices, i));
3908
+ for (var m = 0; m < notices.length; m += 1) {
3909
+ if (at(notices, m).id !== id2)
3910
+ kept.push(at(notices, m));
3302
3911
  }
3303
3912
  notices = kept;
3304
3913
  renderNotices();
@@ -3380,20 +3989,23 @@ function reportPage() {
3380
3989
  return;
3381
3990
  }
3382
3991
  var raw = parseInput();
3992
+ inputRaw = raw;
3383
3993
  normalizeData(raw);
3384
3994
  state.workspaces = makeWorkspaces();
3385
3995
  storageOk = probeStorage();
3386
3996
  if (storageOk)
3387
3997
  storageKey = 'poc-report-draft:' + formId.replace(/[^A-Za-z0-9_.:-]/g, '_');
3388
3998
  var restored = loadDraft();
3999
+ if (!restored && raw.draft)
4000
+ restored = loadSavedDraft(raw.draft);
3389
4001
  if (restored)
3390
- pushNotice('restored', '已恢复上次未提交的草稿;同一份草稿生成的回执编号不会变。', false);
4002
+ pushNotice('restored', '已恢复这份文件里上次填写的内容,可以继续修改后保存。', false);
3391
4003
  if (!storageOk)
3392
- pushNotice('storage', '浏览器没有可用的本地存储,草稿不会自动保存;请填完后及时生成回传文件。', true);
4004
+ pushNotice('storage', '浏览器没有可用的本地存储,草稿不会自动保存;请填完后及时点「保存」。', true);
3393
4005
  ensureChrome();
3394
4006
  attachListeners();
3395
4007
  renderPage();
3396
- updateTabsUI();
4008
+ autosizeAll();
3397
4009
  }
3398
4010
  function start() {
3399
4011
  if (booted)