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

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

import { useRouter } from 'vue-router';

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

import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getBusinessPlanList } from '#/api/archive/operationsManagement/operationsManagement';

import { columns, querySchema, mapFormToApi, mapApiToView } from './config-data';

const router = useRouter();
const formOptions: VbenFormProps = {
  commonConfig: {
    labelWidth: 80,
    componentProps: {
      allowClear: true,
    },
  },
  schema: querySchema(),
  wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
};
// 列表中显示配置
const gridOptions: VxeGridProps = {
  checkboxConfig: {
    // 高亮
    highlight: true,
    // 翻页时保留选中状态
    reserve: true,
    // 点击行选中
    trigger: 'default',
  },
  columns,
  size: 'medium',
  height: 'auto',
  proxyConfig: {
    ajax: {
      query: async ({ page }, formValues = {}) => {
        const apiParams = mapFormToApi(formValues, page);
        const resp = await getBusinessPlanList(apiParams);
        const mappedData = mapApiToView(resp?.rows || []);
        return { items: mappedData, total: resp?.total || 0 };
      },
    },
  },
  rowConfig: {
    keyField: 'id',
  },
  toolbarConfig: {
    custom: true,
    refresh: true,
    zoom: true,
  },
  id: 'business-plan-detailed-record',
};
const [BasicTable, BasicTableApi] = useVbenVxeGrid({
  formOptions,
  gridOptions,
});
const handleTaskClick = (taskId: number) => {
  router.push(`/schedule/detail/${taskId}`);
};
</script>
<template>
  <Page :auto-content-height="true">
    <BasicTable>
      <template #action="{ row }">
        <el-button
          size="small"
          type="primary"
          plain
          @click="() => handleTaskClick(row.taskId)"
        >
          查看
        </el-button>
      </template>
    </BasicTable>
  </Page>
</template>
<style scoped lang="scss">
:deep(.el-tooltip__trigger:focus) {
  outline: none;
}
</style>
