import { getUserInfo } from '../../views/partner/mine/api'
import { Toast } from 'vant'

const state = {
  userInfo: {}
}

const getters = {
  userInfo (state) {
    return state.userInfo
  }
}

const actions = {
  fetchUserInfo ({ commit }) {
    getUserInfo().then(res => {
      if (res.status) {
        commit('UPDATE_USERINFO', res.data)
      } else {
        Toast(res.msg)
      }
    }).catch(err => {
      Toast(err)
    })
  }
}

const mutations = {
  UPDATE_USERINFO (state, value) {
    state.userInfo = value
  }
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
