import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  /* 状态对象 */
  state: {
    result: false, // 获取信息是否成功
    // eslint-disable-next-line no-mixed-spaces-and-tabs
    code: '',
    msg: '', // 获取成功失败时返回的错误信息
    wxcode: '', // 微信code
    wxopenid: '', // 微信openid
    data: {}, // {userId,userName,userCode}
    token: {} // 令牌

  },
  mutations: {
    setResult (state, result) {
      state.result = result
    },
    setCode (state, code) {
      state.code = code
    },
    setMsg (state, msg) {
      state.msg = msg
    },
    setWxCode (state, wxcode) {
      state.wxcode = wxcode
    },
    setwxopenid (state, wxopenid) {
      state.wxopenid = wxopenid
    },
    setData (state, data) {
      state.data.ownerid = data.ownerid
      state.data.ownername = data.ownername
      state.data.hcode = data.hcode
      state.data.hname = data.hname
      state.data.bcode = data.bcode
      state.data.bname = data.bname
      state.data.tel = data.tel
    },
    setToken (state, token) {
      state.token = token
    },
    clearData (state, empty) {
      state.data.ownerid = empty
      state.data.ownername = empty
      state.data.hcode = empty
      state.data.hname = empty
      state.data.bcode = empty
      state.data.bname = empty
      state.data.tel = empty
    }
  },
  getters: {

  },
  actions: {
    // lazy loading openid
  }
})

export default store
