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,
    bgHeight: window.screen.availHeight - 440 - 24 + 'px',
    addDepartment: [], // 添加
    editDepartment: [], // 编辑配置
    delDepartment: [] // 删除配置
  },
  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;
    },
    saveAdd: (state, data) => {
      state.addDepartment.push(data);
    },
    saveEdit: (state, data) => {
      state.editDepartment.push(data);
    },
    saveDel: (state, data) => {
      state.delDepartment.push(data);
    },
    clearData: state => {
      state.addDepartment = [];
      state.editDepartment = [];
      state.delDepartment = [];
    }
  },
  actions: {
    saveAddInfo(context, data) {
      context.commit('saveAdd', data);
    },
    saveEditInfo(context, data) {
      context.commit('saveEdit', data);
    },
    saveDelInfo(context, data) {
      context.commit('saveDel', data);
    },
    clearTreeData(context, data) {
      context.commit('clearData');
    }
  }
});
