<template>
 <div class="h100">
   <common-layout
     ref="layoutRef"
   :filter-form="checkReportHomeFilterForm"
     :get-table-list="getTableList"
   :table-header="checkReportHomeTableHeader"
     :form-attrs="{
     spanAttrs: {
       span:5
     }
     }"
   :table-attrs="{
     'has-operation':true
   }"
   >
     <template #REPORT_STATE="{data}">
       {{getStatus(data.REPORT_STATE)}}
     </template>
     <template #operation="{data}">

       <el-button type="info" v-if="data['REPORT_STATE'] === '5'" disabled>生成中</el-button>
       <el-button type="info" v-if="data['REPORT_STATE'] === '2'" @click="createPort(data)">重新生成</el-button>
       <el-button type="info" v-if="data['REPORT_STATE'] === '0'"  @click="createPort(data)">生成报告</el-button>
       <el-button type="info" v-if="data['REPORT_STATE'] === '1'"  @click="createPort(data)">重新生成</el-button>
       <el-button type="info" v-if="data['REPORT_STATE'] === '1'" @click="exportReportD(data)">导出报告</el-button>
     </template>
   </common-layout>
 </div>
</template>

<script>
import CommonLayout from "@/components/CommonLayout.vue";
import {checkReportHomeFilterForm} from "@/data/all-forms";
import {checkReportHomeTableHeader} from "@/data/all-table-header";
import {onBeforeMount, ref} from "vue";
import {crateReportD,  getSafeReportTableData} from "@/service/zsk/safe-report";
import {getSafeCheckHomeT} from "@/service/zsk/safe-check";
import {safeCheckReportHomeTableData} from "@/service/zsk/check-report";
import {handleMes} from "@/unit/element-ui/tip";
import {baseUrl} from "@/service/config";
import {useRootStore} from "@/stores/useStore";

export default {
  name: "CheckReport",
  components: {CommonLayout},
  setup() {
    function createPort(data) {
      crateReportD(data.UUID).then(res => {
         handleMes(res,() => {
            getTableList()
         })
      })
    }
    function exportReportD(data) {
      window.open(baseUrl +`/ptjkInterface/exportSafeTemplateWord?appkey=${useRootStore().userInfo.ptjk_userkeycode}&UUID=${data.UUID}`,'_blank')

    }
    function getTableList() {
      safeCheckReportHomeTableData({
        PAGEINDEX:layoutRef.value.pageIndex,
        PAGESIZE:layoutRef.value.pageSize,
        MONTH_TIME:layoutRef.value.form.MONTH_TIME,

      }).then(res => {
        layoutRef.value.getResData(res.msg[0].Rows||[],res.msg[0].TotalRowCount)
      })

    }
    function getStatus (value){
      switch (value) {
        case "0":
          return "未生成"
        case "1":
          return "已生成"
        case "5":
          return "生成中"
        case "2":
          return "生成失败"
      }
    }
    onBeforeMount(() => {

    })
    const layoutRef = ref(null)
    return {
      checkReportHomeFilterForm,
      checkReportHomeTableHeader,
      layoutRef,
      getTableList,
      getStatus,
      createPort,
      exportReportD
    }
  }
}
</script>

<style scoped lang="scss">

</style>
