<template>
  <view class="achievement-detail">
    <AchPatentForm v-if="type === 'patent'" :code="code" />
    <SciAchievementSoftware v-else-if="type === 'software'" :code="id" />
    <SciAchievementOther v-else-if="type === 'other'" :code="id" />
    <SciAchievementStandard v-else-if="type === 'standard'" :code="id" />
    <AchDecisionForm v-else-if="type === 'decision'" :code="id" />
    <AchWorkForm v-else-if="type === 'work'" :code="code" />
    <AchAwardsForm v-else-if="type === 'awards'" :code="code" />
    <AchPaperForm v-else-if="type === 'paper'" :code="code" />
    <ConferenceForm v-else-if="type === 'conference'" :code="id" />
    <SpecialActivityForm v-else-if="type === 'special_activity'" :code="id" />
    
    <view v-else class="fallback-container">
      <uv-empty mode="data" text="该类型详情暂未完全适配移动端，请联系管理员"></uv-empty>
      <view class="debug-info" v-if="id">
        <text>类型: {{ type }}</text>
        <text>ID: {{ id }}</text>
        <text>编码: {{ code }}</text>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';

import AchPatentForm from '../todo/components/document/AchPatentForm.vue';
import SciAchievementSoftware from '../todo/components/document/SciAchievementSoftware.vue';
import SciAchievementOther from '../todo/components/document/SciAchievementOther.vue';
import SciAchievementStandard from '../todo/components/document/SciAchievementStandard.vue';
import AchPaperForm from '../todo/components/document/AchPaperForm.vue';
import AchAwardsForm from '../todo/components/document/AchAwardsForm.vue';
import AchWorkForm from '../todo/components/document/AchWorkForm.vue';
import ConferenceForm from '../todo/components/document/ConferenceForm.vue';
import AchDecisionForm from '../todo/components/document/AchDecisionForm.vue';
import SpecialActivityForm from '../todo/components/document/SpecialActivityForm.vue';

const type = ref('');
const id = ref('');
const code = ref('');

onLoad((options: any) => {
  type.value = options.type || '';
  id.value = options.id || '';
  code.value = options.code || '';
  
  if (type.value) {
    uni.setNavigationBarTitle({
      title: getTitleByType(type.value)
    });
  }
});

const getTitleByType = (t: string) => {
  const map: any = {
    patent: '专利详情',
    software: '软著详情',
    other: '其他成果详情',
    standard: '标准详情',
    decision: '决策咨询详情',
    work: '学术著作详情',
    awards: '奖项荣誉详情',
    paper: '学术论文详情',
    conference: '学术会议详情',
    special_activity: '科技专项活动详情'
  };
  return map[t] || '成果详情';
};
</script>

<style lang="scss" scoped>
.achievement-detail {
  min-height: 100vh;
  background-color: #f8fafc;
  padding: 20rpx 0;
}

.fallback-container {
  padding: 100rpx 40rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  
  .debug-info {
    margin-top: 40rpx;
    font-size: 24rpx;
    color: #999;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
}
</style>
