<template>
	<div>
		<el-popover width="320" trigger="click">
			    	   <div>
			    	   	<p style="margin:0 0 15px 0;">{{$t('objFill.erwmask')}}</p>
			    	   	<p v-show="isOK" style="text-align: center; color: #E95252; padding-bottom: 10px; font-weight: bold;">{{$t('objFill.v101.traveltrip.weiscewmdjsc')}}</p>
			    	   	<div v-show="!isOK">
			    	   		<img :src="payPic" style="float: left; margin-right: 15px; width: 150px; height: 150px; border: 1px solid #ccc;" />
			    	   		<p style="padding-right: 10px; font-size: 12px; line-height: 20px; margin-bottom: 10px;">
			    	   			<span style="color: #E95252;">{{payWay=="1"?$t('objFill.weixin'):$t('objFill.zhifubao')}}</span>{{$t('objFill.erweimsxsjts')}}
			    	   		</p>
			    	   		<p class="fz12 color333">{{$t('objFill.daojishi')}}</p>
			    	   		<p style="color: #E95252; font-weight: bold; font-size: 12px; margin: 8px 0;">{{descMin}}{{$t('objFill.fen')}}{{descSecond}}{{$t('objFill.miao')}}</p>
			    	   		<!--<p>
			    	   			<a :href="payPic" target="_blank" download style="margin-left: 0; width: 50px; height: 28px; line-height: 28px; text-align: center; display: inline-block; font-size: 12px;" class="normalBtn">{{$t('objFill.xz')}}</a>
			    	   		</p>-->
			    	   	</div>
		    	   </div>
		    	 
		    	<div slot="reference" @click="getPayDetail(item,1)"  style="width: 46px; height: 46px; display: inline-block; position: relative; cursor: pointer;">
		    		<div style="position: absolute; z-index: 5; left: 0; top: 0; width: 46px; height: 46px; line-height: 46px; text-align: center; background: rgba(0,0,0,.5);">
		    		<i style="color: #fff;" class="el-icon-search"></i>
		    		</div>
		    		<img  src="../../assets/img/erweima.png" width="46px"  height="46px"/>
		    	</div>
		    	</el-popover>
		</el-popover>
	</div>
</template>

<script>
	export default {
		props: ["item"],
		data() {
			return {
				payObj: {},
				payWay: '3',
				minpay: '0',
				payMoney: '0',
				payType: '',
				lastTime: '',
				isShowPic: false,
				payPic: '',
				isDesc: false,
				descMin: 0,
				isOK:false,
				descSecond: 0,
				fylxList: []
			};
		},
		mounted() {},
		methods: {
			getPayDetail(obj, Type) {
				let nowTime = new Date()
				let ExpireDate = ''
				this.apipost('OnlinePay_post_GetURL', {
					OrderID: obj.orderId,
					OrderSource: 8
				}, res => {
					if(res.data.resultCode == 1) {
						if(Object.keys(res.data.data).length == 0) {
							if(Type == 2) {
								this.getCodeUrl(obj)
							} else {
								//this.$message.warning(this.$t('objFill.weishengcewm'))
							}
							this.isOK=true
						} else {
							this.isOK=false
							ExpireDate = new Date(res.data.data.ExpireDate)
							setInterval(() => {
								this.descTime(res.data.data.ExpireDate)
							}, 1000);
							this.payPic=res.data.data.CodeURL
							this.isShowPic = true
						}
					} else {

					}
				}, err => {})

				//				if(nowTime>=ExpireDate){
				//					this.$message.warning('二维码过期,请从新生成')
				//					this.isShowPic=false
				//					this.getCodeUrl(obj)
				//				}else{
				//					this.isShowPic=false
				//				}

			},

			getCodeUrl(obj) {
				this.apipost('Financial_post_GetLowPrice', {
					OrderID: obj.orderId,
					OrderResource: 8
				}, res => {
					if(res.data.resultCode == 1) {
						if(res.data.data.LowDeposit != -1) {
							this.minpay = res.data.data.LowDeposit
							this.payMoney = res.data.data.LowDeposit
						}
					}
				}, err => {})
			},

			getPayPic(obj) {
				let msg = {}
				msg.OrderSource = 8
				msg.body = obj.description
				msg.attach = this.payType + '|' +obj.contactName+'|'+ obj.orderId+'|'+obj.customerId
				msg.total_fee = this.payMoney
				msg.payway = this.payWay
				this.apipost('OnlinePay_post_GetCodeUrl', msg, res => {
					if(res.data.resultCode == 1) {						
						this.payPic = res.data.data.CodeURL
						this.lastTime = new Date(res.data.data.ExpireDate)
						setInterval(() => {
							this.descTime(res.data.data.ExpireDate)
						}, 1000);
						this.isShowPic = true
					} else {
						this.$message.error(res.data.message)
					}
				}, err => {})
			},
			descTime(dateString) {
				// 目标日期时间戳
				const end = Date.parse(new Date(dateString))
				// 当前时间戳
				const now = Date.parse(new Date())
				// 相差的毫秒数
				const msec = end - now
				// 计算时分秒数
				let day = parseInt(msec / 1000 / 60 / 60 / 24)
				let hr = parseInt(msec / 1000 / 60 / 60 % 24)
				let min = parseInt(msec / 1000 / 60 % 60)
				let sec = parseInt(msec / 1000 % 60)
				// 个位数前补零
				hr = hr > 9 ? hr : '0' + hr
				min = min > 9 ? min : '0' + min
				sec = sec > 9 ? sec : '0' + sec
				// 控制台打印
				if(end-now>0){
				this.descMin = min
				this.descSecond = sec
				}else{
			        this.isOK=true
					this.descMin = 0
					this.descSecond = 0
				}
				// 一秒后递归
			},
		},

	};
</script>

<style>

</style>