<template>
  <div class="logo">
    <div class="logo-box">
      <div class="img">
        <img src="../assets/logo.png" class="img-box" alt="" />
      </div>
      <div class="yong-ping">
        <div class="box-cont">
          <div class="title">智慧数字物流管理平台</div>

          <div class="shouji">
            <div class="shoujivv">手机号</div>
            <div class="shouinput">
              <img src="../assets/Icon.png" class="iphone-img" alt="" />
              <input
                type="number"
                placeholder="请输入手机号"
                class="iphontiphone"
                v-model="name"
              />
            </div>
          </div>
          <div class="shouji">
            <div class="shoujivv">密码</div>
            <div class="shouinput">
              <img src="../assets/Icon_1.png" class="iphone-img" alt="" />
              <input
                type="password"
                placeholder="请输入密码"
                class="iphontiphone"
                v-model="pass"
              />
            </div>
          </div>
          <div class="shouji">
            <div class="shoujivv">验证码</div>
            <div class="yanzheng">
              <div class="shouinputt">
                <img src="../assets/Icon_2.png" class="iphone-img" alt="" />
                <input
                  type="text"
                  placeholder="请输入验证码"
                  class="iphontiphonet"
                  v-model="code"
                />
              </div>
              <img :src="imgs" class="yan-img" alt="" @click="qie" />
            </div>
          </div>
          <div class="btna" @click="btn">登录</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "HelloWorld",
  data() {
    return {
      imgs: "",
      uuid: "",
      code: "",
      name: "",
      pass: "",
    };
  },
  methods() {},
  created() {
    this.codes();
  },
  methods: {
    //登录
    btn() {
      let that = this;
      var url = "/api/auth/login";
      let params = {
        code: that.code,
        password: that.pass,
        username: that.name,
        uuid: that.uuid,
      };
      that.$axios
        .post(url, params)
        .then(function (res) {
          console.log(res);
          that.$message({
            message: "登录成功",
            type: "success",
          });
          setTimeout(function () {
            that.$router.push("./home");
          }, 800);
          sessionStorage.setItem("token", res.data.access_token);
        })
        .catch(function (err) {
          console.log(err);
          that.$message.error(err.msg)
          that.codes();
        });
    },
    //切换验证码
    qie() {
      this.codes();
    },
    //获取验证码接口
    codes() {
      let that = this;
      var url = "/api/code";
      let params = {};
      that.$axios
        .get(url)
        .then(function (res) {
          console.log(res)
          that.imgs = "data:image/png;base64," + res.img;
          that.uuid = res.uuid;
        })
        .catch(function (err) {
          console.log(err);
        });
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
@import "../css/logo.css";
</style>