<script setup lang="ts">
import type { VbenFormProps } from '@vben/common-ui';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { ref } from 'vue';
import { useRouter } from 'vue-router';

import { Page } from '@vben/common-ui';

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

// 模拟API，后续需要替换为实际API
import { queryFormSchema, tableColumns } from './questScoring-data';

// 路由实例
const router = useRouter();

// 搜索表单配置
const formOptions: VbenFormProps = {
  commonConfig: {
    labelWidth: 80,
    componentProps: {
      allowClear: true,
    },
  },
  schema: queryFormSchema(),
  wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3',
  fieldMappingTime: [
    [
      'examTime',
      ['params[beginExamTime]', 'params[endExamTime]'],
      ['YYYY-MM-DD', 'YYYY-MM-DD'],
    ],
  ],
};

// 表格配置
const gridOptions: VxeGridProps = {
  columns: tableColumns,
  size: 'medium',
  height: 'auto',
  proxyConfig: {
    ajax: {
      query: async ({ page }, formValues = {}) => {
        // 模拟API调用，后续替换为实际API
        const mockData = {
          rows: Array.from({ length: 37 }, (_, index) => ({
            id: index + 1,
            examName: '考试 1',
            examStartTime: '2025-01-15',
            examEndTime: '2025-01-17',
            totalScore: 120,
            passScore: 120,
            examCount: 56,
            unmarkedCount: 20,
          })),
          total: 37,
        };
        return { items: mockData.rows, total: mockData.total };
      },
    },
  },
  rowConfig: {
    keyField: 'id',
  },
  toolbarConfig: {
    custom: true,
    refresh: true,
    zoom: true,
    export: true,
  },
  id: 'examManage-questScoring-index',
};

// 初始化表格
const [BasicTable, basicTableApi] = useVbenVxeGrid({
  formOptions,
  gridOptions,
});

// 查看详情
function handleView(row: any) {
  router.push(`/examManage/questScoring/examScoring/${row.id}`);
}
</script>

<template>
  <div>
  <Page :auto-content-height="true">
    <BasicTable table-title="总部检查">
      <template #action="{ row }">
        <ElSpace>
          <ElButton
            size="small"
            type="primary"
            plain
            @click="handleView(row)"
          >
            查看
          </ElButton>
        </ElSpace>
      </template>
    </BasicTable>
  </Page>
  </div>
</template>

<style scoped lang="scss">
:deep(.el-tooltip__trigger:focus) {
  outline: none;
}
</style>

