import { CustomerRateQueryParam } from "@/api/customerrate/CustomerRateModel";
import { ref, reactive, computed, onMounted } from "vue";
import { getCustomerRateListApi } from "@/api/customerRate/CustomerRate"
import { ListIitem } from "@/api/base/BaseDataModel";
import { useQueryList } from "@/hooks/useQueryList";

export default function userCustomerRateTable(store) {

    //定义表格数据
    const customerRateList = reactive({
        list: [],
        loading: false,//加载
    });
    //定义列表查询的参数
    const listParm = reactive<CustomerRateQueryParam>({
        titleName: '',
        currencyCode: '',
        pageNum: 1,
        pageSize: 10,
        total: 0
    })
    // 币种列表
    const currencyList = computed((): ListIitem[] => store.getCurrencyList)

    //获取汇率信息列表
    const getCustomerRateList = async () => {
        customerRateList.loading = true
        let res = await getCustomerRateListApi(listParams)
        if (res && res.code == 200) {
            customerRateList.list = res.data.records
            listParm.total = res.data.total;
        }
        customerRateList.loading = false
    }

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

    onMounted(() => {
        store.addCurrencyList()
    })

    return {
        customerRateList,
        listParm,
        currencyList,
        getCustomerRateList,
        sizeChange,
        currentChange,
        searchBtn,
        resetBtn
    }
};