import { bookingStateListApi, ladingBillDateTypeListApi, ladingBillStateTypeListApi, operateStateListApi, payStateListApi, receivableStateListApi } from '@/api/base/basedata';
import type { ListIitem } from '@/api/base/BaseDataModel';
import { useReturnData } from '@/utils/useReturnData';
import { defineStore } from 'pinia'
//定义state类型
export type CurrencyState<T = ListIitem> = {
    bookingStateList: T[]//订舱状态
    operateStateList: T[]//提单操作状态
    receivableStateList: T[]//应收状态
    payStateList: T[]//应付状态
    ladingBillDateTypeList: T[]//提单查询时间类型
    ladingBillStateTypeList: T[]//提单状态类型
}
const { resData } = useReturnData()
//定义` 状态 `store
export const useStateType = defineStore('list_stateType', {
    state: (): CurrencyState => {
        return {
            bookingStateList: [],
            operateStateList: [],
            receivableStateList: [],
            payStateList: [],
            ladingBillDateTypeList: [],
            ladingBillStateTypeList: []
        }
    },
    actions: {
        /**
         * 订舱状态
         */
        async addBookingStateList() {
            // 判断如果有数据就不请求接口
            if (this.bookingStateList.length > 0) return;
            const res = await bookingStateListApi()
            this.bookingStateList = resData(res)
        },
        /**
         * 提单操作状态
         */
        async addOperateStateList() {
            if (this.operateStateList.length > 0) return;
            const res = await operateStateListApi()
            this.operateStateList = resData(res)
        },
        /**
         * 应收状态
         */
        async addReceivableStateList() {
            if (this.receivableStateList.length > 0) return;
            const res = await receivableStateListApi()
            this.receivableStateList = resData(res)
        },
        /**
         * 应付状态
         */
        async addPayStateList() {
            if (this.payStateList.length > 0) return;
            const res = await payStateListApi()
            this.payStateList = resData(res)
        },
        /**
         * 提单查询时间类型
         */
        async addLadingBillDateTypeList() {
            if (this.ladingBillDateTypeList.length > 0) return;
            const res = await ladingBillDateTypeListApi()
            this.ladingBillDateTypeList = resData(res)
        },
        /**
        * 提单状态类型
        */
        async addLadingBillStateTypeList() {
            if (this.ladingBillStateTypeList.length > 0) return;
            const res = await ladingBillStateTypeListApi()
            this.ladingBillStateTypeList = resData(res)
        },
    },
    getters: {
        getBookingStateList(state) {
            return state.bookingStateList;
        },
        getOperateStateList(state) {
            return state.operateStateList;
        },
        getReceivableStateList(state) {
            return state.receivableStateList;
        },
        getPayStateList(state) {
            return state.payStateList;
        },
        getLadingBillDateTypeList(state) {
            return state.ladingBillDateTypeList
        },
        getLadingBillStateTypeList(state) {
            return state.ladingBillStateTypeList
        }
    }
})