<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 { columns, mockData, querySchema } from './config-data';

const router = useRouter();
const route = useRoute();
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',
  handleSubmit: (values: any) => {
    console.log('👉 表单提交数据', values);
  },
  handleReset: async (values: any) => {
    const res = await values;
    console.log('👉 重置后数据', res);
  },
  // 日期选择格式化
  // fieldMappingTime: [
  //   [
  //     'createTime',
  //     ['params[beginTime]', 'params[endTime]'],
  //     ['YYYY-MM-DD 00:00:00', 'YYYY-MM-DD 23:59:59'],
  //   ],
  // ],
};
// 列表中显示配置
const gridOptions: VxeGridProps = {
  checkboxConfig: {
    // 高亮
    highlight: true,
    // 翻页时保留选中状态
    reserve: true,
    // 点击行选中
    trigger: 'default',
    checkMethod: ({ row }) => row?.roleId !== 1,
  },
  columns,
  size: 'medium',
  height: 'auto',
  data: mockData,
  // proxyConfig: {
  //   ajax: {
  //     query: async ({ page }, formValues = {}) => {
  //       const resp = await getRoleList({
  //         ...formValues,
  //         pageNum: page.currentPage,
  //         pageSize: page.pageSize,
  //       });
  //       return { items: resp.rows, total: resp.total };
  //     },
  //   },
  // },
  rowConfig: {
    keyField: 'roleId',
  },
  toolbarConfig: {
    custom: true,
    refresh: true,
    zoom: true,
  },
  id: 'system-role-index',
};
const [BasicTable] = 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>
        <el-button size="small" type="primary" plain>打印</el-button>
      </template>
    </BasicTable>
  </Page>
</template>
<style scoped lang="scss">
:deep(.el-tooltip__trigger:focus) {
  outline: none;
}
</style>
