gaoluyang
2026-11-03 2d8b1a28fa5c8b852f0d0078bac4894bfb4abed5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
<script setup lang="ts">
  import { computed, ref } from "vue";
  import { onLoad, onPullDownRefresh } from "@dcloudio/uni-app";
  import { getSimpleDictDataList, type DictData } from "../../../api/crm";
  import {
    approveTask,
    copyTask,
    delegateTask,
    getApprovalDetail,
    getBpmSimpleDeptList,
    getBpmSimpleUserList,
    getTaskListByProcessInstanceId,
    getTaskListByReturn,
    rejectTask,
    returnTask,
    signCreateTask,
    signDeleteTask,
    transferTask,
    type BpmApprovalDetail,
    type BpmApprovalNode,
    type BpmDept,
    type BpmTask,
    type BpmUser,
  } from "../../../api/bpm";
  import { useAuth } from "../../../stores/auth";
  import {
    DICT,
    FIELD_PERMISSION,
    NODE_STATUS_META,
    OPERATION_BUTTON,
    OPERATION_BUTTON_NAME,
    TASK_STATUS,
    buildTree,
    dateTimeText,
    dictLabel,
    durationText,
    flattenTree,
    processStatusText,
    toast,
  } from "../shared";
  import { parseFormFields, pickWritableVariables, type FormField } from "../form-parser";
  import BpmFormRenderer from "../components/BpmFormRenderer.vue";
  import DeptTreePicker from "../components/DeptTreePicker.vue";
  import PickerSheet from "../../mes/process-design/components/PickerSheet.vue";
  import type { SheetOption } from "../../mes/process-design/shared";
 
  const { state } = useAuth();
 
  const processInstanceId = ref("");
  const taskId = ref("");
  const activityId = ref("");
 
  const loading = ref(false);
  const loadError = ref("");
  const detail = ref<BpmApprovalDetail>();
 
  const dicts = ref<DictData[]>([]);
  const users = ref<BpmUser[]>([]);
  const records = ref<BpmTask[]>([]);
  /** 流转记录加载失败原因(非空时在空态处提示) */
  const recordsError = ref("");
 
  /** Tab:审批详情 / 流转记录(流程图已按移动端方案以时间线替代) */
  const activeTab = ref<"form" | "record">("form");
 
  const processInstance = computed(() => detail.value?.processInstance);
  const processDefinition = computed(() => detail.value?.processDefinition);
  const runningTask = computed(() => detail.value?.todoTask);
 
  /** 表单字段与值(只读回显 + 可写字段收集) */
  const fields = ref<FormField[]>([]);
  const formValue = ref<Record<string, any>>({});
  const permissions = ref<Record<string, string>>({});
 
  /* ---------- 表单字段选择(UserSelect / DeptSelect / DictSelect) ---------- */
 
  const depts = ref<BpmDept[]>([]);
  /**
   * 部门树。
   * `/system/dept/simple-list` 返回**扁平列表**(靠 parentId 关联),
   * 与 web 端 dept-select.vue 里 `handleTree(data)` 的用法一致。
   * 旧实现递归读 list[].children,扁平数据里没有该字段,导致层级全丢。
   */
  const deptTree = ref<BpmDept[]>([]);
  const fieldSheetVisible = ref(false);
  const fieldSheetTitle = ref("");
  const fieldSheetOptions = ref<SheetOption[]>([]);
  const fieldSheetMultiple = ref(false);
  const activeField = ref<FormField>();
  const fieldSheetSelected = ref<Array<number | string>>([]);
 
  /** 部门选择面板(树形,独立于通用 PickerSheet) */
  const deptSheetVisible = ref(false);
  const deptSheetTitle = ref("选择部门");
  const deptSheetMultiple = ref(false);
  const deptSheetSelected = ref<Array<number | string>>([]);
 
  /**
   * 字段名 -> 已加载的候选选项,传给 BpmFormRenderer 做回显。
   * 表单值里存的是后端的原始 id / 枚举值,渲染器自己不请求数据,
   * 没有这张映射表就只能显示「122」这种原始值。
   */
  const fieldOptions = ref<Record<string, SheetOption[]>>({});
 
  async function ensurePickerData(kind: string) {
    if (!state.accessToken) return;
    if (kind === "user" && !users.value.length) {
      users.value = (await getBpmSimpleUserList(state.accessToken)) || [];
    }
    if (kind === "dept" && !depts.value.length) {
      depts.value = (await getBpmSimpleDeptList(state.accessToken)) || [];
      deptTree.value = buildTree<BpmDept>(depts.value);
    }
    if (kind === "dict" && !dicts.value.length) {
      dicts.value = await getSimpleDictDataList(state.accessToken);
    }
  }
 
  /** 部门树拍平为「值 -> 名称」选项(带层级缩进),单选时父级也可作为值 */
  function deptFlatOptions(): SheetOption[] {
    return flattenTree<BpmDept>(deptTree.value).map(({ node, depth }) => ({
      key: Number(node.id),
      label: `${" ".repeat(depth)}${node.name || node.id}`,
    }));
  }
 
  /**
   * 目标字段的候选选项(依赖 ensurePickerData 已加载对应数据)。
   * 与选择面板展示的选项完全一致,因此可以直接用来把值反查成名称。
   */
  function buildFieldOptions(field: FormField): SheetOption[] {
    if (field.kind === "user") {
      return users.value.map(u => ({ key: Number(u.id), label: u.nickname || String(u.id) }));
    }
    if (field.kind === "dept") return deptFlatOptions();
    if (field.kind === "dict") {
      return dicts.value
        .filter(item => item.dictType === field.dictType)
        .map(item => ({ key: item.value, label: item.label }));
    }
    return [];
  }
 
  /**
   * 缓存字段选项供渲染器回显。
   * 部门树选项带层级缩进(全角空格),回显时要去掉,否则「部门」后面会跟一串空白。
   */
  function cacheFieldOptions(field: FormField, options: SheetOption[]) {
    fieldOptions.value[field.field] = options.map(item => ({
      ...item,
      label: String(item.label).replace(/^\s+/, ""),
    }));
  }
 
  /** 预加载「已有值」的动态字段选项,保证一进页面就显示名称而不是原始 id */
  async function primeFieldOptions() {
    for (const field of fields.value) {
      if (field.kind !== "user" && field.kind !== "dept" && field.kind !== "dict") continue;
      const value = formValue.value[field.field];
      const empty =
        value === undefined || value === null || value === "" ||
        (Array.isArray(value) && value.length === 0);
      if (empty) continue;
      try {
        await ensurePickerData(field.kind);
        const options = buildFieldOptions(field);
        if (options.length) cacheFieldOptions(field, options);
      } catch {
        // 预加载失败不阻塞详情:回显退化为原始值,不影响办理
      }
    }
  }
 
  async function onFieldPick(field: FormField) {
    activeField.value = field;
    fieldSheetTitle.value = field.title;
    fieldSheetMultiple.value = field.multiple;
    const current = formValue.value[field.field];
    const currentKeys = Array.isArray(current)
      ? [...current]
      : current === undefined || current === null || current === ""
        ? []
        : [current];
    fieldSheetSelected.value = currentKeys;
    deptSheetSelected.value = [...currentKeys];
 
    uni.showLoading({ title: "加载选项…", mask: true });
    try {
      await ensurePickerData(field.kind);
      // 部门走树形面板(对齐 web 端 antd TreeSelect:树状 + 可搜 + 父级可选)
      if (field.kind === "dept") {
        if (!deptTree.value.length) {
          toast("暂无可选项");
          return;
        }
        deptSheetTitle.value = field.title;
        deptSheetMultiple.value = field.multiple;
        cacheFieldOptions(field, deptFlatOptions());
        deptSheetVisible.value = true;
        return;
      }
      fieldSheetOptions.value = buildFieldOptions(field);
      if (!fieldSheetOptions.value.length) {
        toast(
          field.kind === "user" || field.kind === "dict"
            ? "暂无可选项"
            : "该字段类型请在 Web 端填写",
        );
        return;
      }
      // 缓存下来供渲染器回显名称
      cacheFieldOptions(field, fieldSheetOptions.value);
      fieldSheetVisible.value = true;
    } catch (error) {
      toast(error instanceof Error ? error.message : "选项加载失败");
    } finally {
      uni.hideLoading();
    }
  }
 
  function onFieldSheetConfirm(keys: Array<number | string>) {
    const field = activeField.value;
    if (!field) return;
    if (field.multiple) formValue.value[field.field] = [...keys];
    else formValue.value[field.field] = keys[0];
  }
 
  /** 部门树面板确认(多选已按 web 端 SHOW_CHILD 只保留叶子) */
  function onDeptConfirm(keys: Array<number | string>) {
    onFieldSheetConfirm(keys);
  }
 
  /* ---------- 操作弹层 ---------- */
 
  type OperationKind =
    | "approve"
    | "reject"
    | "return"
    | "transfer"
    | "delegate"
    | "addSign"
    | "copy";
 
  const operationVisible = ref(false);
  const operationKind = ref<OperationKind>("approve");
  const operationSubmitting = ref(false);
  const operationReason = ref("");
  const operationAssignees = ref<number[]>([]);
  const operationReturnKey = ref("");
  const operationSignType = ref<"before" | "after">("after");
 
  const userSheetVisible = ref(false);
  const userSheetOptions = ref<SheetOption[]>([]);
  const userSheetMultiple = ref(false);
 
  const returnNodes = ref<Array<{ taskDefinitionKey: string; name: string }>>([]);
  const showReturnSheet = ref(false);
 
  /** 当前任务是否可操作(与 web 端 isHandleTaskStatus 一致) */
  const canOperate = computed(() => runningTask.value?.status === TASK_STATUS.RUNNING);
 
  /**
   * 实际生效的字段权限:
   * 无在办任务时(流程已结束 / 只是查看)全部按只读处理,避免误改。
   */
  const effectivePermissions = computed<Record<string, string>>(() => {
    if (canOperate.value) return permissions.value;
    const locked: Record<string, string> = {};
    fields.value.forEach(f => {
      locked[f.field] = FIELD_PERMISSION.READ;
    });
    return locked;
  });
 
  /** 按钮显隐:读 buttonsSetting,缺省显示(与 web 端一致) */
  function isButtonVisible(type: number) {
    const setting = runningTask.value?.buttonsSetting?.[String(type)];
    if (setting && setting.enable !== undefined) return Boolean(setting.enable);
    return true;
  }
 
  function buttonName(type: number) {
    const setting = runningTask.value?.buttonsSetting?.[String(type)];
    return setting?.displayName || OPERATION_BUTTON_NAME[type] || "";
  }
 
  /** 是否显示减签:当前任务有子任务 */
  const canDeleteSign = computed(() => Boolean(runningTask.value?.children?.length));
  const deleteSignTasks = computed(() => runningTask.value?.children || []);
 
  /* ---------- 加载 ---------- */
 
  function statusText() {
    return (
      dictLabel(dicts.value, DICT.BPM_PROCESS_INSTANCE_STATUS, processInstance.value?.status) ||
      processStatusText(processInstance.value?.status)
    );
  }
 
  function nodeMeta(node: BpmApprovalNode) {
    return NODE_STATUS_META[Number(node.status)] ?? { label: "未知", color: "#909398" };
  }
 
  function taskMeta(task: BpmTask) {
    return NODE_STATUS_META[Number(task.status)] ?? { label: "--", color: "#909398" };
  }
 
  async function load() {
    if (!state.accessToken || !processInstanceId.value) return;
    loading.value = true;
    loadError.value = "";
    try {
      if (!dicts.value.length) dicts.value = await getSimpleDictDataList(state.accessToken);
      if (!users.value.length) {
        users.value = (await getBpmSimpleUserList(state.accessToken)) || [];
      }
 
      const data = await getApprovalDetail(state.accessToken, {
        processInstanceId: processInstanceId.value,
        taskId: taskId.value || undefined,
        activityId: activityId.value || undefined,
      });
      if (!data) throw new Error("查询不到审批详情信息");
      detail.value = data;
 
      // 表单:仅流程表单(formType === 10)才渲染
      fields.value = parseFormFields(data.processDefinition?.formFields);
      permissions.value = (data.formFieldsPermission as Record<string, string>) || {};
      formValue.value = { ...(data.processInstance?.formVariables || {}) };
      // 预加载「已有值」的动态字段选项:否则用户/部门字段只显示原始 id
      await primeFieldOptions();
 
      // 流转记录(独立接口,与 web 端 task-list.vue 一致)
      try {
        records.value =
          (await getTaskListByProcessInstanceId(state.accessToken, processInstanceId.value)) || [];
        recordsError.value = "";
      } catch (error) {
        records.value = [];
        recordsError.value = error instanceof Error ? error.message : "流转记录加载失败";
      }
    } catch (error) {
      loadError.value = error instanceof Error ? error.message : "审批详情加载失败";
    } finally {
      loading.value = false;
    }
  }
 
  /* ---------- 操作面板 ---------- */
 
  function openOperation(kind: OperationKind) {
    if (!runningTask.value?.id) {
      toast("当前没有可办理的任务");
      return;
    }
    operationKind.value = kind;
    operationReason.value = "";
    operationAssignees.value = [];
    operationReturnKey.value = "";
    operationSignType.value = "after";
    operationVisible.value = true;
 
    if (kind === "return") loadReturnNodes();
  }
 
  async function loadReturnNodes() {
    if (!state.accessToken || !runningTask.value?.id) return;
    try {
      const list = await getTaskListByReturn(state.accessToken, String(runningTask.value.id));
      returnNodes.value = (list || [])
        .filter(item => item.taskDefinitionKey)
        .map(item => ({
          taskDefinitionKey: String(item.taskDefinitionKey),
          name: item.name || String(item.taskDefinitionKey),
        }));
      if (!returnNodes.value.length) toast("当前没有可退回的节点");
    } catch (error) {
      returnNodes.value = [];
      toast(error instanceof Error ? error.message : "可退回节点加载失败");
    }
  }
 
  function openUserSheet(multiple: boolean) {
    userSheetMultiple.value = multiple;
    userSheetOptions.value = users.value.map(user => ({
      key: Number(user.id),
      label: user.nickname || String(user.id),
    }));
    userSheetVisible.value = true;
  }
 
  function onUsersPicked(keys: Array<number | string>) {
    operationAssignees.value = keys.map(Number);
  }
 
  function assigneeText() {
    if (!operationAssignees.value.length) return "请选择人员";
    return operationAssignees.value
      .map(id => users.value.find(u => Number(u.id) === id)?.nickname ?? id)
      .join("、");
  }
 
  function returnNodeText() {
    if (!operationReturnKey.value) return "请选择退回节点";
    return (
      returnNodes.value.find(n => n.taskDefinitionKey === operationReturnKey.value)?.name ??
      operationReturnKey.value
    );
  }
 
  const operationTitle = computed(
    () => buttonNameByKind(operationKind.value) || "审批",
  );
 
  function buttonNameByKind(kind: OperationKind) {
    const map: Record<OperationKind, number> = {
      approve: OPERATION_BUTTON.APPROVE,
      reject: OPERATION_BUTTON.REJECT,
      return: OPERATION_BUTTON.RETURN,
      transfer: OPERATION_BUTTON.TRANSFER,
      delegate: OPERATION_BUTTON.DELEGATE,
      addSign: OPERATION_BUTTON.ADD_SIGN,
      copy: OPERATION_BUTTON.COPY,
    };
    return buttonName(map[kind]);
  }
 
  /** 需要单选人员的操作:转办 / 委派 */
  function needsSingleUser(kind: OperationKind) {
    return kind === "transfer" || kind === "delegate";
  }
 
  /** 需要多选人员的操作:加签 / 抄送 */
  function needsMultiUser(kind: OperationKind) {
    return kind === "addSign" || kind === "copy";
  }
 
  /** 是否需要审批意见(通过时可选,其余必填) */
  function reasonRequired(kind: OperationKind) {
    return kind !== "approve";
  }
 
  /* ---------- 提交 ---------- */
 
  async function submitOperation() {
    const task = runningTask.value;
    if (!state.accessToken || !task?.id || operationSubmitting.value) return;
 
    const kind = operationKind.value;
    const reason = operationReason.value.trim();
 
    if (reasonRequired(kind) && !reason) {
      toast("请填写审批意见");
      return;
    }
    if (needsSingleUser(kind) && !operationAssignees.value.length) {
      toast("请选择人员");
      return;
    }
    if (needsMultiUser(kind) && !operationAssignees.value.length) {
      toast("请选择人员");
      return;
    }
    if (kind === "return" && !operationReturnKey.value) {
      toast("请选择退回节点");
      return;
    }
 
    operationSubmitting.value = true;
    try {
      if (kind === "approve") {
        // 与 web 端一致:只提交「可写字段」的流程变量
        const variables = pickWritableVariables(fields.value, formValue.value, permissions.value);
        await approveTask(state.accessToken, {
          id: String(task.id),
          reason,
          variables,
        });
      } else if (kind === "reject") {
        await rejectTask(state.accessToken, { id: String(task.id), reason });
      } else if (kind === "return") {
        await returnTask(state.accessToken, {
          id: String(task.id),
          reason,
          targetTaskDefinitionKey: operationReturnKey.value,
        });
      } else if (kind === "transfer") {
        await transferTask(state.accessToken, {
          id: String(task.id),
          reason,
          assigneeUserId: operationAssignees.value[0] as number,
        });
      } else if (kind === "delegate") {
        await delegateTask(state.accessToken, {
          id: String(task.id),
          reason,
          delegateUserId: operationAssignees.value[0] as number,
        });
      } else if (kind === "addSign") {
        await signCreateTask(state.accessToken, {
          id: String(task.id),
          type: operationSignType.value,
          reason,
          userIds: operationAssignees.value,
        });
      } else if (kind === "copy") {
        await copyTask(state.accessToken, {
          id: String(task.id),
          reason,
          copyUserIds: operationAssignees.value,
        });
      }
      toast("操作成功");
      operationVisible.value = false;
      await load();
    } catch (error) {
      toast(error instanceof Error ? error.message : "操作失败");
    } finally {
      operationSubmitting.value = false;
    }
  }
 
  /** 减签:对指定子任务执行 */
  async function handleDeleteSign(child: BpmTask) {
    if (!state.accessToken || !child.id) return;
    uni.showModal({
      title: "减签",
      editable: true,
      placeholderText: "请输入减签原因",
      success: async res => {
        if (!res.confirm) return;
        const reason = String(res.content || "").trim();
        if (!reason) {
          toast("请填写减签原因");
          return;
        }
        try {
          await signDeleteTask(state.accessToken as string, {
            id: String(child.id),
            reason,
          });
          toast("已减签");
          await load();
        } catch (error) {
          toast(error instanceof Error ? error.message : "减签失败");
        }
      },
    });
  }
 
  onLoad(async query => {
    processInstanceId.value = query?.id ? String(query.id) : "";
    taskId.value = query?.taskId ? String(query.taskId) : "";
    activityId.value = query?.activityId ? String(query.activityId) : "";
    uni.setNavigationBarTitle({ title: "审批详情" });
    await load();
  });
 
  onPullDownRefresh(async () => {
    await load();
    uni.stopPullDownRefresh();
  });
