<template>
	<view class="padding-b-120" :style="'background-color: '+theme.bg+';color: '+theme.text" style="height: 100vh;">
		<myNav :title="i18n.mine.share.title"></myNav>
		
		<view class="width-440 margin-0-auto margin-t-100 height-468">
			<image class="width-440 height-468" src="/static/imgs/my/fenxiang@2x.png" mode=""></image>
		</view>
		<view class="borderBox">
			<text class="font-32 color-0165EE">{{i18n.mine.share.code}}</text>
			<image class="width-200 height-200" :src="qrcCode?qrcCode:'/static/APEClogo@2x.png'" mode=""></image>
			<text @click="copy(referral_code)" class="font-36 numbold-font color-0165EE">{{referral_code}}</text>
			<view @click="save()" class="copyBtn">{{i18n.mine.share.copy}}</view>
		</view>
		
		<view class="bottomBox" :style="'background-color: '+theme.fu_bg">
			<view @click="router.push('/pages/my/share/team')" class="width-300 margin-0-auto height-100b padding-w-20 flex align-center justify-around">
				<image class="width-28 height-22" src="/static/imgs/my/team@2x.png" mode=""></image>
				<text class="font-30">{{i18n.mine.share.team}}</text>
			</view>
			<!-- <view class="height-17 margin-w-50" style="border: 1px solid #0165EE;"></view>
			<view @click="router.push('/pages/my/share/commission')" class="width-300 height-100b padding-w-20 flex align-center justify-around">
				<image class="width-22 height-28" src="/static/imgs/my/mingxi@2x.png" mode=""></image>
				<text class="font-30 color-333333">佣金明细</text>
			</view> -->
		</view>
		
	</view>
</template>

<script>
	import clipboard from "@/components/clipboard.js"
	export default {
		data() {
			return {
				referral_code: "",
				qrcCode:'',
				theme:'',
			}
		},
		onLoad: function() {
			this.getInfo()
		},
		onShow:function(){
			if (uni.getStorageSync("theme") == "dark") {
				this.theme = this.$store.state.darkTheme
			}else{
				this.theme = this.$store.state.lightTheme
			}
		},
		computed: {
			i18n() {
				return this.$t('message');
			},
		},
		methods: {
			save(){
				var that = this;
				uni.saveImageToPhotosAlbum({
					filePath: that.qrcCode,
					success(res) {
						that.tos(that.i18n.mine.share.codeSuceed)
					}
				})
			},
			// 复制地址
			copy(data) {
				// #ifndef H5
				clipboard.setText(data);
				// #endif
				// #ifdef H5 
					  let result
				      let textarea = document.createElement("textarea")
				      textarea.value = data
				      textarea.readOnly = "readOnly"
				      document.body.appendChild(textarea)
				      textarea.select() // 选中文本内容
				      textarea.setSelectionRange(0, data.length) 
				      result = document.execCommand("copy") 
				      textarea.remove()    
				// #endif
				this.tos(this.i18n.mine.share.copySuceed)
			},
			getInfo() {
				this.post('/my/get_share').then(res => {
					if (res.code == 1) {
						// console.log(res)
						this.referral_code = res.data.referral_code
						this.qrcCode = res.data.qrcode
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.borderBox{
		width: 600rpx;
		height: 584rpx;
		margin: 20rpx auto;
		padding: 50rpx 0;
		// background: #EFF6FF;
		border: 1rpx dashed #3ECEB2;
		border-radius: 10rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: space-between;
	}
	.copyBtn{
		width: 278rpx;
		height: 72rpx;
		background: linear-gradient(180deg, #52F3C9 0%, #3ECEB2 100%);
		box-shadow: 0rpx 6rpx 10rpx rgba(61, 128, 212, 0.12);
		border-radius: 6rpx;
		font-size: 36rpx;
		text-align: center;
		line-height: 72rpx;
		color: #FFFFFF;
	}
	.bottomBox{
		width: 100%;
		height: 120rpx;
		padding: 0 70rpx;
		// background: #EFF6FF;
		position: fixed;
		bottom: 0rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
</style>
