import axios from '@/libs/api.request'

export const allowOrNot = (upobj) => {
  let url="/web/auth/userCtl/allowOrNot"
  return axios.request({
    url: url,
    data:upobj,
    method: 'post'
  }).catch((e)=>{
    console.log(e)
  })
}

export const login = (upobj) => {
  let url="/web/auth/userCtl/pmlogin"
if(upobj.mobile){
  if(axios.confapp.regrole=="pr"){
    if(!axios.confapp.companykey){
      console.log("当第三方应用调转到注册页面时，如果是注册自由个体用户，那么需要提供公司key")
      return false
    }
    url="/web/auth/userCtl/pmloginByVCodeForFreeUser"//注册个人用户,请求头必须添加公司KEY，如果不添加需要报错
  }else{
    url="/web/auth/userCtl/pmloginByVCode"//注册租户
  }
}else{
    url="/web/auth/userCtl/pmlogin"
}

  return axios.request({
    url: url,
    data:upobj,
    method: 'post'
  }).catch((e)=>{
    console.log(e)
  })
}

export const getUserInfo = (token) => {
  return axios.request({
    url: '/web/auth/userCtl/getUserInfo',
    method: 'post'
  })
}
export const sendVCode = (obj) => {
  return axios.request({
    url: '/web/auth/userCtl/pmSendVCode',
    method: 'post',
    data:obj
  })
}

export const logout = (token) => {
  return axios.request({
    url: 'logout',
    method: 'post'
  })
}

export const getUnreadCount = () => {
  return axios.request({
    url: 'message/count',
    method: 'get'
  })
}

export const getMessage = () => {
  return axios.request({
    url: 'message/init',
    method: 'get'
  })
}

export const getContentByMsgId = msg_id => {
  return axios.request({
    url: 'message/content',
    method: 'get',
    params: {
      msg_id
    }
  })
}

export const hasRead = msg_id => {
  return axios.request({
    url: 'message/has_read',
    method: 'post',
    data: {
      msg_id
    }
  })
}

export const removeReaded = msg_id => {
  return axios.request({
    url: 'message/remove_readed',
    method: 'post',
    data: {
      msg_id
    }
  })
}

export const restoreTrash = msg_id => {
  return axios.request({
    url: 'message/restore',
    method: 'post',
    data: {
      msg_id
    }
  })
}
