<template>
	<view class="page">
		<uni-nav-bar rightWidth='136rpx' title="邀请战队成员" fixed :border="false" statusBar backgroundColor="#24234B"
			color="#FFFFFF">
			<template #left>
				<view class="cl-topbar__icon" @click="navigateBack">
					<text class="cl-icon-arrow-left"></text>
				</view>
			</template>
		</uni-nav-bar>
		<view class="topBody">
			<image class="img" :src="myinfo.share_img" mode="aspectFill"></image>
			<view class="numlist">
				<view class="num" @click="sharePyq">
					<image src="http://c.yujianmate.com/images/v1/w3/share_pyq.png" mode="widthFix"></image>
					<view class="name">朋友圈</view>
				</view>
				<view class="num" @click="shareWx">
					<image src="http://c.yujianmate.com/images/v1/w3/share_wx.png" mode="widthFix"></image>
					<view class="name">微信好友</view>
				</view>
				<view class="num" @click="saveImg">
					<image src="http://c.yujianmate.com/images/v1/w3/share_down.png" mode="widthFix"></image>
					<view class="name">下载</view>
				</view>
			</view>
		</view>
		<!-- 提示框 -->
		<DialogBox ref="DialogBox"></DialogBox>
	</view>
</template>

<script>
	import uniNavBar from '../../components/uni-ui/uni-nav-bar/uni-nav-bar.vue'
	export default {
		components: {
			uniNavBar
		},
		data() {
			return {
				title: '',
				sel: 1,
				nodata: true,
				myinfo: {},
				list: [],
			}
		},
		onLoad() {
			// setTimeout(function() {
			// 	uni.setNavigationBarColor({
			// 		frontColor: '#ffffff',
			// 		backgroundColor: '#00000000',
			// 		animation: {
			// 			duration: 400,
			// 			timingFunc: 'easeIn'
			// 		}
			// 	})
			// }, 200);
			this.loadInfo();
		},
		onShow() {},
		methods: {
			navigateBack() {
				uni.navigateBack(1)
			},
			onBack() {},
			chkSel() {
				if (this.sel == 1) {
					this.sel = 0;
				} else {
					this.sel = 1;
				}
			},
			loadInfo() {
				console.log({
					uuid: getApp().globalData.uuid,
					skey: getApp().globalData.skey
				});
				uni.request({
					url: this.$apiHost + '/Web/getinfo',
					data: {
						uuid: getApp().globalData.uuid,
						type: 'tuan'
					},
					header: {
						"content-type": "application/json",
						'sign': getApp().globalData.headerSign
					},
					success: (res) => {
						console.log("----:", res.data);
						this.myinfo = res.data;
					},
					complete: (com) => {
						// uni.hideLoading();
					},
					fail: (e) => {
						console.log("----e:", e);
					}
				});
			},
			sharePyq() {
				let that = this;
				uni.share({
					provider: "weixin",
					scene: "WXSceneTimeline",
					type: 2,
					imageUrl: that.myinfo.share_img,
					success: function(res) {
						console.log("success:" + JSON.stringify(res));
					},
					fail: function(err) {
						console.log("fail:" + JSON.stringify(err));
					}
				});
			},
			shareWx() {
				let that = this;
				uni.share({
					provider: "weixin",
					scene: "WXSceneSession",
					type: 2,
					imageUrl: that.myinfo.share_img,
					success: function(res) {
						console.log("success:" + JSON.stringify(res));
					},
					fail: function(err) {
						console.log("fail:" + JSON.stringify(err));
					}
				});
			},
			saveImg() {
				// #ifdef APP-PLUS
				let that = this;
				uni.showLoading({
					title: '正在保存...',
				})
				uni.downloadFile({
					url: that.myinfo.share_img,
					success: (res) => {
						if (res.statusCode === 200) {
							uni.saveImageToPhotosAlbum({
								filePath: res.tempFilePath,
								success: function() {
									uni.showToast({
										title: '已保存到相册'
									});
								},
								fail: function(e) {
									uni.showToast({
										icon: 'none',
										title: '保存到相册失败'
									});
								},
								complete: function() {
									uni.hideLoading()
								}
							});
						} else {
							uni.showToast({
								icon: 'none',
								title: '邀请码下载失败'
							})
							uni.hideLoading()
						}
					},
					fail: function() {
						uni.showToast({
							icon: 'none',
							title: '邀请码下载错误'
						})
					},
					complete() {
						uni.hideLoading()
					}
				})

				// #endif
			}

		}
	}
</script>

<style scoped lang="scss">
	@import 'share_img.scss';
</style>