
import Api from '../../util/Api/index'
import ToolClass from '../../util/PublicMethod/index'

export default {
  namespaced: true,
  state: {
    UserInfo: null // 用户信息
  },
  mutations: {
    UpdateUserPlaylist (state, data) {
      state.UserPlaylist = data || []
    },
    EditUserInfo (state, data) { // 编辑用户信息
      state.UserInfo = state.UserInfo === null ? {} : state.UserInfo
      state.UserInfo[data.name] = data.value
    }
  },
  actions: {
    PostActivityJoin (context, payload) { // 活动报名
      payload = { ...payload, IsSigIn: true }
      return new Promise((resolve, reject) => {
        ToolClass.WxRequest({
          url: Api.PostActivityJoin.url,
          method: Api.PostActivityJoin.method,
          ...payload,
          success (res) {
            resolve(res)
          },
          error (res) {
            reject(res)
          }
        })
      })
    },
    PostActivityVote (context, payload) { // 活动投票
      payload = { ...payload, IsSigIn: true }
      return new Promise((resolve, reject) => {
        ToolClass.WxRequest({
          url: Api.PostActivityVote.url,
          method: Api.PostActivityVote.method,
          ...payload,
          success (res) {
            resolve(res)
          },
          error (res) {
            reject(res)
          }
        })
      })
    },
    GetUserPhone (context, payload) { // 获取用户手机号
      payload = { ...payload, IsSigIn: true }
      return new Promise((resolve, reject) => {
        ToolClass.WxRequest({
          url: Api.GetUserPhone.url,
          method: Api.GetUserPhone.method,
          ...payload,
          success (res) {
            resolve(res)
          },
          error (res) {
            reject(res)
          }
        })
      })
    },
    MainSignIn (context, payload) { // 登录
      payload = { ...payload, IsSigIn: true }
      return new Promise((resolve, reject) => {
        ToolClass.WxRequest({
          url: Api.MainSignIn.url,
          method: Api.MainSignIn.method,
          ...payload,
          success (res) {
            resolve(res)
          },
          error (res) {
            reject(res)
          }
        })
      })
    }
  }
}
