import { Base } from "../../static/util/base.js";

class Login extends Base {

  constructor() {
    super();
  }

  /**
   * 账号密码登录
   * @param data
   * @param callBack
   */
  login(data, callBack) {
    var params = {
      url: "/admin/employee/login",
      type: "POST",
      data: {
        username: data.username,
        password: data.password
      },

      sCallBack: function(res) {
        callBack && callBack(res);
      }
    };
    this.request(params);
  }

  //获取手机验证码
  getVerificCode(phone, callBack) {
    const params = {
      url: '/auth/sendCode',
      type: 'GET',
      data:{phone},
      sCallBack: function (res) {
        callBack && callBack(res)
      }
    }
    this.request(params);
  }

  //短信验证码登录
  verificationCodeLogin(phone, code, callBack) {
    const params = {
      url: "/auth/login",
      type: "PUT",
      data: {
        phone,
        code
      },
      sCallBack: function(res) {
        callBack && callBack(res);
      }
    };
    this.request(params);
  }

  //验证手机号是否注册
  selectphone(phone, callBack) {
    const params = {
      url: '/auth/selectPhone',
      data: {
        phone
      },
      sCallBack: function (res) {
        callBack && callBack(res.data)
      }
    }
    this.request(params);
  }

  //微信openid直接登录
  wxOpenidLogin(code,callBack){
    const params = {
      url: '/auth/loginByWx',
      data:{
        code:code
      },
      sCallBack: function (res) {
        callBack && callBack(res)
      }
    }
    this.request(params);
  }

  userInfo(callBack) {
    var params = {
      url: "/user/userinfo",
      type: "get",
      sCallBack: function(res) {
        callBack && callBack(res);
      }
    };
    this.request(params);
  }
}

const _login = new Login();
export { _login };