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

import { ElCard } from 'element-plus';

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

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

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

// 计算属性，获取添加剂库存数据
const additiveInventoryData = computed(() => {
  return props.taskDetail || [];
});

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

// 表格列配置
const tableColumns: any = [
  {
    field: 'additiveType',
    title: '添加剂类型',
    // width: 120,
    fixed: 'left',
    formatter: ({ row }) => {
      return `${row.additiveType}-${row.additiveModel || ''}`;
    },
  },
  {
    field: 'registerDate',
    title: '登记日期',
    width: 180,
    formatter: ({ row }) => {
      return row.registerDate || '-';
    },
  },
  {
    field: 'initialInventory',
    title: '期初库存',
    // width: 120,
    formatter: ({ row }) => {
      return formatNumber(row.initialInventory);
    },
  },
  {
    field: 'purchase',
    title: '进货',
    // width: 100,
    formatter: ({ row }) => {
      return formatNumber(row.purchase);
    },
  },
  {
    field: 'useAmount',
    title: '使用',
    // width: 100,
    formatter: ({ row }) => {
      return formatNumber(row.useAmount);
    },
  },
  {
    field: 'expectedInventory',
    title: '期末应存',
    // width: 120,
    formatter: ({ row }) => {
      return formatNumber(row.expectedInventory);
    },
  },
  {
    field: 'actualInventory',
    title: '期末实存',
    // width: 120,
    formatter: ({ row }) => {
      return formatNumber(row.actualInventory);
    },
  },
];

// 初始化表格配置
const gridOptions: any = {
  size: 'medium',
  toolbarConfig: {
    custom: false,
    refresh: false,
    zoom: false,
  },
  pagerConfig: {
    enabled: false,
  },
  proxyConfig: {
    ajax: {
      query: async () => {
        return {
          items: props.taskDetail || [],
        };
      },
    },
  },
  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="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>
