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

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