<template>
  <view class="setup-wrapper">
    <CommonSection title="立项概览" :isFirst="true">
      <CommonInfoRow label="项目名称" :value="projectData?.projectName" />
      <CommonInfoRow label="项目编号" :value="projectData?.projectCode" />
      <CommonInfoRow label="项目学科分类" :value="getDictLabel('project_class', projectData?.disciplineFirstName)" />
      <CommonInfoRow label="成果归属单位" :value="projectData?.deptName" />
      <CommonInfoRow label="项目分类" :value="projectData?.projectClazzName" />
      <CommonInfoRow label="项目状态" :value="getStatusLabel(spontaneityProjectStatusOptions, projectData?.projectStatus)" />
      <CommonInfoRow label="立项日期" :value="formatDate(projectData?.approvalDate)" />
      <CommonInfoRow label="计划开始日期" :value="formatDate(projectData?.planStartDate)" />
      <CommonInfoRow label="计划结项日期" :value="formatDate(projectData?.planEndDate)" />
      <CommonInfoRow label="实际完成日期" :value="formatDate(projectData?.actualEndDate)" />
      <CommonInfoRow label="批准经费(元)" :value="formatWithComma(projectData?.approvedFunds)" isAmount />
      <CommonInfoRow label="所属年度" :value="projectData?.statisticalYear" />
      <CommonInfoRow label="项目负责人" :value="projectData?.projectLeaderName" />
      <CommonInfoRow label="项目负责人类型" :value="getDictLabel('sci_leader_type', projectData?.projectLeaderType)" />
      <CommonInfoRow label="所属平台">
        <view class="platform-tags" v-if="platformList.length > 0">
          <view v-for="(item, index) in platformList" :key="index" class="platform-tag">
            {{ item.platformName === '其他' ? item.platformName : `${item.platformName} (${item.platformType})` }}
          </view>
        </view>
        <text v-else>--</text>
      </CommonInfoRow>
      <CommonInfoRow label="所属团队" :value="projectData?.belongTeam" />
      <CommonInfoRow label="成果形式" :value="projectData?.outcome" />
      <CommonInfoRow label="财务账户" :value="projectData?.financeAccount" />
      <CommonInfoRow label="备注" :value="projectData?.remark" :noBorder="true" />
    </CommonSection>
  </view>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import { useDict } from '@/hooks/useDict';
import { formatWithComma } from '@/utils/format';
import { formatDate } from '@/utils/date';
import { spontaneityProjectStatusOptions, getStatusLabel } from '@/constants/index';
import CommonSection from '@/components/ui/CommonSection.vue';
import CommonInfoRow from '@/components/ui/CommonInfoRow.vue';

const { getDictLabel } = useDict('sci_leader_type', 'project_class');

/**
 * 自发类项目 立项信息展示组件
 */
const props = defineProps<{
  /** 项目主数据详情 */
  projectData: any;
}>();

/**
 * 平台信息解析
 */
const platformList = computed(() => {
  const belong = props.projectData?.belongPlatform;
  if (belong) {
    if (belong === '其他') return [{ platformName: '其他' }];
    try {
      const data = JSON.parse(belong);
      return Array.isArray(data) ? data : [];
    } catch (e) {
      return [{ platformName: belong }];
    }
  }
  return [];
});
</script>

<style lang="scss" scoped>
.setup-wrapper {
  /* 基础容器样式 */
  width: 100%;
  padding-bottom: 20px;
}

.platform-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8rpx;
  justify-content: flex-end;
}

.platform-tag {
  font-size: 24rpx;
  background-color: #e6f7ff;
  color: #1a9cff;
  padding: 4rpx 16rpx;
  border-radius: 6rpx;
  border: 1px solid #bae7ff;
}
</style>
