import request from '@/utils/request'
import { encrypt } from '@/utils/jsencrypt' // 公钥,私钥都声明在里面

const VUE_APP_ENABLE_SECRET = true; // 登录账密凭据加密

// 登录方法
export function login(username, password, code, uuid) {
  const data = {
    username,
    password,
    code,
    uuid
  }
  if(VUE_APP_ENABLE_SECRET)
  {
    data.username = encrypt(username);
    data.password = encrypt(password);
  }
  return request({
    url: '/login',
    method: 'post',
    data: data,
    headers: {
      isToken: false
    }
  })
}

// 短信登录方法
export function smsLogin(mobile, smsCode, uuid) {
  const data = {
    mobile,
    smsCode,
    uuid
  }
  return request({
    url: '/sms/login',
    method: 'post',
    data: data,
    headers: {
      isToken: false
    }
  })
}

// 获取用户详细信息
export function getInfo() {
  return request({
    url: '/getInfo',
    method: 'get'
  })
}

// 退出方法
export function logout() {
  return request({
    url: '/logout',
    method: 'post'
  })
}

// 获取验证码
export function getCodeImg() {
  return request({
    url: '/gkyzm',
    method: 'get',
    headers: {
      isToken: false
    }
  })
}

// 发送短信验证码
export function getSmsCode(mobile,code,uuid) {

  const data = {
    mobile,
    code,
    uuid
  }

  return request({
    url: '/sms/code',
    method: 'post',
    data: data
  })
}

// 发送注册短信验证码
export function getRegisterSmsCode(mobile) {
  return request({
    url: '/sms/code',
    method: 'post',
    data: mobile
  })
}


//注册前校验身份信息
export function registerCheck(mobile) {
  return request({
    url: 'register/check',
    method: 'post',
    data: mobile
  })
}

//注册接口
export function registerOn(mobile) {
  return request({
    url: 'register/on',
    method: 'post',
    data: mobile
  })
}

// 春耕app登录: 用户
export function chungengUserLogin(code) {
  return request({
    url: '/chungeng/userLogin',
    method: 'post',
    data: {code},
    headers: {
      isToken: false
    }
  })
}

// 春耕app登录: 农户
export function chungengFarmerLogin(code) {
  return request({
    url: '/chungeng/farmerLogin',
    method: 'post',
    data: {code},
    headers: {
      isToken: false
    }
  })
}
