<template>
   <div class="position-stat">
     <!-- 搜索 -->
       <PositionStatSearch :search-form="searchForm" :search-options="searchOptions" @search="handleSearch"
            @reset="handleReset">
            <template #button="{ form }">
                <el-button type="primary" @click="handleExport()">
                    导出
                </el-button>
            </template>
        </PositionStatSearch>
    <!-- 表格 -->
    <PositionStatTable :table-data="tableTree" :columns="tableColumnsOptions" row-key="id" />

    <!-- 分页 -->
     <PositionStatPagination :current-page="currentPage" :page-size="pageSize" :total="total" @change="handleChange" />
   </div>
</template>

<script setup lang="ts">
// 组件
import PositionStatSearch from '@/components/common/Search.vue'
import PositionStatTable from '@/components/common/Table.vue'
import PositionStatPagination from '@/components/common/Pagination.vue'
// 配置以及表单验证
import { search, tableColumns } from './options'

// 接口


// 导出表格
import {exportToExcel} from '@/utils/exportToExcel'
/**
 * @description: 定义搜索数据
 */
const searchOptions = ref(search)
const searchForm = ref({
    orderNo: '',
    tradeType: '',
    account: '',
    startTime: '',
    endTime: '',
})
/**
 * @description: 定义表格数据
 */
const tableTree = ref([])
const tableColumnsOptions = ref(tableColumns)
/**
 * @description: 定义分页数据
 */
const currentPage = ref(1)
const pageSize = ref(10)
const total = ref(0)
/**
 * @description: 定义公共数据处理方法
 */
/**
 * @description: 定义公共请求数据方法
 */
/**
 * @description: 页面加载完成需要请求的数据
 */
/**
 * @description: 定义搜索方法
 */
const handleSearch = async () => {
   console.log("搜索");
   
}
const handleReset = () => {
   console.log('重置搜索')
}
const handleExport = () => {
    exportToExcel({
        tableData: tableTree.value,
        columns: tableColumnsOptions.value,
        title: '导出资金明细',
        defaultFileNamePrefix: '资金明细',
    })
}
/**
 * @description: 定义分页方法
 */
const handleChange = (page: {currentPage: number, size: number})  => {
    currentPage.value = page.currentPage
}
</script>
