<template>
	<view class="ordersVerification">
		<view style="height: 24rpx;width: 100%;background:#F9F9F9 ;"></view>
		<!-- 表单 -->
		<view class="form">
			<uni-forms ref="baseForm" :modelValue="FormData">
				<uni-forms-item label="收货人" labelWidth="150rpx">
					<uni-easyinput v-model="FormData.name" placeholder="请输入收货人" />
				</uni-forms-item>
				<uni-forms-item label="联系方式" labelWidth="150rpx">
					<uni-easyinput v-model="FormData.contact" placeholder="请输入联系方式" />
				</uni-forms-item>
				<uni-forms-item label="兑换时间" labelWidth="150rpx">
					<uni-easyinput v-model="FormData.date" placeholder="请输入兑换时间" />
				</uni-forms-item>				
			</uni-forms>
		</view>
		
		<!-- 商品信息 -->
		<view class="card" >
			<view class="toptitle">
				<view>{{hotelName}}</view>
				<view v-if="items.status == 3">未核销</view>
				<view v-if="items.status == 4">已核销</view>
			</view>
			<view class="shopCard">
				<image style="border-radius: 12rpx;"  :src="productImg[0]"></image>
				<view style="margin-left: 24rpx;">
					<text class="name">{{items.product_name}}</text>
					<text class="tag" v-if="items.source_type == 3"> {{items.integral}}积分</text>
				</view>
			</view>
			<view class="points" v-if="items.source_type == 3">
				<text class="totalName">共计:</text>
				<text class="totalContent">{{items.integral}}积分</text>
			</view>
			<view class="btn" >
				<text>核销</text>
			</view>
		</view>
		
		<!-- 核销订单按钮 -->
		<view class="bottombtn" @click="verificationOrder">
			<view class="btnitem">
				<text>核销订单</text>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default{
		data(){
			return{
				//产品图片
				productImg:'',
				//酒店名称
				hotelName:'',
				//订单号
				order_no:'',
				//订单详情
				items:'',
				//订单id
				order_id:'',
				// 表单数据
				FormData:{
					name:'',
					contact:'',
					date:'',
				},
			}
		},
		onLoad(o) {
			if(o.order_no){
				this.order_no = o.order_no
				this.orderDetail()
			}
		},
		methods:{
			//订单详情
			orderDetail(){
				this.$api.orders.confirmOrderDetail({
					order_no:this.order_no
				}).then(res=>{
					if(res.code == 0){
						this.items = res.data
						this.FormData.name = res.data.receiver
						this.FormData.contact = res.data.phone
						this.FormData.date = res.data.created_at
						this.order_no = res.data.order_no
						this.productImg = JSON.parse(res.data.img_urls)
						//酒店详情
						this.hotelDetail(res.data.hotel_id)
					}else{
						uni.showToast({
							icon:'none',
							title:res.msg
						})
						setTimeout(()=>{
							uni.redirectTo({
								url:'/pages/my/verification/verification'
							})
						},500)
					}
				})
			},
			//酒店详情
			hotelDetail(id){
				this.$api.hotel.getHotelDetail({
					hotel_id:id
				}).then(res=>{
					this.hotelName = res.data.name
				})
			},
			
			// 核销订单
			verificationOrder(){
				let _this = this
				uni.showModal({
					title: '提示',
					content: '是否核销订单',
					cancelColor:'#333333',
					confirmColor:'#FF6200',
					success: function (res) {
						if (res.confirm) {
							_this.$api.orders.confirmOrder({
								order_no:_this.order_no
							}).then(res=>{
								if(res.code == 0){
									uni.showToast({
										icon:'none',
										title:'核销成功'
									})
									_this.orderDetail()
									setTimeout(()=>{
										uni.redirectTo({
											url:'/pages/my/verification/verification?type='+2
										})
									},500)
									
								}else{
									uni.showToast({
										icon:'none',
										title:res.msg
									})
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			// // 选择兑换时间
			// bindDateChange: function(e) {
			// 	this.FormData.date=e.detail.value
			// },
			// 获取时间
			// getDate(type) {
			// 	const date = new Date();
			// 	let year = date.getFullYear();
			// 	let month = date.getMonth() + 1;
			// 	let day = date.getDate();
			
			// 	if (type === 'start') {
			// 		year = year - 60;
			// 	} else if (type === 'end') {
			// 		year = year + 2;
			// 	}
			// 	month = month > 9 ? month : '0' + month;
			// 	day = day > 9 ? day : '0' + day;
			// 	return `${year}-${month}-${day}`;
			// }
		},
	}
</script>

<style lang="scss" scoped>
	$pageColor:#F9F9F9;
	$bgColor:#FFFFFF;

	// flex布局居中对齐
	@mixin flexlayout {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.ordersVerification {
		height: 100%;
		background: $pageColor;
	}
	::v-deep .uni-forms-item.is-direction-left{
		border-bottom: 2rpx solid #F0F0F0;
	}
	::v-deep .uni-forms-item.is-direction-left:last-child{
		border-bottom: 0rpx solid #F0F0F0;
	}
	::v-deep .is-input-border {
		border: none;
	}
	.form {
		width: 750rpx;
		height: 328rpx;
		background: $bgColor;
		border-radius: 16rpx;
		padding:10rpx 30rpx;
		box-sizing: border-box;
	}
	.card{
		margin-top: 24rpx;
		// width: 750rpx;
		// height: 426rpx;
		background: $bgColor;
		border-radius: 16rpx;
		padding:32rpx 28rpx 24rpx 28rpx;
		box-sizing: border-box;
		.toptitle{
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-size: 28rpx;
			font-family: PingFang-SC-Bold, PingFang-SC;
			font-weight: bold;
			color: #080F18;
		}
		.shopCard{
			margin-top: 28rpx;
			width: 694rpx;
			height: 164rpx;
			background: #F4F5F6;
			border-radius: 10rpx;
			display: flex;
			align-items: center;
			image{
				width: 132rpx;
				height: 132rpx; 
				margin-left: 16rpx;
				display: inline-block;
			}
			.name{
				font-size: 28rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #080F18;
				display: block;
			}
			.tag{
				font-size: 24rpx;
				font-family: PingFang-SC-Medium, PingFang-SC;
				font-weight: 500;
				color: #666666;
			}
		}
		.points{
			display: flex;
			justify-content: flex-end;
			align-items: center;
			margin-top: 30rpx;
			.totalName{
				font-size: 22rpx;
				font-family: PingFang-SC-Medium, PingFang-SC;
				font-weight: 500;
				color: #080F18;
				margin-right: 10rpx;
			}
			.totalContent{
				font-size: 30rpx;
				font-family: PingFang-SC-Heavy, PingFang-SC;
				font-weight: 800;
				color: #080F18;
			}
		}
		.btn{
			width: 170rpx;
			height: 60rpx;
			background: #FFFFFF;
			border-radius: 30rpx;
			border: 2rpx solid #D0D0D0;
			margin-left: 524rpx;
			margin-top: 15rpx;
			@include flexlayout()
			text{
				font-size: 26rpx;
				font-family: PingFang-SC-Medium, PingFang-SC;
				font-weight: 500;
				color: #080F18;
			}
		}
	}
	.bottombtn{
		width: 690rpx;
		height: 92rpx;
		background: linear-gradient(270deg, #FF6200 0%, #FF9342 100%);	
		border-radius: 12rpx;
		margin-left: 30rpx;
		position: fixed;
		bottom: 72rpx;
		@include flexlayout()
		.btnitem{
			@include flexlayout()
			text{
				font-size: 30rpx;
				font-family: PingFang-SC-Bold, PingFang-SC;
				font-weight: bold;
				color: $bgColor;
			}
		}
	}
	.date{
		width: 545rpx;
		height: 74rpx;
		background: #FFFFFF;
		display: flex;
		align-items:center;
		padding-left: 20rpx; 
		box-sizing: border-box;
		position: relative;
	}
</style>
