
<template>
  <div class="layoutEmbedded">
    <a-spin :spinning="loading" style="width: 100%;height: 100%;">
      <!-- 申报项目详情 -->
      <a-button type="primary" @click="onExport">导出</a-button>
      <project-info v-model="projectInfo" v-if="projType" />
      <project-info-Key v-model="projectInfo" v-else />
    </a-spin>
  </div>
</template>
<script>
import { budgetList } from '@/views/report/project/config'
import { getType } from '@/views/utils/auth'
import projectInfo from '@/views/report/project/components/projectInfo'
import projectInfoKey from "@/views/report/project/components/keyProject/projectInfo"
export default {
  name: "projectView",
  components: {
    projectInfo, projectInfoKey
  },
  data () {
    return {
      projectInfo: {
        projName: '',
        startDate: '',
        endDate: '',
        applyMoney: '',
        projClassName: '',
        appPersonName: '',
        sex: '',
        titleName: '',
        degreeName: '',
        specName: '',
        jobUnit: '',
        mobile: '',
        address: '',
        appUnitName: '',
        linkName: '',
        linkEmail: '',
        linkTel: '',
        knowledgeName: '',
        projContent: '',
        projTarget: '',
        projKeywords: '',
        // 合作单位
        together: [{ unitName: '', unitAddress: '', projectWork: '' }, { unitName: '', unitAddress: '', projectWork: '' }],
        // 项目组成员
        members: [],
        // 经费
        budget: budgetList(),
        projDoc: null,
        fileList: [{ fileName: '', url: '', remarks: '', id: '' }],
        auditList: [{ result: '', unit: '', time: '' }],
      },
      loading: false,
      projType: getType() == "1"
    };
  },
  props: {
    value: {
      type: String,
      default: () => {
        return null
      }
    }
  },
  created () {
    this.getProjectInfoById()
  },
  methods: {
    getProjectInfoById () {
      if (this.value != null) {
        this.loading = true
        this.$api.project.getProjectInfoById({ id: this.value }).then(({ data = {} }) => {
          if (data) {
            this.projectInfo = data
            this.loading = false
          } else
            this.$emit('close', 'close')
        }).catch(() => { this.$emit('close', 'close') })
      }
    },
    onExport () {
      this.$api.project.export({ id: this.value }).then((res) => {
        let blob = new Blob([res], {
          type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=utf-8",
        });
        const fileName = this.projectInfo.projName + '.doc';
        let downloadElement = document.createElement('a')
        let href = window.URL.createObjectURL(blob); //创建下载的链接
        downloadElement.href = href;
        downloadElement.download = fileName; //下载后文件名
        document.body.appendChild(downloadElement);
        downloadElement.click(); //点击下载
        document.body.removeChild(downloadElement); //下载完成移除元素
        window.URL.revokeObjectURL(href); //释放blob
      })
    }
  },
}
</script>


