<template>
  <div class="phonelogin">
    <img src="./logobig.png" alt="" class="logobig" />
    <div class="logTit">
      <span class="titletxt">欢迎登陆</span>
    </div>
    <div class="loginBox">
      <button
        open-type="getPhoneNumber"
        class="login_button"
        style="padding: 30rpx; color: white; margin-top: 25vh"
        @getphonenumber="getPhoneNumber"
      >
        授权手机号快捷登录
      </button>
    </div>
    <div class="bottomTips">
      <label class="radio">
        <radio value="r1" checked="true" color="#8a0554" />
        已阅读并同意<span style="color: #8a0554"
          >《服务协议条款及隐私政策》</span
        >
      </label>
    </div>
    <!--    <van-dialog id="van-toast" />-->
  </div>
</template>
  <script>
import { loginByWeixin2 } from "@/js_sdk/http.js";

export default {
  data() {
    return {
      loginForm: {
        userName: "",
        password: "",
        code: "",
        type: "FRAME",
        captchaId: "",
        captchaImage: "",
        rememberMe: true,
      },
    };
  },
  mounted() {
    // login()
    this.captchaImageRefresh(this.loginForm);
  },
  methods: {
    getPhoneNumber(e) {
      wx.login({
        success(res) {
          console.log(res);
          let data = {
            loginCode: res.code,
            phoneCode: e.detail.code,
          };
          loginByWeixin2(data).then((e) => {
            console.log(e.data.user);
            wx.setStorageSync("USERINFO", JSON.stringify(e.data.user));
            uni.switchTab({
              url: "/pages/index/index",
            });
          });
        },
      });
    },
    goqy() {
      uni.navigateTo({
        url: "/pages/subPackages/gocompnay/index",
      });
    },
    gozhfw() {
      wx.navigateToMiniProgram({
        appId: "wx15404cced62d7b37",
        success(res) {
          // 打开成功
        },
        fail(e) {
          console.log(e);
        },
      });
    },
    captchaImageRefresh: function (_form) {
      _form.captchaId = this.$common.uuid(8);
      _form.captchaImage =
        this.$constant.BASE_URI +
        "/captcha/captchaImage?type=math&captchaId=" +
        _form.captchaId +
        "&s=" +
        Math.random();
    },
    forgetPsw() {
      wx.showModal({
        title: "提示！",
        content: "管理端修改密码需要拨打客服电话咨询，是否拨打？",
        success: function (res) {
          if (res.confirm) {
            uni.makePhoneCall({
              phoneNumber: "13921516068", //电话号码
              success: function (e) {},
              fail: function (e) {},
            });
          }
        },
      });
    },
    login() {
      const _this = this;
      if (!this.loginForm.userName || !this.loginForm.password) {
        uni.showModal({
          title: "提示",
          content: "请输入账号和密码",
          icon: "error",
          showCancel: false,
        });
        return;
      }
      login(this.loginForm).then((res) => {
        if (res.errmsg == "成功") {
          uni.showToast({
            title: "登录成功",
            icon: "none",
            mask: true,
            duration: 2000,
          });
          this.$auth.setUser(res.data.token);
          this.$auth.setUserInfo(res.data);
          uni.switchTab({
            url: "/pages/index/index",
          });
        } else {
          this.captchaImageRefresh(this.loginForm);
        }
      });

      // this.$auth.setUserType(this.$auth.TYPE_FRAME);
    },
    onShareAppMessage: function () {},
  },
};
</script>
  <style lang="scss">
.phonelogin {
  background: white;
  height: 100%;
  overflow: hidden;
  .login_button {
    height: 96rpx;
    background: #8a0554;
    border-radius: 48rpx 48rpx 48rpx 48rpx;
    color: white;

    &:after {
      border: none;
    }
  }
  .logTit {
    width: 80vw;
    left: 10vw;
    top: 280rpx;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: absolute;
    z-index: 1;
    color: rgba(51, 51, 51, 1);
    font-size: 4vw;
    p {
      color: rgba(102, 102, 102, 1);
      font-size: 4vw;
      margin-top: 0.5vw;
    }

    .titletxt {
      font-size: 62rpx;
      font-family: Taipei Sans TC Beta-Bold, Taipei Sans TC Beta;
      font-weight: bold;
      color: rgba(52, 19, 39, 1);
    }
  }
  .logobig {
    width: 100vw;
    height: 100vh;
    position: absolute;
    left: 0;
    z-index: 0;
  }

  .loginBox {
    width: 70vw;
    left: 15vw;
    padding-top: 75vw;
    position: absolute;
  }
  .inputBox {
    position: relative;
    display: flex;
    align-items: center;
    img {
      position: absolute;
      width: 7vw;
      // padding-top: 40px;
    }
    .yanzhengImg {
      right: 0;
      width: 20vw;
      height: 10vw;
    }
    .yanzhengImgBox {
      height: 50px;
      display: flex;
      align-items: center;
    }
    input {
      background: black;
      width: 100%;
      height: 76rpx;
      padding: 5rpx 0 5rpx 70rpx;
      background-color: rgba(255, 255, 255, 1);
      border: 1rpx solid rgba(29, 24, 188, 0.05);
      margin: 5rpx 0;
      font-size: 4vw;
    }
    input::-webkit-input-placeholder {
      color: rgba(153, 153, 153, 1);
    }
    .yanzhengma {
      width: 60%;
    }
  }
  .pswBox {
    width: 100%;
    display: flex;
    justify-content: flex-end;
    margin: 20px 0;
    color: #8a0554;
  }
  .van-button {
    margin-top: 15rpx;
    border-radius: 60px;
  }
  .loginbtn {
    margin-top: 50rpx;
  }
  .bottomTips {
    width: 100vw;
    position: fixed;
    bottom: 100rpx;
    text-align: center;
    color: #999999;
    font-size: 28rpx;
  }
  @media screen and (max-height: 454px) {
    .bottomTips {
      display: none;
    }
  }
}
</style>
  