import Vue from 'vue'
import Vuex from 'vuex'
import {
	mapMutations
} from 'vuex';

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		orderType: '', // 订单类型 1 普通订单  2 拼团订单 3 秒杀订单 4 优惠券 5 购物车订单 和 goodsDetails 的 type 相同
		orderInfo: {}, // 订单数据　订单步骤1：展示结算数据
		orderAddress: {}, // 下单时选择的地址
		goodsDetails: {}, // 商品详情 1普通 2拼团 3秒杀 4优惠券
		goods_id: '', // 拼团商品 id
		pintuangroup_headid: '', // 拼团团长id 有为开团 无为参团
		groupbuyInfo: {}, // 秒杀详情
		loadmore: {}, // 下拉加载返回的数据
		hasLogin: false, // 登录状态
		token: "", // 储存token
        showLoginModel: false, // 登录框
	},
	getters: {
		getOrderAddress(state) {
			return state.orderAddress || {};
		},
		getGoodsType(state) {
			return state.goodsDetails.type;
		},
		getGoodsInfo(state) {
			return state.goodsDetails.goods;
		}
	},
	mutations: {
		// 登录
		loginIn(state, token) {
			state.hasLogin = true;
			state.token = token;
			uni.setStorage({
				key: "token",
				data: token
			})
		},
		// 退出登录
		logout(state) {
			state.hasLogin = false;
			state.token = "";
			uni.removeStorage({
				key: "token"
			})
			uni.removeStorage({
				key: "user_info"
			})
		},
		setOrderType(state, type) {
			state.orderType = type;
		},
		updateOrderInfo(state, info) {
			state.orderInfo = info;
		},
		updateAddress(state, address) {
			state.orderAddress = address;
		},
		setGoodsDetails(state, goods) {
			state.goodsDetails = goods;
		},
		setGoodsId(state, id) {
			state.goods_id = id;
		},
		setGroupbuyInfo(state, info) {
			state.groupbuyInfo = info;
		},
		setGroupHeadId(state, id) {
			state.pintuangroup_headid = id;
		},
		setLoadMore(state, info) {
			state.loadmore = info;
		}
	}
})
export default store;
