<script lang="ts" setup>
// 导入部分
import type { VbenFormProps } from '@vben/common-ui';
import type { VxeGridProps } from '#/adapter/vxe-table';
import { Page } from '@vben/common-ui';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { ElButton, ElSpace } from 'element-plus';
import { tableColumns, OIL_GUN_TEMENT_MOCK_DATA, queryFormSchema } from './oilGunTement-data';
import { useRouter } from 'vue-router';
// 路由实例
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-4',
};

// 油枪自检损益表表格配置
const oilGunTementGridOptions: VxeGridProps = {
  columns: tableColumns,
  height: '800px',
  proxyConfig: {
    autoLoad: true,
    ajax: {
      query: async () => ({ items: OIL_GUN_TEMENT_MOCK_DATA, total: OIL_GUN_TEMENT_MOCK_DATA.length }),
    },
  },
  rowConfig: { keyField: 'id' },
  pagerConfig: { enabled: true, pageSize: 100, pageSizes: [10, 20, 50, 100] },
};

// 创建表格实例
const [OilGunTementTable] = useVbenVxeGrid({ formOptions, gridOptions: oilGunTementGridOptions });

// 查询按钮点击事件
const handleQuery = () => {
  console.log('查询数据');
  // TODO: 添加查询逻辑
};

// 重置按钮点击事件
const handleReset = () => {
  console.log('重置表单');
  // TODO: 添加重置逻辑
};

// 查看按钮点击事件
const handleView = (row: any) => {
  console.log('查看数据:', row);
  router.push(`/schedule/detail/${row.id}`);
  // TODO: 添加查看逻辑
};

// 导出按钮点击事件
const handleExport = (row: any) => {
  console.log('导出数据:', row);
  // TODO: 添加导出逻辑
};

// 损益报表按钮点击事件
const handleProfitLossReport = (row: any) => {
  console.log('生成损益报表:', row);
  // TODO: 添加损益报表逻辑
};
</script>

<template>
  <Page :auto-content-height="true">
    <div class="oil-gun-tement-container">
      <!-- 油枪自检损益表表格 -->
      <OilGunTementTable table-title="油枪自检损益表列表">
        <template #toolbar-tools>
          <ElSpace>
            <ElButton 
              @click="handleExport"
              v-access:code="['system:oilGunTement:export']"
            >
              导出
            </ElButton>
          </ElSpace>
        </template>
        <template #action="{ row }">
          <ElSpace>
            <ElButton size="small" @click="handleView(row)">查看</ElButton>
            <ElButton size="small" @click="handleExport(row)">导出</ElButton>
            <ElButton size="small" type="primary" @click="handleProfitLossReport(row)">损益报表</ElButton>
          </ElSpace>
        </template>
      </OilGunTementTable>
    </div>
  </Page>
</template>

<style scoped lang="scss">
.oil-gun-tement-container {
  min-height: calc(100vh - 120px);
  padding: 16px;
  background-color: #fff;
}
</style>
