import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		baseURL: 'http://doctortest.igxys.com', //请求线上地址配置
		urlFile: '/index', //项目部署所在文件夹
		hasLogin: false, //是否登录
		userInfo: {
			ext_info: {
				status: ''
			}
		}, //登录信息
		loginInterceptor: false, //是否打开强制登录
		orderInfo: {}, //订单信息
		// 是否显示page页面
		addressPageShow: false,
		addressData: {
			city: "",
			detail: "",
			district: "",
			id: '',
			is_default: '',
			phone: "",
			province: "",
			real_name: ""
		},
		token: '',
		// #ifdef H5 
		setWeiChatInfo: '',
		weichatInfo: {}, //保存微信注册信息
		weichatObj: '', //微信对象
		weichatBrowser: '', //当前是否为微信内置浏览器
		// #endif
		// shareData:'',//分享信息
		chooseType: '', //用户类型
	},
	mutations: {
		// 保存用户类型
		setChooseType(state, provider) {
			console.log('保存用户类型', provider)
			state.chooseType = provider
			uni.removeStorage({
				key: 'chooseType'
			})
			//缓存用户登陆类型
			uni.setStorageSync('chooseType', provider)
			let a = uni.getStorageSync('chooseType')
			console.log(a)
		},
		// 登录
		login(state) {
			state.hasLogin = true;
		},
		// 退出登录
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorage({
				key: 'chooseType'
			})
			uni.removeStorage({
				key: 'userInfo'
			})
			uni.removeStorage({
				key: 'token'
			})
		},
		// 保存用户信息
		setUserInfo(state, provider) {
			state.userInfo = provider;
			if (!state.userInfo.level_info) {
				state.userInfo.level_info = {
					grade: 0
				}
			}
			uni.setStorage({ //缓存用户登陆状态
				key: 'userInfo',
				data: provider
			})
		},
		// #ifdef H5
		//保存微信信息
		setWeiChatInfo(state, provider) {
			state.weichatInfo = provider;
		},
		//保存微信对象
		setWeiChatObj(state, provider) {
			state.weichatObj = provider;
			console.log(state.weichatObj, '微信用户');
		}
		// #endif
	},
	actions: {}
})

export default store
