export default {
  state: {
    status: null,
    timer: null,
    token: wx.getStorageSync('token'),
    refreshUse: wx.getStorageSync('refreshUse'), // 当接口401的时候是否调用了需要接口
    userInfo: wx.getStorageSync('userInfo'),
    userPhone: wx.getStorageSync('userPhone'),
    // 申请id
    projectId: "",
    applyId: '',
    tokenInfo: wx.getStorageSync('tokenInfo'),
    hasClearToken: false,
    tokenIsValid: true,
    isActivated: wx.getStorageSync('isActivated'),
    companyName: ''
  },
  mutations: {
    // 续约接口是否被调用过
    setRefreshUse(state, refreshUse) {
      wx.setStorageSync('refreshUse', refreshUse);
      state.refreshUse = refreshUse;
    },
    // 设置token
    setToken(state, token) {
      wx.setStorageSync('token', token);
      console.log("设置token--")
      state.token = token;
    },
    //设置租户状态
    setActivated(state, isActivated) {
      wx.setStorageSync('isActivated', isActivated);
      state.isActivated = isActivated
    },
    // 设置token用户信息
    setTokenInfo(state, tokenInfo) {
      console.log("重新存入token");
      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
    },
    setProjectId(state, data) {
      state.projectId = data
    },
    setUserPhone(state, data) {
      wx.setStorageSync('userPhone', data);
      state.userPhone = data
    },
    setCompanyName(state, value) {
      state.companyName = value;
    },
  },
  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);
    }
  }
};
