<style lang="scss" scoped>
	@import url("@/asset/css/flex.css");
    .orcodeBox{
        background: #fff;
        border-radius: 8rpx;
    }
    .Title{
        
    }
    .orcodeImg img{
        width: 500rpx;
        height: 500rpx;
    }
    .SureBox{
        font-size: 28rpx;
        border-top: 1px solid #F2F2F2;
    }
    .SureBox view:last-child{
        color: #295EEB;
    }
    .SureBox view:first-child{
        border-right: 1px solid #ddd;
        color: #8C8C8C;
    }

</style>
<template>
     <u-popup mode="center" border-radius="20" 
        :popup="false" 
        v-model="currencyVisible" :maskCloseAble="true" 
        length="80%" :safeAreaInsetBottom="true" 
        @close="close" :z-index="9999">
        <view class="orcodeBox">
            <view class="Title PY30 color000 column justify-center items-center">
                <text class="fz28">领队小程序码（1/1）</text>
                <text class="fz24">KJKSWDGGHFHGV</text>
            </view>
            <view class="orcodeImg row items-center justify-center PX40">
                <img src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Upload/Goods/638868977886703780.png"/>
            </view>
            <view class="SureBox row MT40">
                <view class="flex1 PY20 text-center" @click="close">取消</view>
                <view class="flex1 PY20 text-center" @click="preservation">保存</view>
            </view>
        </view>
    </u-popup>
</template>
<script>
export default {
    props:['title'],
    data() {
        return {
            currencyVisible: true,
            textarea: '',
        }
    },
    watch: {
        title:{
            handler(newVal,oldVal){
                
            },
            deep: true,
            immediate:true,
        }
    },
    mounted() {
        this.currencyVisible = true
    },
    methods: {
        close(){
            this.currencyVisible = false
            this.$emit('close')
        },
        preservation(){
            uni.showLoading({
					title: "正在生成",
				});
				let that = this;
				uni.canvasToTempFilePath({
						canvasId: "firstCanvas",
						success: (res) => {
							uni.hideLoading();
							uni.showLoading({
								title: "正在保存",
							});
							uni.saveImageToPhotosAlbum({
								filePath: res.tempFilePath,
								success: function() {
									uni.showToast({
										title: "保存成功",
									});
								},
								fail: function(err) {
									if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
										uni.authorize({
											scope: 'scope.writePhotosAlbum',
											success: (res) => {
												console.log('11111');
											},
											fail: (res) => {
												uni.showModal({
													content: '检测到您没打开保存到相册权限，是否去设置打开？',
													confirmText: "确认",
													cancelText: '取消',
													success: (res) => {
														if (res.confirm) {
															uni.openSetting({
																success: (res) => {
																	console.log(res);
																	if (res.authSetting['scope.writePhotosAlbum']) {
																		that.preservation()
																	}
																}
															})
														} else {
															console.log('取消');
														}
													}
												})
											}
										})
									} else {
										that.$refs.uTips.show({
											title: "保存失败，请稍后重试",
											type: "error",
											duration: "2300",
										});
									}
								},
								complete: function() {
									uni.hideLoading();
								},
							});
						},
						fail: function(e) {
							console.log(e);
							that.$refs.uTips.show({
								title: "生成失败，请稍后重试",
								type: "error",
								duration: "2300",
							});
						},
					},
					this
				);
            
        },
    }
}
</script>