@skillre/dsh-plugin-work-dashboard 0.14.0 → 0.15.1

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