export default {
  state: {
    status: null,
    token: wx.getStorageSync('token'),
    projectId: '',
    refreshToken: '',
    userInfo: wx.getStorageSync('userInfo'),
    userPhone: wx.getStorageSync('userPhone'),
    // 申请id
    applyId: '',
    tokenInfo: wx.getStorageSync('tokenInfo'),
    hasClearToken: false,
    tokenIsValid: true,
    isActivated: wx.getStorageSync('isActivated')
  },
  mutations: {
    setToken(state, token) {
      wx.setStorageSync('token', token);
      state.token = token;
    },
    setActivated(state, isActivated) {
      wx.setStorageSync('isActivated', isActivated);
      state.isActivated = isActivated
    },
    setTokenInfo(state, tokenInfo) {
      wx.setStorageSync('tokenInfo', tokenInfo);
      state.tokenInfo = tokenInfo;
    },
    setStatus(state, status) {
      state.status = status;
    },
    setUserInfo(state, userInfo) {
      state.userInfo = { ...state.userInfo, ...userInfo };
      wx.setStorageSync('userInfo', userInfo);
      state.userInfo = userInfo;
    },
    clearToken(state) {
      wx.removeStorageSync('token');
      state.token = ''
    },
    clearTokenInfo(state) {
      wx.removeStorageSync('tokenInfo')
      state.tokenInfo = {};
    },
    clearUserInfo(state) {
      wx.removeStorageSync('userInfo')
      state.userInfo = {};
    },
    setApplyId(state, applyId) {
      state.applyId = applyId
    },
    setTokenIsValid(state, data) {
      state.tokenIsValid = data
    },
    setProjectId(state, data) {
      state.projectId = data
    },
    setUserPhone(state, data) {
      wx.setStorageSync('userPhone', data);
      state.userPhone = data
    }

  },
  actions: {
    setToken({ commit }, data) {
      commit('setToken', data);
    },
    setRefreshToken({ commit }, data) {
      commit('setRefreshToken', data);
    },
    setStatus({ commit }, data) {
      commit('setStatus', data);
    },
    setUserInfo({ commit }, data) {
      commit('setUserInfo', data);
    },
    setApplyId({ commit }, data) {
      commit('setApplyId', data);
    },
    clearUserInfo({ commit }) {
      commit('clearUserInfo');
    },
    hasClearToken({ commit }, data) {
      commit('hasClearToken', data);
    },
    setProjectId({ commit }, data) {
      commit('setProjectId', data);
    }
  }
};
