<template>
	<view class="pageBgImg">
		<topNavbar title="预约详情"></topNavbar>
		<!-- 详情 -->
		<view class="pad">
			<view class="card">
				<imitate v-if="type==1" :info="info"/>
				<opera  v-else-if="type==2" :info="info"/>
				<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, simulationDetail, cancelSimulationDevice, masterDetail, masterCancelBooking } 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()
			}else if(this.type==1) {
				this.simulationDetailFn()
			}else {
				this.masterDetailFn()
			}
		},
		methods: {
			// 获得考场模拟详情
			async examSimulationGetFn() {
				const {data: res} = await examSimulationGet({id: this.id})
				this.info = res
			},
			// 获得考场模拟详情
			async masterDetailFn() {
				const {data: res} = await masterDetail({id: this.id})
				this.info = res
			},
			
			// 获得模拟预约详情
			async simulationDetailFn(item) {
				const {data: res} = await simulationDetail({id: this.id})
				this.info = res
			},
			// 取消考场模拟预约
			async cancelSimulationFn() {
				const res = await cancelSimulation({id: this.id})
				console.log('没来到这里？')
				// console.log(res)
				// if(res.code==0) {
					this.$u.toast('取消成功')
					this.examSimulationGetFn()
				// }
			},
			// 取消模拟预约
			async cancelSimulationDeviceFn() {
				const {data: res} = await cancelSimulationDevice({id: this.id})
				this.$u.toast('取消成功')
				this.simulationDetailFn()
			},
			// 取消实操预约
			async masterCancelBookingFn() {
				const {data: res} = await masterCancelBooking({id: this.id})
				this.$u.toast('取消成功')
				this.masterDetailFn()
			},
			
			// 取消预约事件
			popupBtnClick(val) {
				if(val==1) {
					if(this.type==1) {
						this.cancelSimulationDeviceFn()
					}else if(this.type==3) {
						this.cancelSimulationFn()
					}else {
						this.masterCancelBookingFn()
					}
				}
				this.show = false
				console.log(val)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.card {
		padding: 0 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>