<template>
	<view>
		<view class="card">
			<image
				src="https://guosen-bucket-ldt.obs.cn-south-1.myhuaweicloud.com:443/aa85f1da8bd84ad2944fe88dd4ef7045-hyRO9DPsxdFr399bc3fe4c0fb52273af5c8f694e1356.png">
			</image>
			<view class="info">
				<view class="data">
					<view class="top">
						<image :src="userinfo.avatar" mode=""></image>
						<text class="nickname">{{userinfo.nickName}}</text>
					</view>
					<view class="bottom">
						<view>我是联兑通独家代理</view>
						<view>扫码成为渠道合伙人</view>
					</view>
				</view>
				<view class="qrcode">
					<image :show-menu-by-longpress="true" :src="promotionQrCode" mode=""></image>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				userinfo: {},
				promotionQrCode: ''
			}
		},
		onLoad() {
			this.getQrCode()
			this.fetchUserDetail()
		},
		methods: {
			fetchUserDetail() {
				this.$api.loginUser.detail({
					id: this.vuex_userId
				}).then(res => {
					this.userinfo = res.data
				})
			},
			getQrCode() {
				if (this.$cache.get('promotionQrCode')) {
					this.promotionQrCode = this.$cache.get('promotionQrCode')
				} else {
					this.createWxaQrCode()
				}
			},
			createWxaQrCode() {
				let params = {
					type: this.$global.platform.SHOP,
					path: '/pages/login/register?promotionCode=' + this.vuex_userId
				}
				this.$api.wxApp.createWxaQrCode(params).then(res => {
					if (!this.$isEmpty(res.data.link)) {
						this.promotionQrCode = res.data.link
						this.$cache.put('promotionQrCode', res.data.link)
					} else {
						this.$dialog.showModalAndBack('获取推广码失败')
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.card {
		margin: 20rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		background-color: #FFFFFF;

		image {
			width: 100%;
			height: 882rpx;
		}

		.info {
			width: 100%;
			padding: 30rpx 30rpx 30rpx 50rpx;
			display: flex;
			justify-content: space-between;

			.data {
				display: flex;
				flex-direction: column;
				justify-content: center;

				.top {
					display: flex;

					image {
						width: 80rpx;
						height: 80rpx;
						border-radius: 50%;
					}

					.nickname {
						display: flex;
						justify-content: center;
						align-items: center;
						margin-left: 20rpx;
						font-weight: 800;
						font-size: 34rpx;
					}
				}

				.bottom {
					line-height: 40rpx;
					color: #333333;
					margin-top: 30rpx;
					margin-left: 10rpx;
				}
			}

			.qrcode {
				display: flex;
				justify-content: center;
				align-items: center;

				image {
					width: 250rpx;
					height: 250rpx;
				}
			}

		}
	}
</style>
