<template>
  <div class="project-member-page">
    <div class="header-section">
      <h3>{{ t('project.management.detail.menu.projectMember') }}</h3>
    </div>
    <el-divider />

    <el-card shadow="never">
      <el-table
        v-loading="loading"
        border
        :data="memberList"
        style="width: 100%"
      >
        <el-table-column type="index" :label="t('project.management.table.id')" width="60" align="center" />
        <el-table-column :label="t('project.management.member.name')" align="center" prop="name" width="150" />
        <el-table-column :label="t('project.management.member.phoneNumber')" align="center" prop="phoneNumber" width="150" />
        <el-table-column :label="t('project.management.member.dept')" align="center" prop="dept" min-width="200" show-overflow-tooltip />
        <el-table-column :label="t('project.management.member.time')" align="center" prop="time" width="180" />
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { inject, ref, onMounted } from 'vue';
import { useI18n } from 'vue-i18n';
import { queryProjectMember } from '@/api/project/management';
import { ProjectMemberVO, ProjectMemberQuery } from '@/api/project/management/types';

const { t } = useI18n();

// 接收从父组件传递的项目ID
const projectId = inject<any>('projectId');

// 列表数据
const memberList = ref<ProjectMemberVO[]>([]);
const loading = ref(true);
const total = ref(0);

// 查询参数
const queryParams = ref<ProjectMemberQuery>({
  pageNum: 1,
  pageSize: 10,
  id: projectId?.value || 0
});

/** 查询项目成员列表 */
const getList = async () => {
  loading.value = true;
  try {
    queryParams.value.id = projectId?.value || 0;
    const res = await queryProjectMember(queryParams.value);
    memberList.value = res.rows;
    total.value = res.total;
  } catch (error) {
    console.error('Failed to fetch project members:', error);
  } finally {
    loading.value = false;
  }
};

// 组件挂载时加载数据
onMounted(() => {
  getList();
});
</script>

<style scoped>
.project-member-page {
  height: 100%;
}

.header-section {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.info-section {
  padding: 16px 0;
}

.info-section p {
  line-height: 2;
  font-size: 14px;
  color: #606266;
  margin: 8px 0;
}

.info-section strong {
  color: #303133;
  margin-right: 8px;
}

h3 {
  font-size: 18px;
  font-weight: 600;
  color: #303133;
  margin: 0;
}

.info-tip {
  color: #909399;
  font-style: italic;
  margin-top: 16px;
}

</style>
