import request from "@/utils/request";

const client_id = "web";
const client_secret = "123456";
const scope = "server";

// 登录方法
export function login(phone, code) {
  return request({
    url: "/erp/user/dCodeLogin",
    method: "POST",
    data: { phone, code }
  });
}

// 刷新方法
export function refreshToken() {
  return request({
    url: "/erp/refresh",
    method: "post"
  });
}

// 获取用户详细信息
export function getInfo() {
  return request({
    url: "/erp/user/loginUserInfo",
    method: "get",
  });
}

// 退出方法
export function logout() {
  return request({
    url: "/erp/user/logout",
    method: "delete"
  });
}

// 获取验证码
export function getCode(phone) {
  return request({
    url: `/erp/user/dCodeLoginState/${phone}`,
    method: "GET"
  });
}

// 手机短信验证码获取
export function getNoteCode(phone) {
  return request({
    url: `/erp/user/smsCodeLoginState/${phone}`
  })
}

/**获取钉钉扫码前的后台KEY*/
export function getDingKey() {
  return request({url: '/erp/user/dLoginState'})
}

/**钉钉登录*/
export function ddlogin(params) {
  let { code, stateKey, state } = params
  return request({
    url: `/erp/user/dLogin?code=${code}&stateKey=${stateKey}&state=${state}`,
    method: 'POST'
  })
}

/** 选择公司 */
export function selectCompany(companyId) {
  return request({
    url: `/erp/user/chooseCompany/${companyId}`,
    method: 'PUT'
  })
}