<template>
	<view class="content">
		<view id="poster" class="poster">
			<view class="top">
				<view class="top-cont">
					<image class="top-cont-img" src="https://cdn.douhuofalv.com/images/2023/04/24/a45643fc33ca42b7a430aee573a93da4.png" mode="widthFix"></image>
					<!-- <view class="top-cont-name">法律咨询服务包</view> -->
				</view>
				<image class="top-img" src="https://cdn.douhuofalv.com/images/2023/04/20/2ea5fc20ffc90e7feec7ba2650b81c99.png" mode="widthFix"></image>
			</view>
			<!-- <image class="backImg" src="https://cdn.douhuofalv.com/55a3e41ea916f770bb1be3864af.png" mode="widthFix"></image> -->
			<view class="confirm">
				<view class="confirm-white">
					<view class="confirm-top">订单号 {{seekData.order_no}}</view>
					<view class="confirm-list">
						<view class="confirm-item" v-for="(item, index) in seekData.params">
							<view class="confirm-item-label">{{item.title}}</view>
							<view class="confirm-item-text" v-if="item.key == 'address'">{{item.value_text.province_name}}{{item.value_text.city}}</view>
							<view class="confirm-item-text" v-else><text v-if="item.key == 'price'">￥</text> {{item.value_text}}</view>
						</view>
						<view class="confirm-item" v-if="seekData.lawyer">
							<view class="confirm-item-label">所属律师</view>
							<view class="confirm-item-text">{{seekData.lawyer.name}}</view>
						</view>
					</view>
					
					<view class="confirm-user">
						<view class="confirm-user-text"><image src="https://cdn.douhuofalv.com/images/2023/04/20/c359f2fa277e6658157c7108f37d0d44.png" mode="widthFix"></image> 业务联系人</view>
						<view class="confirm-user-name">{{parent.nickname}}</view>
					</view>
					<view class="confirm-user" v-if="seekData.center_user">
						<view class="confirm-user-text"><image src="https://douhuo-storage.oss-cn-beijing.aliyuncs.com/images/2023/06/15/e49b01d43843a4e32b1f7a45473c88a7.png" mode="widthFix"></image> 运营中心</view>
						<view class="confirm-user-name">{{seekData.center_user}}</view>
					</view>
				</view>
				
				<view class="idcardBtn">
					<view class="idcardBtn-go" @click="shareClick">保存图片</view>
				</view>
			</view>
			
			<!-- 打卡海报 -->
			<view class="postertBack" v-if="isImgLay"></view>
			<view class="postert" v-if="isImgLay">
				<view class="poster-Cont">
					<image class="poster-Cont-img" :src="posterImg" mode="widthFix"></image>
				</view>
				<view class="sign-btn">
					<view class="remove-btn">长按图片保存</view>
					<view class="sign-img-block">
						<button class="sign-img-btn" size="mini" @click="isImgLay = false">取消</button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { VueCanvasPoster } from 'vue-canvas-poster'
	import { seekOrderSee } from '@/apis/interfaces/synthesis'
	import html2canvas from 'html2canvas';
	export default {
		components: {
		    VueCanvasPoster
		},
		data() {
			return {
				seekData  : '', // 咨询详情数据
				parent    : '', // 联系人
				isImgLay  : false,
				posterImg: "", //生成的海报图片路径
			}
		},
		
		created() {
			// 获取综法咨询-咨询详情
			this.getBusiness();
		},
		
		methods: {
			// 综法咨询-咨询详情
			getBusiness(){
				seekOrderSee(this.$Route.query.synthesisId).then(res => {
					this.seekData = res
					this.parent   = res.user.parent
				}).catch(err => {
					uni.showToast({
						title: err.message,
						icon : 'none'
					})
				})
			},
			
			// 保存图片
			shareClick() {
				html2canvas(document.querySelector("#poster"), {
				      allowTaint: true,
				      backgroundColor: "white",
				      useCORS: true, //支持图片跨域
				      scale: 1,
				    }).then((canvas) => {
						this.isImgLay = true
						this.posterImg = canvas.toDataURL('image/png')
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background-image: linear-gradient(to bottom,#041f79, #111e4b);
		width: 100vw;
		height: 100%;
		overflow-y: scroll;
		position: fixed;
	}
	
	.poster {
		background-image: linear-gradient(to bottom,#041f79, #111e4b);
	}
	
	.top {
		position: relative;
		height: 320rpx;
		z-index: 4;
		.top-img {
			position: absolute;
			right: 0;
			top: 0;
			width: 35%;
		}
		.top-cont {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			padding: 80rpx 30rpx 0;
			box-sizing: border-box;
			text-align: center;
			.top-cont-name {
				font-weight: 600;
				font-size: 74rpx;
				background-image: linear-gradient(to right,#f1c694, #fffbf6 70%);
				background-image: -webkit-linear-gradient(to right,#f1c694, #fffbf6 70%);
				-webkit-background-clip:text; 
				-webkit-text-fill-color:transparent;
				margin-bottom: 10rpx;
			}
			.top-cont-img {
				width: 90%;
				margin-bottom: 15rpx;
			}
		}
	}
	
	.backImg {
		width: 100%;
		position: absolute;
		left: 0;
		top: 0;
	}
	
	.confirm {
		padding: 0 30rpx 30rpx;
		box-sizing: border-box;
		position: relative;
		top: 0;
		left: 0;
		z-index: 9;
		width: 100%;
		.confirm-white {
			border-radius: 15rpx;
			background-color: #ffffff;
			position: relative;
			&::after {
				content: '';
				position: absolute;
				width: calc(100% - 80rpx);
				height: 60rpx;
				background-color: rgba(255, 255, 255, .3);
				bottom: -30rpx;
				left: 40rpx;
				border-radius: 0 0 15rpx 15rpx;
			}
			&::before {
				content: '';
				position: absolute;
				width: calc(100% - 160rpx);
				height: 120rpx;
				background-color: rgba(255, 255, 255, .1);
				bottom: -60rpx;
				left: 80rpx;
				border-radius: 0 0 15rpx 15rpx;
			}
			.confirm-top {
				background-color: #f7faff;
				border-radius: 15rpx 15rpx 0 0;
				line-height: 110rpx;
				padding: 0 30rpx;
				box-sizing: border-box;
				font-weight: 600;
				font-size: 34rpx;
			}
			.confirm-list {
				padding: 10rpx 30rpx;
				box-sizing: border-box;
				.confirm-item {
					display: flex;
					line-height: 40rpx;
					padding: 20rpx 0;
					.confirm-item-label {
						flex: 1;
						width: 200rpx;
					}
					.confirm-item-text {
						text-align: right;
						width: calc(100% - 200rpx);
					}
				}
			}
			.confirm-user {
				border-top: 2rpx solid #eeeeee;
				line-height: 110rpx;
				display: flex;
				padding: 0 30rpx;
				box-sizing: border-box;
				font-weight: 600;
				font-size: 34rpx;
				color: #041f79;
				.confirm-user-text {
					flex: 1;
					display: flex;
					image {
						width: 32rpx;
						margin: 40rpx 15rpx 0 0;
					}
				}
			}
		}
		
		// 按钮
		.idcardBtn {
			width: 100%;
			display: flex;
			margin-top: 120rpx;
			padding-bottom: 100rpx;
			.idcardBtn-go {
				flex: 2;
				margin: 0 15rpx;
				background-image: linear-gradient(to bottom, #fff2d2, #f9cd9e);
				color: #582700;
				font-weight: 600;
				font-size: 36rpx;
				border-radius: $radius * 3;
				height: 94rpx;
				line-height: 94rpx;
				box-shadow: 0 6rpx 10rpx rgba(0, 0, 0, .5);
				text-align: center;
			}
		}
	}
	
	.postertBack {
	    width: 100vw;
	    height: 100vh;
	    position: fixed;
	    background-color: rgba(0,0,0,.6);
	    left: 0;
	    top: 0;
	    z-index: 9990;
	}
	.postert {
	    width: 100vw;
	    height: 100vh;
	    position: fixed;
	    left: 0;
	    top: 0;
	    z-index: 9999;
	    .poster-Cont {
			background-color: #111e4b;
	        width: 80vw;
	        height: 55vh;
	        top: 20vh;
	        left: 10vw;
	        position: absolute;
	        box-sizing: border-box;
	        border-radius: $radius-m;
			overflow: hidden;
	        .poster-Cont-img {
	            width: 100%;
	            height: 100%;
	        }
			.poster-Cont-code {
				position: absolute;
				bottom: 250px;
				left: 46px;
				width: 140rpx;
				height: 140rpx;
			}
	    }
	}
	
	.sign-btn {
	    position: absolute;
	    top: 78vh;
	    width: 80%;
	    left: 10%;
	    z-index: 9999;
	    .remove-btn {
	        width: 100%;
	        line-height: 90rpx;
	        background-color: #bf9960;
	        color: #FFFFFF;
	        border-radius: $radius-m;
	        margin-top: $margin - 10;
	        text-align: center;
	        font-size: $title-size + 2;
	    }
	    .sign-img-block {
	        display: flex;
	        margin: 30rpx -10rpx 0;
	        .sign-img-btn {
	            flex: 2;
	            line-height: 90rpx;
	            background-color: #ffeeda;
	            border-radius: $radius-m;
	            text-align: center;
	            font-size: $title-size;
	            margin: 0 10rpx;
	        }
	    }
	}
</style>