<template>
	<view class="">
		<!-- <view class="">
			买入
		</view> -->
		<view class="jg" style="height: 20rpx;"></view>
		<empty v-if="loaded === true && list.length === 0"></empty>
		<view class="buy-item" v-for="item in list" v-if="item.status !== -1">
			<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">10:20</view>
				</view> -->
				<view class="info-data">
					<view class="info-tit">可获通证：</view>
					<view class="info-val">{{item.pass}}</view>
				</view>
				<view class="info-data">
					<view class="info-tit">价值：</view>
					<view class="info-val">{{item.price}}</view>
				</view>
				<view class="btn-wrap flex" v-if="item.status == 1 || item.status == 2">
					<view class="btn" @click="open(item.order_id)">
						提交凭证
					</view>
				</view>
			</view>
		</view>
		<uni-load-more :status="loadingType"></uni-load-more>
		<uni-popup ref="popup1" type="center" :maskClick="false">
			<view class="upload-wrap">
				<view class="tit">
					上传支付凭证
				</view>
				<view class="up-wrap" @click="imgsub('upimg')">
					<image :src="upimg" mode="" v-if="upimg"></image>
					<image v-else src="../../static/img/upimg.png" mode=""></image>
				</view>
				<view class="btn-wrap">
					<view class="btn qx" @click="qx">
						取消
					</view>
					<view class="btn" @click="evaluationUpload">提交</view>
				</view>
				
			</view>
		</uni-popup>
		<!-- <u-tabbar v-model="current" :list="tabbar" active-color="#FF0000" inactive-color="#f19c99"></u-tabbar> -->
	</view>
</template>

<script>
	import uniPopup from '@/components/uni-popup/uni-popup.vue';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import empty from '@/components/empty';
	
	import { packageMyReserveList, evaluationUpload } from '@/api/package.js'
	import { upload } from '@/api/user.js';
	
	import {
		tabbar,tabbar1
	} from "@/utils/tabbar.js";
	export default {
		components: {
			uniLoadMore,
			empty,
			uniPopup
		},
		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 {
				tabbar: tabbar,
				tabbar1: tabbar1,
				current: 1,
				list: [],
				loadingType: 'more',
				page: 1,
				limit: 20,
				loaded: false,
				choose_order: '',
				upimg: '',
			}
		},
		onLoad() {
			console.log('买入')
			// this.$refs.upload.open()
			this.loadData()
			// this.$refs.popup1.open()
		},
		//上拉加载更多
		onReachBottom() {
			this.loadData()
		},
		methods: {
			qx() {
				this.upimg = ''
				this.choose_order = ''
				this.$refs.popup1.close()
			},
			imgsub(text) {
				console.log('imgsub');
				upload({
					filename: ''
				}).then(data => {
					// this.upimg = data[0].url;
					this.$set(this,text,data[0].url)
				});
			},
			open(orderId) {
				this.choose_order = orderId
				this.$refs.popup1.open()
				
			},
			navto(url) {
				uni.navigateTo({
					url: url
				})
			},
			loadData() {
				let obj = this
				if(obj.loadingType == 'noMore' || obj.loadingType == 'loading') {
					return 
				}
				obj.loadingType = 'loading'
				packageMyReserveList({
					page: obj.page,
					limit: obj.limit,
					status: 3
				}).then( ({data}) => {
					obj.list = obj.list.concat(data.data)
					this.page++
					if (data.data.length == obj.limit) {
						obj.loadingType = 'more'
					} else {
						obj.loadingType = 'noMore'
					}
					obj.$set(obj, 'loaded', true)
				})
			},
			//提交审核
			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,'上传凭证+++++')
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.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;
				}
			}
			.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;
				}
			}
			
			
		}
	}
	.upload-wrap {
		width: 500rpx;
		height: 500rpx;
		background-color: #fff;
		border-radius: 20rpx;
		.tit {
			padding: 30rpx 25rpx;
			text-align: center;
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #101010;
		}
		
		.up-wrap {
			margin:auto;
			width: 225rpx;
			height: 225rpx;
			background: #FFFFFF;
			border-radius: 10rpx;
		
			image {
				width: 225rpx;
				height: 225rpx;
				border-radius: 10rpx;
			}
		}
		.btn-wrap {
			display: flex;
			.btn {
				margin: 50rpx auto 0;
				width: 150rpx;
				line-height: 84rpx;
				background: linear-gradient(30deg, #FF4C4C, #FE6238);
				border-radius: 10rpx;
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FFFFFF;
				text-align: center;
			}
			.qx {
				background: #fff;
				border: 1px solid #999;
				color: #999;
			}
		}
		
	}
</style>
