import { CountryQueryParam } from "@/api/country/CountryModle";
import { reactive } from "vue";
import { getCountryListApi } from "@/api/country/country"
import { useQueryList } from "@/hooks/useQueryList";

export default function userCountryTable() {

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

    //获取国家/地区信息列表
    const getCountryList = async () => {
        countryList.loading = true
        let res = await getCountryListApi(listParams)
        if (res && res.code == 200) {
            countryList.list = res.data.records
            listParm.total = res.data.total;
        }
        countryList.loading = false
    }

    // 重置
    const resetParams = () => {
        listParm.twCode = '';
        listParm.cnName = '';
        listParm.enName = '';
    }
    // 初始化列表、分页数据
    const { sizeChange, currentChange, searchBtn, resetBtn, listParams } = useQueryList<CountryQueryParam>(getCountryList, resetParams, listParm)

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