<template>
	<view class="container">
		<navBar :show-title="true" :title="$t('bind.绑定邀请人')" url="/pages/index/index"></navBar>
		<view class="logoBox">
			<image class="logo" src="../../static/img/itemList1.png" mode="widthFix"></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';
	import navBar from "@/components/nav/nav.vue"
	export default {
		data() {
			return {
				spread: ''
			}
		},
		components: {
			navBar
		},
		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: 2,
							url: '/pages/index/index'
						})
					})
				});

			},
		},
	}
</script>

<style lang="scss">
	.container {
		width: 100%;
		padding: 25rpx;
		line-height: 1;
		min-height: 100vh;
		background-color: rgb(12, 8, 21);
		color: #fff;
	}

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

		.title {
			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, #7D32FF, #3EE0FF);
		text-align: center;
		font-size: 36rpx;
		padding: 30rpx;
		font-weight: bold;
		border-radius: 10rpx;
		color: #FFF;
	}

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

		.logo {
			width: 300rpx;
		}
	}

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

		.topTpl {
			background: rgba(255, 255, 255, .09);
			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;
			}

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