<template>
	<view class="container">
		<view class="topBox flex">
			<view class="topTpl flex_item">
				<image style="width: 49rpx;height: 45rpx;" src="/static/img/logo.png"></image>
				<view class="tpl clamp">BNB Smart Chain</view>
			</view>
			<view class="topTpl flex_item margin-l-30" v-if="userInfo.address">
				<image class="userIcon" src="/static/img/img10.png"></image>
				<view class="tpls clamp">{{userInfo.address}}</view>
			</view>
		</view>
		<view class="logoBox">
			<image class="logo" src="../../static/img/bindLogo.png" mode="scaleToFill"></image>
		</view>
		<view class="shareBox">
			<view class="title">{{$t('bind.邀请码')}}</view>
			<view class="inputBox ">
				<input class="input" v-model="spread" type="text" placeholder-class="pClass"
					:placeholder="$t('bind.请输入上级邀请码')" />
			</view>
		</view>
		<view class="bindButtom" @click="bindShare">{{$t('bind.立即注册')}}</view>
	</view>
</template>
<script>
	import {
		mapState,
	} from "vuex";
	import {
		addSpread
	} from '@/api/user.js';
	export default {
		data() {
			return {
				spread: ''
			}
		},
		computed: {
			...mapState('user', ['userInfo']),
		},
		onLoad(option) {
			this.spread = option.spread || uni.getStorageSync('spread') || '';
		},
		methods: {
			// 请求载入数据
			async bindShare() {
				const that = this;
				const USER_BIND = 'USER_BIND' + (new Date()).getTime();
				ethereum.request({
					"method": "personal_sign",
					"params": [
						USER_BIND,
						that.userInfo.address
					]
				}).then((res) => {
					addSpread({
						address: that.spread,
						sign: res,
						msg: USER_BIND,
					}).then((res) => {
						that.$util.Tips({
							title: that.$t('bind.绑定成功'),
							icon:'success'
						}, {
							tab: 1,
							url: '/pages/index/index'
						})
					})
				});

			},
		},
	}
</script>

<style lang="scss">
	.container {
		width: 100%;
		padding: 25rpx;
		line-height: 1;
	}

	.shareBox {
		background-color: rgba(255, 255, 255, 1);
		border-radius: 10rpx;
		padding: 40rpx 30rpx;
		margin-top: 100rpx;
		font-weight: 700;

		.title {
			color: rgba(18, 18, 18, 1);
			font-size: 40rpx;
			text-align: center;
		}

		.inputBox {
			background-color: rgba(72, 74, 84, 1);
			border-radius: 40rpx;

			.input {
				margin-top: 50rpx;
				color: rgba(255, 255, 255, 1);
				font-size: 30rpx;
				text-align: center;
				line-height: 2.5em;
				height: 2.5em;
			}

			.pClass {
				color: rgba(255, 255, 255, 0.5);
			}
		}
	}

	.bindButtom {
		margin-top: 100rpx;
		background: linear-gradient(90deg, #38F855, #21EDD3);
		color: rgba(51, 49, 50, 1);
		text-align: center;
		font-size: 36rpx;
		padding: 30rpx;
		font-weight: bold;
		border-radius: 10rpx;
	}

	.logoBox {
		padding-top: 50rpx;
		text-align: center;

		.logo {
			width: 248rpx;
			height: 296rpx;
		}
	}

	.topBox {
		padding-bottom: 31rpx;
		width: 700rpx;

		.topTpl {
			background: #E9EBEC;
			border: 2rpx solid #CCCECF;
			border-radius: 36rpx;
			height: 71rpx;
			padding-left: 10rpx;
			font-weight: bold;
			padding-right: 20rpx;

			&.margin-l-30 {
				width: 0;
				flex-grow: 1;
			}

			.userIcon {
				width: 51rpx;
				height: 48rpx;
				flex-shrink: 0;
			}

			.tpl {
				font-size: 28rpx;
				color: #141414;
			}

			.tpls {
				font-size: 30rpx;
				color: #788387;
			}
		}
	}
</style>