<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 './examScoring-data';

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

// 搜索表单配置
const formOptions: VbenFormProps = {
  commonConfig: {
    labelWidth: 80,
    componentProps: {
      allowClear: true,
    },
  },
  schema: queryFormSchema(),
  wrapperClass: 'grid-cols-1 md:grid-cols-2',
};

// 表格配置
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: `考生${index + 1}`,
            corrector: `批改人${index % 10 + 1}`,
            correctStatus: ['待批改', '已批改'][index % 2],
            correctTime: index % 3 === 0 ? '' : `2025-01-${String(index + 1).padStart(2, '0')} 14:${String(index % 60).padStart(2, '0')}`,
          })),
          total: 37,
        };
        return { items: mockData.rows, total: mockData.total };
      },
    },
  },
  rowConfig: {
    keyField: 'id',
  },
  toolbarConfig: {
    custom: true,
    refresh: true,
    zoom: true,
    export: true,
  },
  id: 'examManage-questScoring-examScoring',
};

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

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

// 批改
function handleCorrect(row: any) {
  router.push(`/examManage/questScoring/examCorrect/${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>
          <ElButton
            size="small"
            type="success"
            plain
            @click="handleCorrect(row)"
          >
            批改
          </ElButton>
        </ElSpace>
      </template>
    </BasicTable>
  </Page>
  </div>
</template>

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