import { defineStore } from 'pinia'
import jeepayStorageWrapper from '@/utils/jeepayStorageWrapper'
import {getCurrentUserInfo} from '@/api/login'
import menuList from '../../components/JeepayUIComponents/JeepayAreaSelect/menuList.json'
import {useRouter} from "vue-router";

const router = useRouter() //这是全部路由
export const useUserStore = defineStore('user', {
    state: () => ({
        userInfo: {
            aqfMenu:['/aqfList','/aqfUserList','/dfList','/taskSettleList'],
            sysUserId: '', // 用户ID
            avatarUrl: '', // 头像
            allMenuRouteTree: [], // 全部动态 router
            entIdList: [] as any, // 用户权限集合
            isAdmin: '', // 是否是超级管理员
            loginUsername: '', // 登录用户名
            state: '', // 用户状态
            sysType: '', // 所属系统
            telphone: '', // 手机号
            sex: '', // 性别
            isHasAgentEnt: false, //是否包含代理商功能
            isHasMemberEnt: false, //是否包含会员功能
            collapsed: false,//是否收起导航栏
        },
        globalLoading: false, //全局加载
    }),

    actions: {
        putToken( token:string ) {
            jeepayStorageWrapper.setToken(token, true)
        },

        refUserInfo(){ // 刷新用户信息
            const that = this

            return getCurrentUserInfo().then(( bizData: any) => {
                const allMenuRouteTree = []
                this.userInfo = Object.assign({}, bizData)
                // console.log(this.userInfo)
            })
            
        },

        logout: () => {
            jeepayStorageWrapper.cleanToken()
            window.location.reload()
        },
        setGlobalLoading(val){
            this.globalLoading = val
        },
        getPathName(){
           const pathname =  window.location.pathname;
           if(pathname == 'undefined' || pathname == undefined){
               return '';
           }else{
               return pathname;
           }

        }
    }

})
