<template>
	<view class="content_box">
		<view class="orderBoxList">
			<view class="orderBox">
				<view class="orderBoxTitle flex-row">
					<text class="orderBoxTitleTxt">预约信息</text>
				</view>

				<view class="orderBoxInfo flex-col">
					<view class="orderBoxInfoRow flex-row">
						<text class="iconfont icon-shijian"></text>
						<text class="orderBoxInfoRowTxt">参观日期：{{timeFormat(info.date, 'MM月DD日')}}</text>
					</view>
					<view class="orderBoxInfoRow flex-row">
						<text class="iconfont icon-shijian"></text>
						<text class="orderBoxInfoRowTxt">参观时段：{{info.time||""}}</text>
					</view>
					<view class="orderBoxInfoRow flex-row">
						<text class="iconfont icon-renshu"></text>
						<text class="orderBoxInfoRowTxt">参观人数：{{info.total||0}}</text></text>
					</view>


				</view>

			</view>
		</view>
		<view class="orderBoxTitle flex-row">
			<text style="padding-top:25rpx" class="orderBoxTitleTxt">可扫“入馆码”入馆</text>
		</view>
		<view class="orderBoxList p0">
			<view class="orderBox">
				<view v-if="info.type==1" class="orderBoxInfo flex-col ewmcode">
					<text>入馆码：{{info.code}}-0</text>
					<view>
						<view class="imgs">
							<view :class="info.status!=1?'isuse':''">
								<cover-image v-if="info.status==2" src="../../static/img/used.png" alt=""></cover-image>
								<!-- <img v-if="info.status!=1"  src="../../static/img/used.png" alt=""> -->
								<canvas canvas-id='qrcode' style="width: 170px;height:170px;margin: 0 auto;">
									<cover-view v-if="showview">
									</cover-view>
								</canvas>

							</view>
						</view>
					</view>
					<!-- <text class="ewminfo">{{isuse?'已使用':'请前往现场核销订单二维码'}}</text> -->
				</view>
				<block v-if="info.type==2">
					<view class="orderBoxInfo flex-col ewmcode" :key='index' v-for="(item,index) in detailsinfo">
						<text>入馆码：{{info.code}}-{{item.code}}</text>
						<view>
							<view class="imgs">
								<view :class="item.status!=1?'isuse':''">
									<cover-image v-if="info.status==2" src="../../static/img/used.png" alt="">
									</cover-image>

									<!-- <img v-if="item.status!=1"  src="../../static/img/used.png" alt=""> -->
									<canvas :canvas-id="'qrcode'+index"
										style="width: 170px;height:170px;margin: 0 auto;">
										<cover-view v-if="showview">
										</cover-view>
									</canvas>
								</view>
								<view class="imgsname">
									<text class="orderBoxTitleTxt">{{item.name}}</text>
									<view class="orderBoxTitleTxt" style="font-size: 28rpx;" v-if="item.is_open==1">
										可凭身份证入场馆
									</view>
									<view style="font-size: 28rpx;" class="orderBoxTitleTxt" v-if="item.is_open==0">
										可凭二维码入场馆
									</view>
								</view>
							</view>

							
						</view>
						<!-- <text class="ewminfo">{{isuse?'已使用':'请前往现场核销订单二维码'}}</text> -->
					</view>
				</block>
			</view>
		</view>
		<!-- <view class="orderBoxList p0">
			<view class="orderBox">
				<view class="orderBoxTitle flex-row" style="justify-content: space-between;">
					<text class="orderBoxTitleTxt">观众信息</text>
					<text v-if="false" :class="isuse?'share shareuse orderBoxInfoRowTxt':'share orderBoxInfoRowTxt'">
						分享二维码
					</text>
				</view>
				<view class="orderBoxInfo flex-col">
					<view class="orderBoxInfoRow flex-row"
						:style="{'margin-bottom':((index+1)==info.details.length?0:'20rpx')}"
						v-for="(item,index) in info.details">
						<view>
							<text class="iconfont icon-iconfontgerenzhongxin iconinfo"></text>
						</view>
						<view class="usercard">
							<text class="orderBoxInfoRowTxt">{{item.name}}</text>
							<text class="orderBoxInfoRowTxt">{{item.idcard}}</text>
						</view>
					</view>
				</view>
			</view>
		</view> -->
		<view>
			<view class="orderBoxInfoRow flex-row" style="margin-top: 25rpx;">
				<!-- <text class="iconfont icon-iconfontgerenzhongxin"></text> -->
				<text v-if="info.type==1" class="orderBoxInfoRowTxt">领队人：{{info.leader||""}}丨 {{info.mobile||""}}</text>
				<text v-if="info.type==2" class="orderBoxInfoRowTxt">联系方式：{{info.mobile||""}}</text>

			</view>
			<view class="orderBoxInfoRow flex-row" v-if="info.type==1" style="margin-top: 20rpx;">
				<!-- <text class="iconfont icon-danwei"></text> -->
				<text class="orderBoxInfoRowTxt">单位名称：{{info.unit||""}}</text>
			</view>
			<view class="orderBoxInfoRow flex-row" style="margin-top: 20rpx">
				<text class="orderBoxInfoRowTxt">下单时间：{{info.created_at||""}}</text>
			</view>
		</view>
		<view class="orderBoxList orderBoxListTip">
			<view class="orderBoxTitle flex-row">
				<text class="stars orderBoxTitleTxt">*</text>
				<text class="orderBoxTitleTxt">参观须知</text>
			</view>
			<view class="flex-row" style="margin-top: 10rpx;">
				<view style="text-indent: 2em;line-height: 27px;" class="orderBoxInfoRowTxt" v-html="info.type==1?vinfo.person_notice:vinfo.team_notice"></view>
			</view>
		</view>
	</view>
