<template>
	<view class="pageBgImg">
		<topNavbar title="预约详情"></topNavbar>
		<!-- 详情 -->
		<view class="pad">
			<view class="card">
				<imitate v-if="type==1"/>
				<opera  v-else-if="type==2"/>
				<examin v-else-if="type==3" :info="info"/>
			</view>
			
			<view class="btnCon">
				<view class="btnBg" @click.stop="$goPage('/pages/carEntry/evaluate/evaluate')" v-if="info.writtenoffStatus==2">去评价</view>
				<view class="btnBorder" @click="show=true" v-if="info.recordStatus==0">取消预约</view>
				<view class="btnBorder" v-if="info.payStatus==1">申请退款</view>
			</view>
		</view>
		<u-popup :show="show"  mode="center" :round="20" >
			<cancelReservation @popupBtnClick="popupBtnClick"/>
		</u-popup>
	</view>
</template>

<script>
	import imitate from './imitate'
	import opera from './opera'
	import examin from './examin'
	import { examSimulationGet, cancelSimulation } from "@/config/api.js"
	export default {
		components: { imitate,  opera, examin},
		data() {
			return {
				type: 1,
				show: false,
				id: '',
				info: ''
			}
		},
		onLoad(options) {
			this.type = options.type
			this.id = options.id
			if(this.type==3) {
				this.examSimulationGetFn()
			}
		},
		methods: {
			async examSimulationGetFn() {
				const {data: res} = await examSimulationGet({id: this.id})
				this.info = res
			},
			// 取消考场模拟预约
			async cancelSimulationFn() {
				const {data: res} = await cancelSimulation({id: this.id})
				if(res.code==0) {
					this.$u.toast('取消成功')
					this.examSimulationGetFn()
				}
			},
			// 取消预约事件
			popupBtnClick(val) {
				if(val==1) {
					this.cancelSimulationFn()
				}else {
					this.show = false
				}
				console.log(val)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.card {
		padding: 24rpx;
	}
	.btnCon {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		margin-top: 76rpx;
		.btnBg {
			width: 212rpx;
			margin-bottom: 40rpx;
		}
		.btnBorder {
			width: 396rpx;
			border: 2rpx solid #E8E9EC;
			background-color: #fff;
			color: #ADADAD;
			margin-bottom: 40rpx;
		}
	}
	
</style>