<script name="approvalInfo" setup>
import { onMounted, ref } from 'vue'
import { expertReviewDetail } from '@/http/apis/projectStoreManage/projectStore'
import MemberOpinion from '@/pages/expertManage/expertReview/components/memberOpinion.vue'
import NoData from '@/components/noData/index.vue'
import Accessory from '@/components/accessory/index.vue'
const props = defineProps({
  detailData: Object
})
const
  collapseModal = ref([]),
  reviewInfoData = ref(),
  getReviewInfo = async () => {
    const res = await expertReviewDetail(props.detailData.projectCode)
    reviewInfoData.value = res.data?.reviews?.map(i => {
      return {
        ...i,
        finalReview: [{
          ...i.finalReview,
          reviewTemplateOptions: i.finalReview?.reviewTemplateOptions?.map(temp => {
            const data = res.data.templates.find(j => i.finalReview.templateId === j.templateId).templates
            return {
              ...temp,
              title: data.find(r => r.serialNo === temp.questionSerialNo)?.title,
              optionsValue: data.find(r => r.serialNo === temp.questionSerialNo)?.options.filter(j => temp.optionSerialNo.includes(j.serialNo)).map(j => j.option).join('、')
            }
          }) || []
        }],
        teamMemberReviews: i.teamMemberReviews.map(t => {
          return {
            ...t,
            reviewTemplateOptions: t?.reviewTemplateOptions?.map(temp => {
              const data = res.data.templates.find(j => t.templateId === j.templateId).templates
              return {
                ...temp,
                title: data.find(r => r.serialNo === temp.questionSerialNo)?.title,
                optionsValue: data.find(r => r.serialNo === temp.questionSerialNo)?.options.filter(j => temp.optionSerialNo.includes(j.serialNo)).map(j => j.option).join('、')
              }
            }) || []
          }
        })

      }
    })
  },
  tabPosition = ref(new Array(4).fill('最终意见')),
  reviewTypes = ['初步方案评审', '部门联审', '建设方案评审', '验收评审']

onMounted(() => {
  getReviewInfo()
})
</script>

<template>
  <el-descriptions :column="2" border class="mb-16">
    <el-descriptions-item label="建议总投资">
      {{ detailData.proposeTotalInvest||'-' }}万元
    </el-descriptions-item>
    <el-descriptions-item label="建议年度预算">
      {{ detailData.proposeAnnualBudget||'-' }}万元
    </el-descriptions-item>
    <el-descriptions-item label="评审意见附件" :span="2">
      <p v-for="(item,index) in detailData.proposeAttachFiles&&JSON.parse(detailData.proposeAttachFiles)" :key="index" class="mb-4">
        <accessory :file-name="item.originalFileName" :file-id="item.id" :is-down-load="true" />
      </p>
    </el-descriptions-item>
  </el-descriptions>
  <el-collapse v-model="collapseModal">
    <el-collapse-item
      v-for="(item,index) in reviewTypes"
      :key="index"
      :name="item"
      :title="item"
    >
      <el-radio-group v-model="tabPosition[index]" class="mb-16">
        <el-radio-button label="最终意见">最终意见</el-radio-button>
        <el-radio-button label="组员意见">组员意见</el-radio-button>
      </el-radio-group>
      <member-opinion v-if="reviewInfoData?.find(i=>i.reviewType===index+1)&&tabPosition[index]==='最终意见'" :member-opinions="reviewInfoData?.find(i=>i.reviewType===index+1).finalReview" />
      <member-opinion v-else-if="reviewInfoData?.find(i=>i.reviewType===index+1)&&tabPosition[index]==='组员意见'" :member-opinions="reviewInfoData?.find(i=>i.reviewType===index+1).teamMemberReviews" />
      <no-data v-else />
    </el-collapse-item>
  </el-collapse>
</template>
