<template>
	<view class="column hidden" style="height: 100%;">
		<!-- <view class="p20 bgf" style="z-index: 999;">
			<u-subsection class="subsection" :list="list" :current="current" bgColor="#e7f1fe" activeColor="#1677ff"
				:fontSize="15" :bold="false" @change="sectionChange" ></u-subsection>
		</view>
		<living v-if="current==0" style="margin-top: -240rpx;"></living> -->
		<liveCourse @child-data-update="onChildDataUpdate" :parent-method="handleParentMethod"></liveCourse>
	</view>
</template>

<script>
	import liveCourse from "@/components/liveCourse.vue"
	import living from "@/components/living.vue"
	export default {
		components: {
			living,
			liveCourse
		},
		data() {
			return {
				list: [{
					name: '直播课',
				}, {
					name: '训练营'
				}],
				current:0,
				childdata:[]
			}
		},
		onLoad() {
			wx.showShareMenu({
			      withShareTicket: true, // 支持群聊分享带shareTicket
			      menus: ['shareAppMessage'] // 同时启用两种分享
			    })
		},
		mounted() {
		},
		methods: {
			handleParentMethod() {
			      uni.showToast({ title: '父组件方法被调用' });
				  if (!this.childdata || Object.keys(this.childdata).length === 0) {
				          uni.showToast({ title: '数据未准备好，无法分享', icon: 'none' });
				          return;
				      }
					  this.$nextTick(()=>{
						  setTimeout(()=>{
								  uni.share({
										  provider: 'weixin',
										  scene: 'WXSceneSession', // 分享到会话
										  type: 0,
										  title: this.childdata.title,
										  path: this.childdata.path+"?course="+this.childdata.params,
										  imageUrl: this.childdata.img,
										  success: (res) => {
											console.log('分享成功', res);
											uni.showToast({
											  title: '分享成功',
											  icon: 'none'
											});
										  },
										  fail: (err) => {
											console.log('分享失败', err);
											uni.showToast({
											  title: '分享失败，请稍后再试',
											  icon: 'none'
											});
										  }
										});
						  },200)
					  })
				  
				 
			    },
			onChildDataUpdate(data){
				this.childdata=data
				console.log('父组件',data)
			},
			onShareAppMessage() {
			    return {
			      title:this.childdata.title ,  // 分享卡片标题
			      path:this.childdata.path+"?course="+this.childdata.params, // 目标页面路径
			      // 携带参数：将当前页面的数据拼接到路径中
			      imageUrl: this.childdata.img, // 分享卡片封面图（可选）
			      success: (res) => {
			        console.log("分享成功", res);
			      },
			      fail: (err) => {
			        console.log("分享失败", err);
			      },
				}
			},
			sectionChange(index){
				this.current=index
			}
		}
	}
</script>

<style lang="scss">
	
</style>