<template>
        <div class="table-container table-main">
            <el-table :data="tableData" 
            :header-cell-style="{ textAlign: 'center' } " 
            :cell-style="{ textAlign: 'center' }" 
            style="width: 100%" 
            max-height="400px" 
            :span-method="objectSpanMethod">
                    <el-table-column   prop="MonitorIdx" label="监测点序号" width="80"/>
                    <!-- <el-table-column prop="updateTime" label="上送时刻" width="180"/> -->
                    <el-table-column prop="deviceName" label="描述"  width="90"/>
                    <el-table-column label="电压通道" >
                        <el-table-column prop="Ua" label="L1">
                          <el-table-column prop="UaData" label="数据(V)">
                            <template #default="scope">
                              <el-icon v-if="scope.row.UaData === '—'&& loading" class="loading-box">
                                <el-icon-loading />
                              </el-icon>
                              <span v-else>
                                {{ scope.row.UaData }}
                              </span>
                            </template>
                          </el-table-column>
                          <el-table-column prop="UaChannel" label="系数">
                            <template #default="scope">
                              <el-tag type="danger" v-if="scope.row.UaChannel === '不合格'">
                                {{ scope.row.UaChannel }}
                              </el-tag>
                              <el-icon v-else-if="scope.row.UaChannel === '—'&& loading" class="loading-box">
                                <el-icon-loading />
                              </el-icon>
                              <span v-else>
                                {{ scope.row.UaChannel }}
                              </span>
                              <!-- <el-tag type="danger" v-if="scope.row.UaChannel === '不合格'">{{ scope.row.UaChannel }}</el-tag> -->
                            </template>
                          </el-table-column>
                        </el-table-column>
                        <el-table-column prop="Ub" label="L2">
                          <el-table-column prop="UbData" label="数据(V)">
                            <template #default="scope">
                              <el-icon v-if="scope.row.UbData === '—'&& loading" class="loading-box">
                                <el-icon-loading />
                              </el-icon>
                              <span v-else>
                                {{ scope.row.UbData }}
                              </span>
                            </template>
                          </el-table-column>
                          <el-table-column prop="UbChannel" label="系数">
                            <template #default="scope">
                              <el-tag type="danger" v-if="scope.row.UbChannel === '不合格'">
                                {{ scope.row.UbChannel }}
                              </el-tag>
                              <el-icon v-else-if="scope.row.UbChannel === '—'&& loading" class="loading-box">
                                <el-icon-loading />
                              </el-icon>
                              <span v-else>
                                {{ scope.row.UbChannel }}
                              </span>
                            </template>
                          </el-table-column>
                        </el-table-column>
                        <el-table-column prop="Uc" label="L3">
                          <el-table-column prop="UcData" label="数据(V)">
                            <template #default="scope">
                              <el-icon v-if="scope.row.UcData === '—'&& loading" class="loading-box">
                                <el-icon-loading />
                              </el-icon>
                              <span v-else>
                                {{ scope.row.UcData }}
                              </span>
                            </template>
                          </el-table-column>
                          <el-table-column prop="UcChannel" label="系数">
                            <template #default="scope">
                              <el-tag type="danger" v-if="scope.row.UcChannel === '不合格'">
                                {{ scope.row.UcChannel }}
                              </el-tag>
                              <el-icon v-else-if="scope.row.UcChannel === '—'&& loading" class="loading-box">
                                <el-icon-loading />
                              </el-icon>
                              <span v-else>
                                {{ scope.row.UcChannel }}
                              </span>
                            </template>
                          </el-table-column>
                        </el-table-column>
                    </el-table-column>
                    <el-table-column label="电流通道" >
                        <el-table-column prop="Ia" label="L1">
                          <el-table-column prop="IaData" label="数据(A)">
                            <template #default="scope">
                              <el-icon v-if="scope.row.IaData === '—'&& loading" class="loading-box">
                                <el-icon-loading />
                              </el-icon>
                              <span v-else>
                                {{ scope.row.IaData }}
                              </span>
                            </template>
                          </el-table-column>
                          <el-table-column prop="IaChannel" label="系数">
                            <template #default="scope">
                              <el-tag type="danger" v-if="scope.row.IaChannel === '不合格'">
                                {{ scope.row.IaChannel }}
                              </el-tag>
                              <el-icon v-else-if="scope.row.IaChannel === '—'&& loading" class="loading-box">
                                <el-icon-loading />
                              </el-icon>
                              <span v-else>
                                {{ scope.row.IaChannel }}
                              </span>
                            </template>
                            </el-table-column>
                        </el-table-column>
                        <el-table-column prop="Ib" label="L2">
                          <el-table-column prop="IbData" label="数据(A)">
                            <template #default="scope">
                              <el-icon v-if="scope.row.IbData === '—'&& loading" class="loading-box">
                                <el-icon-loading />
                              </el-icon>
                              <span v-else>
                                {{ scope.row.IbData }}
                              </span>
                            </template>
                          </el-table-column>
                          <el-table-column prop="IbChannel" label="系数">
                            <template #default="scope">
                              <el-tag type="danger" v-if="scope.row.IbChannel === '不合格'">
                                {{ scope.row.IbChannel }}
                              </el-tag>
                              <el-icon v-else-if="scope.row.IbChannel === '—'&& loading" class="loading-box">
                                <el-icon-loading />
                              </el-icon>
                              <span v-else>
                                {{ scope.row.IbChannel }}
                              </span>
                            </template>
                          </el-table-column>
                        </el-table-column>
                        <el-table-column prop="Ic" label="L3">
                          <el-table-column prop="IcData" label="数据(A)">
                            <template #default="scope">
                              <el-icon v-if="scope.row.IcData === '—'&& loading" class="loading-box">
                                <el-icon-loading />
                              </el-icon>
                              <span v-else>
                                {{ scope.row.IcData }}
                              </span>
                            </template>
                          </el-table-column>
                          <el-table-column prop="IcChannel" label="系数">
                            <template #default="scope">
                              <el-tag type="danger" v-if="scope.row.IcChannel === '不合格'">
                                {{ scope.row.IcChannel }}
                              </el-tag>
                              <el-icon v-else-if="scope.row.IcChannel === '—'&& loading" class="loading-box">
                                <el-icon-loading />
                              </el-icon>
                              <span v-else>
                                {{ scope.row.IcChannel }}
                              </span>
                            </template>
                          </el-table-column>
                        </el-table-column>
                    </el-table-column>
                    <!-- <el-table-column  label="校准结果">
                      <template #default="scope">
                        <el-tag type="danger" v-if="scope.row.Result === '不合格'">{{ scope.row.Result }}</el-tag>
                        <span v-if="scope.row.Result != '不合格'">{{ scope.row.Result }}</span>
                      </template>
                    </el-table-column> -->
                   
            </el-table>
        </div>
