<template>
    <div class="table-main">
        <el-table
            :data="prop.tableData"
            height="368px"
            :header-cell-style="{ textAlign: 'center' }"
            :cell-style="{ textAlign: 'center' }"
        >
            <el-table-column label="A相" v-if="prop.tableData[0].dataA ">
                <el-table-column prop="stdA" :label="'被检值'">
                    <template #default="{ row }">
                        {{ row.dataA.data }}
                    </template>
                </el-table-column>
                <el-table-column prop="dataA" :label="'标准值'">
                    <template #default="{ row }">
                        {{ row.dataA.resultData }}
                    </template>
                </el-table-column>
                <el-table-column prop="isDataA" label="检测结果">
                    <template #default="{ row }">
                        <el-tooltip effect="dark" placement="bottom">
                            <template #content>
                                误差范围：{{ addPercentSigns(row.dataA.radius,row.dataA.unit) }}
                                <br />
                                误差值：{{ row.dataA.errorData }}
                            </template>
                            <el-tag type="success" v-if="row.dataA.isData === 1">符合</el-tag>
                            <el-tag type="danger" v-if="row.dataA.isData === 2">不符合</el-tag>
                        </el-tooltip>
                    </template>
                </el-table-column>
            </el-table-column>
            <el-table-column label="B相" v-if="prop.tableData[0].dataB">
                <el-table-column prop="stdB" :label="'被检值'">
                    <template #default="{ row }">
                        {{ row.dataB.data }}
                    </template>
                </el-table-column>
                <el-table-column prop="dataB" :label="'标准值'">
                    <template #default="{ row }">
                        {{ row.dataB.resultData }}
                    </template>
                </el-table-column>
                <el-table-column prop="isDataB" label="检测结果">
                    <template #default="{ row }">
                        <el-tooltip effect="dark" placement="bottom">
                            <template #content>
                                误差范围：{{ addPercentSigns(row.dataB.radius,row.dataB.unit) }}
                                <br />
                                误差值：{{ row.dataB.errorData }}
                            </template>
                            <el-tag type="success" v-if="row.dataB.isData === 1">符合</el-tag>
                            <el-tag type="danger" v-if="row.dataB.isData === 2">不符合</el-tag>
                        </el-tooltip>
                    </template>
                </el-table-column>
            </el-table-column>
            <el-table-column label="C相" v-if="prop.tableData[0].dataC">
                <el-table-column prop="stdC" :label="'被检值'" >
                    <template #default="{ row }">
                        {{ row.dataC.data }}
                    </template>
                </el-table-column>
                <el-table-column prop="dataC" :label="'标准值'">
                    <template #default="{ row }">
                        {{ row.dataC.resultData }}
                    </template>
                </el-table-column>
                <el-table-column prop="isDataC" label="检测结果">
                    <template #default="{ row }">
                        <el-tooltip effect="dark" placement="bottom">
                            <template #content>
                                误差范围：{{ addPercentSigns(row.dataC.radius,row.dataC.unit) }}
                                <br />
                                误差值：{{ row.dataC.errorData }}
                            </template>
                            <el-tag type="success" v-if="row.dataC.isData === 1">符合</el-tag>
                            <el-tag type="danger" v-if="row.dataC.isData === 2">不符合</el-tag>
                        </el-tooltip>
                    </template>
                </el-table-column>
            </el-table-column>
            <el-table-column label="T相" v-if="prop.tableData[0].dataT">
                <el-table-column prop="stdT" :label="'被检值'" >
                    <template #default="{ row }">
                        {{ row.dataT.data }}
                    </template>
                </el-table-column>
                <el-table-column prop="dataT" :label="'标准值'">
                    <template #default="{ row }">
                        {{ row.dataT.resultData }}
                    </template>
                </el-table-column>
                <el-table-column prop="isDataT" label="检测结果">
                    <template #default="{ row }">
                        <el-tooltip effect="dark" placement="bottom">
                            <template #content>
                                误差范围：{{ addPercentSigns(row.dataT.radius,row.dataT.unit) }}
                                <br />
                                误差值：{{ row.dataT.errorData }}
                            </template>
                            <el-tag type="success" v-if="row.dataT.isData === 1">符合</el-tag>
                            <el-tag type="danger" v-if="row.dataT.isData === 2">不符合</el-tag>
                        </el-tooltip>
                    </template>
                </el-table-column>
            </el-table-column>
        </el-table>
    </div>
</template>

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

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

// 添加单位
const addPercentSigns = (text: string,unit: string) => {
    return text
        .split('~')
        .map(part => `${part}${unit}`)
        .join('~')
}
const mockTableData = [
    {
        stdA: '220.00',
        dataA: '219.85',
        isDataA: 1,
        maxErrorA: '±0.5%',
        errorA: '0.068%',
        unitA: '%',
        stdB: '220.00',
        dataB: '220.12',
        isDataB: 1,
        maxErrorB: '±0.5%',
        errorB: '0.055%',
        unitB: '%',
        stdC: '220.00',
        dataC: '219.95',
        isDataC: 1,
        maxErrorC: '±0.5%',
        errorC: '0.023%',
        unitC: '%',
        stdT: '0.15',
        dataT: '0.12',
        isDataT: 1,
        maxErrorT: '±0.2',
        errorT: '0.03',
        unitT: '',
        unit: 'V'
    }
]
</script>

<style scoped>
.form-grid {
    display: flex;
    flex-direction: row; /* 横向排列 */
    flex-wrap: wrap; /* 允许换行 */
}

.form-grid .el-form-item {
    flex: 1 1 30%; /* 控件宽度 */
    margin-right: 20px; /* 控件间距 */
}

.form-grid .el-form-item:last-child {
    margin-right: 0; /* 最后一个控件不需要右边距 */
}

.dialog-footer {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 10px; /* 调整这里的值以增加或减少间距 */
}

.el-tabs {
    margin-bottom: 20px; /* 添加底部边距 */
}

.el-table th,
.el-table td {
    text-align: center; /* 所有单元格文字居中 */
}
</style>
