import httpRequest from '../../utils/httpRequest'
import { Message } from 'element-ui'
import Vue from 'vue'

export default {
  namespaced: true,
  state: {
    id: 0,
    name: '',
    token: '', // 登录返回的token
    userPhone: '',
    userconfig: {
      userVip: 0 // 用户VIP：0非会员 1VIP(金币) 2包月会员 3包年会员
    }
  },
  actions: {
    fetchUserConfig ({ commit }) {
      if (!Vue.cookie.get('token')) {
        return
      }
      httpRequest({
        url: httpRequest.adornUrl('/user/config'),
        method: 'get',
        params: ''
      }).then(({ data }) => {
        if (data.status) {
          commit('updateUserconfig', data.data)
          return
        }
        Message.error(data.msg)
      })
    }
  },
  mutations: {
    updateId (state, id) {
      state.id = id
    },
    updateName (state, name) {
      state.name = name
    },
    updateToken (state, val) {
      state.token = val
    },
    updateUserPhone (state, val) {
      state.userPhone = val
    },
    updateUserconfig (state, val = {}) {
      state.userconfig = val
    }
  }
}
