import Vue from 'vue';
import Vuex from 'vuex';
import http from '../plugins/http';

Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        userInfo: null,
        keeps: [],
        historys: [],
        institutionInfo: null,
        personalInfo: null,
        showAdd: false,
        couponInfo: null
    },
    mutations: {
        setKeeps(state, keeps) {
            state.keeps = keeps;
        },
        setHistorys(state, historys) {
            state.historys = historys;
        },
        updateUserInfo(state, userInfo) {
            state.userInfo = userInfo;
        },
        updateShowAdd(state, showAdd) {
            state.showAdd = showAdd;
        },
        setCouponInfo(state, couponInfo) {
            state.couponInfo = couponInfo;
        }
    },
    actions: {
        getUserInfo(context) {
            return http.http.get('/user/my').then(res => {
                context.commit('updateUserInfo', res);
                console.log(res);
            });
        }
    }
});
