
import { payableIdListApi, receivableIdListApi } from '@/api/base/basedata';
import type { ListIitem } from '@/api/base/BaseDataModel';
import { useReturnData } from '@/utils/useReturnData';
import { defineStore } from 'pinia'
//定义state类型
type TemplateState<T = ListIitem> = {
    receivableIdList: T[],
    payableIdList: T[],
}
const { resData } = useReturnData()
//定义` 模版列表 `store
export const useTemplateStore = defineStore('templateList', {
    state: (): TemplateState => {
        return {
            receivableIdList: [],
            payableIdList: []
        }
    },
    actions: {
        /**
         * 应收模板名称列表
         * @returns 
         */
        async addReceivableIdList() {
            // 判断如果有数据就不请求接口
            if (this.receivableIdList.length > 0) return;
            const res = await receivableIdListApi()
            this.receivableIdList = resData(res)
        },
        /**
         * 应付模板名称列表
         * @returns 
         */
        async addPayableIdList() {
            if (this.payableIdList.length > 0) return;
            const res = await payableIdListApi()
            this.payableIdList = resData(res)
        }
    },
    getters: {
        getReceivableIdList(state) {
            return state.receivableIdList;
        },
        getPayableIdList(state) {
            return state.payableIdList;
        },
    }
})