<template>
  <div class="table-main">
    <el-table
        :data="prop.tableData"
        stripe
        border
        :header-cell-style="{ textAlign: 'center' }"
        :cell-style="{ textAlign: 'center' }"
        height="368px"
        style="width: 100%"
    >
      <el-table-column type="index" label="序号" width="70" fixed="left"/>

      <el-table-column prop="dataA" :label="'被检设备'">
        <el-table-column prop="timeDev" label="数据时间" width="200"/>
        <el-table-column prop="uaDev" :label="'A相'+(outerUnit==''?'':'（'+outerUnit+'）')" v-if="prop.tableData.length==0||prop.tableData[0]?.uaDev != null"/>
        <el-table-column prop="ubDev" :label="setB+(outerUnit==''?'':'（'+outerUnit+'）')" v-if="prop.tableData.length==0||prop.tableData[0]?.ubDev != null"/>
        <el-table-column prop="ucDev" :label="'C相'+(outerUnit==''?'':'（'+outerUnit+'）')" v-if="prop.tableData.length==0||prop.tableData[0]?.ucDev != null"/>
        <el-table-column prop="utDev" :label="setT+(outerUnit==''?'':'（'+outerUnit+'）')" v-if="prop.tableData[0]?.utDev != null"/>
      </el-table-column>
      <el-table-column prop="dataA" :label="'标准设备'">
        <el-table-column prop="timeStdDev" label="数据时间" width="200"/>
        <el-table-column prop="uaStdDev" :label="'A相'+(outerUnit==''?'':'（'+outerUnit+'）')" v-if="prop.tableData.length==0||prop.tableData[0]?.uaStdDev != null"/>
        <el-table-column prop="ubStdDev" :label="setB+(outerUnit==''?'':'（'+outerUnit+'）')" v-if="prop.tableData.length==0||prop.tableData[0]?.ubStdDev != null"/>
        <el-table-column prop="ucStdDev" :label="'C相'+(outerUnit==''?'':'（'+outerUnit+'）')" v-if="prop.tableData.length==0||prop.tableData[0]?.ucStdDev != null"/>
        <el-table-column prop="utStdDev" :label="setT+(outerUnit==''?'':'（'+outerUnit+'）')" v-if="prop.tableData[0]?.utStdDev != null"/>
      </el-table-column>
    </el-table>
  </div>
</template>

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

const prop = defineProps({
    tableData: {
        type: Array as () => CheckData.TableRow[],
        default: []
    },
    currentCheckItem: {
        type: String,
        default: ''
    }
})

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

const setB = computed(() => {
  return prop.currentCheckItem == '三相电流不平衡度'
      ? '三相电流不平衡度'
      : prop.currentCheckItem == '三相电压不平衡度'
          ? '三相电压不平衡度'
          : 'B相'
})
const setT = computed(() => {
  return prop.currentCheckItem == '频率' ? '频率' : 'T相'
})
</script>

<style scoped></style>
