<template>
	<view class="">
		<!-- <view class="">
			我的预约
		</view> -->

		<view class="navbar flex">
			<view class="nav-item" v-for="(navitem,index) in navList" :class="{'action': index == currentIndex}"
				@click="navClick(index)">
				{{navitem.tit}}
			</view>
		</view>
		<swiper :interval="3000" :duration="1000" :style="{'height': height}" class="swiper-box" @scrolltolower="loadData()">
			<swiper-item>
				<scroll-view scroll-y="true" :style="{'height': height}">
					<empty v-if="navList[currentIndex].loaded === true && navList[currentIndex].list.length === 0">
					</empty>
					<view class="buy-item" v-for="item in navList[currentIndex].list">
						<view class="item-top">
							<view class="top-left">
								<image src="../../static/icon/mrlogo.png" mode=""></image><text
									class="top-name clamp">{{item.order_id}}</text>
							</view>
							<view class="top-right">
								{{item.status | status}}
							</view>
						</view>
						<view class="item-info">
							<view class="info-data">
								<view class="info-tit">收益：</view>
								<view class="info-val">{{item.day}}天/{{item.proportion}}%</view>
							</view>
							<view class="info-data">
								<view class="info-tit">可获通证：</view>
								<view class="info-val">{{item.pass}}%</view>
							</view>
							<view class="info-data" v-if="item.status == 1 || item.status == -1">
								<view class="info-tit">是否中奖：</view>
								<view class="info-val">{{item.status == 1?'中奖':item.status == -1 ? '未中奖': ''}}</view>
							</view>
							<view class="info-data">
								<view class="info-tit">价值：</view>
								<view class="info-val">{{item.price}}</view>
							</view>
							<view class="upimg" v-if="item.status == 1">
								<view class="up-tit">
									打款凭证：
								</view>
								<view class="img-wrap" v-if="item.pay_evaluation" @click="lookimg(item.pay_evaluation)">
									<image :src="item.pay_evaluation" mode=""></image>
								</view>
								<view class="" style="color: #0F253A;font-weight: bold;font-size: 26rpx;" v-else>
									上传支付凭证
								</view>
							</view>
							<view class="btn-wrap flex" v-if="item.status == 1 || item.status == 2">
								<!-- <view class="btn" @click="open(item.id)"> -->
								<view class="btn" @click="navto('/pages/purchase/upload?id=' + item.id + '&paytype=' + JSON.stringify(item.touser) )">
									提交凭证
								</view>
							</view>
						</view>
					</view>
					<uni-load-more :status="navList[currentIndex].loadingType"></uni-load-more>
				</scroll-view>
			</swiper-item>
		</swiper>
		<uni-popup ref="lookimg" type="center">
			<view class="pop-wrap" style="position: relative;" >
				<movable-area class="popup-box">
					<movable-view class="popup-item" :scale="true" direction="all">
						<image :src="chooseImg" mode=""></image>
					</movable-view>
				</movable-area>
				<image src="../../static/icon/close.png" mode="" class="close" style="width: 80rpx;height: 80rpx;" @click="closePup"></image>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import empty from '@/components/empty';

	import {
		packageMyReserveList, evaluationUpload
	} from '@/api/package.js'

	import {
		tabbar,
		tabbar1
	} from "@/utils/tabbar.js";
	import { upload } from '@/api/user.js';
	export default {
		components: {
			uniLoadMore,
			empty
		},
		filters: {
			status(val) {
				let str = ''
				// 状态:0-预约,1-待支付,2-待审核,3-释放中,4-释放完成,5-重新发放,6-完成,-1-没抢到,-2-审核无效
				switch (val) {
					case 0:
						str = '预约'
						break;
					case 1:
						str = '待支付'
						break;
					case 2:
						str = '待审核'
						break;
					case 3:
						str = '释放中'
						break;
					case 4:
						str = '释放完成'
						break;
					case 5:
						str = '重新发放'
						break;
					case 6:
						str = '完成'
						break;
					case -1:
						str = '没抢到'
						break;
					case -2:
						str = '审核无效'
						break;
					default:
						str = ''
				}


				return str
			}
		},
		data() {
			return {
				chooseImg: '',
				height: '',
				currentIndex: 0,
				navList: [{
						status: 'today',
						tit: '当天预约',
						list: [],
						page: 1,
						limit: 10,
						loadingType: 'more',
						loaded: false,
					},
					{
						status: 1,
						tit: '待支付',
						list: [],
						page: 1,
						limit: 10,
						loadingType: 'more',
						loaded: false,
					},
					{
						status: '',
						tit: '所有预约',
						list: [],
						page: 1,
						limit: 10,
						loadingType: 'more',
						loaded: false,
					}
				],
				tabbar: tabbar,
				tabbar1: tabbar1,
				current: 3,
				choose_order: '',
				upimg: '',
			}
		},
		onLoad() {
			console.log('我的预约')
			this.loadData()
		},
		onReady(res) {
			var obj = this;
			uni.getSystemInfo({
				success: resu => {
					const query = uni.createSelectorQuery();
					query.select('.swiper-box').boundingClientRect();
					query.exec(function(res) {
						console.log(res, 'ddddddddddddd');
						obj.height = resu.windowHeight - res[0].top + 'px';
						console.log('打印页面的剩余高度', obj.height);
					});
				},
				fail: res => {}
			});
		},
		methods: {
			lookimg(src) {
				console.log(src,'chooseImg++++++')
				this.chooseImg = src
				this.$refs.lookimg.open()
			},
			closePup() {
				this.chooseImg = ''
				this.$refs.lookimg.close()
			},
			navto(url) {
				uni.navigateTo({
					url: url
				})
			},
			qx() {
				this.upimg = ''
				this.choose_order = ''
				this.$refs.popup1.close()
			},
			open(orderId) {
				this.choose_order = orderId
				this.$refs.popup1.open()
				
			},
			imgsub(text) {
				console.log('imgsub');
				upload({
					filename: ''
				}).then(data => {
					// this.upimg = data[0].url;
					this.$set(this,text,data[0].url)
				});
			},
			//提交审核
			evaluationUpload() {
				let obj = this
				evaluationUpload({
					pay_evaluation: obj.upimg,
					id: obj.choose_order
				}).then( res => {
					this.qx()
					uni.showToast({
						title:'提交成功',
						duration:2000
					});
					this.page = 1
					this.list = []
					this.loadingType = 'more'
					this.loadData()
					console.log(res,'上传凭证+++++')
				})
			},
			navClick(index) {
				this.currentIndex = index
				this.loadData('swiper')
			},
			loadData(text) {
				let obj = this
				let index = obj.currentIndex
				let navItem = obj.navList[index]

				if (text == 'swiper' && navItem.loaded) {
					return
				}
				if (navItem.loadingType == 'loading' || navItem.loadingType == 'noMore') {
					return
				}
				navItem.loadingType = 'loading'
				if(navItem.status == 1) {
					packageMyReserveList({
						page: navItem.page,
						limit: navItem.limit,
						status: 1
					}).then(({
						data
					}) => {
						// console.log(res)
						navItem.list = navItem.list.concat(data.data)
						this.page++
						if (data.data.length == navItem.limit) {
							navItem.loadingType = 'more'
						} else {
							navItem.loadingType = 'noMore'
						}
						obj.$set(navItem, 'loaded', true)
					})
				}else {
					packageMyReserveList({
						page: navItem.page,
						limit: navItem.limit,
						data: navItem.status
					}).then(({
						data
					}) => {
						// console.log(res)
						navItem.list = navItem.list.concat(data.data)
						this.page++
						if (data.data.length == navItem.limit) {
							navItem.loadingType = 'more'
						} else {
							navItem.loadingType = 'noMore'
						}
						obj.$set(navItem, 'loaded', true)
					})
				}
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.navbar {
		background-color: #fff;
		height: 80rpx;

		.nav-item {
			width: 50%;
			text-align: center;
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #333333;
		}

		.action {
			font-weight: bold;
			position: relative;

			&::after {
				content: '';
				width: 84rpx;
				height: 4rpx;
				background: #FF4C4C;
				border-radius: 2px;
				position: absolute;
				bottom: -20rpx;
				left: 0;
				right: 0;
				margin: auto;
			}
		}
	}

	.swiper-box {
		// background-color: red;
		padding-top: 20rpx;
		// padding-bottom: 20rpx;
	}

	.buy-item {
		width: 690rpx;
		// height: 235rpx;
		margin: 0 auto 20rpx;
		background: #FFFFFF;
		box-shadow: 0px 0px 17rpx 0px rgba(0, 0, 0, 0.05);
		border-radius: 20rpx;
		padding: 26rpx 30rpx;

		.item-top {
			display: flex;
			justify-content: space-between;
			height: 50rpx;

			.top-left {
				font-size: 34rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #0F253A;
				line-height: 50rpx;
				display: flex;
				align-items: center;

				image {
					width: 48rpx;
					height: 46rpx;
				}

				.top-name {
					width: 450rpx;
					padding-left: 11rpx;
				}
			}

			.top-right {
				line-height: 50rpx;
				width: 100rpx;
				text-align: right;
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #6D7C88;
			}
		}

		.item-info {
			width: 100%;
			margin-top: 28rpx;
			line-height: 50rpx;
			font-size: 26rpx;
			font-family: PingFang SC;
			display: flex;
			flex-wrap: wrap;

			.info-data {
				width: 50%;
				display: flex;

				.info-tit {

					font-weight: 500;
					color: #6D7C88;
				}

				.info-val {
					color: #0F253A;
					font-weight: bold;
				}
			}
			.upimg {
				padding-top: 10rpx;
				display: flex;
			
				.up-tit {
					display: inline-block;
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #6D7C88;
				}
			
				.img-wrap {
					width: 153rpx;
					height: 152rpx;
			
					border-radius: 20rpx;
			
					image {
						border-radius: 20rpx;
						width: 153rpx;
						height: 152rpx;
						// background-color: red;
					}
				}
			}
			.btn-wrap {
				padding-top: 20rpx;
				width: 100%;
				justify-content: flex-end;
				.btn {
					text-align: center;
					width: 144rpx;
					line-height: 50rpx;
					background: #FFFFFF;
					border: 2rpx solid #FF4C4C;
					border-radius: 25rpx;
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #FF4C4C;
				}
			}

		}
	}
	
	.pop-wrap {
		width: 522rpx;
		height: 800rpx;
		// background-color: red;
	}
	.popup-box {
		width: 522rpx;
		height: 800rpx;
		border-radius: 20rpx;
		position: relative;
		overflow: hidden;
		background-color: #fff;
		.popup-item {
			width: 100%;
			height: 100%;
			
			
			image {
				width: 100%;
				// height: 100%;
			}
		}
		
	}
	.close {
		display: block;
		width: 40rpx;
		height: 40rpx;
		border: 50%;
		position: absolute;
		// background-color: red;
		bottom: -100rpx;
		left: 0;
		right: 0;
		margin: 0 auto;
	}
</style>
