<template>
	<view class="container">
		<view class="img-box">
			<view class="img">
				<image class="qrcode" :src="imgurl" mode="widthFix"  lazy-load :show-menu-by-longpress="true"></image>
			</view>
			
		</view>
	</view>
</template>

<script>
	import { getAppContactWay } from "@/api/user.js"
	export default {
		data() {
			return {
				baseUrl:uni.getStorageSync('requestPath'),
				userId:null,
				imgurl: ''
			}
		},
		onLoad(options) {
			this.userId=options.userId || uni.getStorageSync('userId');
			console.log(options.userId)
			this.getQRCode()
		},
		methods: {
			getQRCode() {
				getAppContactWay(this.userId).then(res=>{
					if(res.code==200){
						this.imgurl = res.data || ''
					} else {
						uni.showToast({
							title: res.msg,
							icon: ''
						})
					}
				})
			},
			downImg() {
				uni.showLoading({
					title: "图片保存中..."
				})
				uni.downloadFile({
					url: this.imgurl,
					fail: function(res) {
					  uni.showModal({
						title: '提示',
						content: '保存失败',
					  })
					  uni.hideLoading();
					},
					success: function(res) {
						var tempFilePath = res.tempFilePath;
						uni.saveImageToPhotosAlbum({
							filePath: tempFilePath,
							success:()=> {
							  uni.showToast({
								title: "保存成功",
								duration: 2000
							  })
							},
							fail:()=>{
							  console.log("图片失败");
							  uni.showToast({
									title: "图片失败",
									duration: 2000,
									icon: "error"
							  })
							  uni.hideLoading();
							},
							complete: function() {
							  uni.hideLoading();
							}
						})
					},
				})
			}
		}
	}
</script>

<style lang="scss">
	.container {
		padding: 15rpx;
		.img-box{
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;
			height:100%;
			.img{
				width: 100%;
				height:100%;
				position: relative;
				.qrcode{
					width: 100%;
					height:100%;
					image{
						width: 100%;
						height:100%;
					}
				}
				
			}
			
			
		}
	}
	 
</style>