<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, WATER_TEST_RECORD_MOCK_DATA, queryFormSchema } from './waterTestRecord-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 waterTestRecordGridOptions: VxeGridProps = {
  columns: tableColumns,
  height: '800px',
  proxyConfig: {
    autoLoad: true,
    ajax: {
      query: async () => ({ items: WATER_TEST_RECORD_MOCK_DATA, total: WATER_TEST_RECORD_MOCK_DATA.length }),
    },
  },
  rowConfig: { keyField: 'id' },
  pagerConfig: { enabled: true, pageSize: 100, pageSizes: [10, 20, 50, 100] },
};

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

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

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

<template>
  <Page :auto-content-height="true">
    <div class="water-test-record-container">
      <!-- 量缸试水记录表格 -->
      <div class="table-container">
        <WaterTestRecordTable table-title="量缸试水记录列表">
          <template #toolbar-tools>
            <ElSpace>
              <ElButton 
                @click="handleExport"
              >
                导出
              </ElButton>
            </ElSpace>
          </template>
          <template #action="{ row }">
            <ElSpace>
              <ElButton type="primary" @click="handleView(row)">
                查看
              </ElButton>
            </ElSpace>
          </template>
        </WaterTestRecordTable>
      </div>
    </div>
  </Page>
</template>

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