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

<script>
	let domain = require("@/utils/domain")
	export default {
		data() {
			return {
				qrCodeUrl: ""
			};
		},
		methods: {
			down() {
				let url = this.qrCodeUrl + '/customer/getQrCode?pageUrl=pages/index/index'
				console.log(url)
				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)
								}
							}
						})
					}
				});
			}
		},
		onLoad() {
			this.qrCodeUrl = domain.baseUrl
			// let urlData = {
			// 	page:'pages/mine/registerForm',
			// 	scene:'556',
			// 	width:300
			// }
			// uni.request({
			// 	url:this.qrCodeUrl + '/customer/getQrCode',
			// 	method:"POST",
			// 	data:urlData,
			// 	success(res) {
			// 		console.log(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>
