<template>
	<view>
		<!-- 公共组件-每个页面必须引入 -->
		<public-module></public-module>
		<template v-if="!isValid">
			<view style="font-size: 36upx;margin-top: 160upx;text-align: center;">该二维码已失效</view>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				endDateTime:"",
				isValid:true,
			}
		},
		async onLoad(params) {
			if(!!params.orderno){
				this.orderno = params.orderno;
				let res = await this.$http.get('/insOrder/queryOrder?orderno='+params.orderno);
				if((res.code == 200) && (res.data.orderstatus==='5')){
			       //获取前一个页面传过来的信息（车辆信息，人员信息，险种信息）
					var submitTime = new Date(res.data.submittime.replace(/-/g,'/'));
					var year = submitTime.getFullYear();//年
					var month = submitTime.getMonth()+1;//月
					month = (month<10)?('0'+month):month;
					var date = submitTime.getDate();//日
					date = (date<10)?('0'+date):date;
					
					this.endDateTime = year+'-'+month+'-'+date+" 23:00:00";
					if(this.isDuringDate()){
						await this.jump(res.data.orderno);
					}
				}else{
					uni.showModal({
						showCancel:false,
						title:"该订单无效或已支付"
					})
				}
				
			}else{
				uni.showModal({
					showCancel:false,
					title:"未查询到该订单"
				})
			}
		},
		methods: {
			async jump(orderno){
				let res = await this.$http.get('/insOrder/getPayCode?orderno='+this.orderno);
				if(res.code == 200){
					// #ifdef H5
					window.location.href = res.data;
					// #endif
					// #ifdef APP-PLUS
					plus.runtime.openURL(res.data);
					// #endif
				}else{
					uni.showToast({
						title:"获取二维码失败"
					})
				}
			},
			
			// isDuringDate() {
			// 	var curDate = new Date();
			// 	// var endDate = new Date("2021/4/10 11:55");
			// 	var endDate = new Date(this.endDateTime);
			// 	if (curDate <= endDate) {
			// 		this.isValid = true;
			// 		return true;
			// 	}
			// 	this.isValid = false;
			// 	return false;
			// }
			
			isDuringDate() {
			    var myDate = new Date();
				
			    var year = myDate.getFullYear();//年
			    var month = myDate.getMonth()+1;//月
				month = (month<10)?('0'+month):month;
			    var date = myDate.getDate();//日
				date = (date<10)?('0'+date):date;
			    var hour = myDate.getHours();//时
				hour = (hour<10)?('0'+hour):hour;
			    var minute = myDate.getMinutes();//分
				minute = (minute<10)?('0'+minute):minute;
				var seconds = myDate.getSeconds();
				seconds = (seconds < 10) ? ("0" + seconds ): seconds;
				
			    var nowtime = year+'-'+month+'-'+date+' '+hour+':'+minute+':'+seconds;
			    var curDate = new Date(nowtime.replace(/-/g,'/')).getTime();
			    var endDate = new Date(this.endDateTime.replace(/-/g,'/')).getTime();
			    if (curDate <= endDate) {
			     this.isValid = true;
			     return true;
			    }
			    this.isValid = false;
			    return false;
			   }
			
			
		}
	}
</script>

<style>

</style>
