import { getCurrencyApi } from '@/api/base/basedata';
import { ListIitem } from '@/api/base/BaseDataModel';
import { useReturnData } from '@/utils/useReturnData';
import { defineStore } from 'pinia'
//定义state类型
export type CurrencyState = {
    currencyList: Array<ListIitem>
    total: number
}
const { resData } = useReturnData()
//定义` 币种 `store
export const useCurrencyStore = defineStore('currency', {
    state: (): CurrencyState => {
        return {
            currencyList: [],
            total: 0
        }
    },
    actions: {
        async addCurrencyList() {
            // 判断如果有数据就不请求接口
            if (this.currencyList.length > 0) return;
            const res = await getCurrencyApi()
            this.currencyList = resData(res)
        }
    },
    getters: {
        getCurrencyList(state) {
            return state.currencyList;
        }
    }
})