import { CountryQueryParam } from "@/api/country/CountryModle";
import { reactive,onMounted } from "vue";
import {getCountryListApi} from "@/api/country/country"

export default function userCountryTable(){

    //定义表格数据
    const countryList = reactive({
         list:[]
    });
        //定义列表查询的参数
        const listParm = reactive<CountryQueryParam>({
            twCode:'',
            cnName: '',
            enName: '',
            pageNum:1,
            pageSize:10,
            name:'',
            total:0
        })

         //获取国家信息列表
    const getCountryList = async() =>{
        let res = await getCountryListApi(listParm)
        if(res && res.code == 200){           
            countryList.list = res.data.records
            listParm.total = res.data.total;
        }
    }
    //页容量改变时触发
    const sizeChange = (size:number) =>{
        listParm.pageSize = size;
        getCountryList();
    }
    //页数改变时触发
    const currentChange = (page:number) =>{
        listParm.pageNum = page;
        getCountryList();
    }
    //搜索
    const searchBtn = () =>{
        getCountryList();
    }
    //重置
    const resetBtn = () =>{
        listParm.twCode='';
        listParm.cnName= '';
        listParm.enName= '';
        getCountryList();
    }
    onMounted(() =>{
        getCountryList();
    })

    return{
        countryList,
        listParm,
        getCountryList,
        sizeChange,
        currentChange,
        searchBtn,
        resetBtn
    }
};