<template>
	<view class="pageBgImg">
		<topNavbar title="预约详情"></topNavbar>
		<!-- 详情 -->
		<view class="pad">
			<view class="card">
				<opera :info="info" ref="operaRef"/>
			</view>
			
			<view class="btnCon" >
				<!-- <view class="btnBg" @click.stop="$goPage('/pages/carEntry/evaluate/evaluate')" v-if="info.loginStatus==2">去评价</view> -->
				<view class="btnBorder" @click="canceClick" v-if="info.loginStatus==0">取消预约</view>
			</view>
		</view>
		<u-popup :show="show"  mode="center" :round="20" >
			<cancelReservation @popupBtnClick="popupBtnClick"/>
		</u-popup>
	</view>
</template>

<script>
	import opera from './opera'
	import {  masterDetail, masterCancelBooking } from "@/config/api.js"
	export default {
		components: {  opera, },
		data() {
			return {
				type: 1,
				show: false,
				id: '',
				info: ''
			}
		},
		onLoad(options) {
			this.id = options.id
			this.masterDetailFn()
		},
		methods: {
			// 获得实操拟详情
			async masterDetailFn() {
				const {data: res} = await masterDetail({id: this.id})
				res.bookingDetailRespVOS = res.bookingDetailRespVOS.sort((a,b)=>{
					return parseInt(a.classTime.slice(0,2)) - parseInt(b.classTime.slice(0,2))
				})
				this.info = res
			},
			// 取消实操预约
			async masterCancelBookingFn() {
				let ids = this.$refs.operaRef.ids
				const {data: res} = await masterCancelBooking(ids.join())
				this.$refs.operaRef.ids = []
				this.$u.toast('取消成功')
				this.masterDetailFn()
			},
			
			// 取消预约事件
			popupBtnClick(val) {
				if(val==1) {
					this.masterCancelBookingFn()
				}
				this.show = false
			},
			canceClick() {
				let ids = this.$refs.operaRef.ids
				if(!ids.length) return this.$u.toast('请选择取消时间段')
				this.show=true
			}
		}
	}
</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>