</template>

<script>
	import uQRCode from "@/utils/qrcode.js"
	export default {
		data() {
			return {
				info: {},
				vinfo: {},
				detailsinfo: [],
				showview: false,
				timer: null,
				optionid: "",
				timer: null
			}
		},
		onLoad(options) {
			this.loadIntroduce();
			if (!this.util.isNull(options.id)) {
				this.optionid = options.id
				this.loadInfo(options.id);
			}
		},

		onShow() {
			var that = this
			this.timer = setInterval(function() {
				that.loadInfo(that.optionid);
			}, 4000)
		},

		onHide() {
			clearInterval(this.timer)
		},

		onUnload() {
			clearInterval(this.timer)
		},

		methods: {
			qrFun: function(text, qrcode) {
				var id = "qrcode";
				if (qrcode) {
					id = qrcode
				}
				uQRCode.make({
					canvasId: id,
					componentInstance: this,
					text: text,
					size: 170,
					// margin: 10,
					backgroundColor: '#ffffff',
					foregroundColor: '#000000',
					fileType: 'jpg',
					errorCorrectLevel: uQRCode.errorCorrectLevel.H,
					success: res => {

					}
				})
			},
			loadIntroduce() {
				var that = this;
				this.util.request({
					api: '/api/mobile/visit/introduce',
					utilSuccess: function(res) {
						that.vinfo = res;
						
					},
					utilFail: function(res) {

					}
				})

			},
			timeFormat(time, format) {
				return this.$moment(time).format(format);
			},
			loadInfo(id) {
				var that = this;
				this.util.request({
					api: '/api/mobile/user/my-visit-order-show',
					data: {
						id: id
					},
					customLoading:true,
					utilSuccess: function(res) {
						that.info = res;
						that.detailsinfo = res.details;
						if (res.status != 1) {
							clearInterval(that.timer)
						}
						if (res.type == 1) {
							that.qrFun(res.code + "-" + "0");
							setTimeout(function() {
								that.showview = true
							}, 500)

						}
						if (res.type == 2) {
							for (var i = 0; i < res.details.length; i++) {
								that.qrFun(res.code + "-" + res.details[i].code, 'qrcode' + i);
							}
							setTimeout(function() {
								that.showview = true
							}, 500)
						}
					},
					utilFail: function(res) {
						uni.showToast({
							icon: "none",
							title: res
						})
					}
				})
			}
		}
	}
</script>

