<template>
  <div class="qualification">
    <el-table :data="qualificationList" border>
      <el-table-column prop="qualificationType" label="资质类型" />
      <el-table-column prop="qualificationNo" label="资质证书编号" />
      <el-table-column prop="authority" label="签发机构" />
      <el-table-column prop="deadline" label="截止日期" />
      <el-table-column label="操作" width="150">
        <template #default="scope">
          <el-button link type="primary" size="small" @click="handleView(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { ElMessage } from 'element-plus';
import { getCurrentPartnerInfo, getPartnerQualificationList } from '@/api/partner';

const qualificationList = ref([]);
const loading = ref(false);

const handleView = (row: any) => {
  console.log('查看资质', row);
};

const fetchQualificationList = async () => {
  loading.value = true;
  try {
    const partnerResponse = await getCurrentPartnerInfo();
    if (partnerResponse.code === 200 && partnerResponse.data) {
      const partnerId = partnerResponse.data.id;
      const response = await getPartnerQualificationList(partnerId);
      if (response.code === 200) {
        qualificationList.value = response.rows || response.data || [];
      }
    }
  } catch (error) {
    console.error('获取资质列表失败', error);
    ElMessage.error('获取资质列表失败');
  } finally {
    loading.value = false;
  }
};

onMounted(() => {
  fetchQualificationList();
});
</script>

<style scoped lang="scss">
.qualification {
  padding: 20px;
}

.toolbar {
  margin-bottom: 20px;
  display: flex;
  justify-content: flex-end;
}
</style>
