<template>
	<view>
		<view class="page dis f-c a-c" id="panelcanvas">
			<view class="quotation-header dis a-c">
				<image :src="caricon" class="image-icon" mode=""></image>
				<view class="dis f-c j-c">
					<text>{{dataInfo.licenseno}}</text>
					<text>{{carinfo.modelcname}}</text>
				</view>
			</view>
			<view class="quotation-data">
				<view class="circulate-impany dis a-c">
					<image :src="logoimg" mode="" style="width: 30px;height: 30px;">
					</image>
					<text>{{dataInfo.inscompany}}报价单</text>
				</view>
				<view class="circulate-data dis a-c">
					<text>订单号：</text>
					<text>{{dataInfo.orderno}}</text>
				</view>
				<view class="circulate-data dis a-c">
					<text>车主姓名：</text>
					<text>{{ownerinfo.name}}</text>
				</view>
				<view class="circulate-data dis a-c">
					<text>投保人姓名：</text>
					<text>{{applyinfo.name}}</text>
				</view>
				<view class="circulate-data dis a-c">
					<text>被保人姓名：</text>
					<text>{{insureinfo.name}}</text>
				</view>
				<view class="circulate-data dis a-c">
					<text>发动机号：</text>
					<text>{{carinfo.engineNo}}</text>
				</view>
				<view class="circulate-data dis a-c">
					<text>车架号：</text>
					<text>{{carinfo.vinNo}}</text>
				</view>
				<view class="circulate-data dis a-c">
					<text>座位数：</text>
					<text>{{carinfo.seatCount}}</text>
				</view>
				<view class="circulate-data dis a-c " v-if="dataInfo.jqstartdate">
					<text>交强投保时间：</text>
					<text>{{ dataInfo.jqstartdate }}</text>
				</view>
				<view class="circulate-data dis a-c " v-if="dataInfo.systartdate">
					<text>商业投保时间：</text>
					<text>{{ dataInfo.systartdate }}</text>
				</view>
				<view class="coverage dis j-s f-c" style="border: none;" v-if="dataInfo.sypremium">
					<view class="coverage-title dis">
						<view style=" width: 46%;">
							<text>商业险金额</text>
						</view>
						<view style=" width: 27%;">
							<text>保险金额</text>
						</view>
						<view style=" width: 27%;">
							<text>保费</text>
						</view>
					</view>
					<view class="coverage-sum dis j-s" v-for="(item,index) in dataInfo.kindinfo" :key="index">
						<view style=" width: 46%;">
							<text>{{item.kindName}}</text>
						</view>
						<view v-if="['D4', 'SY_FJ_YBW2'].includes(item.kindCode)">
							<text>{{item.unitAmount}}/座*{{dataInfo.carinfo.seatCount-1}}</text>
						</view>
						<view v-else-if="['MJ1', 'MJ2', 'MJ3', 'MJ4'].includes(item.kindCode)">
							<text>{{item.deductibleRate}}</text>
						</view>
						<view v-else-if="['TY1', 'TY2', 'TY3', 'TY4'].includes(item.kindCode)">
							<text>{{item.serviceTimes}}/次</text>
						</view>
						<view v-else>
							<text>{{item.amount}}</text>
						</view>
						<view>
							<text>￥{{item.coveragePremium}}</text>
						</view>
					</view>
				</view>
				<view class="circulate-sum dis f-c ">
					<view class=" dis j-s " v-if="dataInfo.jqpremium">
						<view>交强险:</view>
						<view>￥{{dataInfo.jqpremium}}</view>
					</view>
					<view class=" dis j-s " v-if="dataInfo.taxamount">
						<view>车船税:</view>
						<view>￥{{dataInfo.taxamount}}</view>
					</view>
					<view class=" dis j-s " v-if="dataInfo.jypremium">
						<view>驾意险:</view>
						<view>￥{{dataInfo.jypremium}}</view>
					</view>
					<view class=" dis j-s " v-if="dataInfo.sypremium">
						<view>商业险:</view>
						<view>￥{{dataInfo.sypremium}}</view>
					</view>
					<view class=" dis j-s " v-if="dataInfo.jqdiscountrate">
						<view>交强险优惠比例:</view>
						<view>{{dataInfo.jqdiscountrate}}%</view>
					</view>
					<view class=" dis j-s " v-if="dataInfo.sydiscountrate">
						<view>商业险优惠比例:</view>
						<view>{{dataInfo.sydiscountrate}}%</view>
					</view>
					<view class=" dis j-s ">
						<view>应缴金额:</view>
						<view style="color:#2D4D89;font-weight: 600;">￥{{dataInfo.sumpremium}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class=" dis a-c j-s" style="padding: 16px;">
			<u-button type="primary" style="width: 100%;background: #2D4D89;" @click="sendPayCode">发送到微信</u-button>
			<!-- <button type="default" @tap="sendPayCode">发送到微信</button> -->
		</view>
	</view>
</template>

<script>
	import {
		pathToBase64,
		base64ToPath
	} from '@/common/pdf.js'
	export default {
		data() {
			return {
				payImg: "",
				posterUrl: "",
				caricon: "", //carlogo
				show: false,
				companyId: "",
				dataInfo: {},
				carinfo: {}, //车辆信息
				ownerinfo: {}, //车主信息
				applyinfo: {}, //投保人信息
				insureinfo: {}, //被保人信息
				insCompanyList: [{
						name: "中煤财险",
						icon: "../../static/insuranceicon/zhongmei.png"
					}, //华农
					{
						name: "恒邦财险",
						icon: "../../static/insuranceicon/hengbang.png"
					},
					{
						name: "安盛天平",
						icon: "../../static/insuranceicon/ansheng.png"
					},
					{
						name: "中国人寿",
						icon: "../../static/insuranceicon/renshou.png"
					},
					{
						name: "众安财险",
						icon: "../../static/insuranceicon/zhongan.png"
					},
					{
						name: "永诚财险",
						icon: "../../static/insuranceicon/yongcheng.png"
					},
					{
						name: "永安财险",
						icon: "../../static/insuranceicon/yongan.png"
					},
					{
						name: "紫金财险",
						icon: "../../static/insuranceicon/zijin.png"
					},
					{
						name: "国任财险",
						icon: "../../static/insuranceicon/guoren.png"
					},
					{
						name: "华泰财险",
						icon: "../../static/insuranceicon/huatai.png"
					},
					{
						name: "大家财险",
						icon: "../../static/insuranceicon/dajia.png"
					},
					{
						name: "太平财险",
						icon: "../../static/insuranceicon/taiping.png"
					},
					{
						name: "华农财险",
						icon: "../../static/insuranceicon/huanong.png"
					},
					{
						name: "泰康财险",
						icon: "../../static/insuranceicon/taikang.png"
					},
				],
				logoimg: "",
			}
		},
		async onLoad(options) {
			this.companyId = options.companyId;
			let params = {
				companyId: options.companyId
			};
			let res = await this.$http.post('/insurance/order/getByCompanyId', params);
			var data = res.data;
			data.kindinfo.map((ele, index) => {
				switch (ele.kindCode) {
					case "A":
						if (ele.amount == 1) {
							ele.amount = "投保"
						} else {
							ele.amount = ele.amount
						}
						break;
					case "D4":
					case "SY_FJ_YBW2":
						ele.unitAmount = this.toChinesNum(ele.unitAmount);
						break;
					case "MJ1":
					case "MJ2":
					case "MJ3":
					case "MJ4":
						ele.deductibleRate = ele.deductibleRate + "%";
						break;
					default:
						ele.amount = this.toChinesNum(ele.amount);
				}
				return ele;
			});
			this.insCompanyList.map(ele => {
				if (ele.name == data.inscompany) {
					uni.getImageInfo({
						src: ele.icon,
						success: image => {
							pathToBase64(image.path)
								.then(base64 => {
									this.logoimg = base64;
								})
								.catch(error => {});
						},
						fail: err => {}
					});
				}
				return ele;
			})
			this.dataInfo = data;
			this.carinfo = data.carinfo;
			this.ownerinfo = data.ownerinfo;
			this.applyinfo = data.applyinfo;
			this.insureinfo = data.insureinfo;
			uni.getImageInfo({
				src: '../../static/icon/Group@2x.png',
				success: image => {
					pathToBase64(image.path)
						.then(base64 => {
							this.caricon = base64
						})
						.catch(error => {});
				},

			});
		},
		methods: {
			//本地图片转换成base64
			turnBase64Image() {
				this.
				uni.getImageInfo({
					src: img,
					success: image => {
						pathToBase64(image.path)
							.then(base64 => {
								this[key] = base64;
							})
							.catch(error => {});
					},
					fail: err => {}
				});
			},
			toChinesNum(num) {
				let overWan = Math.floor(num / 10000);
				let result = overWan + "万";
				return result;
			},
			//分享图片到微信
			sendPayCode() {
				if (this.payImg) {
					uni.share({
						provider: "weixin",
						scene: "WXSceneSession",
						type: 2,
						imageUrl: this.payImg
					})
				}
			},
			//页面截图转路径
			receiveRenderData(val) {
				this.posterUrl = val.replace(/[\r\n]/g, ''); // 去除base64位中的空格
				const imageStr = this.posterUrl;
				// 将base64转化为临时地址
				base64ToPath(imageStr).then(path => {
					this.payImg = path
				}).catch(error => {});
			},
			showLoading() {
				uni.showLoading({
					title: '正在生成图片'
				});
			},

			hideLoading() {
				uni.hideLoading();
			},
		},
	}
</script>
<script module="canvasImage" lang="renderjs">
	import html2canvas from 'html2canvas'
	export default {
		data() {
			return {

			}
		},
		mounted() {
			// #ifdef APP-PLUS
			setTimeout(() => {
				this.canvasImage.generateImage()
			}, 1000);
			// #endif


		},
		methods: {
			// #ifdef APP-PLUS
			generateImage() {
				setTimeout(() => {
					this.$ownerInstance.callMethod('showLoading')
					const dom = document.getElementById('panelcanvas') // 需要生成图片内容的 dom 节点
					html2canvas(dom, {
						width: dom.clientWidth, //dom 原始宽度
						height: dom.clientHeight,
						scrollY: 0, // html2canvas默认绘制视图内的页面，需要把scrollY，scrollX设置为0
						scrollX: 0,
						useCORS: true, //支持跨域
						// allowTaint: false,
						scale: 2, // 设置生成图片的像素比例，默认是1，如果生成的图片模糊的话可以开启该配置项
					}).then((canvas) => {
						// 生成成功
						this.$ownerInstance.callMethod('hideLoading')
						this.$ownerInstance.callMethod('receiveRenderData', canvas.toDataURL('image/png'))
					}).catch(err => {
						// 生成失败 弹出提示弹窗
						this.$ownerInstance.callMethod('_errAlert', `【生成图片失败，请重试】${err}`)
					})
				}, 300)
			}
			// #endif
		},
	}
</script>
<style lang="scss" scoped>
	@import '@/style/mixin.scss';

	.page {
		padding: 10px 16px;
		box-sizing: border-box;
	}

	.image-icon {
		width: 45px;
		height: 45px;
	}

	.quotation-header {
		width: 100%;
		height: 60px;
		background: rgba(45, 77, 137, 0.06);
		border-radius: 0px 0px 0px 0px;
		border: 1px dashed rgba(45, 77, 137, 0.2);
		padding: 10px;

		>view {
			padding: 10px;
			margin-left: 25px;

			text:first-child {
				color: #232832;
				font-weight: bold;
				font-size: 14px;
			}
		}

	}

	.quotation-data {
		width: 100%;
		margin-top: 10px;
		border: 1px solid #000000;

		.circulate-impany {
			height: 37px;
			padding: 8px 6px;
			background: rgba(45, 77, 137, 0.1);
			border-bottom: 1px solid #000000;
			font-weight: 700;
		}

		.circulate-data {
			height: 37px;
			color: #232832;
			padding: 8px 6px;
			border-bottom: 1px solid #000000;

			text:first-child {
				color: #232832;
				font-weight: bold;
				font-size: 14px;
			}

			text:last-child {
				color: rgba(35, 40, 50, 0.8);
				font-size: 14px;
			}
		}

		.coverage {
			.coverage-title {
				width: 100%;

				view:nth-child(1) {
					border-left: none;
					border-top: none;
				}

				view:nth-child(2) {
					border-top: none;
					border-left: none;
					border-right: none;
				}

				view:nth-child(3) {
					border-right: none;
					border-top: none;
				}

				view {
					text-align: center;
					background: #F8F8F8;
					color: #232832;
					padding: 6px;
					border: 1px solid #000;
					font-size: 12px;
					box-sizing: border-box;
				}

			}

			.coverage-sum {
				width: 100%;

				view:nth-child(1) {
					border-left: none;
				}

				view:nth-child(2) {
					border-left: none;
					border-right: none;
					width: 27%;
				}

				view:nth-child(3) {
					width: 27%;
					border-right: none;
				}

				view {
					text-align: center;
					font-size: 12px;
					background: #F8F8F8;
					color: #232832;
					padding: 6px;
					border: 1px solid #000;
					border-top: none;
				}
			}
		}

		.circulate-sum {
			padding: 10px;

			view {
				view:nth-child(1) {
					width: 70%;
					text-align: end;
				}

				view:nth-child(2) {
					width: 25%;
					text-align: start;
				}
			}
		}
	}

	.infoBottom {
		height: 140upx;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		background: #ea552d;
		border-top: 1upx solid #ea552d;
		z-index: 99;
		margin-top: 100px;
	}

	.infoBottom>button {
		// font-size: 30upx;
		background: #fff;
		color: #333;
		flex: 1;
		margin: 0upx 30px;
		font-weight: bold;
	}



	/* 底部的样式End */
</style>