import { PartitionTemplateResult } from '@/api/costfeeitem/CostFeeItemSetModel'
import { isArrayLength } from '@/utils/is'
import { defineStore } from 'pinia'
//定义state类型
export type ZoningState = {
    loadId: string
    feeIdList: string[]
    orderNumber: number,
    feeId: string
}
//定义store
export const zoningStore = defineStore('zoningStore', {
    state: (): ZoningState => {
        return {
            loadId: "",//加载的模版编号
            feeIdList: [],//费用编号
            orderNumber: 1,
            feeId: ""//费用id
        }
    },
    actions: {
        // 添加加载模版的id
        addLoadId(id: string) {
            this.loadId = id
        },
        // 添加整合模版的费用编号
        async addFeeIdList(data: PartitionTemplateResult) {
            data.feeIdList && data.feeIdList.length > 0 ?
                this.feeIdList = [data.feeId, ...data.feeIdList] :
                this.feeIdList = [data.feeId]
            return this.feeIdList
        },
        /**
         * 根据数组长度添加序号
         */
        addOrderNumber(num: number) {
            this.orderNumber = num + 1
        },
    },
    getters: {
        getLoadId(state) {
            return state.loadId;
        },
        getFeeIdList(state) {
            return state.feeIdList;
        },
        getOrderNumber(state) {
            return state.orderNumber;
        },
    }
})