</template>
  
  <script lang="ts" setup name="ErrorSystemDialog">
  import { defineProps } from 'vue';
  import { ElIcon, ElLoading, ElTag } from 'element-plus';
  //import IndicatorTypeDialog from "@/views/machine/errorSystem/components/IndicatorTypeDialog.vue"; // 导入子组件

  const props = defineProps<{
      tableData: Array<{
        id: string;
        deviceName?: string;
        MonitorIdx: number;
        UaData?: number | string;
        UaChannel?: number | string;
        UbData?: number | string;
        UbChannel?: number | string;
        UcData?: number | string;
        UcChannel?: number | string;
        IaData?: number | string;
        IaChannel?: number | string;
        IbData?: number | string;
        IbChannel?: number | string;
        IcData?: number | string;
        IcChannel?: number | string;
        Result?: string | string;
        updateTime?: string;
      }>
      loading: boolean; // 定义 loading 属性
  }>();

  function objectSpanMethod({ row, column, rowIndex, columnIndex }: { row: any, column: any, rowIndex: number, columnIndex: number }) {
    if (columnIndex === 0) {
        if (rowIndex % 4 === 0) {
            return {
                rowspan: 4,
                colspan: 1,
            };
        } else {
            return {
                rowspan: 0,
                colspan: 0,
            };
        }
    }
    if (columnIndex === 1) {
        if (rowIndex % 2 === 0) {
            return {
                rowspan: 2,
                colspan: 1,
            };
        } else {
            return {
                rowspan: 0,
                colspan: 0,
            };
        }
    }
}

  // const tableData = ref([
  //   {
  //     id: '1',
  //     updateTime: '2024-10-10 10:30:00', 
  //     deviceName:'被检设备1',
  //     MonitorIdx: 1, 
  //     Ua:1.0003,
  //     Ub:1.0003,
  //     Uc:0.0096,
  //     Ia:1.0003,
  //     Ib:1.0003,
  //     Ic:1.0008,
  //     Result: '合格', 
  //   },
  //   {
  //     id: '2',
  //     updateTime: '2024-10-10 10:30:00', 
  //     deviceName:'被检设备1',
  //     MonitorIdx: 2, 
  //     Ua:1.0003,
  //     Ub:1.0003,
  //     Uc:0.0096,
  //     Ia:1.0003,
  //     Ib:1.0003,
  //     Ic:1.0008,
  //     Result: '合格', 
  //   },
  //   {
  //     id: '3',
  //     updateTime: '2024-10-10 10:30:00', 
  //     deviceName:'被检设备1',
  //     MonitorIdx: 3, 
  //     Ua:1.0003,
  //     Ub:1.0003,
  //     Uc:0.0096,
  //     Ia:1.0003,
  //     Ib:1.0003,
  //     Ic:1.0008,
  //     Result: '合格', 
  //   },
  //   {
  //     id: '4',
  //     updateTime: '2024-10-10 10:30:00', 
  //     deviceName:'被检设备1',
  //     MonitorIdx: 4, 
  //     Ua:1.0003,
  //     Ub:1.0003,
  //     Uc:0.0096,
  //     Ia:1.0003,
  //     Ib:1.0003,
  //     Ic:1.0008,
  //     Result: '合格', 
  //   },
  // ])


  // 监听 tableData 的变化

  </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; /* 所有单元格文字居中 */
}

.table-container {
  max-height: 400px; /* 根据需要调整高度 */
  overflow-y: auto; /* 允许垂直滚动 */
  overflow-x: hidden; /* 隐藏水平滚动条 */
}

/* 确保 el-icon-loading 的动画效果没有被覆盖 */
.loading-box {
  animation: rotate 2s linear infinite;
}

@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}
</style>