import { approvalTypeListApi, costFeeQueryDepartmentListApi, customerFeeSetNameListApi, feeApprovalStatusListApi, getFeeItemCategoryListDataApi, notifyUserTypeListApi, sysUserListApi } from '@/api/base/basedata';
import { ListIitem } from '@/api/base/BaseDataModel';
import { useReturnData } from '@/utils/useReturnData';
import { defineStore } from 'pinia'
//定义state类型
export type FeesetState<T = ListIitem> = {
    /**
     * 费项类型
     */
    feeItemCategoryList: T[]
    /**
     * 成本费用查询部门
     */
    costFeeQueryDepartmentList: T[]
    /**
     * 费用名称
     */
    customerFeeSetNameList: T[]
    /**
     * 通知人员类型
     */
    notifyUserTypeList: T[]
    /**
     * 用户人员列表
     */
    sysUserList: T[]
    /**
     * 费用审批状态
     */
    feeApprovalStatusList: T[]
    /**
     * 审批类型
     */
    approvalTypeList: T[]
}
const { resData } = useReturnData()
//定义` 费用设置列表 `store
export const useFeesetList = defineStore('list_feeset', {
    state: (): FeesetState => {
        return {
            feeItemCategoryList: [],
            costFeeQueryDepartmentList: [],
            customerFeeSetNameList: [],
            notifyUserTypeList: [],
            sysUserList: [],
            feeApprovalStatusList: [],
            approvalTypeList: []
        }
    },
    actions: {
        /**
         * 费项类型
         */
        async addFeeItemCategoryList() {
            // 判断如果有数据就不请求接口
            if (this.feeItemCategoryList.length > 0) return;
            const res = await getFeeItemCategoryListDataApi()
            this.feeItemCategoryList = resData(res)
        },
        /**
         * 成本费用查询部门
         */
        async addCostFeeQueryDepartmentList() {
            if (this.costFeeQueryDepartmentList.length > 0) return;
            const res = await costFeeQueryDepartmentListApi()
            this.costFeeQueryDepartmentList = resData(res)
        },
        /**
         * 费用名称
         */
        async addCustomerFeeSetNameList() {
            if (this.customerFeeSetNameList.length > 0) return;
            const res = await customerFeeSetNameListApi()
            this.customerFeeSetNameList = resData(res)
        },
        /**
         * 通知人员类型
         */
        async addNotifyUserTypeList() {
            if (this.notifyUserTypeList.length > 0) return;
            const res = await notifyUserTypeListApi()
            this.notifyUserTypeList = resData(res)
        },
        /**
         * 用户人员列表
         */
        async addSysUserList() {
            if (this.sysUserList.length > 0) return;
            const res = await sysUserListApi()
            this.sysUserList = resData(res)
        },
        /**
         * 费用审批状态接口
         */
        async addFeeApprovalStatusList() {
            if (this.feeApprovalStatusList.length > 0) return;
            const res = await feeApprovalStatusListApi()
            this.feeApprovalStatusList = resData(res)
        },
        /**
         * 审批类型
         */
        async addApprovalTypeList() {
            if (this.approvalTypeList.length > 0) return;
            const res = await approvalTypeListApi()
            this.approvalTypeList = resData(res)
        },
    },
    getters: {
        getFeeItemCategoryList(state) {
            return state.feeItemCategoryList;
        },
        getCostFeeQueryDepartmentList(state) {
            return state.costFeeQueryDepartmentList;
        },
        getCustomerFeeSetNameList(state) {
            return state.customerFeeSetNameList;
        },
        getNotifyUserTypeList(state) {
            return state.notifyUserTypeList;
        },
        getSysUserList(state) {
            return state.sysUserList;
        },
        getFeeApprovalStatusList(state) {
            return state.feeApprovalStatusList
        },
        getApprovalTypeList(state) {
            return state.approvalTypeList
        }
    }
})