All files / src/views/logic TaskReviewDialog.logic.ts

100% Statements 125/125
100% Branches 12/12
100% Functions 8/8
100% Lines 125/125

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 1251x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 2x 2x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 1x 1x 1x 2x 2x 1x 1x 1x 2x 2x 1x 1x 1x 5x 5x 1x 1x 1x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 16x 16x 16x 16x 16x 16x 16x
import { ref, computed } from 'vue';
import { Task, currentReviewTask as inspectCurrentReviewTask } from './Inspect.logic';
 
// 定义托盘信息接口
export interface TrayInfo {
  id: string;
  name: string;
  status: string;
  completedAt?: string;
  operator?: string;
  result?: string;
  remarks?: string;
}
 
// 定义子任务详细信息接口
export interface SubtaskDetail {
  id: number;
  item: string;
  condition: string;
  completedAt: string;
  operator: string;
  result: string;
  remarks: string;
  trays: TrayInfo[];
}
 
// 响应式数据
export const reviewComment = ref('');
export const selectedSubtaskIndex = ref<number | null>(null);
export const selectedTray = ref<TrayInfo | null>(null);
export const expandedSubtasks = ref<Record<number, boolean>>({});
export const trayInfoExpanded = ref<Record<number, boolean>>({});
export const expandedTrays = ref<Record<string, boolean>>({}); // 添加这行
 
// 计算属性:获取当前选中的子任务详细信息
export const selectedSubtaskDetail = computed<SubtaskDetail | null>(() => {
  if (selectedSubtaskIndex.value === null) return null;
  
  // 使用从Inspect.logic导入的currentReviewTask
  const subtask = inspectCurrentReviewTask.value?.subtasks[selectedSubtaskIndex.value];
  if (!subtask) return null;
  
  return {
    id: selectedSubtaskIndex.value,
    item: subtask.item,
    condition: subtask.condition,
    completedAt: '2024-12-15 14:30:25',
    operator: '张三',
    result: '合格',
    remarks: '检测过程正常,数据符合标准',
    trays: [
      {
        id: 'A',
        name: '托盘A',
        status: '已完成',
        completedAt: '2024-12-15 14:25:10',
        operator: '李四',
        result: '合格',
        remarks: '托盘A检测完成,结果正常'
      },
      {
        id: 'B',
        name: '托盘B',
        status: '已完成',
        completedAt: '2024-12-15 14:28:45',
        operator: '王五',
        result: '合格',
        remarks: '托盘B检测完成,结果正常'
      }
    ]
  };
});
 
// 选择子任务
export function selectSubtask(index: number) {
  selectedSubtaskIndex.value = index;
  selectedTray.value = null; // 重置选中的托盘
  // 自动展开子任务详情
  expandedSubtasks.value[index] = true;
  // 自动展开托盘信息区域
  trayInfoExpanded.value[index] = true;
}
 
// 展开/收起子任务详情
export function toggleSubtask(index: number) {
  expandedSubtasks.value[index] = !expandedSubtasks.value[index];
}
 
// 展开/收起托盘信息
export function toggleTrayInfo(index: number) {
  trayInfoExpanded.value[index] = !trayInfoExpanded.value[index];
}
 
// 展开/收起单个托盘详情
export function toggleTrayDetail(trayId: string) {
  expandedTrays.value[trayId] = !expandedTrays.value[trayId];
}
 
// 选择托盘(同时展开/收起托盘详情)
export function selectTray(tray: TrayInfo) {
  selectedTray.value = tray;
  // 点击托盘时也展开/收起托盘详情
  toggleTrayDetail(tray.id);
}
 
// 显示托盘详情
export function showTrayDetail(subtaskIndex: number, trayId: string) {
  console.log(`显示子任务${subtaskIndex + 1}的托盘${trayId}详情`);
  // 这里可以打开一个托盘详情对话框
}
 
// 提交审核意见
export function submitReviewComment(submitReview: (comment: string) => void) {
  submitReview(reviewComment.value);
}
 
// 重置状态
export function resetReviewState() {
  reviewComment.value = '';
  selectedSubtaskIndex.value = null;
  selectedTray.value = null;
  expandedSubtasks.value = {};
  trayInfoExpanded.value = {};
  expandedTrays.value = {}; // 重置托盘展开状态
}