<script setup>
	/**
	 * 视频左侧菜单弹窗
	 */
	import {
		onMounted,
		ref,
		reactive,
		getCurrentInstance,
		watch,
		defineExpose,
	} from 'vue';
	const {
		proxy
	} = getCurrentInstance()
	import videoApi from '@/api/video.js';
	// 顶部状态栏
	import statusBar from '@/components/header/statusBar.vue'
	// 工具库
	import util from '@/common/js/util.js'

	onMounted(() => {
		// open()
	})

	// 打开弹窗
	function open() {
		proxy.$refs.leftMenu.open()
	}

	// 关闭弹窗
	function close() {
		proxy.$refs.leftMenu.close()
	}

	function getUserInfos(userRecommend) {
		videoApi.getUserInfo({
			query: {
				userRecommend: userRecommend,
			}
		}).then(rs => {
			console.log(rs)
			if (rs.data !== null) {
				uni.navigateTo({
					url: '/pages/index/beInvited?header=' + rs.data.userPortrait + '&userId=' + rs.data
						.userId + '&userNickname=' +
						rs.data.userNickname
				});
			}
		})

	}

	function scanQRCode() {
		uni.scanCode({
			success: (res) => {
				console.log('扫描结果：' + res.result);

				let result = JSON.parse(res.result)

				if (result.type == 'ADDFRIEND') {
					uni.navigateTo({
						url: `/pages/news/addFriend?account=${result.account}`
					});
					return
				}

				getUserInfos(res.result)
			},
			fail: (err) => {
				console.error('扫描失败：' + err);
				uni.showToast({
					title: '扫描失败',
					icon: 'none'
				});
			}
		});
	}

	// 实名跳转
	function link(url) {
		// 验证
		util.isAuth({
			success: rs => {
				uni.navigateTo({
					url,
				})
			},
		})
	}

	// 
	defineExpose({
		open,
		close,
	})
</script>

<template>
	<uni-popup ref="leftMenu" type="left">
		<view class="leftMenuAlt f1 plr30">
			<!-- 状态条 -->
			<statusBar />
			<!-- 扫一扫 -->
			<view class="df fdr jcr aic mtb30">
				<uni-icons type="scan" size="40rpx" />
				<text class="ml10 c333 f24" @click="scanQRCode">扫一扫</text>
			</view>

			<!-- 菜单列表 -->
			<view class="menuList mtb30 f1">
				<scroll-view scroll-y="true" class="scroll f1" :show-scrollbar="false">
					<view class="list">

						<navigator url="/pages/index/wallet/wallet" class="item df fdr aic mtb15 ptb40 plr30 bfff br20"
							hover-class="none">
							<image class="wh80 mr25" src="/static/leftMenu1.png" mode="aspectFit" />
							<text class="text f1 c333 f28">我的钱包</text>
						</navigator>

						<template v-if="util.config.showVivo">
							<navigator url="/pages/index/integralMall"
								class="item df fdr aic mtb15 ptb40 plr30 bfff br20" hover-class="none">
								<image class="wh80 mr25" src="/static/leftMenu2.png" mode="aspectFit" />
								<text class="text f1 c333 f28">卷轴积分</text>
							</navigator>

							<navigator url="/pages/index/durian" class="item df fdr aic mtb15 ptb40 plr30 bfff br20"
								hover-class="none">
								<image class="wh80 mr25" src="/static/leftMenu3.png" mode="aspectFit" />
								<text class="text f1 c333 f28">榴莲果树</text>
							</navigator>

							<view @click="link('/pages/index/myTeam')"
								class="item df fdr aic mtb15 ptb40 plr30 bfff br20">
								<image class="wh80 mr25" src="/static/leftMenu5.png" mode="aspectFit" />
								<text class="text f1 c333 f28">我的团队</text>
							</view>
						</template>

						<view @click="link('/pages/index/myQrCode')"
							class="item df fdr aic mtb15 ptb40 plr30 bfff br20">
							<image class="wh80 mr25" src="/static/leftMenu6.png" mode="aspectFit" />
							<text class="text f1 c333 f28">邀请好友分享APP</text>
						</view>

						<!-- <navigator url="/pages/shop/settle" class="item df fdr aic mtb15 ptb40 plr30 bfff br20">
							<image class="wh80 mr25" src="/static/leftMenu7.png" mode="aspectFit" />
							<text class="text f1 c333 f28">商家入驻</text>
						</navigator> -->

						<!-- 	<view class="item df fdr aic mtb15 ptb40 plr30 bfff br20">
							<image class="wh80 mr25" src="/static/leftMenu9.png" mode="aspectFit" />
							<text class="text f1 c333 f28">联系客服</text>
						</view>

						<view class="item df fdr aic mtb15 ptb40 plr30 bfff br20">
							<image class="wh80 mr25" src="/static/leftMenu8.png" mode="aspectFit" />
							<text class="text f1 c333 f28">九亿打车</text>
						</view> -->

					</view>
				</scroll-view>
			</view>
		</view>
	</uni-popup>
</template>

<style lang="scss" scoped>
	// 左侧菜单弹窗
	.leftMenuAlt {
		width: 600rpx;
		background-color: #F4F4F4;
	}
</style>