<script>
import tools from "@/common/js/tools";
import tokenpocketBnb from "@/common/wallet/tokenpocket-wallet/tokenpocket-bnb";
import {register} from "@/api/member";

export default {
  name: "invite-page",
  components: {},
  data() {
    return {
      formData: {
        address: '',
        inviteCode: ''
      }
    };
  },
  mounted() {
  },
  methods: {
    async getAccount(){
      console.log('---------------------------------',tokenpocketBnb)
      tokenpocketBnb.getAccounts().then(async (Address) => {
        console.log(Address)
        if (Address) {
          this.formData.address=Address
          this.login()
        } else {
          // tools.goToError(2)
        }
      }).catch((e)=>{
        console.log(e)
        // tools.goToError(2)
      })
    },
    login(){
      register(this.formData).then((res) => {
        if(res.code===1){
          tools.setLoginInfo(res.data)
          setTimeout(()=>{
            uni.reLaunch({
              url: '/pages/index/index'
            })
          },50)
        }else {
          uni.reLaunch({
            url: 'pages/login/register?address='+Address
          })
        }
      })
    }

  },
}
</script>

<template>
  <view class="flex-common-css box-b align-items-center flex-justify-center">
    <view class="fs-14 fc-f mb-10">
      请输入邀请码
    </view>
    <view class="w-80 mb-50">
      <input class="input-b" v-model="formData.inviteCode" placeholder="" placeholder-class="text-align-center fs-14"></input>
    </view>
    <view class="but-b b-rad-20 text-align-center fc-f fs-14" @click="getAccount">
      确认绑定
    </view>
  </view>
</template>

<style scoped lang="scss">
.box-b {
  background-image: linear-gradient(46deg, #3364d1, #42d6dd);
}
.input-b{
  height: 50px;
  border: none;
  border-radius: 10px;
  background: #fff;
  text-align: center;
}
.w-80{
  width: 80%;
}
.but-b{
  background-image: linear-gradient(46deg, #7a8fbf, #59b3b7);
  width: 60%;
  line-height: 40px;
  border: 1px solid #fff;
}
</style>
