<template>
  <view class="container">
    <view class="bg1"></view>
    <view class="bg2"></view>
    <image class="logo" src="/static/logo.png" mode="" />
    <view class="form">
      <view class="input-box">
        <u-input
          v-model="account"
          :clearable="false"
          placeholder="请输入您的账号"
          height="102"
          type="text"
          :border="false"
        />
      </view>
      <view class="input-box">
        <u-input
          v-model="code"
          :clearable="false"
          placeholder="请输入验证码"
          height="102"
          type="text"
          :border="false"
        />
        <view class="code-btn" @click="getCode">{{ text }}</view>
      </view>
      <view class="input-box">
        <u-input
          v-model="password"
          :clearable="false"
          :password-icon="false"
          placeholder="请输入密码"
          height="102"
          type="password"
          :border="false"
        />
      </view>
    </view>
    <view class="tip"
      >注册/登录即代表同意<view class="protocal"> 《隐私政策》</view>及<view
        class="protocal"
        >《服务》</view
      ></view
    >
    <view class="login-btn" @click="login">登录</view>
  </view>
</template>
<script>
export default {
  data() {
    return {
      account: "zhangzj", //
      code: "112233",
      password: "123456",
      text: "获取验证码",
      timer: null,
      isfinished: true,
    };
  },
  onLoad(options) {
    // wx.showShareMenu({
    // 	withShareTicket: true
    // })
    // wx.hideShareMenu({
    // })
  },
  onShow() {},
  computed: {},
  methods: {
    getCode() {
      let that = this;
      if(!that.isfinished) return;
      that.getsendCode();
      let seconds = 120;
      that.timer = setInterval(function() {
        that.isfinished = false;
        that.text = seconds + "s后重新发送";
        seconds--;
        if (seconds <= 0) {
          that.isfinished = true;
          clearInterval(that.timer);
          that.text = "获取验证码";
        }
      }, 1000);
    },
    getsendCode() {
      // type 1:登录短信 2:定金合同短信 3:成交合同短信
      this.$u.api.sendUser({body:{user:this.account}}).then((res)=>{
      		console.log(res)
       })
      
    },
    login() {
      if (this.account == "") return;
      if (this.password == "") return;
      let params = {
        body:{
          account: this.account,
          password: this.password
        }
      };
      this.$u.api.login(params).then((res) => {
        console.log(res)
        if(res.ErrNo=='0000'){
          uni.setStorageSync('token',res.result.SESSIONID)
          this.$u.vuex("vuex_token",res.result.SESSIONID);
          uni.switchTab({
            url: '/pages/tabs/index'
          })
        }
      });
    },
  },
  // onShareAppMessage(){

  // },

  onHide() {
    clearInterval(this.timer);
  },
  destroyed() {
    clearInterval(this.timer);
  },
};
</script>

<style lang="scss" scoped>
.container {
  width: 750rpx;
  height: 100vh;
  .bg1 {
    width: 319rpx;
    height: 548rpx;
    position: fixed;
    top: 0;
    left: 0;
    background: url("https://static.quhouse.com/87fb6d8e9b37462e832c782ec5f73452.png")
      no-repeat;
    background-size: 319rpx 548rpx;
    z-index: -1;
  }
  .bg2 {
    width: 542rpx;
    height: 562rpx;
    position: fixed;
    right: 0;
    bottom: 0;
    background: url("https://static.quhouse.com/1677e9e68a5242c3b10b6a08ea848a4b.png")
      no-repeat;
    background-size: 542rpx 562rpx;
    z-index: -1;
  }

  .logo {
    width: 360rpx;
    height: 102rpx;
    margin: 260rpx 195rpx 130rpx;
  }
  .form {
    padding: 0 75rpx;
    .input-box {
      width: 100%;
      padding: 0 20rpx;
      height: 102rpx;
      line-height: 102rpx;
      border-bottom: 1px solid #e0e0e0;
      display: flex;
      align-items: center;
      justify-content: space-between;
      .code-btn {
        font-size: 30rpx;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #303030;
      }
    }
  }
  .tip {
    margin: 30rpx 75rpx 120rpx;
    display: flex;
    align-items: center;
    height: 37rpx;
    font-size: 26rpx;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #666;
    line-height: 37rpx;
    .protocal {
      color: #333;
    }
  }
  .login-btn {
    margin-left: 75rpx;
    width: 600rpx;
    height: 98rpx;
    line-height: 98rpx;
    background: linear-gradient(135deg, #f9b017 0%, #ff6d25 100%);
    box-shadow: 0px 2rpx 12rpx 0px rgba(255, 109, 37, 0.5);
    border-radius: 49rpx;
    font-size: 32rpx;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #ffffff;
    text-align: center;
  }
}
</style>
