@skillre/dsh-plugin-work-dashboard 0.11.1 → 0.12.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.
package/lib/form.js CHANGED
@@ -195,6 +195,7 @@ export function projectForForm(record) {
195
195
  },
196
196
  progress: blankProgress(progress.length),
197
197
  existingProgressCount: progress.length,
198
+ history: progressHistory(progress),
198
199
  // G4 only. Read here so a G4 form opens with the current conclusion in
199
200
  // place rather than blank, which would invite overwriting it by omission.
200
201
  outcome: {
@@ -219,6 +220,43 @@ function numberText(value) {
219
220
  const raw = text(value);
220
221
  return raw === '' ? '' : raw;
221
222
  }
223
+ /** How many recorded rounds the form lists read-only. */
224
+ export const HISTORY_LIMIT = 5;
225
+ /**
226
+ * Flatten the recorded rounds for the read-only history block.
227
+ *
228
+ * Newest first, because the round a colleague is about to continue is the newest
229
+ * one: reading it first is what makes "这次什么变了" answerable. The order is
230
+ * reversed rather than re-sorted by date because the ledger's own array order is
231
+ * the append order, and a hand-edited `date` must not reshuffle history.
232
+ */
233
+ export function progressHistory(progress) {
234
+ const entries = [];
235
+ for (let index = progress.length - 1; index >= 0 && entries.length < HISTORY_LIMIT; index -= 1) {
236
+ const entry = progress[index];
237
+ if (entry === null || entry === undefined)
238
+ continue;
239
+ const customer = entry.customer ?? {};
240
+ const next = entry.next ?? {};
241
+ entries.push({
242
+ seq: typeof entry.seq === 'number' ? entry.seq : null,
243
+ date: dateText(entry.date),
244
+ type: text(entry.type),
245
+ change: text(entry.change),
246
+ actual: text(entry.actual),
247
+ completion: text(entry.completion),
248
+ evidence: (Array.isArray(entry.evidence) ? entry.evidence : [])
249
+ .map((item) => text(item?.title).trim())
250
+ .filter((title) => title !== ''),
251
+ syncedWith: text(customer.synced_with),
252
+ recognition: text(customer.recognition),
253
+ nextGoal: text(next.goal),
254
+ nextOwner: text(next.owner),
255
+ nextDeadline: dateText(next.deadline),
256
+ });
257
+ }
258
+ return entries;
259
+ }
222
260
  /** One empty progress entry, with `seq` continuing the existing count. */
223
261
  export function blankProgress(existingCount) {
224
262
  return {
@@ -279,6 +317,7 @@ export function blankProject() {
279
317
  },
280
318
  progress: blankProgress(0),
281
319
  existingProgressCount: 0,
320
+ history: [],
282
321
  outcome: {
283
322
  achievement: '',
284
323
  customer_recognition: '',
@@ -411,81 +450,247 @@ export function projectToYaml(project) {
411
450
  function orNull(value) {
412
451
  return value === '' ? null : value;
413
452
  }
453
+ /**
454
+ * Which blocks of a change set a given intent may carry.
455
+ *
456
+ * ## Why this is a correctness rule, not tidiness
457
+ *
458
+ * The form pre-fills every field from the ledger, so a change set built from the
459
+ * whole project always carries values the colleague never looked at. Under
460
+ * `poc-submit`'s "skip null, apply the rest" merge, those pre-filled values are
461
+ * written back. That turns a read-only snapshot into an overwrite: if the ledger
462
+ * changed while the form sat in someone's WeChat, submitting it silently reverts
463
+ * the field to the day the form was generated.
464
+ *
465
+ * So the rule is: **emit only the blocks the person could actually edit.** A
466
+ * `progress` form sends its round and nothing else, and cannot clobber a plan it
467
+ * never displayed.
468
+ *
469
+ * `stage` and `status` are the exception: they are always emitted because they are
470
+ * the ledger's own routing keys, and a brand-new project has no file to inherit
471
+ * them from.
472
+ */
473
+ const CHANGE_SCOPE = {
474
+ new: ['identity', 'gate0'],
475
+ // `supplement` resolves per project against its stage, so the union is allowed
476
+ // here and narrowed by `resolveSections` at emit time.
477
+ supplement: ['identity', 'gate0', 'plan', 'gate12', 'progress', 'outcome'],
478
+ progress: ['progress'],
479
+ };
414
480
  /**
415
481
  * Build one project's change set from the form state.
416
482
  *
417
- * Every field the form can edit appears, so `poc-submit` can apply the whole
418
- * object with `setIfPresent` semantics: a blank field means "I did not change
419
- * this", which the merge step must not read as "delete it".
483
+ * Blocks outside the intent's scope are emitted as `null` (or an empty list), which
484
+ * `poc-submit` treats as "not changed" and skips. A blank field inside a block that
485
+ * IS in scope means the same thing: the colleague did not touch it.
486
+ *
487
+ * @param project the form's own view of the project
488
+ * @param intent what the colleague was asked to do; defaults to `supplement`, the
489
+ * widest scope, so an older caller keeps its previous behaviour
490
+ * @param baseline the project's values when the form was generated. When given,
491
+ * a field equal to its seed is emitted as `null` — "I did not touch this".
420
492
  */
421
- export function projectToChangeSet(project) {
422
- return {
493
+ export function projectToChangeSet(project, intent = 'supplement', baseline) {
494
+ // A supplement form is narrowed to the project's own stage, exactly as the page
495
+ // was: asking for a G1 plan change must not also re-emit a G0 block the page
496
+ // rendered read-only.
497
+ const scope = intent === 'supplement'
498
+ ? new Set(resolveSections(intent, project.stage).editable)
499
+ : new Set(CHANGE_SCOPE[intent]);
500
+ const inScope = (section) => scope.has(section);
501
+ /**
502
+ * A field's value, or `null` when it is still what the form was seeded with.
503
+ *
504
+ * ## Why this is the difference between working and silently losing data
505
+ *
506
+ * The page pre-fills every field from the ledger, and `poc-submit` merges with
507
+ * "skip null, apply the rest". Without this comparison, a colleague who changed
508
+ * ONE Gate 0 field re-sent the other four exactly as they were at export time —
509
+ * so anything another person changed while the form sat in WeChat was reverted.
510
+ * That is a data-loss bug wearing the costume of a normal merge.
511
+ *
512
+ * With it, the change set means what its name says: only the fields this person
513
+ * actually edited.
514
+ */
515
+ const seed = (path) => {
516
+ if (baseline === undefined)
517
+ return '';
518
+ const raw = path(baseline);
519
+ return raw === undefined || raw === null ? '' : String(raw);
520
+ };
521
+ const changed = (section, value, seeded) => {
522
+ if (!inScope(section))
523
+ return null;
524
+ const trimmed = value.trim();
525
+ if (trimmed === '')
526
+ return null;
527
+ return trimmed === seeded.trim() ? null : trimmed;
528
+ };
529
+ const changedList = (section, value, seeded) => {
530
+ if (!inScope(section))
531
+ return null;
532
+ if (value.length === 0)
533
+ return null;
534
+ if (baseline !== undefined && JSON.stringify(value) === JSON.stringify(seeded))
535
+ return null;
536
+ return [...value];
537
+ };
538
+ const blank = {
423
539
  schema_version: FORM_SCHEMA_VERSION,
424
540
  poc_id: project.pocId.trim(),
425
- name: project.name.trim(),
426
- org: {
427
- system: orNull(project.system.trim()),
428
- company: orNull(project.company.trim()),
429
- department: orNull(project.department.trim()),
430
- },
431
- amount_wan: project.amountWan === '' ? null : Number(project.amountWan),
432
- poc_type: orNull(project.pocType.trim()),
433
- owner: orNull(project.owner.trim()),
434
- sales: orNull(project.sales.trim()),
435
- tech_owner: orNull(project.techOwner.trim()),
436
- exec_sponsor: orNull(project.execSponsor.trim()),
541
+ name: '',
542
+ org: { system: null, company: null, department: null },
543
+ amount_wan: null,
544
+ poc_type: null,
545
+ owner: null,
546
+ sales: null,
547
+ tech_owner: null,
548
+ exec_sponsor: null,
549
+ // Always emitted: the ledger routes on these, and a new project has no file to
550
+ // inherit them from.
437
551
  stage: project.stage,
438
552
  status: project.status,
439
- stage_since: orNull(project.stageSince.trim()),
553
+ stage_since: null,
440
554
  gate0: {
441
- why_customer: orNull(project.gate0.why_customer.trim()),
442
- why_us: orNull(project.gate0.why_us.trim()),
443
- decision_chain: orNull(project.gate0.decision_chain.trim()),
444
- post_poc_decision: orNull(project.gate0.post_poc_decision.trim()),
445
- competitor: orNull(project.gate0.competitor.trim()),
446
- review: {
447
- conclusion: orNull(project.gate0.conclusion.trim()),
448
- reviewer: orNull(project.gate0.reviewer.trim()),
449
- reviewed_at: orNull(project.gate0.reviewed_at.trim()),
450
- },
555
+ why_customer: null, why_us: null, decision_chain: null,
556
+ post_poc_decision: null, competitor: null,
557
+ review: { conclusion: null, reviewer: null, reviewed_at: null },
451
558
  },
452
559
  plan: {
453
- customer_pain: orNull(project.plan.customer_pain.trim()),
454
- expected_recognition: orNull(project.plan.expected_recognition.trim()),
455
- our_edge: orNull(project.plan.our_edge.trim()),
456
- criteria: project.plan.criteria
457
- .filter((item) => (item.name ?? '').trim() !== '')
458
- .map((item) => ({
459
- id: orNull((item.id ?? '').trim()),
460
- name: item.name.trim(),
461
- metric: orNull((item.metric ?? '').trim()),
462
- baseline: orNull((item.baseline ?? '').trim()),
463
- target: orNull((item.target ?? '').trim()),
464
- })),
465
- scenarios: project.plan.scenarios
466
- .filter((item) => (item.name ?? '').trim() !== '')
467
- .map((item) => ({
468
- id: orNull((item.id ?? '').trim()),
469
- name: item.name.trim(),
470
- goal: orNull((item.goal ?? '').trim()),
471
- })),
472
- risks: project.plan.risks
473
- .filter((item) => item.name.trim() !== '')
474
- .map((item) => ({
475
- name: item.name.trim(),
476
- level: orNull(item.level.trim()),
477
- mitigation: orNull(item.mitigation.trim()),
478
- })),
479
- timeline: {
480
- start: orNull(project.plan.timeline_start.trim()),
481
- end: orNull(project.plan.timeline_end.trim()),
482
- },
483
- gate1: { conclusion: orNull(project.plan.gate1_conclusion.trim()) },
484
- gate2: { ready: orNull(project.plan.gate2_ready.trim()) },
560
+ customer_pain: null, expected_recognition: null, our_edge: null,
561
+ criteria: [], scenarios: [], risks: [],
562
+ timeline: { start: null, end: null },
563
+ gate1: { conclusion: null }, gate2: { ready: null },
485
564
  },
486
- // Append-only: this is the list of NEW rounds, never the existing history.
487
- progress: progressIsEmpty(project.progress) ? [] : [serializeProgress(project.progress)],
565
+ outcome: {
566
+ achievement: null, customer_recognition: null, our_proof: null, remaining_risks: null,
567
+ conclusion: { proved: null, recognized: null, next_business: null },
568
+ business: { milestone: null, owner: null, deadline: null, status: null },
569
+ overall: null,
570
+ },
571
+ progress: [],
488
572
  };
573
+ // Identity. `pocId` is the ledger's primary key and is never a change; it is
574
+ // always carried so the merge knows which project this is.
575
+ blank.name = changed('identity', project.name, seed((b) => b.name)) ?? '';
576
+ blank.org = {
577
+ system: changed('identity', project.system, seed((b) => b.system)),
578
+ company: changed('identity', project.company, seed((b) => b.company)),
579
+ department: changed('identity', project.department, seed((b) => b.department)),
580
+ };
581
+ const amount = project.amountWan.trim();
582
+ blank.amount_wan = inScope('identity') && amount !== '' && amount !== seed((b) => b.amountWan)
583
+ ? Number(amount)
584
+ : null;
585
+ blank.poc_type = changed('identity', project.pocType, seed((b) => b.pocType));
586
+ blank.owner = changed('identity', project.owner, seed((b) => b.owner));
587
+ blank.sales = changed('identity', project.sales, seed((b) => b.sales));
588
+ blank.tech_owner = changed('identity', project.techOwner, seed((b) => b.techOwner));
589
+ blank.exec_sponsor = changed('identity', project.execSponsor, seed((b) => b.execSponsor));
590
+ blank.stage_since = changed('identity', project.stageSince, seed((b) => b.stageSince));
591
+ // Gate 0.
592
+ blank.gate0 = {
593
+ why_customer: changed('gate0', project.gate0.why_customer, seed((b) => b.gate0.why_customer)),
594
+ why_us: changed('gate0', project.gate0.why_us, seed((b) => b.gate0.why_us)),
595
+ decision_chain: changed('gate0', project.gate0.decision_chain, seed((b) => b.gate0.decision_chain)),
596
+ post_poc_decision: changed('gate0', project.gate0.post_poc_decision, seed((b) => b.gate0.post_poc_decision)),
597
+ competitor: changed('gate0', project.gate0.competitor, seed((b) => b.gate0.competitor)),
598
+ review: {
599
+ conclusion: changed('gate0', project.gate0.conclusion, seed((b) => b.gate0.conclusion)),
600
+ reviewer: changed('gate0', project.gate0.reviewer, seed((b) => b.gate0.reviewer)),
601
+ reviewed_at: changed('gate0', project.gate0.reviewed_at, seed((b) => b.gate0.reviewed_at)),
602
+ },
603
+ };
604
+ // Plan. Lists are compared as a whole: a list that matches its seed exactly is
605
+ // "untouched", and any edit re-sends the whole list because the merge replaces it.
606
+ const criteria = project.plan.criteria
607
+ .filter((item) => (item.name ?? '').trim() !== '')
608
+ .map((item) => ({
609
+ id: orNull((item.id ?? '').trim()),
610
+ name: item.name.trim(),
611
+ metric: orNull((item.metric ?? '').trim()),
612
+ baseline: orNull((item.baseline ?? '').trim()),
613
+ target: orNull((item.target ?? '').trim()),
614
+ }));
615
+ const scenarios = project.plan.scenarios
616
+ .filter((item) => (item.name ?? '').trim() !== '')
617
+ .map((item) => ({
618
+ id: orNull((item.id ?? '').trim()),
619
+ name: item.name.trim(),
620
+ goal: orNull((item.goal ?? '').trim()),
621
+ }));
622
+ const risks = project.plan.risks
623
+ .filter((item) => item.name.trim() !== '')
624
+ .map((item) => ({
625
+ name: item.name.trim(),
626
+ level: orNull(item.level.trim()),
627
+ mitigation: orNull(item.mitigation.trim()),
628
+ }));
629
+ // The seed lists are normalized through the SAME mapping as the emitted ones.
630
+ // Comparing raw form rows against normalized output made every list look
631
+ // changed ('' vs null), so an untouched plan was re-sent and could overwrite a
632
+ // concurrent edit — the exact failure this diff exists to prevent.
633
+ const seedCriteria = (baseline?.plan.criteria ?? [])
634
+ .filter((item) => (item.name ?? '').trim() !== '')
635
+ .map((item) => ({
636
+ id: orNull((item.id ?? '').trim()),
637
+ name: item.name.trim(),
638
+ metric: orNull((item.metric ?? '').trim()),
639
+ baseline: orNull((item.baseline ?? '').trim()),
640
+ target: orNull((item.target ?? '').trim()),
641
+ }));
642
+ const seedScenarios = (baseline?.plan.scenarios ?? [])
643
+ .filter((item) => (item.name ?? '').trim() !== '')
644
+ .map((item) => ({
645
+ id: orNull((item.id ?? '').trim()),
646
+ name: item.name.trim(),
647
+ goal: orNull((item.goal ?? '').trim()),
648
+ }));
649
+ const seedRisks = (baseline?.plan.risks ?? [])
650
+ .filter((item) => item.name.trim() !== '')
651
+ .map((item) => ({
652
+ name: item.name.trim(),
653
+ level: orNull(item.level.trim()),
654
+ mitigation: orNull(item.mitigation.trim()),
655
+ }));
656
+ blank.plan = {
657
+ customer_pain: changed('plan', project.plan.customer_pain, seed((b) => b.plan.customer_pain)),
658
+ expected_recognition: changed('plan', project.plan.expected_recognition, seed((b) => b.plan.expected_recognition)),
659
+ our_edge: changed('plan', project.plan.our_edge, seed((b) => b.plan.our_edge)),
660
+ criteria: changedList('plan', criteria, seedCriteria) ?? [],
661
+ scenarios: changedList('plan', scenarios, seedScenarios) ?? [],
662
+ risks: changedList('plan', risks, seedRisks) ?? [],
663
+ timeline: {
664
+ start: changed('plan', project.plan.timeline_start, seed((b) => b.plan.timeline_start)),
665
+ end: changed('plan', project.plan.timeline_end, seed((b) => b.plan.timeline_end)),
666
+ },
667
+ gate1: { conclusion: changed('gate12', project.plan.gate1_conclusion, seed((b) => b.plan.gate1_conclusion)) },
668
+ gate2: { ready: changed('gate12', project.plan.gate2_ready, seed((b) => b.plan.gate2_ready)) },
669
+ };
670
+ // Outcome: the G4 block.
671
+ blank.outcome = {
672
+ achievement: changed('outcome', project.outcome.achievement, seed((b) => b.outcome.achievement)),
673
+ customer_recognition: changed('outcome', project.outcome.customer_recognition, seed((b) => b.outcome.customer_recognition)),
674
+ our_proof: changed('outcome', project.outcome.our_proof, seed((b) => b.outcome.our_proof)),
675
+ remaining_risks: null,
676
+ conclusion: {
677
+ proved: changed('outcome', project.outcome.proved, seed((b) => b.outcome.proved)),
678
+ recognized: changed('outcome', project.outcome.recognized, seed((b) => b.outcome.recognized)),
679
+ next_business: changed('outcome', project.outcome.next_business, seed((b) => b.outcome.next_business)),
680
+ },
681
+ business: {
682
+ milestone: changed('outcome', project.outcome.milestone, seed((b) => b.outcome.milestone)),
683
+ owner: changed('outcome', project.outcome.businessOwner, seed((b) => b.outcome.businessOwner)),
684
+ deadline: changed('outcome', project.outcome.businessDeadline, seed((b) => b.outcome.businessDeadline)),
685
+ status: changed('outcome', project.outcome.businessStatus, seed((b) => b.outcome.businessStatus)),
686
+ },
687
+ overall: changed('outcome', project.outcome.overall, seed((b) => b.outcome.overall)),
688
+ };
689
+ // Append-only: this is the list of NEW rounds, never the existing history.
690
+ blank.progress = inScope('progress') && !progressIsEmpty(project.progress)
691
+ ? [serializeProgress(project.progress)]
692
+ : [];
693
+ return blank;
489
694
  }
490
695
  /** Build the document a colleague sends back. */
491
696
  export function buildChangeDocument(options) {
@@ -494,7 +699,7 @@ export function buildChangeDocument(options) {
494
699
  generatedAt: (options.now ?? new Date()).toISOString(),
495
700
  generatedBy: 'POC 信息收集表单 v3.1',
496
701
  intent: options.intent,
497
- changes: options.projects.map((project) => projectToChangeSet(project)),
702
+ changes: options.projects.map((project, index) => projectToChangeSet(project, options.intent, options.baseline?.[index])),
498
703
  };
499
704
  }
500
705
  /** `true` when the form's progress entry carries no user content. */
@@ -624,12 +829,18 @@ export function buildFormHtml(options) {
624
829
  generatedAt: now.toISOString(),
625
830
  today: now.toISOString().slice(0, 10),
626
831
  projects,
832
+ // The values as generated, index-aligned with `projects`. The page diffs
833
+ // against these so it only sends what the colleague actually changed — see
834
+ // projectToChangeSet. Without it, an untouched pre-filled field would be sent
835
+ // back and would revert any edit made while the form sat in WeChat.
836
+ baseline: projects.map((project) => JSON.parse(JSON.stringify(project))),
627
837
  // Each project's stage decides which sections are the subject, so the
628
838
  // resolution is per project rather than per document.
629
839
  sections: projects.map((project) => resolveSections(intent, project.stage)),
630
840
  draftKey: draftKeyFor(options.mode, projects.map((project) => project.pocId).filter((id) => id !== '')),
631
841
  enums: ENUMS,
632
842
  g0Fields: G0_PROMPTS,
843
+ returnCss: RETURN_CSS,
633
844
  };
634
845
  const data = scriptSafe(JSON.stringify(payload));
635
846
  const title = intent === 'new'
@@ -656,7 +867,8 @@ export function buildFormHtml(options) {
656
867
  <div class="footer-info" id="footerInfo">正在初始化…</div>
657
868
  <div class="footer-actions">
658
869
  <button type="button" class="btn" id="previewBtn">预览变更集</button>
659
- <button type="button" class="btn btn-primary" id="downloadBtn">下载变更集</button>
870
+ <button type="button" class="btn" id="downloadBtn">下载变更集 (.json)</button>
871
+ <button type="button" class="btn btn-primary" id="returnBtn">生成回传文件 (.html)</button>
660
872
  </div>
661
873
  </footer>
662
874
  </div>
@@ -725,6 +937,113 @@ export function checkFormCompatibility(payload) {
725
937
  reason: `这个表单声明的版本是 v${declared},当前台账读取的是 v${FORM_SCHEMA_VERSION},无法确认字段含义一致,已拒绝导入。`,
726
938
  };
727
939
  }
940
+ /** The element id the returned page carries its change set in. */
941
+ export const RETURN_DATA_ID = 'poc-return-data';
942
+ /**
943
+ * Read a returned form — either the `.html` this generator emits or a `.json`
944
+ * change set — back into a change document.
945
+ *
946
+ * ## Why both formats, and why HTML is the default
947
+ *
948
+ * The documented workflow is "colleague fills it in and sends the HTML back on
949
+ * WeChat". That only works if the returned HTML actually carries the answers, so
950
+ * {@link buildFormHtml}'s page writes a `RETURN_DATA_ID` script block holding the
951
+ * exact change set. The same page is also readable by a human: it renders the
952
+ * answers as formatted HTML, so the person who receives it can see what was
953
+ * submitted before handing it to DSH.
954
+ *
955
+ * The `.json` path is kept because it is stricter and smaller, and because forms
956
+ * already in circulation emit it.
957
+ *
958
+ * ## Safety
959
+ *
960
+ * The HTML is never executed and never given to a DOM parser: the block is found
961
+ * with a string search and the slice is handed to `JSON.parse`. Nothing in the
962
+ * returned file can run.
963
+ */
964
+ export function readReturnDocument(input) {
965
+ const raw = input.trim();
966
+ if (raw === '')
967
+ return { document: null, reason: '文件是空的。' };
968
+ // A JSON change set: the common case for a `.json` return.
969
+ if (raw.startsWith('{')) {
970
+ let parsed;
971
+ try {
972
+ parsed = JSON.parse(raw);
973
+ }
974
+ catch {
975
+ return { document: null, reason: '这个 .json 文件解析失败,可能传输过程中被截断或改坏了。' };
976
+ }
977
+ return acceptDocument(parsed);
978
+ }
979
+ // A returned HTML page: find the data block by its id and parse only that.
980
+ //
981
+ // The marker is searched for exhaustively rather than once, because the FORM
982
+ // page also contains the literal marker inside its own generator source (the
983
+ // code that writes the return page). A single `indexOf` finds that copy first,
984
+ // and a blank form then reports "the data block is corrupt" instead of the
985
+ // truth: this form was never filled in. So every occurrence is tried and the
986
+ // first one that parses as a change document wins.
987
+ const marker = `id="${RETURN_DATA_ID}"`;
988
+ let at = raw.indexOf(marker);
989
+ while (at >= 0) {
990
+ const open = raw.indexOf('>', at);
991
+ const close = open < 0 ? -1 : raw.indexOf('</script>', open);
992
+ if (open >= 0 && close >= 0) {
993
+ const body = raw.slice(open + 1, close).trim();
994
+ let parsed;
995
+ try {
996
+ parsed = JSON.parse(body);
997
+ }
998
+ catch {
999
+ // Not the real block (a source-code copy, or a truncated file). Keep
1000
+ // looking: a later occurrence may still be intact.
1001
+ parsed = undefined;
1002
+ }
1003
+ if (parsed !== undefined) {
1004
+ const accepted = acceptDocument(parsed);
1005
+ // Only a successfully accepted document ends the search; a marker copy
1006
+ // that parses to some other JSON is skipped.
1007
+ if (accepted.document !== null)
1008
+ return accepted;
1009
+ // A real-looking block that fails the schema gate is the answer: stop and
1010
+ // report it rather than silently falling through to "not a return file".
1011
+ if (Array.isArray(parsed.changes))
1012
+ return accepted;
1013
+ }
1014
+ }
1015
+ at = raw.indexOf(marker, at + marker.length);
1016
+ }
1017
+ return {
1018
+ document: null,
1019
+ reason: '这个 HTML 里没有可读的回传数据。它可能是**原始空白表单**——组员要填完后点' +
1020
+ '【生成回传文件 (.html)】,发回的是新生成的那个文件,而不是最初收到的表单。',
1021
+ };
1022
+ }
1023
+ /** Validate a parsed return against the schema gate, then hand it back. */
1024
+ function acceptDocument(parsed) {
1025
+ if (typeof parsed !== 'object' || parsed === null) {
1026
+ return { document: null, reason: '这个文件不是变更集格式。' };
1027
+ }
1028
+ const record = parsed;
1029
+ // A change document carries `changes`; a raw form payload carries `projects`.
1030
+ // The latter is the BLANK form, and reading it as a submission would silently
1031
+ // import an empty round.
1032
+ if (!Array.isArray(record.changes)) {
1033
+ if (Array.isArray(record.projects)) {
1034
+ return {
1035
+ document: null,
1036
+ reason: '这是**尚未填写/未生成回传文件**的原始表单,里面没有组员填的内容。' +
1037
+ '请让组员填完后点【生成回传文件 (.html)】或【下载变更集 (.json)】,把那个文件发回。',
1038
+ };
1039
+ }
1040
+ return { document: null, reason: '这个文件里没有 changes 数组,不是表单变更集。' };
1041
+ }
1042
+ const gate = checkFormCompatibility(record);
1043
+ if (!gate.compatible)
1044
+ return { document: null, reason: gate.reason };
1045
+ return { document: parsed, reason: '' };
1046
+ }
728
1047
  /** Styles: one inline sheet, the console's own design tokens. */
729
1048
  const FORM_CSS = `
730
1049
  /* ===========================================================================
@@ -780,6 +1099,15 @@ body{
780
1099
  padding-top:10px;border-top:1px solid var(--border);
781
1100
  }
782
1101
  .banner-step{margin:0 auto;font-size:10px;color:var(--text-3);font-variant-numeric:tabular-nums}
1102
+ /* On a phone the two-column banner squeezed the title into one word per line.
1103
+ * Stack it: title and pills full width, actions on their own row. */
1104
+ @media(max-width:720px){
1105
+ .banner{grid-template-columns:minmax(0,1fr);gap:10px}
1106
+ .banner-side{align-items:flex-start}
1107
+ .banner-pills{justify-content:flex-start}
1108
+ .banner-actions{width:100%;justify-content:space-between}
1109
+ .banner-title{font-size:18px;line-height:25px}
1110
+ }
783
1111
 
784
1112
  /* ---------- the fixed two-column contract, same ratio as the detail page --- */
785
1113
  .columns{display:grid;grid-template-columns:minmax(0,1.72fr) minmax(0,1fr);gap:18px;align-items:start}
@@ -850,6 +1178,15 @@ body{
850
1178
  .field-error{color:var(--red);font-size:10px;display:none}
851
1179
  .field.has-error .field-error{display:block}
852
1180
 
1181
+ /* ---------- locked fields: shown so the ledger's state is visible, but not
1182
+ * editable. Muted rather than hidden, because "what does the ledger already
1183
+ * say" is exactly what a colleague needs before answering. ------------------ */
1184
+ .input.is-locked,.textarea.is-locked,.select.is-locked{
1185
+ background:var(--inset);color:var(--text-2);border-color:var(--border);
1186
+ cursor:not-allowed;opacity:1;
1187
+ }
1188
+ .field-locked{color:var(--text-3);font-style:italic}
1189
+
853
1190
  /* ---------- id pickers: which scenario / criterion this round touched ------ */
854
1191
  .pick-list{display:flex;flex-wrap:wrap;gap:6px}
855
1192
  .pick{
@@ -860,8 +1197,93 @@ body{
860
1197
  .pick:has(input:checked){background:var(--primary-soft);border-color:var(--primary)}
861
1198
  .pick input{accent-color:var(--primary);margin:0}
862
1199
  .pick-id{font-family:var(--mono);font-size:9px;color:var(--text-3)}
1200
+ .pick-empty{
1201
+ margin-top:2px;padding:7px 11px;border:1px dashed var(--border);border-radius:7px;
1202
+ font-size:11px;color:var(--text-3);background:var(--inset);
1203
+ }
863
1204
  .pick-name{overflow-wrap:anywhere}
864
1205
 
1206
+ /* ---------- project snapshot: the orientation strip under the banner ------- */
1207
+ .snapshot{
1208
+ display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:0;
1209
+ background:var(--surface);border:1px solid var(--border);border-radius:10px;
1210
+ overflow:hidden;box-shadow:var(--shadow-1);
1211
+ }
1212
+ @media(max-width:900px){.snapshot{grid-template-columns:repeat(2,minmax(0,1fr))}}
1213
+ @media(max-width:520px){
1214
+ /* Two columns even on a phone: five stacked cells cost a full screen before
1215
+ * the first field. The amount cell spans the row to avoid a dangling gap. */
1216
+ .snapshot{grid-template-columns:repeat(2,minmax(0,1fr))}
1217
+ .snap-cell{padding:8px 11px}
1218
+ .snap-cell:last-child{grid-column:1/-1;border-top:1px solid var(--border)}
1219
+ .snap-value{font-size:11.5px;line-height:16px}
1220
+ }
1221
+ .snap-cell{
1222
+ display:flex;flex-direction:column;gap:3px;padding:10px 14px;min-width:0;
1223
+ border-left:1px solid var(--border);
1224
+ }
1225
+ .snap-cell:first-child{border-left:0}
1226
+ @media(max-width:900px){
1227
+ .snap-cell:nth-child(odd){border-left:0}
1228
+ .snap-cell:nth-child(n+3){border-top:1px solid var(--border)}
1229
+ }
1230
+ .snap-label{
1231
+ font-size:9.5px;font-weight:650;letter-spacing:.05em;text-transform:uppercase;color:var(--text-3);
1232
+ }
1233
+ .snap-value{
1234
+ font-size:12px;line-height:17px;font-weight:600;color:var(--text);
1235
+ font-variant-numeric:tabular-nums;overflow-wrap:anywhere;
1236
+ }
1237
+ .snap-cell[data-tone="ok"] .snap-value{color:var(--green)}
1238
+ .snap-cell[data-tone="warn"] .snap-value{color:var(--amber)}
1239
+ .snap-cell[data-tone="info"] .snap-value{color:var(--primary)}
1240
+ .snap-cell[data-tone="muted"] .snap-value{color:var(--text-3);font-weight:500}
1241
+
1242
+ /* ---------- read-only context: shown so the ledger is legible, collapsed so it
1243
+ * does not push the fields-to-fill below the fold. A <details> is used rather
1244
+ * than a JS toggle because it works with no script and prints expanded. ------ */
1245
+ .read-context{border:1px solid var(--border);border-radius:8px;background:var(--inset)}
1246
+ .read-context>summary{
1247
+ padding:8px 12px;font-size:11px;font-weight:600;color:var(--text-2);
1248
+ cursor:pointer;list-style:none;display:flex;align-items:center;gap:7px;
1249
+ }
1250
+ .read-context>summary::-webkit-details-marker{display:none}
1251
+ .read-context>summary::before{
1252
+ content:'';width:0;height:0;flex:none;
1253
+ border-left:4px solid var(--text-3);border-top:3.5px solid transparent;border-bottom:3.5px solid transparent;
1254
+ transition:transform .12s ease;
1255
+ }
1256
+ .read-context[open]>summary::before{transform:rotate(90deg)}
1257
+ .read-context>summary:hover{color:var(--text)}
1258
+ .read-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:0 18px;padding:2px 12px 11px}
1259
+ @media(max-width:720px){.read-grid{grid-template-columns:minmax(0,1fr)}}
1260
+ .read-pair{padding:6px 0;border-top:1px dashed var(--border);min-width:0}
1261
+ .read-pair dt{font-size:10px;font-weight:600;color:var(--text-3);margin-bottom:2px}
1262
+ .read-pair dd{font-size:11.5px;line-height:17px;color:var(--text-2);white-space:pre-wrap;overflow-wrap:anywhere}
1263
+ .read-pair dd.read-empty{color:var(--text-3);font-style:italic}
1264
+ .read-list-block{padding:0 12px 10px}
1265
+ .read-list-block h3{margin:6px 0 5px;font-size:10px;font-weight:650;letter-spacing:.04em;text-transform:uppercase;color:var(--text-3)}
1266
+ .read-list{list-style:none;display:flex;flex-direction:column;gap:4px}
1267
+ .read-list li{padding:5px 9px;background:var(--surface);border:1px solid var(--border);border-radius:6px;font-size:11.5px;line-height:17px;overflow-wrap:anywhere}
1268
+ .read-id{font-family:var(--mono);font-size:9px;color:var(--text-3);margin-right:6px}
1269
+ .read-dim{color:var(--text-3)}
1270
+
1271
+ /* ---------- progress history: what has already been reported --------------- */
1272
+ .hist-list{list-style:none;display:flex;flex-direction:column;gap:0;padding:0 12px 10px}
1273
+ .hist-item{
1274
+ display:grid;grid-template-columns:minmax(0,1fr);gap:3px;
1275
+ padding:8px 0;border-top:1px dashed var(--border);
1276
+ }
1277
+ .hist-item:first-child{border-top:0}
1278
+ .hist-head{display:flex;flex-wrap:wrap;align-items:center;gap:6px}
1279
+ .hist-seq{font-family:var(--mono);font-size:9.5px;color:var(--text-3)}
1280
+ .hist-date{font-size:11px;font-weight:650;color:var(--text-2);font-variant-numeric:tabular-nums}
1281
+ .hist-type{font-size:9.5px;color:var(--primary);background:var(--primary-soft);padding:1px 6px;border-radius:4px}
1282
+ .hist-change{font-size:9.5px;color:var(--amber);background:var(--amber-soft);padding:1px 6px;border-radius:4px}
1283
+ .hist-pct{font-size:9.5px;color:var(--text-3);font-variant-numeric:tabular-nums;margin-left:auto}
1284
+ .hist-actual{margin:2px 0 0;font-size:11.5px;line-height:17px;color:var(--text-2);white-space:pre-wrap;overflow-wrap:anywhere}
1285
+ .hist-meta{margin:1px 0 0;font-size:10px;color:var(--text-3);overflow-wrap:anywhere}
1286
+
865
1287
  /* ---------- atoms ---------- */
866
1288
  .btn{
867
1289
  padding:6px 12px;border-radius:6px;border:1px solid var(--border);background:var(--surface);
@@ -885,19 +1307,18 @@ body{
885
1307
  .pill-green{background:var(--green-soft);color:var(--green)}
886
1308
  .pill-red{background:var(--red-soft);color:var(--red)}
887
1309
 
888
- /* ---------- readiness strip: the same reminder band as the detail page ----- */
889
- .readiness{
890
- display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px;
891
- padding:11px 14px;border-radius:10px;background:var(--surface);
892
- border:1px solid var(--border);border-left:3px solid var(--slate);
1310
+ /* ---------- what is still missing: the one actionable strip ------------- */
1311
+ .missing{
1312
+ display:flex;align-items:flex-start;gap:12px;padding:9px 14px;
1313
+ background:var(--amber-soft);border:1px solid rgba(183,121,25,.24);
1314
+ border-left:3px solid var(--amber);border-radius:8px;
893
1315
  }
894
- .readiness[data-tone="green"]{border-left-color:var(--green)}
895
- .readiness[data-tone="amber"]{border-left-color:var(--amber)}
896
- .readiness[data-tone="red"]{border-left-color:var(--red)}
897
- @media(max-width:720px){.readiness{grid-template-columns:minmax(0,1fr)}}
898
- .ready-cell{display:flex;flex-direction:column;gap:2px;min-width:0}
899
- .ready-label{font-size:9.5px;font-weight:650;letter-spacing:.05em;text-transform:uppercase;color:var(--text-3)}
900
- .ready-value{font-size:11px;line-height:17px;color:var(--text-2);overflow-wrap:anywhere}
1316
+ .missing-label{
1317
+ flex:none;font-size:9.5px;font-weight:700;letter-spacing:.05em;text-transform:uppercase;
1318
+ color:var(--amber);padding-top:2px;
1319
+ }
1320
+ .missing-list{list-style:none;display:flex;flex-direction:column;gap:2px;min-width:0}
1321
+ .missing-list li{font-size:11.5px;line-height:17px;color:#8A5E12;overflow-wrap:anywhere}
901
1322
 
902
1323
  /* ---------- notices / footer ---------- */
903
1324
  .notice{
@@ -927,6 +1348,80 @@ body{
927
1348
  body{padding:0}
928
1349
  }
929
1350
  `;
1351
+ /**
1352
+ * Styles for the RETURNED page — the read-only report a colleague sends back.
1353
+ *
1354
+ * It is a separate sheet on purpose. The form's sheet is built for input
1355
+ * affordances (focus rings, hover borders, a sticky footer); a report has none of
1356
+ * those and needs a reading rhythm instead: one column, generous line height, and
1357
+ * a label/value grid that stays legible when someone opens it on a phone in
1358
+ * WeChat. Sharing the form's tokens keeps it recognisably the same product.
1359
+ */
1360
+ const RETURN_CSS = `
1361
+ :root{
1362
+ --text:#192638;--text-2:#4A5A70;--text-3:#7A8AA0;
1363
+ --bg:#F5F7FB;--surface:#fff;--inset:#F7F9FC;
1364
+ --border:#E6EBF2;--green:#218568;--amber:#B77919;--primary:#2864E8;
1365
+ --mono:ui-monospace,SFMono-Regular,Menlo,monospace;
1366
+ }
1367
+ *{box-sizing:border-box;margin:0;padding:0}
1368
+ body{
1369
+ font-family:'Avenir Next','PingFang SC','Microsoft YaHei',system-ui,sans-serif;
1370
+ background:var(--bg);color:var(--text);font-size:13px;line-height:20px;
1371
+ -webkit-font-smoothing:antialiased;padding:24px 20px 60px;
1372
+ }
1373
+ .ret-shell{max-width:820px;margin:0 auto;display:flex;flex-direction:column;gap:14px}
1374
+ .ret-note{
1375
+ background:rgba(40,100,232,.07);border:1px solid rgba(40,100,232,.2);
1376
+ border-radius:8px;padding:10px 14px;font-size:11.5px;line-height:18px;color:var(--text-2);
1377
+ }
1378
+ .ret-bar{
1379
+ display:flex;flex-wrap:wrap;gap:10px;justify-content:space-between;align-items:baseline;
1380
+ font-size:11.5px;font-weight:600;color:var(--text-2);
1381
+ }
1382
+ .ret-dim{font-weight:400;color:var(--text-3)}
1383
+ .ret-card{
1384
+ background:var(--surface);border:1px solid var(--border);border-radius:10px;
1385
+ padding:18px 20px;display:flex;flex-direction:column;gap:16px;
1386
+ }
1387
+ .ret-head{padding-bottom:12px;border-bottom:1px solid var(--border)}
1388
+ .ret-head h1{margin:0;font-size:19px;line-height:27px;font-weight:700;letter-spacing:-.01em;overflow-wrap:anywhere}
1389
+ .ret-meta{margin-top:4px;font-size:10.5px;color:var(--text-3);font-family:var(--mono)}
1390
+ .ret-sec h2{
1391
+ margin:0 0 7px;font-size:11px;font-weight:650;letter-spacing:.05em;
1392
+ text-transform:uppercase;color:var(--text-3);
1393
+ }
1394
+ .ret-sec dl{display:flex;flex-direction:column;gap:0}
1395
+ .ret-pair{
1396
+ display:grid;grid-template-columns:132px minmax(0,1fr);gap:12px;
1397
+ padding:6px 0;border-top:1px dashed var(--border);
1398
+ }
1399
+ .ret-pair:first-child{border-top:0}
1400
+ .ret-pair dt{font-size:11.5px;color:var(--text-3);line-height:19px}
1401
+ .ret-pair dd{font-size:12.5px;line-height:20px;color:var(--text);white-space:pre-wrap;overflow-wrap:anywhere}
1402
+ .ret-list{list-style:none;display:flex;flex-direction:column;gap:5px}
1403
+ .ret-list li{
1404
+ padding:6px 10px;background:var(--inset);border-radius:6px;
1405
+ font-size:12px;line-height:18px;overflow-wrap:anywhere;
1406
+ }
1407
+ .ret-list li b{font-family:var(--mono);font-size:9.5px;color:var(--text-3);margin-right:6px}
1408
+ .ret-new{border-left:3px solid var(--green);padding-left:13px}
1409
+ .ret-new h2{color:var(--green)}
1410
+ .ret-tag{
1411
+ margin-left:7px;padding:1px 6px;border-radius:4px;font-size:9px;
1412
+ background:rgba(33,133,104,.12);color:var(--green);text-transform:none;letter-spacing:0;
1413
+ }
1414
+ @media(max-width:560px){
1415
+ body{padding:14px 12px 40px}
1416
+ .ret-card{padding:14px 15px}
1417
+ .ret-pair{grid-template-columns:minmax(0,1fr);gap:2px}
1418
+ }
1419
+ @media print{
1420
+ body{background:#fff;padding:0}
1421
+ .ret-note{display:none}
1422
+ .ret-card{break-inside:avoid;border-color:#ccc}
1423
+ }
1424
+ `;
930
1425
  /**
931
1426
  * The generated page script.
932
1427
  *
@@ -1061,22 +1556,36 @@ const FORM_SCRIPT = `
1061
1556
  var opts = options || {};
1062
1557
  var help = opts.help ? '<p class="field-help">' + escapeHtml(opts.help) + '</p>' : '';
1063
1558
  var req = opts.required ? '<span class="req">*</span>' : '';
1559
+ // A locked field is shown, not hidden: the person needs to know what the
1560
+ // ledger already says. It is rendered as a disabled control (so it reads as a
1561
+ // field) with no 'data-path' (so no handler can write it), plus a lock note.
1562
+ var locked = opts.readonly === true;
1563
+ var lockAttr = locked ? ' disabled' : '';
1564
+ var pathAttr = locked ? '' : ' data-path="' + escapeHtml(path) + '"';
1064
1565
  var input;
1065
1566
  if (opts.multiline) {
1066
- input = '<textarea class="textarea" data-path="' + escapeHtml(path) + '">' + escapeHtml(value) + '</textarea>';
1567
+ input = '<textarea class="textarea' + (locked ? ' is-locked' : '') + '"' + pathAttr + lockAttr + '>' + escapeHtml(value) + '</textarea>';
1067
1568
  } else if (opts.enum) {
1068
- input = '<select class="select" data-path="' + escapeHtml(path) + '">';
1069
- input += '<option value="">— 未填 —</option>';
1569
+ input = '<select class="select' + (locked ? ' is-locked' : '') + '"' + pathAttr + lockAttr + '>';
1570
+ if (locked && value === '') input += '<option value="">— 未填 —</option>';
1070
1571
  for (var i = 0; i < opts.enum.length; i += 1) {
1071
1572
  var option = opts.enum[i];
1072
1573
  input += '<option value="' + escapeHtml(option) + '"' + (option === value ? ' selected' : '') + '>' + escapeHtml(option) + '</option>';
1073
1574
  }
1074
1575
  input += '</select>';
1075
1576
  } else {
1076
- input = '<input class="input" type="' + (opts.date ? 'date' : opts.number ? 'number' : 'text') + '" data-path="' + escapeHtml(path) + '" value="' + escapeHtml(value) + '">';
1577
+ // lang="zh-CN" on a date input: the browser otherwise formats the picker as
1578
+ // mm/dd/yyyy in an English locale, which reads as "month 20" to a Chinese
1579
+ // colleague. The attribute is per-element because it must override the
1580
+ // browser's own locale, not the document's.
1581
+ var langAttr = opts.date ? ' lang="zh-CN"' : '';
1582
+ input = '<input class="input' + (locked ? ' is-locked' : '') + '" type="' + (opts.date ? 'date' : opts.number ? 'number' : 'text') + '"' + pathAttr + langAttr + ' value="' + escapeHtml(value) + '"' + lockAttr + '>';
1077
1583
  }
1078
- return '<div class="field" data-field="' + escapeHtml(path) + '">' +
1079
- '<label class="field-label">' + escapeHtml(label) + req + '</label>' + help + input + '</div>';
1584
+ // The note is redundant when 'help' already explains why the field is locked,
1585
+ // and printing both made a two-line field into a four-line one.
1586
+ var lockNote = locked && !opts.help ? '<p class="field-help field-locked">只读 · 由台账/评审流程维护</p>' : '';
1587
+ return '<div class="field' + (locked ? ' is-locked' : '') + '" data-field="' + escapeHtml(path) + '">' +
1588
+ '<label class="field-label">' + escapeHtml(label) + req + '</label>' + help + input + lockNote + '</div>';
1080
1589
  }
1081
1590
 
1082
1591
  /**
@@ -1101,22 +1610,25 @@ const FORM_SCRIPT = `
1101
1610
  escapeHtml(def.hint) + '">' + escapeHtml(project.gate0[def.key]) + '</textarea>' +
1102
1611
  '</div>';
1103
1612
  }
1104
- // The fifth prerequisite lives in the identity block, so it is counted here
1105
- // but edited there — showing it twice would let the two copies disagree.
1613
+ // The fifth prerequisite lives in the identity block of the ledger, but it is
1614
+ // a G0 requirement, so it is EDITED here — once. It used to be rendered both
1615
+ // here and in the identity card with the same 'data-path', so two inputs owned
1616
+ // one value: typing in one left the other showing stale text, and the last
1617
+ // render won. One field, one input.
1106
1618
  var techFilled = text(project.techOwner).trim() !== '';
1107
1619
  if (techFilled) present += 1;
1108
1620
  cards += '<div class="g0-card" data-present="' + (techFilled ? 'true' : 'false') + '">' +
1109
1621
  '<div class="g0-card-head"><span class="g0-card-label">客户技术责任人' +
1110
1622
  '<span class="req">*</span></span>' +
1111
1623
  (techFilled ? '' : '<span class="g0-card-missing">缺失</span>') + '</div>' +
1112
- '<input class="input" data-path="techOwner" value="' + escapeHtml(project.techOwner) + '" placeholder="第五项必填,在下方身份区也能改">' +
1624
+ '<input class="input" data-path="techOwner" value="' + escapeHtml(project.techOwner) + '" placeholder="谁在客户侧配合验证">' +
1113
1625
  '</div>';
1114
1626
 
1115
1627
  var tone = present === 5 ? 'badge-ok' : present === 0 ? 'badge-warn' : 'badge-info';
1116
1628
  return '<section class="sec">' +
1117
1629
  '<header class="sec-head"><h2 class="sec-title">Gate 0 · 值不值得做</h2>' +
1118
1630
  '<span class="sec-kicker">五必填 <span class="badge ' + tone + '">' + present + ' / 5</span></span></header>' +
1119
- '<p class="sec-hint">这五项齐了,G0 评审才有意义。四项在 gate0 区,第五项是身份区的「客户技术责任人」——两处都能改,改的是同一个字段。</p>' +
1631
+ '<p class="sec-hint">这五项齐了,G0 评审才有意义。第五项「客户技术责任人」也在这里填,身份区不再重复。</p>' +
1120
1632
  '<div class="g0-grid">' + cards + '</div>' +
1121
1633
  '<div class="grid-2">' +
1122
1634
  field('主要竞争对手', 'gate0.competitor', project.gate0.competitor, {}) +
@@ -1268,9 +1780,11 @@ const FORM_SCRIPT = `
1268
1780
  */
1269
1781
  function idPicker(label, path, unused, options, selected, hint) {
1270
1782
  if (options.length === 0) {
1783
+ // Nothing to pick: say so in one muted line instead of two help paragraphs.
1784
+ // A G0 project has no plan yet by design, so this is normal, not a gap.
1271
1785
  return '<div class="field"><label class="field-label">' + escapeHtml(label) + '</label>' +
1272
1786
  '<p class="field-help">' + escapeHtml(hint) + '</p>' +
1273
- '<p class="field-help">先在左边的计划里加上,再来勾选。</p></div>';
1787
+ '<p class="pick-empty">还没有可选项——这个项目还没有' + escapeHtml(label.replace('这一轮', '')) + ',先补计划。</p></div>';
1274
1788
  }
1275
1789
  var chosen = {};
1276
1790
  for (var i = 0; i < selected.length; i += 1) chosen[text(selected[i])] = true;
@@ -1348,87 +1862,130 @@ const FORM_SCRIPT = `
1348
1862
  function identityCard(project) {
1349
1863
  return '<section class="sec">' +
1350
1864
  '<header class="sec-head"><h2 class="sec-title">基本信息</h2></header>' +
1865
+ '<p class="sec-hint">项目编号、阶段、状态是台账的路由键,填表不改它们——阶段推进走 Gate 评审,不靠改表单字段。</p>' +
1351
1866
  '<div class="grid-2">' +
1352
- field('项目编号', 'pocId', project.pocId, { required: DATA.mode === 'blank', help: DATA.mode === 'blank' ? '新建时必填,格式 POC-XXX。' : '' }) +
1867
+ field('项目编号', 'pocId', project.pocId, { required: DATA.mode === 'blank', readonly: DATA.mode !== 'blank', help: DATA.mode === 'blank' ? '新建时必填,格式 POC-XXX。' : '台账主键,不可改。' }) +
1353
1868
  field('项目名称', 'name', project.name, { required: true }) +
1354
1869
  field('体系', 'system', project.system, { enum: DATA.enums.system }) +
1355
1870
  field('客户公司', 'company', project.company, {}) +
1356
1871
  field('部门', 'department', project.department, {}) +
1357
1872
  field('预计金额(万元)', 'amountWan', project.amountWan, { number: true }) +
1358
1873
  field('项目类型', 'pocType', project.pocType, { enum: DATA.enums.pocType }) +
1359
- field('阶段', 'stage', project.stage, { enum: DATA.enums.stage }) +
1360
- field('状态', 'status', project.status, { enum: DATA.enums.status }) +
1874
+ field('阶段', 'stage', project.stage, { enum: DATA.enums.stage, readonly: true, help: '阶段由 Gate 评审推进,不能在这里改。' }) +
1875
+ field('状态', 'status', project.status, { enum: DATA.enums.status, readonly: true, help: '暂停/关闭请走评审流程。' }) +
1361
1876
  field('进入阶段日期', 'stageSince', project.stageSince, { date: true, help: '不填就算不出停滞天数。' }) +
1362
1877
  field('负责人(我方)', 'owner', project.owner, { required: true }) +
1363
1878
  field('销售', 'sales', project.sales, {}) +
1364
- field('客户技术责任人', 'techOwner', project.techOwner, { required: true, help: 'G0 五必填之一。' }) +
1365
1879
  field('客户业务决策人', 'execSponsor', project.execSponsor, {}) +
1366
1880
  '</div></section>';
1367
1881
  }
1368
1882
 
1369
1883
  /**
1370
- * The readiness strip: what this form will still be missing after it is filled.
1884
+ * The project snapshot: where this project actually stands, at a glance.
1371
1885
  *
1372
- * Mirrors the dashboard's reminder band. A colleague filling a form cannot know
1373
- * that a blank 'stage_since' makes the stall clock uncomputable, or that an
1374
- * unpassed G0 blocks the upgrade review — so the form says it while they can
1375
- * still fix it, rather than surfacing it weeks later on the dashboard.
1886
+ * The complaint that drove this block was "通过这个表单看项目的时候,情况好像也看不太
1887
+ * 清楚". The banner showed a title and three pills; everything else a reader needs
1888
+ * to orient — how far G0 has got, whether a plan exists, how many rounds have
1889
+ * been recorded and how stale the newest one is — was either scattered across
1890
+ * sections or missing entirely.
1891
+ *
1892
+ * So this is a five-cell strip of FACTS, each a number plus its meaning. It is
1893
+ * read-only, sits directly under the banner, and is the same information the
1894
+ * dashboard's own card would show. Deliberately not editable: it is orientation,
1895
+ * not a task.
1376
1896
  */
1377
- function readinessCard(project, canEdit) {
1378
- var editable = canEdit || {};
1379
- var gate0Filled = 0;
1897
+ function snapshotCard(project) {
1898
+ var g0Filled = 0;
1380
1899
  for (var i = 0; i < DATA.g0Fields.length; i += 1) {
1381
- if (text(project.gate0[DATA.g0Fields[i].key]).trim() !== '') gate0Filled += 1;
1900
+ if (text(project.gate0[DATA.g0Fields[i].key]).trim() !== '') g0Filled += 1;
1382
1901
  }
1383
- if (text(project.techOwner).trim() !== '') gate0Filled += 1;
1902
+ if (text(project.techOwner).trim() !== '') g0Filled += 1;
1903
+ var g0Tone = g0Filled === 5 ? 'ok' : g0Filled === 0 ? 'warn' : 'info';
1384
1904
 
1385
- var clocks = [];
1386
- if (text(project.stageSince).trim() === '') clocks.push('进入阶段日期');
1387
- if (text(project.gate0.reviewed_at).trim() === '') clocks.push('G0 评审日期');
1388
- var clockTone = clocks.length === 0 ? 'green' : 'slate';
1389
- var clockValue = clocks.length === 0
1390
- ? '两个时钟都已启动,停滞与陈旧能算出来'
1391
- : '缺 ' + clocks.join('、') + ' —— 补了才算得出停滞和陈旧';
1905
+ var crit = project.plan.criteria.length;
1906
+ var scn = project.plan.scenarios.length;
1907
+ var planTone = (crit >= 2 && crit <= 3 && scn >= 3 && scn <= 5) ? 'ok'
1908
+ : (crit === 0 && scn === 0) ? 'muted' : 'warn';
1909
+ var planValue = crit === 0 && scn === 0
1910
+ ? '还没有计划'
1911
+ : '指标 ' + crit + ' · 场景 ' + scn;
1912
+
1913
+ var rounds = project.existingProgressCount;
1914
+ var newest = project.history && project.history.length > 0 ? project.history[0] : null;
1915
+ var roundTone = rounds === 0 ? 'warn' : 'ok';
1916
+ var roundValue = rounds === 0 ? '还没有进展记录' : '最近 ' + (newest && newest.date ? newest.date : '无日期');
1392
1917
 
1393
1918
  var conclusion = text(project.gate0.conclusion).trim();
1394
- var gateTone = 'slate';
1395
- var gateValue = '还没有 G0 评审结论';
1396
- if (conclusion === '通过' && gate0Filled === 5) {
1397
- gateTone = 'amber';
1398
- gateValue = '五必填已齐且评审通过 —— 可以申请升 G1';
1399
- } else if (conclusion === '未通过-退出' || conclusion === '未通过-降级') {
1400
- gateTone = 'red';
1401
- gateValue = 'G0 结论「' + conclusion + '」,不再提示升级';
1402
- } else if (gate0Filled === 5) {
1403
- gateTone = 'green';
1404
- gateValue = '五必填已齐,可以安排 G0 评审';
1405
- } else {
1406
- gateValue = '还缺 ' + (5 - gate0Filled) + ' 项,评审前要补齐';
1407
- }
1919
+ var gateValue = conclusion === '' ? '待评审' : conclusion;
1920
+ var gateTone = conclusion === '通过' ? 'ok' : conclusion === '' ? 'muted' : 'warn';
1408
1921
 
1409
- var crit = project.plan.criteria.length;
1410
- var scn = project.plan.scenarios.length;
1411
- var focusTone = (crit >= 2 && crit <= 3 && scn >= 3 && scn <= 5) ? 'green' : 'amber';
1412
- var focusValue = '指标 ' + crit + ' 条、场景 ' + scn + ' 个';
1413
-
1414
- var tone = gateTone === 'red' ? 'red' : (clockTone === 'slate' || focusTone === 'amber' || gateTone === 'amber') ? 'amber' : 'green';
1415
- return '<section class="readiness" data-tone="' + tone + '">' +
1416
- '<div class="ready-cell"><span class="ready-label">Gate 0 五必填</span>' +
1417
- '<span class="ready-value">' + gate0Filled + ' / 5 · ' + escapeHtml(gateValue) + '</span></div>' +
1418
- '<div class="ready-cell"><span class="ready-label">陈旧度时钟</span>' +
1419
- '<span class="ready-value">' + escapeHtml(clockValue) + '</span></div>' +
1420
- // The focus cell only means something once a plan is expected. A brand-new
1421
- // project has no plan by design (R3 asks for one only after G0 passes), so
1422
- // showing "0 条指标,要求 2–3" would invent a failure.
1423
- (DATA.intent === 'new' ? '' :
1424
- '<div class="ready-cell"><span class="ready-label">计划聚焦</span>' +
1425
- '<span class="ready-value">' + escapeHtml(focusValue) +
1426
- (focusTone === 'green' ? '' : ' · 要求指标 2–3、场景 3–5') + '</span></div>') +
1922
+ var amount = text(project.amountWan).trim();
1923
+ var amountValue = amount === '' ? '未填' : amount + ' 万';
1924
+
1925
+ function cell(label, value, tone) {
1926
+ return '<div class="snap-cell" data-tone="' + tone + '">' +
1927
+ '<span class="snap-label">' + escapeHtml(label) + '</span>' +
1928
+ '<span class="snap-value">' + escapeHtml(value) + '</span></div>';
1929
+ }
1930
+ return '<section class="snapshot">' +
1931
+ cell('Gate 0 五必填', g0Filled + ' / 5', g0Tone) +
1932
+ cell('G0 评审结论', gateValue, gateTone) +
1933
+ cell('方案', planValue, planTone) +
1934
+ cell('进展', rounds + ' 轮 · ' + roundValue, roundTone) +
1935
+ cell('金额', amountValue, 'muted') +
1427
1936
  '</section>';
1428
1937
  }
1429
1938
 
1939
+
1430
1940
  /**
1431
- * The page: banner, readiness strip, then the detail page's fixed two columns.
1941
+ * "What is still missing" — and only that.
1942
+ *
1943
+ * This replaces a three-cell readiness band that restated the snapshot (G0 count,
1944
+ * plan counts) and added two clock hints. Restating the same numbers twice on one
1945
+ * screen is what makes a form feel noisy, so the snapshot owns the facts and this
1946
+ * strip owns the one thing facts cannot say: **what to do next.**
1947
+ *
1948
+ * Empty by design when nothing is actionable. A strip that always shows something
1949
+ * trains people to ignore it.
1950
+ */
1951
+ function missingCard(project, canEdit) {
1952
+ var editable = canEdit || {};
1953
+ var notes = [];
1954
+
1955
+ if (text(project.stageSince).trim() === '' && (editable.identity || DATA.mode === 'blank')) {
1956
+ notes.push('「进入阶段日期」空着,台账算不出这个项目停滞了多久。');
1957
+ }
1958
+
1959
+ var g0Filled = 0;
1960
+ for (var i = 0; i < DATA.g0Fields.length; i += 1) {
1961
+ if (text(project.gate0[DATA.g0Fields[i].key]).trim() !== '') g0Filled += 1;
1962
+ }
1963
+ if (text(project.techOwner).trim() !== '') g0Filled += 1;
1964
+ if (g0Filled < 5 && g0Filled > 0 && !editable.gate0) {
1965
+ // Not this page's job, but the person should know their round will land on a
1966
+ // project whose G0 is still incomplete.
1967
+ notes.push('Gate 0 还缺 ' + (5 - g0Filled) + ' 项,评审前要补齐。');
1968
+ }
1969
+
1970
+ // A plan-stage form is the one place the 2–3 / 3–5 counts are actionable.
1971
+ if (editable.plan) {
1972
+ var crit = project.plan.criteria.length;
1973
+ var scn = project.plan.scenarios.length;
1974
+ if (crit < 2) notes.push('成功指标还差 ' + (2 - crit) + ' 条(要求 2–3)。');
1975
+ else if (crit > 3) notes.push('成功指标 ' + crit + ' 条,超过 3 条上限。');
1976
+ if (scn < 3) notes.push('验证场景还差 ' + (3 - scn) + ' 个(要求 3–5)。');
1977
+ else if (scn > 5) notes.push('验证场景 ' + scn + ' 个,超过 5 个上限。');
1978
+ }
1979
+
1980
+ if (notes.length === 0) return '';
1981
+ var items = '';
1982
+ for (var n = 0; n < notes.length; n += 1) items += '<li>' + escapeHtml(notes[n]) + '</li>';
1983
+ return '<section class="missing"><span class="missing-label">还需要补</span>' +
1984
+ '<ul class="missing-list">' + items + '</ul></section>';
1985
+ }
1986
+
1987
+ /**
1988
+ * The page: banner, snapshot, what-is-missing, then the fixed two columns.
1432
1989
  *
1433
1990
  * Commitments left (Gate 0, criteria, scenarios), the record right (identity,
1434
1991
  * plan narrative, risks, gates), next actions closing across both. That is the
@@ -1483,11 +2040,13 @@ const FORM_SCRIPT = `
1483
2040
  var canEdit = {};
1484
2041
  for (var e = 0; e < plan_.editable.length; e += 1) canEdit[plan_.editable[e]] = true;
1485
2042
 
1486
- var body = banner + readinessCard(project, canEdit);
2043
+ var body = banner + snapshotCard(project) + missingCard(project, canEdit);
1487
2044
 
1488
- // 'progress' intent is the one-screen case: the round and nothing else.
2045
+ // 'progress' intent is the one-screen case: the round and nothing else. The
2046
+ // history goes above it, because "what has already been reported" is the
2047
+ // context the new round is written against.
1489
2048
  if (DATA.intent === 'progress') {
1490
- body += progressCard(project) + nextCard(project);
2049
+ body += historyCard(project) + progressCard(project) + nextCard(project);
1491
2050
  byId('formBody').innerHTML = body;
1492
2051
  bindSwitch();
1493
2052
  markFooter();
@@ -1496,20 +2055,34 @@ const FORM_SCRIPT = `
1496
2055
 
1497
2056
  var left = '';
1498
2057
  if (canEdit.gate0) left += g0Card(project); else left += contextGate0(project);
1499
- // A new project has no plan yet, so there is nothing to show read-only —
1500
- // an empty "方案 · 只读" block would only suggest work that does not exist.
2058
+
2059
+ // Read-only context is driven by the Host's resolved 'context' list, NOT by
2060
+ // "intent !== new". The old check was the bug behind "什么都能填、什么都能改":
2061
+ // a G0 supplement rendered a read-only PLAN block for a plan that does not
2062
+ // exist yet, which both invented a failure ("指标 0,要求 2–3") and told the
2063
+ // colleague they were looking at a stage the project has not reached.
2064
+ var showContext = {};
2065
+ for (var ci = 0; ci < plan_.context.length; ci += 1) showContext[plan_.context[ci]] = true;
2066
+
1501
2067
  if (canEdit.plan) left += planCard(project);
1502
- else if (DATA.intent !== 'new') left += contextPlan(project);
2068
+ else if (showContext.plan) left += contextPlan(project);
2069
+
2070
+ // The G4 conclusion is the SUBJECT of a G4 form, so it belongs in the wide
2071
+ // left column with the other commitments — not squeezed into the narrow record
2072
+ // column, which left most of the page empty and made the form look broken.
2073
+ if (canEdit.outcome) left += outcomeCard(project);
1503
2074
 
1504
2075
  var right = '';
1505
2076
  if (canEdit.identity) right += identityCard(project); else right += contextIdentity(project);
1506
2077
  if (canEdit.plan) right += planNarrative(project) + riskCard(project);
1507
2078
  if (canEdit.gate12) right += gateCard(project);
1508
- if (canEdit.outcome) right += outcomeCard(project);
1509
2079
 
1510
2080
  if (left !== '') body += '<div class="columns"><div class="col">' + left + '</div><div class="col">' + right + '</div></div>';
1511
2081
  else if (right !== '') body += '<div class="columns"><div class="col"></div><div class="col">' + right + '</div></div>';
1512
2082
 
2083
+ // History sits immediately above the new round: read what happened, then say
2084
+ // what changed. A new project has no history, so the block is simply absent.
2085
+ body += historyCard(project);
1513
2086
  if (canEdit.progress || DATA.intent === 'new') body += progressCard(project) + nextCard(project);
1514
2087
 
1515
2088
  byId('formBody').innerHTML = body;
@@ -1538,7 +2111,16 @@ const FORM_SCRIPT = `
1538
2111
  info.textContent = intentLabel() + ' · 共 ' + DATA.projects.length + ' 个项目 · 草稿自动保存在本机浏览器';
1539
2112
  }
1540
2113
 
1541
- /** Read-only Gate 0 summary: a completed stage is context, not a task. */
2114
+ /**
2115
+ * Read-only Gate 0 summary: a completed stage is context, not a task.
2116
+ *
2117
+ * It used to render only "五必填 3 / 5" and a sentence — the actual answers were
2118
+ * never shown. That is the "看不清项目情况" complaint in its purest form: a
2119
+ * colleague supplementing the plan could not read what G0 had already decided,
2120
+ * and a reviewer opening the returned file could not check whether the new round
2121
+ * contradicted it. The answers are now shown in full, collapsed by default so
2122
+ * they inform without pushing the fields-to-fill down the page.
2123
+ */
1542
2124
  function contextGate0(project) {
1543
2125
  var present = 0;
1544
2126
  for (var i = 0; i < DATA.g0Fields.length; i += 1) {
@@ -1546,21 +2128,143 @@ const FORM_SCRIPT = `
1546
2128
  }
1547
2129
  if (text(project.techOwner).trim() !== '') present += 1;
1548
2130
  var tone = present === 5 ? 'badge-ok' : 'badge-warn';
2131
+
2132
+ var rows = '';
2133
+ for (var j = 0; j < DATA.g0Fields.length; j += 1) {
2134
+ rows += readPair(DATA.g0Fields[j].label, project.gate0[DATA.g0Fields[j].key]);
2135
+ }
2136
+ rows += readPair('客户技术责任人', project.techOwner);
2137
+ rows += readPair('主要竞争对手', project.gate0.competitor);
2138
+ rows += readPair('G0 评审结论', project.gate0.conclusion);
2139
+ rows += readPair('G0 评审人', project.gate0.reviewer);
2140
+ rows += readPair('评审日期', project.gate0.reviewed_at);
2141
+
1549
2142
  return '<section class="sec">' +
1550
- '<header class="sec-head"><h2 class="sec-title">Gate 0 · 只读</h2>' +
2143
+ '<header class="sec-head"><h2 class="sec-title">Gate 0 · 值不值得做</h2>' +
1551
2144
  '<span class="sec-kicker"><span class="badge ' + tone + '">五必填 ' + present + ' / 5</span></span></header>' +
1552
- '<p class="sec-hint">这一阶段已完成,内容作为上下文展示。要修改请单独导出「补充信息」表单并选择 G0。</p>' +
2145
+ '<details class="read-context"><summary>已完成的立项内容(只读,点开查看)</summary>' +
2146
+ '<dl class="read-grid">' + rows + '</dl></details>' +
2147
+ '<p class="sec-hint">要改 Gate 0,请单独导出「补充信息」表单并选择 G0 阶段。</p>' +
1553
2148
  '</section>';
1554
2149
  }
1555
2150
 
1556
- /** Read-only plan summary. */
2151
+ /** One label/value row in a read-only context block. */
2152
+ function readPair(label, value) {
2153
+ var raw = text(value).trim();
2154
+ return '<div class="read-pair"><dt>' + escapeHtml(label) + '</dt>' +
2155
+ '<dd' + (raw === '' ? ' class="read-empty"' : '') + '>' + (raw === '' ? '未填写' : escapeHtml(raw)) + '</dd></div>';
2156
+ }
2157
+
2158
+ /**
2159
+ * Read-only plan summary.
2160
+ *
2161
+ * Same defect as the Gate 0 block: it reported counts ("指标 0 · 场景 0") but not
2162
+ * the plan itself. A G3 colleague recording a proof needs to know which scenarios
2163
+ * and criteria the proof is supposed to attach to — that is the whole point of
2164
+ * the pickers below it. Counts alone told them nothing.
2165
+ */
1557
2166
  function contextPlan(project) {
1558
2167
  var crit = project.plan.criteria.length;
1559
2168
  var scn = project.plan.scenarios.length;
2169
+ var rows = '';
2170
+ rows += readPair('客户核心痛点', project.plan.customer_pain);
2171
+ rows += readPair('期望客户认可什么', project.plan.expected_recognition);
2172
+ rows += readPair('我方优势 / 赢点', project.plan.our_edge);
2173
+ rows += readPair('计划开始', project.plan.timeline_start);
2174
+ rows += readPair('计划结束', project.plan.timeline_end);
2175
+ rows += readPair('G1 结论', project.plan.gate1_conclusion);
2176
+ rows += readPair('G2 Ready', project.plan.gate2_ready);
2177
+
2178
+ var lists = '';
2179
+ if (crit > 0) {
2180
+ var critItems = '';
2181
+ for (var c = 0; c < crit; c += 1) {
2182
+ var criterion = project.plan.criteria[c];
2183
+ critItems += '<li><span class="read-id">' + escapeHtml(criterion.id) + '</span>' +
2184
+ escapeHtml(criterion.name) +
2185
+ (text(criterion.target).trim() === '' ? '' : '<span class="read-dim"> · 目标 ' + escapeHtml(criterion.target) + '</span>') +
2186
+ '</li>';
2187
+ }
2188
+ lists += '<div class="read-list-block"><h3>关键成功指标</h3><ul class="read-list">' + critItems + '</ul></div>';
2189
+ }
2190
+ if (scn > 0) {
2191
+ var scnItems = '';
2192
+ for (var s = 0; s < scn; s += 1) {
2193
+ var scenario = project.plan.scenarios[s];
2194
+ scnItems += '<li><span class="read-id">' + escapeHtml(scenario.id) + '</span>' + escapeHtml(scenario.name) +
2195
+ (text(scenario.goal).trim() === '' ? '' : '<span class="read-dim"> · ' + escapeHtml(scenario.goal) + '</span>') +
2196
+ '</li>';
2197
+ }
2198
+ lists += '<div class="read-list-block"><h3>验证场景</h3><ul class="read-list">' + scnItems + '</ul></div>';
2199
+ }
2200
+ if (project.plan.risks.length > 0) {
2201
+ var riskItems = '';
2202
+ for (var r = 0; r < project.plan.risks.length; r += 1) {
2203
+ var risk = project.plan.risks[r];
2204
+ riskItems += '<li>' + escapeHtml(risk.name) +
2205
+ (text(risk.level).trim() === '' ? '' : '<span class="read-dim"> · ' + escapeHtml(risk.level) + '</span>') +
2206
+ (text(risk.mitigation).trim() === '' ? '' : '<span class="read-dim"> · 应对 ' + escapeHtml(risk.mitigation) + '</span>') +
2207
+ '</li>';
2208
+ }
2209
+ lists += '<div class="read-list-block"><h3>风险</h3><ul class="read-list">' + riskItems + '</ul></div>';
2210
+ }
2211
+
2212
+ var body = rows + lists;
2213
+ if (text(body).trim() === '') {
2214
+ return '<section class="sec">' +
2215
+ '<header class="sec-head"><h2 class="sec-title">方案 · 只读</h2>' +
2216
+ '<span class="sec-kicker">还没有方案</span></header>' +
2217
+ '<p class="sec-hint">这个项目还没有填过计划。方案在 G1 阶段补充。</p></section>';
2218
+ }
1560
2219
  return '<section class="sec">' +
1561
- '<header class="sec-head"><h2 class="sec-title">方案 · 只读</h2>' +
2220
+ '<header class="sec-head"><h2 class="sec-title">方案 · 已确认内容</h2>' +
1562
2221
  '<span class="sec-kicker">指标 ' + crit + ' · 场景 ' + scn + '</span></header>' +
1563
- '<p class="sec-hint">方案已锁定为只读。要改计划,请导出「补充信息」表单并选择对应阶段。</p>' +
2222
+ '<details class="read-context"><summary>方案详情(只读,点开查看)</summary>' +
2223
+ '<dl class="read-grid">' + rows + '</dl>' + lists + '</details>' +
2224
+ '<p class="sec-hint">要改计划,请导出「补充信息」表单并选择 G1 / G2 阶段。</p>' +
2225
+ '</section>';
2226
+ }
2227
+
2228
+ /**
2229
+ * The recorded rounds, newest first, read-only.
2230
+ *
2231
+ * The single most useful thing the form can show: what has already been
2232
+ * reported. Without it a colleague writes "已完成压测" for the third week
2233
+ * running, and the reviewer cannot tell what is new. Shown collapsed so it
2234
+ * informs the new entry without pushing it off screen.
2235
+ */
2236
+ function historyCard(project) {
2237
+ var history = project.history || [];
2238
+ if (history.length === 0) return '';
2239
+ var rows = '';
2240
+ for (var i = 0; i < history.length; i += 1) {
2241
+ var entry = history[i];
2242
+ var head = '<div class="hist-head">' +
2243
+ '<span class="hist-seq">#' + (entry.seq === null ? '?' : entry.seq) + '</span>' +
2244
+ '<span class="hist-date">' + escapeHtml(entry.date || '无日期') + '</span>' +
2245
+ (entry.type ? '<span class="hist-type">' + escapeHtml(entry.type) + '</span>' : '') +
2246
+ (entry.change ? '<span class="hist-change">' + escapeHtml(entry.change) + '</span>' : '') +
2247
+ (entry.completion ? '<span class="hist-pct">' + escapeHtml(entry.completion) + '</span>' : '') +
2248
+ '</div>';
2249
+ var body = '';
2250
+ if (entry.actual) body += '<p class="hist-actual">' + escapeHtml(entry.actual) + '</p>';
2251
+ var meta = [];
2252
+ if (entry.evidence.length) meta.push('证据 ' + entry.evidence.length + ' 条');
2253
+ if (entry.syncedWith) meta.push('同步 ' + entry.syncedWith);
2254
+ if (entry.recognition) meta.push('客户' + entry.recognition);
2255
+ if (entry.nextGoal) meta.push('下一步 ' + entry.nextGoal);
2256
+ if (entry.nextDeadline) meta.push('截止 ' + entry.nextDeadline);
2257
+ if (meta.length) body += '<p class="hist-meta">' + escapeHtml(meta.join(' · ')) + '</p>';
2258
+ rows += '<li class="hist-item">' + head + body + '</li>';
2259
+ }
2260
+ var more = project.existingProgressCount > history.length
2261
+ ? '<p class="sec-hint">仅显示最近 ' + history.length + ' 条,共 ' + project.existingProgressCount + ' 条。</p>'
2262
+ : '';
2263
+ return '<section class="sec">' +
2264
+ '<header class="sec-head"><h2 class="sec-title">已有进展</h2>' +
2265
+ '<span class="sec-kicker">共 ' + project.existingProgressCount + ' 条 · 只读</span></header>' +
2266
+ '<details class="read-context" open><summary>最近 ' + history.length + ' 条(只读)</summary>' +
2267
+ '<ol class="hist-list">' + rows + '</ol></details>' + more +
1564
2268
  '</section>';
1565
2269
  }
1566
2270
 
@@ -1820,60 +2524,147 @@ const FORM_SCRIPT = `
1820
2524
  var raw = text(value).trim();
1821
2525
  return raw === '' ? null : raw;
1822
2526
  }
2527
+ // Only the blocks this page let the person edit, mirroring the Host's
2528
+ // projectToChangeSet. Everything else is emitted as null/empty so the merge
2529
+ // step skips it: the page pre-fills from the ledger, and re-sending a
2530
+ // pre-filled value would overwrite a field that changed after export.
2531
+ var plan_ = DATA.sections[state.active] || { editable: ['identity', 'gate0', 'plan', 'progress'] };
2532
+ var scope = {};
2533
+ for (var s = 0; s < plan_.editable.length; s += 1) scope[plan_.editable[s]] = true;
2534
+ if (scope.plan) scope.gate12 = true;
2535
+ function inScope(section) { return scope[section] === true; }
2536
+
2537
+ // The seed snapshot: what these fields held when the form was generated.
2538
+ var base = (DATA.baseline || [])[state.active] || null;
2539
+ function seeded(path) {
2540
+ if (!base) return '';
2541
+ var parts = path.split('.');
2542
+ var node = base;
2543
+ for (var i = 0; i < parts.length; i += 1) {
2544
+ if (node === null || node === undefined) return '';
2545
+ node = node[parts[i]];
2546
+ }
2547
+ return text(node);
2548
+ }
2549
+ /**
2550
+ * A value, or null when it is unchanged or out of scope.
2551
+ *
2552
+ * This diff is the whole reason a returned form is safe to merge: it means
2553
+ * "only what this person edited", not "a snapshot of the project on the day
2554
+ * the form was exported".
2555
+ */
2556
+ function changed(section, path, value) {
2557
+ if (!inScope(section)) return null;
2558
+ var raw = text(value).trim();
2559
+ if (raw === '') return null;
2560
+ return raw === seeded(path).trim() ? null : raw;
2561
+ }
2562
+ /** A list, or null when it is unchanged as a whole. */
2563
+ function changedList(section, list, baseList) {
2564
+ if (!inScope(section)) return null;
2565
+ if (list.length === 0) return null;
2566
+ if (baseList && JSON.stringify(list) === JSON.stringify(baseList)) return null;
2567
+ return list;
2568
+ }
2569
+
1823
2570
  var criteria = [];
1824
- for (var i = 0; i < project.plan.criteria.length; i += 1) {
2571
+ if (inScope('plan')) for (var i = 0; i < project.plan.criteria.length; i += 1) {
1825
2572
  var c = project.plan.criteria[i];
1826
2573
  if (text(c.name).trim() === '') continue;
1827
2574
  criteria.push({ id: orNull(c.id), name: text(c.name).trim(), metric: orNull(c.metric), baseline: orNull(c.baseline), target: orNull(c.target) });
1828
2575
  }
1829
2576
  var scenarios = [];
1830
- for (var j = 0; j < project.plan.scenarios.length; j += 1) {
2577
+ if (inScope('plan')) for (var j = 0; j < project.plan.scenarios.length; j += 1) {
1831
2578
  var sc = project.plan.scenarios[j];
1832
2579
  if (text(sc.name).trim() === '') continue;
1833
2580
  scenarios.push({ id: orNull(sc.id), name: text(sc.name).trim(), goal: orNull(sc.goal) });
1834
2581
  }
1835
2582
  var risks = [];
1836
- for (var k = 0; k < project.plan.risks.length; k += 1) {
2583
+ if (inScope('plan')) for (var k = 0; k < project.plan.risks.length; k += 1) {
1837
2584
  var r = project.plan.risks[k];
1838
2585
  if (text(r.name).trim() === '') continue;
1839
2586
  risks.push({ name: text(r.name).trim(), level: orNull(r.level), mitigation: orNull(r.mitigation) });
1840
2587
  }
2588
+ var basePlan = base && base.plan ? base.plan : null;
2589
+ var baseCriteria = basePlan ? basePlan.criteria.filter(function (x) { return text(x.name).trim() !== ''; }).map(function (x) {
2590
+ return { id: orNull(x.id), name: text(x.name).trim(), metric: orNull(x.metric), baseline: orNull(x.baseline), target: orNull(x.target) };
2591
+ }) : null;
2592
+ var baseScenarios = basePlan ? basePlan.scenarios.filter(function (x) { return text(x.name).trim() !== ''; }).map(function (x) {
2593
+ return { id: orNull(x.id), name: text(x.name).trim(), goal: orNull(x.goal) };
2594
+ }) : null;
2595
+ var baseRisks = basePlan ? basePlan.risks.filter(function (x) { return text(x.name).trim() !== ''; }).map(function (x) {
2596
+ return { name: text(x.name).trim(), level: orNull(x.level), mitigation: orNull(x.mitigation) };
2597
+ }) : null;
2598
+
1841
2599
  var rounds = [];
1842
2600
  var entry = project.progress;
1843
2601
  var touched = text(entry.date).trim() !== '' || text(entry.actual).trim() !== '' || text(entry.goal).trim() !== '';
1844
- if (touched) rounds.push(progressEntryOf(entry));
2602
+ if (inScope('progress') && touched) rounds.push(progressEntryOf(entry));
2603
+ var outcome = project.outcome || {};
2604
+ var amount = text(project.amountWan).trim();
1845
2605
  return {
1846
2606
  schema_version: DATA.schemaVersion,
1847
2607
  poc_id: text(project.pocId).trim(),
1848
- name: text(project.name).trim(),
1849
- org: { system: orNull(project.system), company: orNull(project.company), department: orNull(project.department) },
1850
- amount_wan: text(project.amountWan).trim() === '' ? null : Number(project.amountWan),
1851
- poc_type: orNull(project.pocType),
1852
- owner: orNull(project.owner),
1853
- sales: orNull(project.sales),
1854
- tech_owner: orNull(project.techOwner),
1855
- exec_sponsor: orNull(project.execSponsor),
2608
+ name: changed('identity', 'name', project.name) || '',
2609
+ org: {
2610
+ system: changed('identity', 'system', project.system),
2611
+ company: changed('identity', 'company', project.company),
2612
+ department: changed('identity', 'department', project.department)
2613
+ },
2614
+ amount_wan: (inScope('identity') && amount !== '' && amount !== seeded('amountWan')) ? Number(amount) : null,
2615
+ poc_type: changed('identity', 'pocType', project.pocType),
2616
+ owner: changed('identity', 'owner', project.owner),
2617
+ sales: changed('identity', 'sales', project.sales),
2618
+ tech_owner: changed('identity', 'techOwner', project.techOwner),
2619
+ exec_sponsor: changed('identity', 'execSponsor', project.execSponsor),
1856
2620
  stage: project.stage,
1857
2621
  status: project.status,
1858
- stage_since: orNull(project.stageSince),
2622
+ stage_since: changed('identity', 'stageSince', project.stageSince),
1859
2623
  gate0: {
1860
- why_customer: orNull(project.gate0.why_customer),
1861
- why_us: orNull(project.gate0.why_us),
1862
- decision_chain: orNull(project.gate0.decision_chain),
1863
- post_poc_decision: orNull(project.gate0.post_poc_decision),
1864
- competitor: orNull(project.gate0.competitor),
1865
- review: { conclusion: orNull(project.gate0.conclusion), reviewer: orNull(project.gate0.reviewer), reviewed_at: orNull(project.gate0.reviewed_at) }
2624
+ why_customer: changed('gate0', 'gate0.why_customer', project.gate0.why_customer),
2625
+ why_us: changed('gate0', 'gate0.why_us', project.gate0.why_us),
2626
+ decision_chain: changed('gate0', 'gate0.decision_chain', project.gate0.decision_chain),
2627
+ post_poc_decision: changed('gate0', 'gate0.post_poc_decision', project.gate0.post_poc_decision),
2628
+ competitor: changed('gate0', 'gate0.competitor', project.gate0.competitor),
2629
+ review: {
2630
+ conclusion: changed('gate0', 'gate0.conclusion', project.gate0.conclusion),
2631
+ reviewer: changed('gate0', 'gate0.reviewer', project.gate0.reviewer),
2632
+ reviewed_at: changed('gate0', 'gate0.reviewed_at', project.gate0.reviewed_at)
2633
+ }
1866
2634
  },
1867
2635
  plan: {
1868
- customer_pain: orNull(project.plan.customer_pain),
1869
- expected_recognition: orNull(project.plan.expected_recognition),
1870
- our_edge: orNull(project.plan.our_edge),
1871
- criteria: criteria,
1872
- scenarios: scenarios,
1873
- risks: risks,
1874
- timeline: { start: orNull(project.plan.timeline_start), end: orNull(project.plan.timeline_end) },
1875
- gate1: { conclusion: orNull(project.plan.gate1_conclusion) },
1876
- gate2: { ready: orNull(project.plan.gate2_ready) }
2636
+ customer_pain: changed('plan', 'plan.customer_pain', project.plan.customer_pain),
2637
+ expected_recognition: changed('plan', 'plan.expected_recognition', project.plan.expected_recognition),
2638
+ our_edge: changed('plan', 'plan.our_edge', project.plan.our_edge),
2639
+ criteria: changedList('plan', criteria, baseCriteria) || [],
2640
+ scenarios: changedList('plan', scenarios, baseScenarios) || [],
2641
+ risks: changedList('plan', risks, baseRisks) || [],
2642
+ timeline: {
2643
+ start: changed('plan', 'plan.timeline_start', project.plan.timeline_start),
2644
+ end: changed('plan', 'plan.timeline_end', project.plan.timeline_end)
2645
+ },
2646
+ gate1: { conclusion: changed('gate12', 'plan.gate1_conclusion', project.plan.gate1_conclusion) },
2647
+ gate2: { ready: changed('gate12', 'plan.gate2_ready', project.plan.gate2_ready) }
2648
+ },
2649
+ // The G4 conclusion block. It was absent from this serializer while the page
2650
+ // could edit it, so every G4 answer was dropped on download.
2651
+ outcome: {
2652
+ achievement: changed('outcome', 'outcome.achievement', outcome.achievement),
2653
+ customer_recognition: changed('outcome', 'outcome.customer_recognition', outcome.customer_recognition),
2654
+ our_proof: changed('outcome', 'outcome.our_proof', outcome.our_proof),
2655
+ remaining_risks: null,
2656
+ conclusion: {
2657
+ proved: changed('outcome', 'outcome.proved', outcome.proved),
2658
+ recognized: changed('outcome', 'outcome.recognized', outcome.recognized),
2659
+ next_business: changed('outcome', 'outcome.next_business', outcome.next_business)
2660
+ },
2661
+ business: {
2662
+ milestone: changed('outcome', 'outcome.milestone', outcome.milestone),
2663
+ owner: changed('outcome', 'outcome.businessOwner', outcome.businessOwner),
2664
+ deadline: changed('outcome', 'outcome.businessDeadline', outcome.businessDeadline),
2665
+ status: changed('outcome', 'outcome.businessStatus', outcome.businessStatus)
2666
+ },
2667
+ overall: changed('outcome', 'outcome.overall', outcome.overall)
1877
2668
  },
1878
2669
  progress: rounds
1879
2670
  };
@@ -1923,9 +2714,78 @@ const FORM_SCRIPT = `
1923
2714
  if (node.scrollIntoView) node.scrollIntoView({ behavior: 'smooth', block: 'start' });
1924
2715
  }
1925
2716
 
2717
+ /**
2718
+ * The bare-minimum required fields, checked before a download.
2719
+ *
2720
+ * ## The bug this replaces
2721
+ *
2722
+ * The list was unconditional: it demanded 'progress.date', 'progress.change',
2723
+ * 'progress.actual' and 'progress.next.goal' on EVERY form. But a G0/G1
2724
+ * supplement form does not render the progress block at all, so those four
2725
+ * values are empty by construction and no amount of filling anything on the
2726
+ * page could satisfy them. Every supplement, new and batch form refused to
2727
+ * download, forever, with a toast that named no field — the form was a dead end.
2728
+ *
2729
+ * The rule is now: **only demand what this page actually asks for.** The scope
2730
+ * comes from the same 'sections' resolution the renderer used, so the validator
2731
+ * cannot drift from what is on screen. Returns the list of missing labels so the
2732
+ * toast can name them instead of saying "还有必填项没填".
2733
+ */
2734
+ function validateRequired() {
2735
+ var project = current();
2736
+ var plan_ = DATA.sections[state.active] || { editable: ['identity', 'gate0', 'plan', 'progress'] };
2737
+ var scope = {};
2738
+ for (var s = 0; s < plan_.editable.length; s += 1) scope[plan_.editable[s]] = true;
2739
+ // 'gate12' is the plan's verdict block; it rides with 'plan' on the page.
2740
+ if (scope.plan) scope.gate12 = true;
2741
+
2742
+ var required = [];
2743
+ if (scope.identity) {
2744
+ required.push(['name', '项目名称']);
2745
+ required.push(['owner', '负责人(我方)']);
2746
+ required.push(['techOwner', '客户技术责任人']);
2747
+ }
2748
+ if (scope.progress) {
2749
+ required.push(['progress.date', '进展日期']);
2750
+ // v3.1 makes 'change' mandatory: a round that does not say what moved is
2751
+ // how a timeline decays into "communicated with customer".
2752
+ required.push(['progress.change', '这一次什么变了']);
2753
+ required.push(['progress.actual', '实际结果']);
2754
+ required.push(['progress.next.goal', '下一步目标']);
2755
+ }
2756
+
2757
+ var missing = [];
2758
+ for (var i = 0; i < required.length; i += 1) {
2759
+ var key = required[i][0];
2760
+ var label = required[i][1];
2761
+ var value = text(pathValue(project, key)).trim();
2762
+ var node = document.querySelector('[data-field="' + key + '"]');
2763
+ if (node) node.className = value === '' ? 'field has-error' : 'field';
2764
+ if (value === '') missing.push(label);
2765
+ }
2766
+ validateRequired.missing = missing;
2767
+ return missing.length === 0;
2768
+ }
2769
+
2770
+ /** Read a dotted path off the project, treating 'progress.*' as the new round. */
2771
+ function pathValue(project, path) {
2772
+ var parts = path.split('.');
2773
+ var node = project;
2774
+ for (var i = 0; i < parts.length; i += 1) {
2775
+ if (node === null || node === undefined) return '';
2776
+ node = node[parts[i]];
2777
+ }
2778
+ return node;
2779
+ }
2780
+
1926
2781
  function downloadYaml() {
1927
2782
  if (!validateRequired()) {
1928
- showToast('还有必填项没填');
2783
+ // Name the fields: a toast that says only "还有必填项没填" leaves the person
2784
+ // hunting a long page for a red border that may be below the fold.
2785
+ var missing = validateRequired.missing || [];
2786
+ showToast('还有 ' + missing.length + ' 项必填没填:' + missing.join('、'));
2787
+ var first = document.querySelector('.field.has-error');
2788
+ if (first && first.scrollIntoView) first.scrollIntoView({ behavior: 'smooth', block: 'center' });
1929
2789
  return;
1930
2790
  }
1931
2791
  var stamp = DATA.today.replace(/-/g, '');
@@ -1945,32 +2805,296 @@ const FORM_SCRIPT = `
1945
2805
  save(true);
1946
2806
  }
1947
2807
 
1948
- /** The bare-minimum required fields, checked before a download. */
1949
- function validateRequired() {
1950
- var ok = true;
1951
- var project = current();
1952
- var required = [
1953
- ['name', project.name],
1954
- ['owner', project.owner],
1955
- ['techOwner', project.techOwner],
1956
- ['progress.date', project.progress.date],
1957
- // v3.1 makes 'change' mandatory: a round that does not say what moved is
1958
- // how a timeline decays into "communicated with customer". The ledger
1959
- // rejects a null, so the form must refuse to download one.
1960
- ['progress.change', project.progress.change],
1961
- ['progress.actual', project.progress.actual],
1962
- ['progress.next.goal', project.progress.next.goal]
1963
- ];
1964
- for (var i = 0; i < required.length; i += 1) {
1965
- var key = required[i][0];
1966
- var value = text(required[i][1]).trim();
1967
- var node = document.querySelector('[data-field="' + key + '"]');
1968
- if (node) node.className = value === '' ? 'field has-error' : 'field';
1969
- if (value === '') ok = false;
2808
+ /**
2809
+ * Download the HTML itself, with the answers embedded, so it can be sent back.
2810
+ *
2811
+ * ## Why this exists
2812
+ *
2813
+ * The documented workflow is "colleague fills the HTML, sends it to me on WeChat,
2814
+ * I hand it to DSH". But the form's answers live only in 'localStorage' and in
2815
+ * the downloaded JSON — the HTML file on disk never changes, so forwarding the
2816
+ * file forwarded a blank form. The colleague had to find, download and attach a
2817
+ * second file, and the person receiving it needed a JSON viewer to read it.
2818
+ *
2819
+ * So this writes a **copy of this page** whose 'RETURN_DATA' block carries the
2820
+ * change set. The recipient opens it in any browser and reads the answers as
2821
+ * formatted HTML, while 'readReturnDocument' parses the same block
2822
+ * programmatically. One file, no second download, no tooling on either end.
2823
+ *
2824
+ * The embedded block is inert data, never executed: it is parsed with
2825
+ * 'JSON.parse' on a string, and the page renders it with 'textContent'.
2826
+ */
2827
+ function downloadReturnFile() {
2828
+ if (!validateRequired()) {
2829
+ var missing = validateRequired.missing || [];
2830
+ showToast('还有 ' + missing.length + ' 项必填没填:' + missing.join('、'));
2831
+ var first = document.querySelector('.field.has-error');
2832
+ if (first && first.scrollIntoView) first.scrollIntoView({ behavior: 'smooth', block: 'center' });
2833
+ return;
2834
+ }
2835
+ var document_ = toChangeDocument();
2836
+ var payload = JSON.stringify(document_);
2837
+ // Escape the three sequences that can break out of a script element or a
2838
+ // template placeholder, then embed.
2839
+ var safe = payload
2840
+ .replace(/</g, '\\\\u003c')
2841
+ .replace(/>/g, '\\\\u003e')
2842
+ .replace(/\\u2028/g, '\\\\u2028')
2843
+ .replace(/\\u2029/g, '\\\\u2029');
2844
+ var page = buildReturnPage(safe, document_);
2845
+ var stamp = DATA.today.replace(/-/g, '');
2846
+ var blob = new Blob([page], { type: 'text/html;charset=utf-8' });
2847
+ var url = URL.createObjectURL(blob);
2848
+ var anchor = document.createElement('a');
2849
+ anchor.href = url;
2850
+ anchor.download = 'poc-return-' + stamp + '.html';
2851
+ document.body.appendChild(anchor);
2852
+ anchor.click();
2853
+ document.body.removeChild(anchor);
2854
+ setTimeout(function () { URL.revokeObjectURL(url); }, 4000);
2855
+ showToast('已生成回传文件,请通过企业微信发给发起人');
2856
+ save(true);
2857
+ }
2858
+
2859
+ /**
2860
+ * The self-contained page a colleague sends back.
2861
+ *
2862
+ * Deliberately plain: it is a READ-ONLY report, not another form. It carries the
2863
+ * same visual tokens so it reads as the same product, and it repeats the exact
2864
+ * change-set JSON in a machine-readable block for the Host to parse.
2865
+ */
2866
+ function buildReturnPage(safeJson, document_) {
2867
+ var rows = '';
2868
+ var intentText = DATA.intent === 'new' ? '新建项目' : DATA.intent === 'progress' ? '记录进展' : '补充信息';
2869
+ for (var i = 0; i < document_.changes.length; i += 1) {
2870
+ var change = document_.changes[i];
2871
+ // The change set only carries what the colleague could EDIT, so a
2872
+ // progress-intent change has no project name and no Gate 0. The reader still
2873
+ // needs the project's identity and context to make sense of the round, so
2874
+ // the source project is merged back in for DISPLAY ONLY. The embedded JSON
2875
+ // block stays the untouched change set — that is what the Host parses, and
2876
+ // re-sending a pre-filled field would overwrite a newer ledger value.
2877
+ var source = null;
2878
+ for (var si = 0; si < DATA.projects.length; si += 1) {
2879
+ if (DATA.projects[si].pocId === change.poc_id) { source = DATA.projects[si]; break; }
2880
+ }
2881
+ var shown = mergeForDisplay(change, source);
2882
+ var block = '';
2883
+ block += returnSection('项目身份', [
2884
+ ['项目编号', shown.poc_id], ['项目名称', shown.name],
2885
+ ['体系', shown.org && shown.org.system], ['客户公司', shown.org && shown.org.company],
2886
+ ['部门', shown.org && shown.org.department],
2887
+ ['预计金额(万元)', shown.amount_wan === null || shown.amount_wan === undefined ? '' : String(shown.amount_wan)],
2888
+ ['项目类型', shown.poc_type], ['阶段', shown.stage], ['状态', shown.status],
2889
+ ['负责人(我方)', shown.owner], ['销售', shown.sales],
2890
+ ['客户技术责任人', shown.tech_owner], ['客户业务决策人', shown.exec_sponsor]
2891
+ ]);
2892
+ var g0 = shown.gate0 || {};
2893
+ block += returnSection('Gate 0 · 值不值得做', [
2894
+ ['客户为什么要测', g0.why_customer], ['我们为什么测', g0.why_us],
2895
+ ['项目流程 / 决策链', g0.decision_chain], ['测完后客户会做什么决定', g0.post_poc_decision],
2896
+ ['主要竞争对手', g0.competitor],
2897
+ ['G0 评审结论', g0.review && g0.review.conclusion],
2898
+ ['G0 评审人', g0.review && g0.review.reviewer],
2899
+ ['评审日期', g0.review && g0.review.reviewed_at]
2900
+ ]);
2901
+ var plan = shown.plan || {};
2902
+ block += returnSection('方案 · 客户痛点与赢点', [
2903
+ ['客户核心痛点', plan.customer_pain], ['期望客户认可什么', plan.expected_recognition],
2904
+ ['我方优势 / 赢点', plan.our_edge]
2905
+ ]);
2906
+ if (plan.criteria && plan.criteria.length) {
2907
+ var critRows = '';
2908
+ for (var c = 0; c < plan.criteria.length; c += 1) {
2909
+ var cri = plan.criteria[c];
2910
+ critRows += '<li><b>' + escapeHtml(cri.id || '') + '</b> ' + escapeHtml(cri.name || '') +
2911
+ (cri.target ? '<span class="ret-dim"> · 目标 ' + escapeHtml(cri.target) + '</span>' : '') + '</li>';
2912
+ }
2913
+ block += '<div class="ret-sec"><h2>关键成功指标</h2><ul class="ret-list">' + critRows + '</ul></div>';
2914
+ }
2915
+ if (plan.scenarios && plan.scenarios.length) {
2916
+ var scnRows = '';
2917
+ for (var sc = 0; sc < plan.scenarios.length; sc += 1) {
2918
+ var scn = plan.scenarios[sc];
2919
+ scnRows += '<li><b>' + escapeHtml(scn.id || '') + '</b> ' + escapeHtml(scn.name || '') +
2920
+ (scn.goal ? '<span class="ret-dim"> · ' + escapeHtml(scn.goal) + '</span>' : '') + '</li>';
2921
+ }
2922
+ block += '<div class="ret-sec"><h2>验证场景</h2><ul class="ret-list">' + scnRows + '</ul></div>';
2923
+ }
2924
+ if (plan.risks && plan.risks.length) {
2925
+ var riskRows = '';
2926
+ for (var r = 0; r < plan.risks.length; r += 1) {
2927
+ riskRows += '<li>' + escapeHtml(plan.risks[r].name || '') +
2928
+ (plan.risks[r].mitigation ? '<span class="ret-dim"> · 应对 ' + escapeHtml(plan.risks[r].mitigation) + '</span>' : '') + '</li>';
2929
+ }
2930
+ block += '<div class="ret-sec"><h2>风险</h2><ul class="ret-list">' + riskRows + '</ul></div>';
2931
+ }
2932
+ block += returnSection('Gate 结论与时间', [
2933
+ ['计划开始', plan.timeline && plan.timeline.start], ['计划结束', plan.timeline && plan.timeline.end],
2934
+ ['G1 结论', plan.gate1 && plan.gate1.conclusion], ['G2 Ready', plan.gate2 && plan.gate2.ready]
2935
+ ]);
2936
+ for (var p = 0; p < change.progress.length; p += 1) {
2937
+ var entry = change.progress[p];
2938
+ var cust = entry.customer || {};
2939
+ var nxt = entry.next || {};
2940
+ var ev = '';
2941
+ if (entry.evidence && entry.evidence.length) {
2942
+ for (var e = 0; e < entry.evidence.length; e += 1) {
2943
+ ev += (ev ? '、' : '') + escapeHtml(entry.evidence[e].title || '');
2944
+ }
2945
+ }
2946
+ block += '<div class="ret-sec ret-new"><h2>本次新增进展<span class="ret-tag">新</span></h2><dl>' +
2947
+ returnPair('日期', entry.date) + returnPair('类型', entry.type) +
2948
+ returnPair('这一次什么变了', entry.change) + returnPair('目标', entry.goal) +
2949
+ returnPair('实际结果', entry.actual) + returnPair('完成度', entry.completion) +
2950
+ returnPair('证据', ev) + returnPair('同步对象', cust.synced_with) +
2951
+ returnPair('客户反馈', cust.feedback) + returnPair('客户认可度', cust.recognition) +
2952
+ returnPair('G3-1', entry.gate3_1) + returnPair('G3-2', entry.gate3_2) +
2953
+ returnPair('下一步目标', nxt.goal) + returnPair('下一步负责人', nxt.owner) +
2954
+ returnPair('下一步截止', nxt.deadline) + '</dl></div>';
2955
+ }
2956
+ var o = shown.outcome || {};
2957
+ var oc = o.conclusion || {};
2958
+ var ob = o.business || {};
2959
+ block += returnSection('结论与转化', [
2960
+ ['目标达成', o.achievement], ['客户认可', o.customer_recognition],
2961
+ ['我方证据', o.our_proof], ['我们证明了什么', oc.proved],
2962
+ ['客户认可了什么', oc.recognized], ['下一步业务动作', oc.next_business],
2963
+ ['Next Milestone', ob.milestone], ['里程碑负责人', ob.owner],
2964
+ ['里程碑截止', ob.deadline], ['里程碑状态', ob.status],
2965
+ ['POC 总体结论', o.overall]
2966
+ ]);
2967
+ rows += '<article class="ret-card">' +
2968
+ '<header class="ret-head"><h1>' + escapeHtml(shown.name || shown.poc_id || '未命名项目') + '</h1>' +
2969
+ '<div class="ret-meta">' + escapeHtml(shown.poc_id || '') +
2970
+ (shown.org && shown.org.company ? ' · ' + escapeHtml(shown.org.company) : '') +
2971
+ (shown.stage ? ' · ' + escapeHtml(shown.stage) : '') +
2972
+ (shown.poc_type ? ' · ' + escapeHtml(shown.poc_type) : '') + '</div></header>' +
2973
+ block + '</article>';
1970
2974
  }
1971
- return ok;
2975
+ return '<!DOCTYPE html>\\n<html lang="zh-CN">\\n<head>\\n<meta charset="UTF-8">\\n' +
2976
+ '<meta name="viewport" content="width=device-width, initial-scale=1">\\n' +
2977
+ '<title>POC 回传 · ' + escapeHtml(intentText) + '</title>\\n<style>' + DATA.returnCss + '</style>\\n</head>\\n<body>\\n' +
2978
+ '<div class="ret-shell">' +
2979
+ '<div class="ret-note">这是组员填写的 POC 回传文件,内容只读。' +
2980
+ '把整个文件(或下载的 .json)通过企业微信发给发起人,由他交给 DSH 合并进台账。</div>' +
2981
+ '<div class="ret-bar"><span>' + escapeHtml(intentText) + ' · ' + document_.changes.length + ' 个项目</span>' +
2982
+ '<span class="ret-dim">生成于 ' + escapeHtml(readableTime(document_.generatedAt)) + '</span></div>' +
2983
+ rows + '</div>\\n' +
2984
+ // The closing tag is written as '<\\/script>': this string is itself embedded
2985
+ // inside a <script> element, so a literal closing tag here would terminate
2986
+ // the generated page's script and dump the rest of the code as text.
2987
+ '<script type="application/json" id="poc-return-data">' + safeJson + '<\\/script>\\n' +
2988
+ '</body>\\n</html>\\n';
1972
2989
  }
1973
2990
 
2991
+ /**
2992
+ * Merge a change set over its source project, for DISPLAY in the return page.
2993
+ *
2994
+ * The change set is deliberately narrow (only what the colleague could edit), so
2995
+ * a progress-only return carries no project name, no Gate 0 and no plan. Showing
2996
+ * that file as-is produced a report titled "POC-001" with an almost empty body —
2997
+ * the reader could not tell which project it was about.
2998
+ *
2999
+ * So the untouched project is merged underneath for display. The embedded JSON
3000
+ * block is NOT merged: it stays the exact change set, because that is what the
3001
+ * Host applies and a re-sent pre-filled field would revert a newer ledger value.
3002
+ */
3003
+ function mergeForDisplay(change, source) {
3004
+ if (!source) return change;
3005
+ function pick(changeValue, sourceValue) {
3006
+ return changeValue === null || changeValue === undefined || changeValue === '' ? sourceValue : changeValue;
3007
+ }
3008
+ var plan = change.plan || {};
3009
+ var srcPlan = source.plan || {};
3010
+ var outcome = change.outcome || {};
3011
+ var srcOutcome = source.outcome || {};
3012
+ return {
3013
+ poc_id: change.poc_id,
3014
+ name: pick(change.name, source.name),
3015
+ org: {
3016
+ system: pick(change.org && change.org.system, source.system),
3017
+ company: pick(change.org && change.org.company, source.company),
3018
+ department: pick(change.org && change.org.department, source.department)
3019
+ },
3020
+ amount_wan: pick(change.amount_wan, source.amountWan === '' ? null : source.amountWan),
3021
+ poc_type: pick(change.poc_type, source.pocType),
3022
+ owner: pick(change.owner, source.owner),
3023
+ sales: pick(change.sales, source.sales),
3024
+ tech_owner: pick(change.tech_owner, source.techOwner),
3025
+ exec_sponsor: pick(change.exec_sponsor, source.execSponsor),
3026
+ stage: pick(change.stage, source.stage),
3027
+ status: pick(change.status, source.status),
3028
+ gate0: {
3029
+ why_customer: pick(change.gate0 && change.gate0.why_customer, source.gate0.why_customer),
3030
+ why_us: pick(change.gate0 && change.gate0.why_us, source.gate0.why_us),
3031
+ decision_chain: pick(change.gate0 && change.gate0.decision_chain, source.gate0.decision_chain),
3032
+ post_poc_decision: pick(change.gate0 && change.gate0.post_poc_decision, source.gate0.post_poc_decision),
3033
+ competitor: pick(change.gate0 && change.gate0.competitor, source.gate0.competitor),
3034
+ review: {
3035
+ conclusion: pick(change.gate0 && change.gate0.review && change.gate0.review.conclusion, source.gate0.conclusion),
3036
+ reviewer: pick(change.gate0 && change.gate0.review && change.gate0.review.reviewer, source.gate0.reviewer),
3037
+ reviewed_at: pick(change.gate0 && change.gate0.review && change.gate0.review.reviewed_at, source.gate0.reviewed_at)
3038
+ }
3039
+ },
3040
+ plan: {
3041
+ customer_pain: pick(plan.customer_pain, srcPlan.customer_pain),
3042
+ expected_recognition: pick(plan.expected_recognition, srcPlan.expected_recognition),
3043
+ our_edge: pick(plan.our_edge, srcPlan.our_edge),
3044
+ criteria: (plan.criteria && plan.criteria.length) ? plan.criteria : srcPlan.criteria,
3045
+ scenarios: (plan.scenarios && plan.scenarios.length) ? plan.scenarios : srcPlan.scenarios,
3046
+ risks: (plan.risks && plan.risks.length) ? plan.risks : srcPlan.risks,
3047
+ timeline: {
3048
+ start: pick(plan.timeline && plan.timeline.start, srcPlan.timeline_start),
3049
+ end: pick(plan.timeline && plan.timeline.end, srcPlan.timeline_end)
3050
+ },
3051
+ gate1: { conclusion: pick(plan.gate1 && plan.gate1.conclusion, srcPlan.gate1_conclusion) },
3052
+ gate2: { ready: pick(plan.gate2 && plan.gate2.ready, srcPlan.gate2_ready) }
3053
+ },
3054
+ outcome: {
3055
+ achievement: pick(outcome.achievement, srcOutcome.achievement),
3056
+ customer_recognition: pick(outcome.customer_recognition, srcOutcome.customer_recognition),
3057
+ our_proof: pick(outcome.our_proof, srcOutcome.our_proof),
3058
+ remaining_risks: pick(outcome.remaining_risks, srcOutcome.remaining_risks),
3059
+ conclusion: {
3060
+ proved: pick(outcome.conclusion && outcome.conclusion.proved, srcOutcome.proved),
3061
+ recognized: pick(outcome.conclusion && outcome.conclusion.recognized, srcOutcome.recognized),
3062
+ next_business: pick(outcome.conclusion && outcome.conclusion.next_business, srcOutcome.next_business)
3063
+ },
3064
+ business: {
3065
+ milestone: pick(outcome.business && outcome.business.milestone, srcOutcome.milestone),
3066
+ owner: pick(outcome.business && outcome.business.owner, srcOutcome.businessOwner),
3067
+ deadline: pick(outcome.business && outcome.business.deadline, srcOutcome.businessDeadline),
3068
+ status: pick(outcome.business && outcome.business.status, srcOutcome.businessStatus)
3069
+ },
3070
+ overall: pick(outcome.overall, srcOutcome.overall)
3071
+ },
3072
+ progress: change.progress
3073
+ };
3074
+ }
3075
+
3076
+ /** An ISO stamp as a local, readable time: "2026-11-20 18:08". */
3077
+ function readableTime(iso) {
3078
+ var raw = text(iso);
3079
+ var at = raw.indexOf('T');
3080
+ if (at < 0) return raw;
3081
+ return raw.slice(0, at) + ' ' + raw.slice(at + 1, at + 6);
3082
+ }
3083
+
3084
+ function returnPair(label, value) {
3085
+ var raw = text(value).trim();
3086
+ if (raw === '') return '';
3087
+ return '<div class="ret-pair"><dt>' + escapeHtml(label) + '</dt><dd>' + escapeHtml(raw) + '</dd></div>';
3088
+ }
3089
+
3090
+ function returnSection(title, pairs) {
3091
+ var body = '';
3092
+ for (var i = 0; i < pairs.length; i += 1) body += returnPair(pairs[i][0], pairs[i][1]);
3093
+ if (body === '') return '';
3094
+ return '<div class="ret-sec"><h2>' + escapeHtml(title) + '</h2><dl>' + body + '</dl></div>';
3095
+ }
3096
+
3097
+
1974
3098
  function initState() {
1975
3099
  storageAvailable = probeStorage();
1976
3100
  if (!storageAvailable) {
@@ -1994,6 +3118,7 @@ const FORM_SCRIPT = `
1994
3118
  if (byId('clearBtn')) byId('clearBtn').addEventListener('click', clearDraft);
1995
3119
  if (byId('previewBtn')) byId('previewBtn').addEventListener('click', previewYaml);
1996
3120
  if (byId('downloadBtn')) byId('downloadBtn').addEventListener('click', downloadYaml);
3121
+ if (byId('returnBtn')) byId('returnBtn').addEventListener('click', downloadReturnFile);
1997
3122
  setInterval(function () { save(true); }, 30000);
1998
3123
  window.addEventListener('beforeunload', function () { save(true); });
1999
3124
  `;