<template>
  <div>
    <el-dialog
      width="50%"
      title="下载报告"
      v-model="thingDialog"
      @close="closeEvent"
      :close-on-click-modal="false"
    >
      <div class="box">
        <!-- 报告版本 -->
        <div class="singleSelect mb20">
          <h2 class="selectTitle mb10">请选择报告版本</h2>
          <el-radio-group v-model="isFile.versionType">
            <!-- <el-radio label="basic">基础版</el-radio> -->
            <el-radio label="major">专业版</el-radio>
          </el-radio-group>
        </div>

        <!-- 报告类型 -->
        <div class="singleSelect mb20">
          <h2 class="selectTitle mb10">请选择报告类型</h2>
          <el-radio-group v-model="isFile.downloadType">
            <el-radio label="service">服务报告</el-radio>
            <!-- <el-radio label="monitor">监测报告</el-radio> -->
          </el-radio-group>
        </div>

        <!-- 报告格式 -->
        <div class="singleSelect mb20">
          <h2 class="selectTitle mb10">请选择报告格式</h2>
          <el-radio-group v-model="isFile.fileType">
            <!-- <el-radio label="doc">word</el-radio> -->
            <el-radio label="html">html</el-radio>
            <!-- <el-radio label="pdf">PDF</el-radio> -->
            <!-- <el-radio label="json">JSON</el-radio> -->
          </el-radio-group>
        </div>
      </div>
      <!-- pdf -->

      <template #footer>
        <span class="dialog-footer">
          <el-button @click="closeEvent">取消</el-button>
          <el-button type="primary" @click="sureDown">确定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script setup lang="ts" >
import { reactive, ref } from 'vue';
import { ElMessage } from 'element-plus';

interface IProps {
  thingDialog:boolean;
  taskId:string | number;
  scanType:string;
}
const prop = withDefaults(defineProps<IProps>(),{
  thingDialog:false
})

const thingDialog = ref()
const taskId = ref()
const scanType = ref()
watchEffect(()=>{
  thingDialog.value = prop.thingDialog
  taskId.value = prop.taskId
  scanType.value = prop.scanType
})

const emit = defineEmits(['closeEvent'])

const baseUrl = import.meta.env.VITE_APP_BASE_API;

interface IisFile {
  versionType:string,
  downloadType:string,
  fileType:string,
  taskId?:string | number
}
const isFile = reactive<IisFile>({
  versionType:'major',
  downloadType:'service',
  fileType:'html',
})

// 关闭弹框
function closeEvent(){
  emit('closeEvent')
}

// 点击确定
function sureDown(){
  if (!isFile.downloadType) {
        ElMessage.error("请选择请选择报告类型")
      } else if (!isFile.versionType) {
        ElMessage.error("请选择报告版本");
      } else if (!isFile.fileType) {
        ElMessage.error("请选择报告格式");
      } else {
          if(scanType.value === 'main'){
            window.open(
              baseUrl +
                `/business/report/mainDownloadReport?downloadType=${isFile.downloadType}&versionType=${isFile.versionType}&fileType=${isFile.fileType}&taskId=${taskId.value + ''}`
            );
          }else{
            window.open(
              baseUrl +
                `/business/report/webDownloadReport?downloadType=${isFile.downloadType}&versionType=${isFile.versionType}&fileType=${isFile.fileType}&taskId=${taskId.value + ''}`
            );
          }

          isFile.versionType = '',
          isFile.downloadType = '',
          isFile.fileType = ''
          closeEvent();
      }
}
</script>

<style lang="scss" scoped>
.box {
  .singleSelect {
    .selectTitle {
    }
  }
}
</style>
