<template>
	<view class="webkit-box code">
		<view class="webkit-box code-content">
			<view class="sub-title">扫码转入OC COIN</view>
			<view class="code-img">
				<image :src="code" mode="widthFix" />
			</view>
			<view class="hr"></view>
			<view class="sub-title">钱包地址</view>
			<view class="hash">{{address || '-'}}</view>
			<view class="buttons">
				<button class="item red" type="default" @click="showShare()">分享</button>
				<button class="item greed" type="default" @click="copyAddress">复制</button>
			</view>
		</view>
		<view class="footer">OC CHNIA</view>
	</view>
</template>

<script>
	import { code } from '@/apis/interfaces/wallet'
	export default {
		data() {
			return {
				address: '',
				code: ''
			};
		},
		mounted() {
			code().then(res=>{
				this.code = res.image
				this.address = res.address
			}).catch(err=>{
				uni.showToast({
					icon: 'none',
					title: err.message
				})
			})
		},
		methods:{
			copyAddress(){
				uni.setClipboardData({
					data: this.address
				})
			},
			showShare(){
				uni.share({
					provider: 'weixin',
					title: '我正在使用ocChain钱包收款',
					scene: 'WXSceneSession',
					href: 'https://live.funnyzhibo.com/blockdownload',
					imageUrl: 'https://live.funnyzhibo.com/oc-chain.png',
					summary: '我的收款地址' + this.address
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.code{
		height: 100vh;
		background:linear-gradient(to bottom, $mian-color, $mian-color-deep);
		padding-bottom: env(safe-area-inset-bottom);
		padding-bottom: constant(safe-area-inset-bottom);
		box-sizing: border-box;
		// 收款码
		.code-content{
			text-align: center;
			background: white;
			margin: 0 8vw;
			border-radius: $radius;
			padding: $padding * 2;
			height: 70vh;
			box-shadow: 0 0 6rpx 6rpx rgba($color: #000000, $alpha: .02);
			box-sizing: border-box;
			.sub-title{
				font-size: $title-size + 8;
			}
			.code-img{
				width: 20vh;
				height: 20vh;
				margin: $margin * 3 0 $margin * 2;
				display: inline-block;
				background-image: url(../../static/background/wallet-code-background.png);
				padding: $padding;
				box-sizing: border-box;
				background-position: center;
				background-size: cover;
				image{
					width: 100%;
				}
			}
			.hr{
				height: 1rpx;
				background: $border-color;
				margin: $margin * 2 0;
			}
			.hash{
				word-wrap: break-word;
				font-size: $title-size;
				padding: $padding 0;
			}
			.buttons{
				display: flex;
				padding-top: $padding * 2;
				.item{
					width: 40%;
					height: 80rpx;
					line-height: 80rpx;
					border-radius: 40rpx;
					font-size: $title-size;
					color: white;
					&::after{
						border: none;
					}
					&.red{
						background: $red-color;
					}
					&.greed{
						background: $mian-color;
					}
				}
			}
		}
		// 底部
		.footer{
			height: 10vh;
			line-height: 10vh;
			text-align: center;
			font-size: $title-size + 10;
			font-weight: bold;
			color: #58876e;
		}
	}
</style>
