import request from '@/utils/request'
import qs from 'qs'
const powerService = '/api/service-platform-power-base'

const userApi = {
  Login: '/api/auth/login',
  Logout: '/api/auth/logout',
  UserMenu: '/api/user/nav',
  //UserInfo: powerService + '/user/info',
  UserInfo: '/api/user/info',
  Renew: '/api/token/refresh',
  UpdateUserInfo: powerService + '/userpower/updatePassword'
}

/**
 * login func
 * parameter: {
 *     username: '',
 *     password: '',
 *     remember_me: true,
 *     captcha: '12345'
 * }
 * @param parameter
 * @returns {*}
 */
export function login(parameter) {
  return request({
    url: userApi.Login,
    method: 'post',
    data: qs.stringify(parameter),
    headers: {
      'content-type': 'application/x-www-form-urlencoded'
    }
  })
}

export function getInfo() {
  return request({
    url: userApi.UserInfo,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * token 续订
 */
export function tokenRenew() {
  return request({
    url: userApi.Renew,
    method: 'get'
  })
}

export function getSmsCaptcha(parameter) {
  return axios({
    url: api.SendSms,
    method: 'post',
    data: parameter
  })
}

export function getCurrentUserNav() {
  return request({
    url: userApi.UserMenu,
    method: 'get'
  })
}

export function logout() {
  return request({
    url: userApi.Logout,
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function setUserInfo(parameter) {
  return request({
    url: userApi.UpdateUserInfo,
    method: 'post',
    data: qs.stringify(parameter),
    headers: {
      'content-type': 'application/x-www-form-urlencoded'
    }
  })
}
