yaowanxin
2025-09-24 bf04601b6a1cb0d52eebe7b6830e8221c22c6ca0
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
 
<template>
  <div class="phase-goal-list-container">
    <el-table
      v-loading="loading"
      :data="phaseGoalList"
      style="width: 100%"
    >
      <el-table-column prop="phaseName" label="所属阶段" width="180" />
      <el-table-column prop="taskName" label="目标名称" min-width="200" />
      <el-table-column prop="targetValue" label="目标值" width="120" />
      <el-table-column prop="currentValue" label="当前值" width="120" />
      <el-table-column prop="unit" label="单位" width="80" />
      <el-table-column prop="targetDate" label="目标日期" width="120" />
      <el-table-column prop="status" label="状态" width="100">
        <template #default="scope">
          <el-tag :type="getStatusType(scope.row.status)">{{ getStatusText(scope.row.status) }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="completionRate" label="完成度" width="120">
        <template #default="scope">
          <el-progress :percentage="scope.row.completionRate" :stroke-width="6" />
        </template>
      </el-table-column>
      <el-table-column label="操作" width="150" fixed="right">
        <template #default="scope">
          <el-button type="text" size="small" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button type="text" size="small" @click="handleDelete(scope.row)" danger>删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <!-- 无阶段目标时的提示 -->
    <div v-if="!loading && phaseGoalList.length === 0" class="empty-tip">
      <el-empty description="暂无阶段目标数据" />
    </div>
  </div>
</template>
 
<script setup>
import { ref, onMounted, watch } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import { listProjectPhase, updateProjectTask, delProjectTask } from '@/api/oaSystem/projectManagement';
 
const props = defineProps({
  projectId: {
    type: String,
    required: true
  }
});
 
const emit = defineEmits(['refresh']);
 
const phaseGoalList = ref([]);
const loading = ref(true);
 
// 获取阶段目标列表
const getPhaseGoalList = async () => {
  loading.value = true;
  try {
    const { data } = await listProjectPhase(props.projectId);
    // 假设phase数据中包含了目标信息
    // 这里简化处理,实际应该调用专门的获取阶段目标的API
    const phases = data.rows || data;
    phaseGoalList.value = [];
    
    phases.forEach(phase => {
      if (phase.oaProjectPhaseTasks && phase.oaProjectPhaseTasks.length > 0) {
        phase.oaProjectPhaseTasks.forEach(goal => {
          phaseGoalList.value.push({
            ...goal,
            phaseName: phase.phaseName
          });
        });
      }
    });
  } catch (error) {
    ElMessage.error('获取阶段目标列表失败');
    console.error('获取阶段目标列表失败:', error);
  } finally {
    loading.value = false;
  }
};
 
// 编辑阶段目标
const handleEdit = (goal) => {
  // 触发父组件的编辑事件,传递目标数据
  emit('editGoal', goal);
};
 
// 删除阶段目标
const handleDelete = async (goal) => {
  try {
    await ElMessageBox.confirm(
      `确定要删除目标「${goal.taskName}」吗?`,
      '确认删除',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }
    );
    
    // 调用删除API
    await delProjectTask(goal.taskId);
    ElMessage.success('删除阶段目标成功');
    
    // 刷新列表
    getPhaseGoalList();
    emit('refresh');
  } catch (error) {
    if (error !== 'cancel') {
      ElMessage.error('删除阶段目标失败');
      console.error('删除阶段目标失败:', error);
    }
  }
};
 
// 获取状态标签类型
const getStatusType = (status) => {
  const statusTypeMap = {
    notStarted: 'info',
    inProgress: 'primary',
    completed: 'success',
    delayed: 'danger'
  };
  return statusTypeMap[status] || 'default';
};
 
// 获取状态文本
const getStatusText = (status) => {
  const statusTextMap = {
    notStarted: '未开始',
    inProgress: '进行中',
    completed: '已完成',
    delayed: '已延迟'
  };
  return statusTextMap[status] || status;
};
 
// 监听项目ID变化
watch(() => props.projectId, () => {
  if (props.projectId) {
    getPhaseGoalList();
  }
});
 
// 初始化
onMounted(() => {
  if (props.projectId) {
    getPhaseGoalList();
  }
});
</script>
 
<style scoped>
.phase-goal-list-container {
  padding: 10px 0;
}
 
.empty-tip {
  margin-top: 40px;
  text-align: center;
}
</style>