/*
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-11-12 10:18:30
 * @LastEditors: 无尘
 * @LastEditTime: 2019-11-18 17:16:49
 */
import Vuex from 'vuex';
import Vue from 'vue';
import * as types from './types';

Vue.use(Vuex);
export default new Vuex.Store({
  state: {
    user: {},
    token: null,
    title: '',
    show: false,
    tagRealName: '',
    uniqueId: '',
    baseInfo: {}, // 基础信息
    centerInfo: {}, // 活动中心配置
    cardInfo: {}, // 小程序卡片配置
    posterInfo: {}, // 海报配置
    rewardInfo: {}, // 奖励配置
    tempBackData: [] // 后端判断禁用数据
  },
  mutations: {
    [types.LOGIN]: (state, data) => {
      sessionStorage.token = data;
      state.token = data;
    },
    [types.LOGOUT]: state => {
      sessionStorage.removeItem('token');
      state.token = null;
    },
    [types.TITLE]: (state, data) => {
      state.title = data;
    },
    [types.SHOW]: (state, data) => {
      state.show = data;
    },
    modiftTagName(state, data) {
      state.tagRealName = data;
    },
    ['changeUniqueId'](state, id) {
      state.uniqueId = id || '';
    },
    saveBase: (state, data) => {
      state.baseInfo = data;
    },
    saveCenter: (state, data) => {
      state.centerInfo = data;
    },
    saveCard: (state, data) => {
      state.cardInfo = data;
    },
    savePoster: (state, data) => {
      state.posterInfo = data;
    },
    saveReward: (state, data) => {
      state.rewardInfo = data;
    },
    clearData: state => {
      state.baseInfo = {};
      state.centerInfo = {};
      state.cardInfo = {};
      state.posterInfo = {};
      state.rewardInfo = {};
    }
  },
  actions: {
    saveBaseInfo(context, data) {
      context.commit('saveBase', data);
    },
    saveCenterInfo(context, data) {
      context.commit('saveCenter', data);
    },
    saveCardInfo(context, data) {
      context.commit('saveCard', data);
    },
    savePosterInfo(context, data) {
      context.commit('savePoster', data);
    },
    saveRewardInfo(context, data) {
      context.commit('saveReward', data);
    },
    clearActiveData(context, data) {
      context.commit('clearData');
    }
  }
});
