<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, DRAINAGE_RECORD_MOCK_DATA, queryFormSchema, getDrainageRecordList } from './drainageRecord-data';

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

// 排水记录表格配置
const drainageRecordGridOptions: VxeGridProps = {
  columns: tableColumns,
  height: '800px',
  proxyConfig: {
    autoLoad: true,
    ajax: {
      query: async () => {
        const data = await getDrainageRecordList({});
        return { items: data.rows, total: data.total };
      },
    },
  },
  rowConfig: { keyField: 'id' },
  pagerConfig: { enabled: true, pageSize: 10, pageSizes: [10, 20, 50, 100] },
  toolbarConfig: {
    custom: true,
    refresh: true,
    zoom: true,
  },
};

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

// 查看按钮点击事件
const handleView = (row: any) => {
  console.log('查看记录:', row);
  // TODO: 添加查看逻辑
};

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

<template>
  <Page :auto-content-height="true">
    <div class="drainage-record-container">
      <!-- 排水记录表格 -->
      <div class="table-container">
        <DrainageRecordTable table-title="排水记录列表">
          <template #toolbar-tools>
            <ElSpace>
              <ElButton 
                @click="handleExport"
                v-access:code="['archive:drainageRecord:export']"
              >
                导出
              </ElButton>
            </ElSpace>
          </template>
          <template #action="{ row }">
            <ElSpace>
              <ElButton 
                type="primary" 
                size="small" 
                @click="handleView(row)"
                v-access:code="['archive:drainageRecord:view']"
              >
                查看
              </ElButton>
            </ElSpace>
          </template>
        </DrainageRecordTable>
      </div>
    </div>
  </Page>
</template>

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