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

export default function userCurrencyTable(){

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

         //获取币种信息列表
    const getCurrencyList = async() =>{
        let res = await getCurrencyListApi(listParm)
        if(res && res.code == 200){       
            currencyList.list = res.data.records
            listParm.total = res.data.total;
        }
    }
    //页容量改变时触发
    const sizeChange = (size:number) =>{
        listParm.pageSize = size;
        getCurrencyList();
    }
    //页数改变时触发
    const currentChange = (page:number) =>{
        listParm.pageNum = page;
        getCurrencyList();
    }
    //搜索
    const searchBtn = () =>{
        getCurrencyList();
    }
    //重置
    const resetBtn = () =>{
        listParm.code= ''; 
        listParm.description ='';
        getCurrencyList();
    }
    onMounted(() =>{
        getCurrencyList();
    })

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