import type { ListIitem } from '@/api/base/BaseDataModel';
import { api_GetCustomerList, api_GetSalesmanUserList } from '@/api/newsInfo/newsInfo';
import { useReturnData } from '@/utils/useReturnData';
import { defineStore } from 'pinia'
//定义state类型
export type CurrencyState<T = ListIitem> = {
    salesmanUsesList: T[]//业务人员
    customerList: T[]//客户人员
}
const { resData } = useReturnData()
//定义` 人员 `store
export const usePersonnel = defineStore('list_personnel', {
    state: (): CurrencyState => {
        return {
            salesmanUsesList: [],
            customerList: []
        }
    },
    actions: {
        /**
         * 业务人员
         */
        async addGetSalesmanUserList() {
            // 判断如果有数据就不请求接口
            if (this.salesmanUsesList.length > 0) return;
            const res = await api_GetSalesmanUserList()
            this.salesmanUsesList = resData(res)
        },
        /**
         * 客户人员
         */
        async addGetCustomerList() {
            // 判断如果有数据就不请求接口
            if (this.customerList.length > 0) return;
            const res = await api_GetCustomerList()
            this.customerList = resData(res)
        }
    },
    getters: {
        getSalesmanUsesList(state) {
            return state.salesmanUsesList;
        },
        getCustomerList(state) {
            return state.customerList;
        }
    }
})