import { axios } from './axios';
import store from '../store/index.js';

// 获取用户信息
export const getUserInfo = async function(userId) {
	const result = new Promise((resolve, reject) => {
		axios({
			url: '/user/user/detail',
			method: 'get',
			params: {
				userId: userId || store.state.userId
			}
		}).then(res => {
			store.commit('changeUserInfo', res.data);
			store.commit('changeUserId', res.data.userId);
			uni.setStorageSync('userInfo', res.data);
			uni.setStorageSync('userId', res.data.userId);
			resolve(res.data);
		})
	})
	return result;
}

export default{
	axios,
	getUserInfo
}
