<template>
  <el-button v-if="tableData.length > 0" type="primary" @click="exportData" style="margin-bottom: 10px">导出</el-button>
  <div class="table-main">
    <el-table v-if="tableData.length > 0" :data="tableData" stripe border :header-cell-style="{ textAlign: 'center' } "
              :cell-style="{ textAlign: 'center' }" height="315px"
              style="width: 100%;">
      <el-table-column type="index" label="序号" width="70" fixed="left"/>
      <el-table-column prop="time" label="数据时间"/>
      <template v-if="!isThreePhase && phaseT === 0">
        <el-table-column prop="dataA" :label="'A相'+(unit==''?'':'（'+unit+'）')"/>
        <el-table-column prop="dataB" :label="'B相'+(unit==''?'':'（'+unit+'）')"/>
        <el-table-column prop="dataC" :label="'C相'+(unit==''?'':'（'+unit+'）')"/>
      </template>
      <template v-if="!isThreePhase && phaseT === 1">
        <el-table-column prop="dataT" :label="tableHeader+(unit==''?'':'（'+unit+'）')"/>
      </template>
      <template v-if="isThreePhase">
        <el-table-column prop="dataB" :label="'负序不平衡度'+(unit==''?'':'（'+unit+'）')"/>
      </template>
    </el-table>
  </div>

</template>

<script lang="tsx" setup>
import {CheckData} from "@/api/check/interface";
import {computed} from "vue";

const {tableData, currentScriptTypeName} = defineProps<{
  tableData: CheckData.RawDataItem[]
  currentScriptTypeName: string
}>()

const emit = defineEmits(['exportRawDataHandler'])

const unit = computed(() => {
  return tableData.length > 0 ? tableData[0].unit : '';
})

const phaseT = computed(() => {
  return tableData[0].dataT == '/' ? 0 : 1
})

const tableHeader = computed(() => {
  if (phaseT.value === 1) {
    let index = currentScriptTypeName.indexOf('=');
    return currentScriptTypeName.substring(0, index);
  }
  return currentScriptTypeName
})

const isThreePhase = computed(() => {
  return currentScriptTypeName.includes('三相电压不平衡度') || currentScriptTypeName.includes('三相电流不平衡度')
})

const exportData = () => {
  emit('exportRawDataHandler')
}
</script>

<style scoped>

</style>