<style lang="less">
page {
  width: 100%;
  height: 100%;
}
.login-box {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
}
.login {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0.2);
  image {
    position: relative;
    width: 384rpx;
    height: 144rpx;
    top: 336rpx;
    left: 50%;
    transform: translateX(-50%);
  }
  .bind-btn {
    position: fixed;
    bottom: 200rpx;
    left: 50%;
    transform: translateX(-50%);
    width: 548rpx;
    height: 100rpx;
    line-height: 100rpx;
    border-radius: 56rpx;
    background: rgba(61, 203, 204, 1);
    border: none;
    font-family: PingFang SC;
    font-size: 32rpx;
    font-weight: 400;
    letter-spacing: 0px;
    text-align: center;
    color: #fff;
  }
}
</style>
<template>
  <div class="login-box">
    <page-top-bar title="" 
  titleColor="#1B2129"></page-top-bar>
   <div class="login">
       <image src="{{h5StaticPath +'/page-bind-tenant/logo_title.png'}}" alt=""/>
       <button class="bind-btn"
        @click.stop="goBindTenant">登录</button>
   </div>
  </div>
</template>

<script>
import wepy from '@wepy/core';
import { mapState } from '@wepy/x';
import store from '@/store';
import config from '@/config';
import { wxLogin } from '@/service/user';
wepy.page({
  store,
  data: {
    h5StaticPath: config.h5StaticPath,
    isActivated: 0
  },
  computed: {
    ...mapState({
      token: state => state.user.token,
      isActivated: state => state.user.isActivated
    })
  },
  onLoad() {
    if (this.isActivated && this.isActivated == 1) {
      this.goHome();
    } else {
      console.log('this.isActivated===45', this.isActivated);
      this.checkTenantRegist();
    }
  },
  onShow() {},
  methods: {
    goBindTenant() {
      this.goAuth();
    },
    // 判断用户是否认证过
    checkTenantRegist() {
      wxLogin(1)
        .then(res => {
          this.isActivated = res.isActivated;
          let tokenInfo = {
            expireTime: res.expireTime,
            startTime: res.startTime,
            refreshTokenExpireTime: res.refreshTokenExpireTime,
            refreshToken: res.refreshToken
          };
          store.commit('setToken', res.token);
          store.commit('setActivated', res.isActivated);
          store.commit('setTokenInfo', tokenInfo);
          if (this.isActivated && this.isActivated == 1) {
            // 已经激活
            store.commit('setUserInfo', res.tokenUser);
            this.goHome();
          } else if (this.isActivated == 0) {
            // 未激活
            // this.goAuth();
          } else {
            // 作废
          }
        })
        .catch(error => {});
    },
    goHome() {
      // console.log("gohome");
      wx.navigateTo({
        url: '/packagesEnv/pages/home/index'
      });
    },
    goAuth() {
      console.log('被点击了');
      wx.navigateTo({
        url: '/pages/auth/index'
      });
    }
  },
  created() {}
});
</script>
<config>
{
navigationBarTitleText: '登录',
navigationStyle:"custom",
usingComponents: {
    'page-top-bar': '~@/components/common/page-top-bar',      
  },
}
</config>
