<template>
	<view v-if="OrderStatus == 0">
		{{wait_for}}
	</view>
</template>

<script>
	export default {
		props: {
			item: {
				type: Object,
				default: () => {}
			},
			status:{
				type:[Number,String],
				default:0
			},
			createtime:{
				type:String,
				default:'2022-11-11 00:00:00'
			}
		},
		data() {
			return {
				wait_for: ''
			}
		},
		mounted() {
			this.tiem(this['OrderStatus'],this['Ordercreatetime']);
		},
		computed:{
			OrderStatus(){
				return this['status']
			},
			Ordercreatetime(){
				return this['createtime']
			}
		},
		methods: {
			// 待支付倒计时
			/**
			 * @param {Number} status 订单的状态
			 * @param {Number} createtime 下单时间
			 */
			tiem() {
				console.log(this['OrderStatus'],'状态');
				if (this['OrderStatus'] != 0) return;
				// 多久之后过期之后的时间
				let date = new Date(this['Ordercreatetime'].replace(/-/g, "/"));
				date.setMinutes(date.getMinutes() + 30);
				this['countDown'] = setTimeout(() => {
					// 最终停止时间时间戳
					let end = date.getTime();
					// 当前时间时间戳
					let start = new Date().getTime();
					let x = new Date(end - start);
					console.log(end - start, '执行2');
					if ((end - start) <= 0) {
						this.$emit('end')
						// this['status'] = 5;
						return;
					};
					this.tiem(this['OrderStatus'], this['Ordercreatetime'].replace(/-/g, "/"))
					let m = x.getMinutes();
					m = m > 9 ? m : `0${m}`;
					let s = x.getSeconds();
					s = s > 9 ? s : `0${s}`;
					this['wait_for'] = `${m}:${s}`;
				}, 1000)
			},
		}
	}
</script>

<style>
</style>
