<template>
	<!-- 没有关注公众号须先关注公众号才可以使用 -->
		<view class="qrcodeContainer" v-show="isNeedOfficialAccountQrcode">
			<view class="qrcodeContent">
				<img src="../../static/images/qrcodeBg_1.png" alt="" srcset="">
			</view>
		</view>
</template>

<script>
	import dataHandling from "../../util/dataHandling";
	import api from "../../api/api";
	import { ref,toRefs } from "vue";
	import {nanoid} from 'nanoid';
	
	export default {
		name:'follow',
		props: ['redirectUrl'],
		data() {
			return {
				businessNo:null,
				isNeedOfficialAccountQrcode:true,
			};
		},
		setup(props,content) {
			const redirectUrl = ref(props.redirectUrl);
			const sendFollowData = (e) =>{
				content.emit('getFollowData',e)
			}
			return {redirectUrl,sendFollowData}
		},
		onLoad(){
		},
		mounted(){
			if(!uni.getStorageSync('businessNo')){
				uni.setStorageSync('businessNo', nanoid().replace(/\_/g,""));	
			}else{
				this.businessNo = uni.getStorageSync('businessNo');
			}
			if(dataHandling.getQueryString('subscribe')==0){
				this.isNeedOfficialAccountQrcode = true;
				return false;
			}else{
				this.isNeedOfficialAccountQrcode = false;
			}
			this.sendFollowData(this.isNeedOfficialAccountQrcode)
			if(dataHandling.getQueryString('openId')) {
				uni.setStorageSync('openId',dataHandling.getQueryString('openId'))
			}else if(!dataHandling.getQueryString('openId') && dataHandling.getQueryString('isBack') != 1){
				api.getWxUserInfo({userApplyType:1,businessNo:uni.getStorageSync('businessNo'),redirectUrl:this.redirectUrl}).then(res=>{
					if(res['success']){
						window.location.href =  res.data.paymentForm.action;
					}
				})	
			}
				
			if(
			sessionStorage.getItem('shareTipsFlag')!='1' && 
			!this.isNeedOfficialAccountQrcode && 
			dataHandling.getQueryString('subscribe')=='1'){
				uni.showModal({
					title: '',
					content: '好东西就要分享，您的分享，是我们持续提供好工具的动力',
					showCancel:false,
					confirmText:'确定',
					success: function (res) {
						if (res.confirm) {
							sessionStorage.setItem('shareTipsFlag','1')
						} 
					}
				});	
			}
			
		}
	}
</script>

<style lang="scss">
.qrcodeContainer{
		width: 100%;
		height: 100vh;
		overflow: hidden;
		img{
			max-width: 100%;
		}
	}
</style>
