<script lang="ts" setup>
// @ts-ignore
import { ElCard, ElDescriptions, ElDescriptionsItem } from 'element-plus';

// @ts-ignore
import { useVbenVxeGrid } from '#/adapter/vxe-table';

// 定义组件的Props接口
interface TankWaterProps {
  taskDetail: any;
}

// 接收父组件传递的任务详情数据
const props = defineProps<TankWaterProps>();

// 表格列配置
const tableColumns: any = [
  {
    field: 'tankNumber',
    title: '罐号',
    minWidth: 100,
    fixed: 'left',
    editRender: { name: 'input' },
  },
  {
    field: 'oilProduct',
    title: '油品名称',
    minWidth: 120,
  },
  {
    field: 'levelGauge',
    title: '液位仪',
    minWidth: 200,
    children: [
      {
        field: 'levelGaugeOilHeightH1',
        title: '油高h1(mm)',
        minWidth: 150,
      },
      {
        field: 'levelGaugeWaterHeight',
        title: '水高(mm)',
        minWidth: 150,
      },
    ],
  },
  {
    field: 'manualTank',
    title: '手工量缸',
    minWidth: 250,
    children: [
      {
        field: 'manualTankOilHeightH2',
        title: '油高h2(mm)',
        minWidth: 150,

        editRender: {
          name: 'input',
          immediate: true,
        },
      },
      {
        field: 'manualTankWaterHeight',
        title: '水高(mm)',
        minWidth: 150,
      },
    ],
  },
  {
    field: 'heightDifference',
    title: '高度差(mm)(h2-h1)',
    minWidth: 250,
  },
  {
    field: 'tankTemperature',
    title: '油罐温度（℃）',
    minWidth: 100,
  },
];

// 初始化表格配置
const gridOptions: any = {
  size: 'medium',
  toolbarConfig: {
    custom: false,
    refresh: false,
    zoom: false,
  },
  pagerConfig: {
    enabled: false,
  },
  proxyConfig: {
    ajax: {
      query: async () => {
        return {
          items: props.taskDetail?.formTankWaterRecords || [],
        };
      },
    },
  },
  columns: tableColumns,
};

// 使用BasicTable组件
const [BasicTable] = useVbenVxeGrid({
  gridOptions,
});
</script>

<template>
  <ElCard>
    <template #header>
      <div class="flex items-center gap-4">
        <div style="width: 4px; height: 12px; background-color: #215acd"></div>
        <span
          class="text-lg font-bold text-gray-800"
          style="font-size: 14px; font-weight: 600"
        >
          量缸试水详情
        </span>
      </div>
    </template>

    <div class="task-info">
      <ElDescriptions :column="1" class="mb-6">
        <ElDescriptionsItem label="开始测量时间:">
          {{ taskDetail?.measurementStartTime || '-' }}
        </ElDescriptionsItem>
        <ElDescriptionsItem label="异常记录:">
          {{ taskDetail?.abnormalDescription || '-' }}
        </ElDescriptionsItem>
      </ElDescriptions>

      <div class="section-title">
        <div class="section-bar"></div>
        <div class="section-text">测量信息</div>
      </div>

      <BasicTable table-title="" class="mt-4 w-full" />
    </div>
  </ElCard>
</template>

<style scoped lang="scss">
.task-info {
  .section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 20px 0 12px 0;

    .section-bar {
      width: 4px;
      height: 12px;
      background-color: #215acd;
    }

    .section-text {
      font-size: 14px;
      font-weight: 600;
      color: var(--text-color-primary);
    }
  }

  :deep(.el-descriptions) {
    margin-bottom: 0 !important;
  }

  :deep(.el-descriptions__label) {
    font-size: 14px;
    font-weight: 400;
    color: var(--text-color-secondary);
  }

  :deep(.el-descriptions__content) {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-color-primary);
  }

  :deep(.el-descriptions__table) {
    background: transparent !important;
  }

  :deep(.el-table) {
    margin-top: 12px;
  }

  :deep(.el-table__header-wrapper) {
    background-color: #f5f7fa;
  }

  :deep(.el-table th) {
    font-weight: 600;
    color: var(--text-color-primary);
  }
}
</style>