</script>
 
<template>
  <view class="page">
    <scroll-view class="content" scroll-y>
      <view v-if="loadError" class="state error" @click="load">{{ loadError }},点击重试</view>
      <view v-else-if="loading && !detail" class="state">加载中...</view>
 
      <template v-else-if="detail">
        <!-- 顶部流程信息 -->
        <view class="hero">
          <view class="hero-main">
            <text class="hero-name">{{ processInstance?.name || '未命名流程' }}</text>
            <text class="hero-meta">
              {{ processInstance?.startUser?.nickname || '--' }} ·
              {{ dateTimeText(processInstance?.startTime) }} 提交
            </text>
          </view>
          <text class="hero-status">{{ statusText() }}</text>
        </view>
 
        <!-- Tab 切换 -->
        <view class="tabs">
          <text
            class="tab"
            :class="{ active: activeTab === 'form' }"
            @click="activeTab = 'form'"
          >
            审批详情
          </text>
          <text
            class="tab"
            :class="{ active: activeTab === 'record' }"
            @click="activeTab = 'record'"
          >
            流转记录
          </text>
        </view>
 
        <!-- Tab:审批详情(表单 + 时间线) -->
        <template v-if="activeTab === 'form'">
          <view v-if="fields.length" class="card">
            <text class="card-title">表单信息</text>
            <BpmFormRenderer
              v-model="formValue"
              :fields="fields"
              :permissions="effectivePermissions"
              :disabled="!canOperate"
              :field-options="fieldOptions"
              @pick="onFieldPick"
            />
          </view>
          <view v-else class="card">
            <text class="card-title">表单信息</text>
            <text class="empty-tip">该流程未配置表单字段</text>
          </view>
 
          <!-- 流程时间线(替代 web 端流程图,数据同源 activityNodes) -->
          <view class="card">
            <text class="card-title">审批时间线</text>
            <view v-if="detail.activityNodes?.length" class="timeline">
              <view
                v-for="node in detail.activityNodes"
                :key="node.id || node.name"
                class="node"
              >
                <view class="node-dot" :style="{ background: nodeMeta(node).color }" />
                <view class="node-body">
                  <view class="node-head">
                    <text class="node-name">{{ node.name || '--' }}</text>
                    <text class="node-status" :style="{ color: nodeMeta(node).color }">
                      {{ nodeMeta(node).label }}
                    </text>
                  </view>
                  <text class="node-time">
                    {{ dateTimeText(node.startTime) }} → {{ dateTimeText(node.endTime) }}
                  </text>
                  <view v-if="node.tasks?.length" class="node-tasks">
                    <view v-for="(t, i) in node.tasks" :key="i" class="node-task">
                      <text class="node-user">
                        {{ t.assigneeUser?.nickname || t.ownerUser?.nickname || '--' }}
                      </text>
                      <text v-if="t.reason" class="node-reason">{{ t.reason }}</text>
                    </view>
                  </view>
                </view>
              </view>
            </view>
            <text v-else class="empty-tip">暂无审批节点</text>
          </view>
        </template>
 
        <!-- Tab:流转记录 -->
        <template v-else>
          <view class="card">
            <text class="card-title">流转记录</text>
            <view v-if="records.length" class="records">
              <view v-for="(item, index) in records" :key="item.id || index" class="record">
                <view class="record-head">
                  <text class="record-name">{{ item.name || '--' }}</text>
                  <text class="record-status" :style="{ color: taskMeta(item).color }">
                    {{ dictLabel(dicts, DICT.BPM_TASK_STATUS, item.status) !== '--'
                      ? dictLabel(dicts, DICT.BPM_TASK_STATUS, item.status)
                      : taskMeta(item).label }}
                  </text>
                </view>
                <text class="record-line">
                  审批人:{{ item.assigneeUser?.nickname || item.ownerUser?.nickname || '--' }}
                </text>
                <text class="record-line">
                  开始:{{ dateTimeText(item.createTime) }}
                </text>
                <text class="record-line">
                  结束:{{ dateTimeText(item.endTime) }}
                </text>
                <text class="record-line">审批建议:{{ item.reason || '--' }}</text>
                <text class="record-line">耗时:{{ durationText(item.durationInMillis) }}</text>
              </view>
            </view>
            <text v-else class="empty-tip">{{ recordsError || '暂无流转记录' }}</text>
          </view>
        </template>
      </template>
    </scroll-view>
 
    <!-- 底部操作栏:仅当有在办任务时可操作 -->
    <view v-if="canOperate" class="footer">
      <text v-if="isButtonVisible(1)" class="op primary" @click="openOperation('approve')">
        {{ buttonName(1) }}
      </text>
      <text v-if="isButtonVisible(2)" class="op danger" @click="openOperation('reject')">
        {{ buttonName(2) }}
      </text>
      <text v-if="isButtonVisible(6)" class="op" @click="openOperation('return')">
        {{ buttonName(6) }}
      </text>
      <text v-if="isButtonVisible(3)" class="op" @click="openOperation('transfer')">
        {{ buttonName(3) }}
      </text>
      <text v-if="isButtonVisible(4)" class="op" @click="openOperation('delegate')">
        {{ buttonName(4) }}
      </text>
      <text v-if="isButtonVisible(5)" class="op" @click="openOperation('addSign')">
        {{ buttonName(5) }}
      </text>
      <text v-if="isButtonVisible(7)" class="op" @click="openOperation('copy')">
        {{ buttonName(7) }}
      </text>
      <text v-if="canDeleteSign" class="op danger" @click="deleteSignTasks.length && handleDeleteSign(deleteSignTasks[0])">
        减签
      </text>
    </view>
 
    <!-- 操作弹层 -->
    <view v-if="operationVisible" class="mask" @click="operationVisible = false">
      <view class="modal" @click.stop>
        <text class="modal-title">{{ operationTitle }}</text>
 
        <!-- 加签:签序 -->
        <view v-if="operationKind === 'addSign'" class="modal-field">
          <text class="modal-label">签序</text>
          <view class="sign-types">
            <text
              class="sign-type"
              :class="{ active: operationSignType === 'before' }"
              @click="operationSignType = 'before'"
            >
              前加签
            </text>
            <text
              class="sign-type"
              :class="{ active: operationSignType === 'after' }"
              @click="operationSignType = 'after'"
            >
              后加签
            </text>
          </view>
        </view>
 
        <!-- 退回节点 -->
        <view v-if="operationKind === 'return'" class="modal-field">
          <text class="modal-label">退回节点</text>
          <view class="picker" @click="showReturnSheet = true">
            {{ returnNodeText() }}
            <text class="arrow">›</text>
          </view>
        </view>
 
        <!-- 人员选择:转办/委派单选,加签/抄送多选 -->
        <view v-if="needsSingleUser(operationKind) || needsMultiUser(operationKind)" class="modal-field">
          <text class="modal-label">
            {{ operationKind === 'transfer' ? '转办人'
              : operationKind === 'delegate' ? '委派人'
              : operationKind === 'addSign' ? '加签人' : '抄送人' }}
          </text>
          <view class="picker" @click="openUserSheet(!needsSingleUser(operationKind))">
            {{ assigneeText() }}
            <text class="arrow">›</text>
          </view>
        </view>
 
        <!-- 审批意见 -->
        <view class="modal-field">
          <text class="modal-label">
            审批意见
            <text v-if="reasonRequired(operationKind)" class="required">*</text>
          </text>
          <textarea
            v-model="operationReason"
            class="modal-textarea"
            placeholder="请输入审批意见"
          />
        </view>
 
        <view class="modal-actions">
          <text class="modal-btn ghost" @click="operationVisible = false">取消</text>
          <text
            class="modal-btn primary"
            :class="{ disabled: operationSubmitting }"
            @click="operationSubmitting ? null : submitOperation()"
          >
            {{ operationSubmitting ? '提交中...' : '确定' }}
          </text>
        </view>
      </view>
    </view>
 
    <!-- 表单字段选择(UserSelect / DictSelect 等走通用面板,部门走树形面板) -->
    <PickerSheet
      v-model:show="fieldSheetVisible"
      :title="fieldSheetTitle"
      :multiple="fieldSheetMultiple"
      :items="fieldSheetOptions"
      :selected-keys="fieldSheetSelected"
      @confirm="onFieldSheetConfirm"
    />
 
    <DeptTreePicker
      v-model:show="deptSheetVisible"
      :title="deptSheetTitle"
      :multiple="deptSheetMultiple"
      :nodes="deptTree"
      :selected-keys="deptSheetSelected"
      @confirm="onDeptConfirm"
    />
 
    <PickerSheet
      v-model:show="userSheetVisible"
      :title="userSheetMultiple ? '选择人员(可多选)' : '选择人员'"
      :multiple="userSheetMultiple"
      :items="userSheetOptions"
      :selected-keys="operationAssignees"
      @confirm="onUsersPicked"
    />
 
    <PickerSheet
      v-model:show="showReturnSheet"
      title="选择退回节点"
      :items="returnNodes.map(n => ({ key: n.taskDefinitionKey, label: n.name }))"
      :selected-keys="operationReturnKey ? [operationReturnKey] : []"
      @confirm="keys => { operationReturnKey = keys[0] === undefined ? '' : String(keys[0]); }"
    />
  </view>
