<template>
	<page-meta :page-style="'overflow:'+(showCodes||showCancel?'hidden':'visible')"></page-meta>
	<view class="containers">
		<view class="db">
			<view class="dblist">
				<view>
					<view class="dbitem">
						<text class="dbtype">{{info.type_text}}</text>
						<view class="dbstatus bm">
							<view>{{info.audit_status_text}}</view>
							<view>
								<view class="label-with-en">
									<view>访问日期：{{info.date}}{{ info.end_date?'至'+info.end_date:'' }}</view>
									<view class="en-text">Visit Date: {{info.date}}{{ info.end_date?' to '+info.end_date:'' }}</view>
								</view>
								<view class="label-with-en">
									<view>访问时间：{{info.time?info.time:''}}</view>
									<view class="en-text">Visit Time: {{info.time?info.time:''}}</view>
								</view>
								<!-- <view class="label-with-en">
									<view>访问时间：{{info.visit_time.start_time}}至{{info.visit_time.end_time}}</view>
									<view class="en-text">Visit Time: {{info.visit_time.start_time}} to {{info.visit_time.end_time}}</view>
								</view> -->
							</view>
							<view v-if="info.type=='2'" class="label-with-en">
								<view>施工时段：{{info.work_start_time}}至{{info.work_end_time}}</view>
								<view class="en-text">Construction Period: {{info.work_start_time}} to {{info.work_end_time}}</view>
							</view>
						</view>
						<view class="dbinfo justify-left">
							<view>
								<view class="label-with-en">
									<view>被访人：<text>{{info.accept_admin.name}}</text></view>
									<view class="en-text">Host: <text>{{info.accept_admin.name}}</text></view>
								</view>
								<view class="label-with-en">
									<view>部门：<text>{{info.accept_admin.department.name}}</text></view>
									<view class="en-text">Department: <text>{{info.accept_admin.department.name}}</text></view>
								</view>
								<view class="label-with-en">
									<view>访问区域：<text>{{info.visit_area.name}}</text></view>
									<view class="en-text">Visit Area: <text>{{info.visit_area.name}}</text></view>
								</view>
							</view>
							<view>
								<view class="label-with-en">
									<view>拜访人：<text>{{info.name}}</text></view>
									<view class="en-text">Visitor: <text>{{info.name}}</text></view>
								</view>
								<view class="label-with-en">
									<view>电话：{{info.mobile}}</view>
									<view class="en-text">Phone: {{info.mobile}}</view>
								</view>
								<view class="label-with-en" v-if="info.type=='1'">
									<view>事由：<text>{{item.reason?info.reason:''}}</text></view>
									<view class="en-text">Reason: <text>{{item.reason?info.reason:''}}</text></view>
								</view>
								<view class="label-with-en" v-else-if="info.type=='3'">
									<view>车辆类型：<text>{{info.plate}}</text></view>
									<view class="en-text">Vehicle Type: <text>{{info.plate}}</text></view>
								</view>
							</view>
						</view>
						<view  class="company">
							<view class="label-with-en">
								<view>拜访公司：<text>{{info.company_name?info.company_name:''}}</text></view>
								<view class="en-text">Company: <text>{{info.company_name?info.company_name:''}}</text></view>
							</view>
							
						</view>
						
						<!-- <view class="dblong">
							<view>长期访客申请：<text>{{info.long_time==0?'否':'是'}}</text></view>
							<view v-if="info.long_time==1">长期访问时间：{{info.start_date?info.start_date:''}} 至 {{info.end_date?info.end_date:''}}</view>
						</view> -->

					</view>
				</view>
				<template v-if="info.type!='3'">
					<view class="dbtext label-with-en">
						<view>随访人员</view>
						<view class="en-text">Follow-up Personnel</view>
					</view>
					<view class="dbitem sfyritem">
						<template v-if="info.follw_people && info.follw_people.length>0">
							<view class="dbinfo justify-left" v-for="people in info.follw_people" :key="people.id || people.name">
								<view>
									<view class="label-with-en">
										<view>随访人：<text>{{people.name}}</text></view>
										<view class="en-text">Follower: <text>{{people.name}}</text></view>
									</view>
									<view class="label-with-en">
										<view>证件类型：<text>{{people.credent==1?'身份证':'护照'}}</text></view>
										<view class="en-text">ID Type: <text>{{people.credent==1?'ID Card':'Passport'}}</text></view>
									</view>
									<view class="label-with-en">
										<view>证件号：<text>{{people.idcard}}</text></view>
										<view class="en-text">ID Number: <text>{{people.idcard}}</text></view>
									</view>
								</view>
								<view>
									<view class="label-with-en">
										<view>电话：<text>{{people.mobile}}</text></view>
										<view class="en-text">Phone: <text>{{people.mobile}}</text></view>
									</view>
								</view>
							</view>
						</template>
						<template v-else>
							<view class="dbinfo justify-left">
								<view class="label-with-en">
									<view>无</view>
									<view class="en-text">None</view>
								</view>
							</view>
						</template>
					</view>
				</template>

				<template>
					<view class="dbtext label-with-en">
						<view>到访车辆</view>
						<view class="en-text">Visiting Vehicles</view>
					</view>
					<view class="dbitem sfyritem">
						<view class="dbinfo dbcars" v-if="info.cars && info.cars.length>0">
							<view class="onechild label-with-en" v-for="(item, index) in info.cars" :key="index">
								<view>车牌：<text>{{item?item:'无'}}</text></view>
								<view class="en-text">License Plate: <text>{{item?item:'None'}}</text></view>
							</view>
						</view>
						<view class="dbinfo dbcars" v-else>
							<view class="onechild label-with-en">
								<view>无</view>
								<view class="en-text">None</view>
							</view>
						</view>
					</view>
				</template>

				<template v-if="info.type=='3'">
					<view class="dbtext label-with-en">
						<view>被访人</view>
						<view class="en-text">Consignee</view>
					</view>
					<view class="dbitem sfyritem">
						<view class="dbinfo justify-left">
							<view class="label-with-en">
								<view>部门：<text>{{info.accept_goods_admin.department.name}}</text></view>
								<view class="en-text">Department: <text>{{info.accept_goods_admin.department.name}}</text></view>
							</view>
							<view class="label-with-en">
								<view>人员：<text>{{info.accept_goods_admin.name}}</text></view>
								<view class="en-text">Personnel: <text>{{info.accept_goods_admin.name}}</text></view>
							</view>
						</view>
					</view>
				</template>
				<view class="dbtext label-with-en">
					<view>被访人员</view>
					<view class="en-text">Host Personnel</view>
				</view>
				<view class="dbitem sfyritem">
					<view class="dbinfo justify-left">
						<view class="label-with-en">
							<view>部门：<text>{{info.accept_admin.department.name}}</text></view>
							<view class="en-text">Department: <text>{{info.accept_admin.department.name}}</text></view>
						</view>
						<view class="label-with-en">
							<view>人员：<text>{{info.accept_admin.name}}</text></view>
							<view class="en-text">Personnel: <text>{{info.accept_admin.name}}</text></view>
						</view>
					</view>
				</view>
				<!-- <block v-if="info.visit_area.name=='生产区'">
					<view class="dbtext label-with-en">
						<view>陪同人员</view>
						<view class="en-text">Accompanying Personnel</view>
					</view>
					<view class="dbitem sfyritem">
						<view class="dbinfo justify-left">
							<view class="label-with-en">
								<view>部门：<text>{{info.accompany.department.name}}</text></view>
								<view class="en-text">Department: <text>{{info.accompany.department.name}}</text></view>
							</view>
							<view class="label-with-en">
								<view>人员：<text>{{info.accompany.name}}</text></view>
								<view class="en-text">Personnel: <text>{{info.accompany.name}}</text></view>
							</view>
						</view>
					</view>
				</block> -->
				<!-- <template v-if="info.accept_admin_sign">
					<view class="dbtext">签字</view>
					<view class="dbitem sfyritem">
						<view class="dbinfo justify-left">
							<image style="width:100%" :src="info.accept_admin_sign_file.url" mode=""></image>
						</view>
					</view>
					
				</template> -->
				<view class="justify-between cancelcode">
					<button :class="info.audit_status<1?'wd100 cancelbtn':'cancelbtn'" v-if="info.audit_status<2&&info.audit_status!=5" @click="showCancelM"
						type="primary" class="button-with-en">
						<view>取消拜访/Cancel Visit</view>
					</button>
						
					<button :class="info.audit_status==3?'wd100 codebtn':'codebtn'" v-if="info.audit_status==1||info.audit_status==3" @click="createdCode"
						type="primary" class="button-with-en">
						<view>出示二维码</view>
						<view class="en-text">Show QR Code</view>
					</button>
				</view>
			</view>

		</view>

		<!-- 二维码 -->
		<u-popup class="codepop" :show="showCodes" mode="center" closeable="true" @close="closeshowCodes">
			<view class="userBox" style="padding:0 120rpx 0rpx 120rpx;">
				<view class="userInfoContent" style="padding: 40rpx;font-size: 28rpx;">
					<view class="label-with-en">
						<text>核销码：{{info.code}}</text>
						<text class="en-text">Verification Code: {{info.code}}</text>
					</view>
				</view>
				<view class="qrcode">
					<canvas canvas-id='qrcode' style="width: 170px;height:170px;margin: 0 auto;">

					</canvas>
				</view>

			</view>
		</u-popup>
		
		
		<!-- 取消 -->
		<u-popup class="cancelpop" :show="showCancel" mode="center" closeable="true" @close="cancelCancel">
			<view class="userBox" style="padding:0 120rpx 0rpx 120rpx;">
				<view class="userInfoContent" style="padding: 40rpx;font-size: 36rpx;">
					<view class="label-with-en">
						<text>是否确认取消此次拜访?</text>
						<text class="en-text">Are you sure to cancel this visit?</text>
					</view>
				</view>
				<view class="justify-between cancelbtns">
					<button @click="cancelCancel" class="cancelbtn button-with-en">
						<view>取消</view>
						<view class="en-text">Cancel</view>
					</button>
					<button @click="confirmCancel" class="codebtn button-with-en">
						<view>确认</view>
						<view class="en-text">Confirm</view>
					</button>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import '@/static/css/bd.css'
	import uQRCode from "@/utils/qrcode.js"
	export default {
		data() {
			return {
				id: "",
				info: {},
				showCodes: false,
				showCancel:false
			}
		},
		onReady() {

		},
		onLoad(options) {
			this.id = options.id
			this.loadDetail()
		},
		methods: {
			closeshowCodes() {
				this.showCodes = false
			},
			createdCode(code) {
				var id = "qrcode";
				this.showCodes = true
				uQRCode.make({
					canvasId: id,
					componentInstance: this,
					text: this.info.code,
					size: 170,
					// margin: 10,
					backgroundColor: '#ffffff',
					foregroundColor: '#000000',
					fileType: 'jpg',
					errorCorrectLevel: uQRCode.errorCorrectLevel.H,
					success: res => {

					}
				})

			},
			showCancelM(){
				this.showCancel = true
			},
			confirmCancel(){
				this.info.audit_status = 5
				this.info.audit_status_text = "已取消"
				let that = this
				this.showCancel = false
				this.util.request({
					api: '/api/mobile/visit/visit-save',
					method: "POST",
					data: that.info,
					utilSuccess: function(res) {
						uni.showToast({
							title: res.msg,
							duration: 2000,
							icon: 'none'
						})
						uni.navigateTo({
							url:'/pages/visit/visithistory'
						})
					},
					utilFail: function(res) {
						uni.showToast({
							title: res,
							duration: 2000,
							icon: 'none'
						})
					}
				})
			},
			cancelCancel(){
				this.showCancel = false
			},
			loadDetail() {
				let that = this
				this.util.request({
					api: '/api/mobile/user/my-visit-detail',
					method: "get",
					data: {
						id: that.id
					},
					utilSuccess: function(res) {
						that.info = res
					},
					utilFail: function(res) {
						uni.showToast({
							title: res,
							duration: 2000,
							icon: 'none'
						})
					}
				})
			},
			isnull(p) {
				if (p == '' || p == undefined || p == null || p == 'undefined' || p == 'null') {
					return ""
				} else {
					return p
				}
			}
		}


	}
