<template>
	<view class="content">
		<view class="qr-box position-relative">
			<view class="title-box">
				<view class="title">
					服务确认二维码
				</view>
				<view class="tip-text">
					请扫码核销
				</view>
			</view>
			<view class="qr-content flex-center">
				<uqrcode :loading='loading' :auto='false' :start='false' sizeUnit='rpx' ref="qrcode" canvas-id="qrcode"
					:value="item.verify_code" size="500"></uqrcode>
			</view>
			<view class="text-code">
				{{item.verify_code}}
			</view>
			<view class="tip-icon top-left"></view>
			<view class="tip-icon bottom-left"></view>
			<view class="tip-icon top-right"></view>
			<view class="tip-icon bottom-right"></view>
		</view>
		<view class="flex bottomBox">
			<view class="buttomBottom" @click="shopLi">
				联系商家
			</view>
			<view class="buttomBottom bgYellow" @click="shopNext">前往商家</view>
		</view>
	</view>
</template>

<script>
	import {
		orderDetail
	} from '@/api/order.js';
	export default {
		data() {
			return {
				orderId: '',
				item: {
					verify_code: ''
				},
				loading: true
			};
		},
		onLoad(option) {
			this.orderId = option.id;
			this.loadOrder();
		},
		methods: {
			// 载入订单详细
			loadOrder() {
				let obj = this;
				orderDetail({}, obj.orderId).then(e => {
					obj.item = e.data;
					obj.$refs.qrcode.make({
						success: () => {
							obj.loading = false;
							console.log('生成成功');
					 },
						fail: err => {
							console.log(err)
						}
					});
				});
			},
			// 联系商家
			shopLi() {
				uni.makePhoneCall({
					phoneNumber: this.item.system_store.phone //仅为示例
				});
			},
			// 前往商家
			shopNext() {
				// 打开地图导航
				uni.openLocation({
					latitude: +this.item.system_store.latitude,
					longitude: +this.item.system_store.longitude,
					fail(e) {
						console.log(e);
					}
				})
			},
		}
	};
</script>

<style lang="scss">
	page {
		background-color: $base-color;
	}

	.qr-box {
		color: $font-color-dark;
		background-color: #FFF;
		text-align: center;
		margin: 0 30rpx;

		.title-box {
			padding-top: 50rpx;
			padding-bottom: 30rpx;
			background-color: #F5F5F5;

			.title {
				font-weight: bold;
				font-size: 44rpx;
			}

			.tip-text {
				font-size: $font-sm;
				color: $font-color-light;
			}
		}

		.qr-content {
			padding-top: 110rpx;
		}

		.tip-icon {
			position: absolute;
			background-color: $base-color;
			border-radius: 99rpx;
			width: 100rpx;
			height: 100rpx;
		}

		.top-left,
		.bottom-left {
			left: -40rpx;
		}

		.top-right,
		.bottom-right {
			right: -40rpx;
		}

		.bottom-left,
		.bottom-right {
			bottom: -40rpx;
		}

		.top-left,
		.top-right {
			top: -40rpx;
		}

		.text-code {
			font-size: 44rpx;
			font-weight: bold;
			padding-top: 60rpx;
			padding-bottom: 110rpx;
		}
	}

	.content {
		padding-top: 90rpx;
	}

	.bottomBox {
		justify-content: space-around;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		border-top: 1px solid $border-color-light;

		.buttomBottom {
			width: 50%;
			text-align: center;
			padding: 30rpx 80rpx;
			line-height: 1;
			color: $base-color;
			font-size: $font-base;
			background-color: #FFF;

			&.bgYellow {
				color: #FFFFFF;
				background: $bg-gradual;
			}
		}
	}
</style>
