const user = {
	state: {
		appUser: {
			token: null, // 登录会话token
			tokenHead: null, // 登录会话token头
			openid: null, // 微信用户OPENID
			userid: null, // 系统用户ID
			userInfo: {}, // 用户信息
			currentTime: null, // 当前时间
		},
		wxInfo: {}, // 微信信息
		wxJssdkUser: {
			code: null, // 微信用户code
			openid: null, // 微信用户OPENID
			appid: null, // 微信号APPID
			ticket: null // ticket
		},
		refleshStatus: false // 刷新状态
	},

	getters: {
		appUser: state => state.appUser,
		wxInfo: state => state.wxInfo,
		userInfo: state => state.appUser.userInfo,
		wxJssdkUser: state => state.appUser.userInfo,
		refleshStatus: state => state.refleshStatus
	},

	mutations: {
		SET_APP_USER: (state, appUser) => {
			state.appUser.token = appUser.token
			state.appUser.tokenHead = appUser.tokenHead
			state.appUser.openid = appUser.openid
			state.appUser.userid = appUser.userid
			state.appUser.currentTime = appUser.currentTime
		},
		SET_WX_INFO: (state, wxInfo) => {
			state.wxInfo = wxInfo
		},
		SET_USER_INFO: (state, userInfo) => {
			state.appUser.userInfo = userInfo
		},
		SET_TOKEN: (state, token) => {
			state.appUser.token = token
		},
		SET_WX_JSSDK_USER: (state, jssdkUser) => {
			state.wxJssdkUser.code = jssdkUser.code
			state.wxJssdkUser.openid = jssdkUser.openid
			state.wxJssdkUser.appid = jssdkUser.appid
			state.wxJssdkUser.ticket = jssdkUser.ticket
		},
		SET_REFLESH_STATUS: (state, refleshStatus) => {
			state.refleshStatus = refleshStatus
		}
	},

	actions: {
		setAppUser: ({
			commit
		}, appUser) => {
			commit('SET_APP_USER', appUser)
		},
		resetAppUser: ({
			commit
		}) => {
			let appUser = {
				token: null, // 登录会话token
				tokenHead: null, // 登录会话token头
				openid: null, // 微信用户OPENID
				userid: null, // 系统用户ID
				userInfo: {}, // 用户信息
				currentTime: null, // 当前时间
			}
			commit('SET_APP_USER', appUser)
		},
		resetWxJssdkUser: ({
			commit
		}) => {
			let wxJssdkUser = {
				code: null, // 微信用户code
				openid: null, // 微信用户OPENID
				appid: null, // 微信号APPID
				ticket: null // ticket
			}
			commit('SET_WX_JSSDK_USER', wxJssdkUser)
		},
		setWxInfo: ({
			commit
		}, wxInfo) => {
			commit('SET_WX_INFO', wxInfo)
		},
		setUserInfo: ({
			commit
		}, userInfo) => {
			commit('SET_USER_INFO', userInfo)
		},
		setToken: ({
			commit
		}, token) => {
			commit('SET_TOKEN', token)
		},
		setWxJssdkUser: ({
			commit
		}, jssdkUser) => {
			commit('SET_WX_JSSDK_USER', jssdkUser)
		},
		setRefleshStatus: ({
			commit
		}, refleshStatus) => {
			commit('SET_REFLESH_STATUS', refleshStatus)
		}
	}
}

export default user