</script>

<style scoped>
	.containers {
		background-color: #eceefe;
		min-height: 100vh;
		padding-top: 20rpx;
	}

	.dbtext {
		padding-top: 10rpx;
		margin-bottom: 30rpx;
		color: #303639;
		font-size: 40rpx;
		padding-left: 30rpx
	}
	.dbcars>view{
		width:100%;
		padding-left:0
	}
	.sfyritem {
		padding-bottom: 10rpx
	}

	.dbinfo>view text {
		color: #8f9596;
	}

	/deep/ .u-popup__content {
		background: #fff;
	}

	.cancelcode {
		margin: 60rpx 0;
		background-color: #eceefe;
	}

	.cancelcode button,.cancelbtns button {
		width: 45%
	}

	.cancelcode button.cancelbtn,.cancelbtns button.cancelbtn {
		background: #dddd;
		border: none;
		color:#333
	}

	.cancelcode button.codebtn,.cancelbtns button.codebtn {
		background: #4f607e;
		border: none;
		color:#fff
	}
	.cancelcode button.wd100{
		width:100%;
		
	}
	.company{
		padding-bottom:30rpx;
		margin-top:-10rpx;
	}
	.company text{
		color: #8f9596;
	}
	.label-with-en {
		margin-bottom: 8rpx;
		display: flex;
		flex-direction: column;
	}
	.label-with-en .en-text {
		font-size: 24rpx;
		color: #999;
		margin-top: 4rpx;
	}
	.dbtext.label-with-en {
		display: flex;
		flex-direction: column;
		padding-top: 10rpx;
		margin-bottom: 30rpx;
		color: #303639;
		font-size: 40rpx;
		padding-left: 30rpx;
	}
	.dbtext.label-with-en .en-text {
		font-size: 28rpx;
		color: #999;
		margin-top: 6rpx;
	}
	.button-with-en {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.button-with-en .en-text {
		font-size: 20rpx;
		opacity: 0.9;
		margin-top: 2rpx;
		font-weight: normal;
	}
	.userInfoContent .label-with-en {
		text-align: center;
	}
	.userInfoContent .label-with-en .en-text {
		font-size: 22rpx;
		margin-top: 8rpx;
	}
	
</style>
