import {
    UserGet,
    RoleGetRoleForEdit
} from '@/api/api'
const userInfo = {
    state: {
        Info: {},//用户信息
        Roles: [],//用户角色
    },
    getters: {},
    mutations: {
        setInfo(state, val) {
            //console.log(val, '用户val')
            state.Info = val;
        },
        setRole(state, val) {
            state.Roles = val;
        },
    },
    actions: {
        UserGet(context, params = false) {
            if (!params && context.state.Info.id) { return; }
            let userID = localStorage.getItem("userId") || '';
            if (!userID) { return; }
            let data = {
                id: userID
            }
            UserGet(data).then(res => {
                //console.log(res, '用户详细信息')
                context.commit('setInfo', res)
            })
        },
        RoleGetRoleForEdit(context, params = false) {
            //console.log('拉角色')
            if (!params && context.state.Roles.length > 0) { return; }
            let userID = localStorage.getItem("userId") || '';
            if (!userID) { return; }
            let data = {
                id: userID
            }
            RoleGetRoleForEdit(data).then(res => {
                //console.log(res, '用户角色信息')
                context.commit('setRole', res.permissions)
            })
        }
    },
}
export default userInfo