/*
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2020-03-04 09:21:53
 * @LastEditors: 无尘
 * @LastEditTime: 2020-03-05 18:15:50
 */
import Vuex from 'vuex';
import Vue from 'vue';
import * as types from './types';
import { initDataRange } from '@/utils/index';

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: [], // 删除配置
    wxEnterpriseType: 0, // 0：总部 1：代理，有些按钮对代理商禁用，新权限管理系统上线后废弃此逻辑
    salesDate: initDataRange()
  },
  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);
    },
    clearAdd: state => {
      state.addDepartment = [];
    },
    clearEdit: state => {
      state.editDepartment = [];
    },
    clearData: state => {
      state.addDepartment = [];
      state.editDepartment = [];
      state.delDepartment = [];
    },
    changeWxEntertype: (state, data) => {
      state.wxEnterpriseType = data;
    },
    changeSalesDate: (state, data) => {
      state.salesDate = data;
    }
  },
  actions: {
    saveAddInfo(context, data) {
      context.commit('saveAdd', data);
    },
    saveEditInfo(context, data) {
      context.commit('saveEdit', data);
    },
    saveDelInfo(context, data) {
      context.commit('saveDel', data);
    },
    clearAddData(context, data) {
      context.commit('clearAdd');
    },
    clearEditData(context, data) {
      context.commit('clearEdit');
    },
    clearTreeData(context, data) {
      context.commit('clearData');
    },
    changeWxEntertypeData(context, data) {
      context.commit('changeWxEntertype', data);
    },
    changeSales(context, data) {
      context.commit('changeSalesDate', data);
    }
  }
});
