import Vue from 'vue';
import Vuex from 'vuex';
import _ from 'lodash';
const jwt = require('jsonwebtoken');
Vue.use(Vuex);
const api = {
  info: `/api/hc/user`,
};
const state = () => ({});
const mutations = {};

const actions = {
  async login({ commit }, { user }) {
    const res = await this.$axios.$post(`${api.info}/login`, user);
    if (res.errcode === 0) {
      console.log(res);
      localStorage.setItem('user', JSON.stringify(res.data));
      // // user = jwt.decode(res.data);
      commit('setUser', user, { root: true });
      res.user = user;
    }
    return res;
  },
};
export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
