<template>
	<view class="registerCode">
		<view class="registerImg">
			<image :src="qrCodeUrl+'/customer/getQrCode?appid='+appid+'&page=pages/mine/registerForm&scene='+projectId" mode=""></image>
		</view>
		<view class="registerBtn" @click="down">
			保存图片到手机
		</view>
	</view>
</template>

<script>
	let domain = require("@/utils/domain")
	export default {
		data() {
			return {
				qrCodeUrl: "",
				projectId:"",
				appid:"",
			};
		},
		onShow() {
			this.projectId = uni.getStorageSync('buildingID').id;
			this.appid = uni.getAccountInfoSync().miniProgram.appId;
			this.qrCodeUrl = domain.baseUrl;
		},
		methods: {
			down() {
				let url = this.qrCodeUrl+'/customer/getQrCode?appid='+this.appid+'&page=pages/mine/registerForm&scene='+this.projectId
				console.log(url)
				uni.getImageInfo({
					src:url,
					success: (res) => {
						console.log(res)
						uni.saveImageToPhotosAlbum({
							filePath:res.path,
							success: () => {
								uni.showToast({
									title: "保存成功",
									icon: "none"
								})
							},
							fail: () => {
								uni.showToast({
									title: "保存失败",
									icon: "none"
								})
							}
						})
					}
				})
				
			// 	uni.getSetting({
			// 		success:(res)=> {
			// 			if(Object.keys(res.authSetting).length>0){
			// 				if(res.authSetting['scope.writePhotosAlbum']==undefined){
			// 					uni.openSetting({
			// 						success: (res) => {
			// 							console.log("设置权限1",res.authSetting)
			// 						}
			// 					})
			// 				}else{
			// 					if(!res.authSetting['scope.writePhotosAlbum']){
			// 						uni.openSetting({
			// 							success: (res) => {
			// 								console.log("设置权限1",res.authSetting)
			// 							}
			// 						})
									
			// 					}
			// 				}
			// 			}else{
			// 				return
			// 			}
			// 		}
			// 	})
			
			
			// 	uni.downloadFile({
			// 		url,
			// 		success: (res) => {
			// 			console.log(res)
			// 			uni.downloadFile({
			// 				url, //图片地址
			// 				success: (res) => {
			// 					console.log('downloadFile success', res)
			// 					if (res.statusCode === 200) {
			// 						console.log('downloadFile res.statusCode === 200', res)
			// 						uni.saveImageToPhotosAlbum({
			// 							filePath: res.tempFilePath,
			// 							success: function() {
			// 								uni.showToast({
			// 									title: "保存成功",
			// 									icon: "none"
			// 								})
			// 							},
			// 							fail: function() {
			// 								uni.showToast({
			// 									title: "保存失败",
			// 									icon: "none"
			// 								})
			// 							}
			// 						})
			// 					} else {
			// 						console.log('downloadFile res.statusCode !== 200', res)
			// 					}
			// 				}
			// 			})
			// 		}
			// 	});
			
			}
		},
	}
</script>

<style lang="scss">
	.registerCode {
		.registerImg {
			width: 300rpx;
			height: 300rpx;
			margin: 130rpx auto;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.registerBtn {
			width: 80%;
			height: 80rpx;
			background: #3384fd;
			color: #FFFFFF;
			border-radius: 10rpx;
			line-height: 80rpx;
			text-align: center;
			font-size: 30rpx;
			margin: 50rpx auto;
		}
	}
</style>
