<template>
	<view class="content">
		<view class="container">


			<u-empty mode="list" v-if="courseList.length == 0">
			</u-empty>
			<view class="f-box" v-for="(item,index) in courseList " :key="index" @click="goDetails()">

				<view class="f-top">
					<view class="">{{item.orderTime || ''}}</view>
					<view class="" v-if="item.auditStatus == 0">待审核</view>
					<view class="" v-if="item.auditStatus == 1">已通过</view>
					<view class="" v-if="item.auditStatus == 2">已拒绝</view>
				</view>
				<view class="f_title" v-if="item.courseName == 1">
					成人班
				</view>
				<view class="f_title" v-if="item.courseName == 2">
					学生班
				</view>
				<!-- <view class="wrap-box">
				<view class="icon-lv">自动挡</view>
				<view class="icon-huang">C2</view>
			</view> -->
				<view class="f-ds">
					<view class="hui-">预约人：</view>
					<view class="hei-">{{item.userName || 0}}</view>
				</view>
				<view class="f-ds">
					<view class="hui-">所属教练：</view>
					<view class="hei-">{{item.coachName || 0}}</view>
				</view>
				<view class="f-ds">
					<view class="hui-">手机号：</view>
					<view class="hei-">{{item.userName || 0 }}</view>
				</view>
				<view style="display: flex;  justify-content: flex-end;" v-if="item.auditStatus == 0">
					<u-button style="width: 120px;" type="success" text="同意"
						@click="reservationCourse(item.id)"></u-button>
					<u-button style="width: 120px;" type="error" text="拒绝" @click="refuseReason(item.id)"></u-button>

				</view>
			</view>
			<u-modal :show="show" :title="title" :showCancelButton="true" @confirm="confirm()" @cancel="show = false">
				<view class="slot-content">
					<view class="">
						<u--textarea v-model="size" placeholder="请输入拒绝理由"></u--textarea>
					</view>

				</view>
			</u-modal>
		</view>
	</view>
</template>

<script>
	import request from '../../utils/request'
	export default {
		data() {
			return {
				show: false,
				title: '拒绝理由',
				id: null,
				courseList: [],
				size: '',
				optId:1,
				param:{
					pageNum:1,
					pageSize:10,
					total:0
				}
			}
		},
		onLoad(options) {
			if (options.id == 1) {
				this.findCourseList()
			}
			if (options.id == 2) {
				this.findCourseLists()
			}

		},
		onPullDownRefresh() {
			console.log("刷新");
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			// 触底加载
			if (this.courseList.length < this.param.total) {
				this.param.pageNum++
				if (this.optId == 1) {
					this.findCourseList()
				}
				if (this.optId == 2) {
					this.findCourseLists()
				}
			} 
		},

		methods: {
			async findCourseList() {
				let res = await request({
					url: `/drivingSchool/system/reservationCourse/applet/getAppReservationCourseListByUserId`,

					method: 'get'
				})
			if (res.code == 0) {
				if (this.param.pageNum != 1) {
					 this.courseList =  this.courseList.concat(res.data.records)
				} else {
					this.courseList = res.data.records
				}
				this.param.total = res.data.total						
			} else {
				uni.showToast({
					title: "网络不佳请稍后再试",
					icon: 'error'
				})		
			}
			},
			async findCourseLists() {
				let res = await request({
					url: `/drivingSchool/system/reservationCourse/applet/getAppReservationCourseListByUserIds`,

					method: 'get'
				})
			if (res.code == 0) {
				if (this.param.pageNum != 1) {
					 this.courseList =  this.courseList.concat(res.data.records)
				} else {
					this.courseList = res.data.records
				}
				this.param.total = res.data.total						
			} else {
				uni.showToast({
					title: "网络不佳请稍后再试",
					icon: 'error'
				})		
			}
			},

			async reservationCourse(id) {
				let res = await request({
					url: '/drivingSchool/system/reservationCourse',
					method: 'put',
					data: {
						id: id,
						auditStatus: 1,

					}
				})
				this.findCourseList()
			},
			async refuseReason(id) {
				this.id = id
				this.show = true

			},
			async confirm() {
				let res = await request({
					url: '/drivingSchool/system/reservationCourse',
					method: 'put',
					data: {
						id: this.id,
						auditStatus: 2,
						refuseReason: this.size
					}
				})
				this.show = false
				this.findCourseList()
			},
			goDetails() {
				// uni.navigateTo({
				// 	url: '/pages/index/Details'
				// })
			},

		}
	}
</script>

<style scoped lang="scss">
	.content {
		width: 100%;
		background: #f4f5f6;
		height: 100vh;
		box-sizing: border-box;
		padding-top: 10px;
	}

	.container {
		width: 100%;
		background: #f4f5f6;
		box-sizing: border-box;

	}

	.f-box {
		width: 95%;
		margin: 10px auto;
		box-sizing: border-box;
		padding: 10px;
		background: #fff;
		border-radius: 10px;
	}

	.f-top {
		width: 100%;
		box-sizing: border-box;
		padding-bottom: 10px;
		border-bottom: 1px solid #EEEEEE;
		font-weight: bold;
		font-size: 14px;
		color: #FF9A1A;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.f_title {
		font-weight: 800;
		font-size: 14px;
		color: #333333;
		margin: 10px 0px;
	}

	.wrap-box {
		width: 100%;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		flex-wrap: wrap;
	}

	.icon-lv {
		background: #E6F5F0;
		border-radius: 2px 2px 2px 2px;

		box-sizing: border-box;
		padding: 5px;
		font-weight: 400;
		font-size: 10px;
		font-size: 10px;
		color: #4AA76F;
		margin-right: 10px;
	}

	.icon-huang {
		background: #FFEDD4;
		border-radius: 2px 2px 2px 2px;

		box-sizing: border-box;
		padding: 5px;
		font-weight: 400;
		font-size: 10px;
		font-size: 10px;
		color: #EDA23A;
	}

	.f-ds {
		display: flex;
		align-items: center;
		margin: 10px 0px;
	}

	.hui- {
		font-weight: 400;
		font-size: 12px;
		color: #737C90;
		margin-right: 10px;
	}

	.hei- {
		font-weight: 400;
		font-size: 12px;
		color: #333333;
	}

	.slot-content {
		width: 300px;
	}
</style>