</template>
 
<style lang="scss" scoped>
  .page{height:100vh;display:flex;flex-direction:column;padding:0 30rpx;box-sizing:border-box;overflow:hidden;background:#f3f6fb}
  .content{height:0;flex:1;padding-bottom:300rpx;box-sizing:border-box}
  .state{padding:60rpx 20rpx;color:#8795a8;font-size:25rpx;text-align:center}
  .state.error{color:#c65050}
  .hero{display:flex;align-items:flex-start;justify-content:space-between;gap:20rpx;padding:26rpx 24rpx;margin:20rpx 0 16rpx;background:#fff;border-radius:16rpx;box-shadow:0 10rpx 24rpx rgba(43,69,107,.08)}
  .hero-main{display:flex;min-width:0;flex:1;flex-direction:column;gap:10rpx}
  .hero-name{color:#20334c;font-size:32rpx;font-weight:600}
  .hero-meta{color:#8795a8;font-size:23rpx}
  .hero-status{flex:none;padding:8rpx 18rpx;color:var(--color-primary, #1769d8);font-size:23rpx;background:#eef4fd;border:1rpx solid #cfe0f8;border-radius:999rpx}
  .tabs{display:flex;gap:14rpx;margin-bottom:16rpx}
  .tab{flex:1;padding:16rpx 0;color:#3d5069;font-size:26rpx;text-align:center;background:#fff;border-radius:14rpx}
  .tab.active{color:#fff;background:var(--color-primary, #1769d8)}
  .card{padding:24rpx 22rpx;margin-bottom:18rpx;background:#fff;border-radius:16rpx;box-shadow:0 10rpx 24rpx rgba(43,69,107,.08)}
  .card-title{display:block;margin-bottom:18rpx;color:#20334c;font-size:28rpx;font-weight:600}
  .empty-tip{display:block;padding:20rpx 0;color:#9aa8ba;font-size:24rpx}
  .timeline{padding-left:8rpx}
  .node{position:relative;padding:0 0 28rpx 34rpx;border-left:2rpx solid #edf1f6}
  .node:last-child{border-left-color:transparent;padding-bottom:0}
  .node-dot{position:absolute;top:6rpx;left:-11rpx;width:20rpx;height:20rpx;border:4rpx solid #fff;border-radius:50%}
  .node-head{display:flex;align-items:center;justify-content:space-between;gap:14rpx}
  .node-name{color:#20334c;font-size:27rpx;font-weight:500}
  .node-status{flex:none;font-size:23rpx}
  .node-time{display:block;margin-top:8rpx;color:#93a1b3;font-size:22rpx}
  .node-tasks{margin-top:12rpx}
  .node-task{display:flex;flex-direction:column;gap:4rpx;padding:10rpx 14rpx;margin-top:8rpx;background:#f7f9fc;border-radius:10rpx}
  .node-user{color:#3d5069;font-size:24rpx}
  .node-reason{color:#78879b;font-size:23rpx}
  .records{display:flex;flex-direction:column;gap:18rpx}
  .record{padding:18rpx 18rpx 14rpx;background:#f7f9fc;border-radius:12rpx}
  .record-head{display:flex;align-items:center;justify-content:space-between;gap:14rpx;margin-bottom:10rpx}
  .record-name{color:#20334c;font-size:26rpx;font-weight:500}
  .record-status{flex:none;font-size:23rpx}
  .record-line{display:block;color:#66778c;font-size:23rpx;line-height:1.7}
  .footer{position:fixed;z-index:20;right:0;bottom:0;left:0;display:flex;flex-wrap:wrap;gap:14rpx;padding:18rpx 30rpx calc(20rpx + env(safe-area-inset-bottom));background:#fff;border-top:1rpx solid #e6ecf4;box-shadow:0 -6rpx 20rpx rgba(43,69,107,.06)}
  .op{flex:1;min-width:150rpx;padding:18rpx 0;color:var(--color-primary, #1769d8);font-size:26rpx;text-align:center;background:#eef4fd;border-radius:14rpx}
  .op.primary{color:#fff;background:var(--color-primary, #1769d8)}
  .op.danger{color:#d9534f;background:#fdeeee}
  .mask{position:fixed;inset:0;z-index:100;display:flex;align-items:flex-end;background:rgba(20,32,48,.45)}
  .modal{width:100%;max-height:82vh;overflow-y:auto;padding:30rpx 30rpx 40rpx;background:#fff;border-radius:24rpx 24rpx 0 0;box-sizing:border-box}
  .modal-title{display:block;margin-bottom:24rpx;color:#20334c;font-size:32rpx;font-weight:600;text-align:center}
  .modal-field{margin-bottom:24rpx}
  .modal-label{display:block;margin-bottom:12rpx;color:#333;font-size:27rpx}
  .required{margin-left:6rpx;color:#ff4d4f}
  .picker{display:flex;align-items:center;justify-content:space-between;gap:12rpx;padding:20rpx 24rpx;color:#333;font-size:27rpx;background:#f7f8fa;border-radius:12rpx}
  .picker.none{color:#b3bcc9}
  .arrow{flex:none;color:#c2cad6;font-size:32rpx;line-height:1}
  .modal-textarea{width:100%;min-height:170rpx;padding:20rpx 24rpx;font-size:27rpx;background:#f7f8fa;border-radius:12rpx;box-sizing:border-box}
  .sign-types{display:flex;gap:14rpx}
  .sign-type{flex:1;padding:16rpx 0;color:#3d5069;font-size:26rpx;text-align:center;background:#f7f8fa;border-radius:12rpx}
  .sign-type.active{color:#fff;background:var(--color-primary, #1769d8)}
  .attach-list{margin-bottom:12rpx}
  .attach-item{display:flex;align-items:center;justify-content:space-between;padding:12rpx 16rpx;margin-bottom:8rpx;background:#f7f8fa;border-radius:10rpx}
  .attach-name{color:#3d5069;font-size:25rpx}
  .attach-remove{color:#d9534f;font-size:24rpx}
  .attach-btn{font-size:26rpx;color:var(--color-primary, #1769d8);background:#eef4fd;border-radius:12rpx}
  .modal-actions{display:flex;gap:20rpx;margin-top:30rpx}
  .modal-btn{flex:1;padding:22rpx 0;font-size:29rpx;text-align:center;border-radius:14rpx}
  .modal-btn.ghost{color:#3d5069;background:#f2f5f9}
  .modal-btn.primary{color:#fff;background:var(--color-primary, #1769d8)}
  .modal-btn.disabled{opacity:.6}
</style>