import { CurrencyQueryParam } from "@/api/currency/CurrencyModle";
import { reactive, onMounted } from "vue";
import { getCurrencyListApi } from "@/api/currency/currency"
import { useQueryList } from "@/hooks/useQueryList";

export default function userCurrencyTable() {

    //定义表格数据
    const currencyList = reactive({
        list: [],
        loading: false//加载
    });
    //定义列表查询的参数
    const listParm = reactive<CurrencyQueryParam>({
        code: '',
        description: '',
        pageNum: 1,
        pageSize: 10,
        total: 0
    })

    //获取币种信息列表
    const getCurrencyList = async () => {
        currencyList.loading = true
        let res = await getCurrencyListApi(listParams)
        if (res && res.code == 200) {
            currencyList.list = res.data.records
            listParm.total = res.data.total;
        }
        currencyList.loading = false
    }

    // 重置
    const resetParams = () => {
        listParm.code = '';
        listParm.description = '';
    }
    // 初始化列表、分页数据
    const { sizeChange, currentChange, searchBtn, resetBtn, listParams } = useQueryList<CurrencyQueryParam>(getCurrencyList, resetParams, listParm)

    return {
        currencyList,
        listParm,
        getCurrencyList,
        sizeChange,
        currentChange,
        searchBtn,
        resetBtn
    }
};