<template>
	<view class="">
		<!-- 分享信息 -->
		<view>
			<uni-popup ref="sharewx" type="bottom" backgroundColor="#fff">
				<view class="popup-content">
					<view class="shareBox">
						<view class="shareOptionItem" @click="uniShare(1)">
							<view class="imgBox">
								<image src="../../static/app-plus/sharemenu/wechatfriend.png" mode="widthFix"></image>
							</view>
							<text>微信好友</text>
						</view>
						<view class="shareOptionItem" @click="uniShare(2)">
							<view class="imgBox">
								<image src="../../static/app-plus/sharemenu/wechatmoments.png" mode="widthFix"></image>
							</view>
							<text>分享朋友圈</text>
						</view>
					</view>
				</view>
				<view class="popup-footer" @click="closeShare()">
					<view>取消</view>
				</view>
			</uni-popup>
		</view>

	</view>
</template>

<script>
	import api from "@/api/api";
	import {
		nanoid
	} from 'nanoid';
	export default {
		data() {
			return {
				WXdata: {}
			}
		},
		methods: {
			open(option) {
				console.log(option, 155)
				this.WXdata = option
				this.$refs.sharewx.open()
				this.share()
			},
			share() {

			},
			// 关闭微信分享啊
			closeShare() {
				this.$refs.sharewx.close()
			},
			uniShare(type) {
				let that = this
				this.closeShare()
				this.submitsuessc(type)
				uni.share({
					provider: "weixin",
					scene: type === 1 ? "WXSceneSession" : "WXSceneTimeline",
					type: 0,
					href: that.WXdata.href,
					title: that.WXdata.title,
					summary: that.WXdata.summary,
					imageUrl: that.WXdata.imageUrl,
					success: function(res) {
						console.log(res, 155)
				
					},
					fail: function(err) {
						console.log("fail:" + JSON.stringify(err));
					}
				});
				// if (type === 1) {
				// let that = this;
				// 			uni.downloadFile({
				// 				url: that.WXdata.imageUrl,
				// 				success: function(images) {
				// 					console.log(images, 1147474)
				// 					uni.compressImage({
				// 						src: images.tempFilePath,
				// 						quality: 20,
				// 						width:  '60%',
				// 						height: '60%',
				// 						success: (res) => {
				// 							console.log('ok--->' + res.tempFilePath);
				// 							that.WXdata.tempImg = res.tempFilePath;		


				// 						}	
				// 					})		
				// 				},
				// 				fail(error) {
				// 					uni.hideLoading();		
				// 				}	
				// 			})	
				// 			}
			},
			submitsuessc(type){
				let platform = uni.getSystemInfoSync().platform
				let that = this
				let UserShareRequestVO = {
					systemType: platform == 'ios'? '1': '0',
					userId: uni.getStorageSync('cffp_userId'),
					businessType: '1', // 分享类型
					businessId: that.WXdata.fileId, // 课程Id
					shareUrl: that.WXdata.href, // 分享链接
					shareType: '2', // 分享类型(1:图片分享; 2:链接分享)
					shareToWhere: type, //分享到哪儿（1好友 2朋友圈）
					shareCode: that.WXdata.shareCode
				}
				api.userShare(UserShareRequestVO).then(res => {
					console.log(res, 1251)
					// console.log('分享成功了吗')
					if (res['success']) {
						// uni.showToast({
						// 	title: '分享成功',
						// 	duration: 2000
						// });
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.popup-footer {
		color: #666;
		font-size: 36rpx;
		border-top: 2rpx solid #f0f0f0;
		display: flex;
		justify-content: center;
		align-items: center;
		padding-top: 36rpx;
	}

	.popup-content {
		font-size: 32rpx;
		color: #666;
		padding-bottom: 40rpx;

		.shareBox {
			display: flex;
			justify-content: space-around;
			align-items: center;

			.shareOptionItem {
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;

				.imgBox {
					width: 100rpx;
				}
			}

		}
	}
</style>
