<script lang="ts" setup>
// @ts-ignore
import { computed, ref } from 'vue';

import { ElCard, ElDescriptions, ElDescriptionsItem } from 'element-plus';

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

// 定义组件的Props接口
interface SalesSurveyProps {
  taskList: any;
}

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

// 计算属性，获取销售调研数据
const salesSurveyData = computed(() => {
  return props.taskList || [];
});

// 格式化日期时间

// 格式化数值，保留两位小数
const formatNumber = (value: number | string) => {
  if (value === undefined || value === null || value === '') return '-';
  const num = Number(value);
  if (isNaN(num)) return '-';
  return num.toFixed(2);
};

// 表格列配置
const tableColumns: any = [
  {
    field: 'competitorName',
    title: '油站',
    // width: 100,
    fixed: 'left',
    formatter: ({ row }) => {
      return row.competitorName || row.stationName || '-';
    },
  },
  {
    field: 'gasCar',
    title: '汽油车',
    width: 180,
    children: [
      {
        field: 'gasRoadFlow',
        title: '路面车流',
        width: 90,
      },
      {
        field: 'gasInFlow',
        title: '进站车流',
        width: 90,
      },
    ],
  },
  {
    field: 'dieselCar',
    title: '柴油车',
    width: 180,
    children: [
      {
        field: 'dieselRoadFlow',
        title: '路面车流',
        width: 90,
      },
      {
        field: 'dieselInFlow',
        title: '进站车流',
        width: 90,
      },
    ],
  },
  {
    field: 'motorcycle',
    title: '摩托车',
    width: 180,
    children: [
      {
        field: 'motorcycleRoadFlow',
        title: '路面车流',
        width: 90,
      },
      {
        field: 'motorcycleInFlow',
        title: '进站车流',
        width: 90,
      },
    ],
  },
];

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

// 表格数据
const tableDatas = ref<any>([]);
// 使用BasicTable组件
const [BasicTable, basicTableApi] = 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">
      <!-- 基本信息 -->
      <div class="section-title">
        <div class="section-bar"></div>
        <span class="section-text">基本信息</span>
      </div>
      <ElDescriptions :column="4" class="mb-6">
        <ElDescriptionsItem label="调查开始时间:">
          {{ taskList[0].surveyStartTime || '-' }}
        </ElDescriptionsItem>
        <ElDescriptionsItem label="调查结束时间:">
          {{ taskList[0].surveyEndTime || '-' }}
        </ElDescriptionsItem>
      </ElDescriptions>

      <!-- 销量调查表格 -->
      <div class="section-title">
        <div class="section-bar"></div>
        <span class="section-text">销量调查数据</span>
      </div>
      <div class="mb-6">
        <BasicTable table-title="" class="w-full" />
      </div>
    </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;
  }
}
</style>