<style>
	.orderBoxFooter {
		padding: 20rpx 0 0 0;
	}

	.fbtn {
		background: #EF9525;
		border-radius: 8rpx;
		font-size: 24rpx;
		color: #FFFFFF;
		padding: 7rpx 17rpx;
	}

	.cancel {
		background: #F7F6F4;
		color: #828282;
	}

	.iconfont {
		color: #6EAC97;
		margin-right: 20rpx;
		font-size: 35rpx;
	}

	.infotop {
		background: #FFFFFF;
		box-shadow: 2rpx 3rpx 10rpx 0px rgba(107, 94, 77, 0.3);
	}

	page {
		background-color: #f7f6f4;
	}

	.orderBoxList {
		padding: 26rpx;
		box-sizing: border-box;
		background: #fff;
		border-radius: 20rpx;
	}

	.orderBoxListTip {
		background: none;
		border-radius: 0rpx;
		padding: 26rpx 10rpx;
	}

	.orderBoxListTip .orderBoxTitle {
		padding-bottom: 10rpx
	}

	.content_box {
		/* background: #FFFFFF; */
		border-radius: 16rpx;
		margin: 30rpx 27rpx;
	}

	.orderBox {
		margin-bottom: 17rpx;
	}

	.orderBoxTitle {
		padding: 0rpx 0rpx 25rpx 0rpx;
		border-bottom: 2rpx solid #F7F6F4;
	}

	.orderBoxInfoRow {
		align-items: center;
		margin: 10rpx
	}

	.orderBoxTitleTxt {
		font-size: 32rpx;
		color: #351C1B;
	}

	.orderBoxStatus {
		background: #EF9525;
		border-top-right-radius: 16rpx;
		border-bottom-left-radius: 16rpx;
		font-size: 24rpx;
		padding: 19rpx 23rpx 17rpx 23rpx;
		color: #FFFFFF;
		position: absolute;
		right: 0;
		top: 0;
	}

	.orderBoxInfo {
		/* padding: 29rpx 0rpx; */
		border-bottom: 2rpx solid #F7F6F4;
	}


	.orderBoxInfoRowTxt {
		font-size: 30rpx !important;
		font-family: PingFang SC;
		color: #828282;
	}

	.orderBoxTime {
		color: #CFCFCF;
		padding: 23rpx 0;
		border-bottom: 2rpx solid #F7F6F4;
		font-size: 24rpx;
	}

	.p0 {
		padding-top: 0;
		border-left: 32rpx solid #ef9525
	}

	.ewmcode {
		text-align: center;
		font-size: 28rpx;
		text-align: left;
		font-size: 28rpx;
		margin-left: 18rpx;
		padding-bottom: 0;
		padding-top: 30rpx;
	}

	.imgs {
		margin: 30rpx 0 0rpx 0;
		font-size: 0;
		display: inline-block;
	}

	.imgs view {
		position: relative;
		display: inline-block;
		margin-bottom: 20rpx;
	}

	.imgs cover-image {
		position: absolute;
		width: 200rpx;
		height: 200rpx;
		z-index: 999;
		opacity: 1;
		right: 0rpx;
		bottom: 0rpx;
	}

	.imgs canvas {
		display: inline-block;
		vertical-align: middle;
	}

	.imgsname {
		display: inline-block;
		text-align: center;
		margin-left: 15rpx;
		flex: 1;
	}

	.imgs text {
		display: block;
		/* margin-left: 40rpx; */
	}

	.imgs .isuse cover-view {
		background-color: rgba(255, 255, 255, 0.6);
		width: 170px;
		height: 170px;
	}


	.ewminfo {
		color: #828282;
		font-size: 24rpx;
	}

	.iconinfo {
		font-size: 35rpx;
	}

	.usercard text {
		display: block;
	}

	.share {
		background: url(../../static/img/share.png) no-repeat left center;
		background-size: 21rpx;
		background-color: #EF9525;
		background-position: 18rpx;
		padding: 7rpx 20rpx;
		padding-left: 46rpx;
		border-radius: 10px;
		color: #fff;
	}

	.shareuse {
		background: url(../../static/img/share_used.png) no-repeat left center;
		background-color: #F7F6F4;
		color: #828282;
		background-position: 18rpx;
		background-size: 21rpx;
	}

	.stars {
		color: #EF9525;
		margin-right: 12rpx
	}
</style>
