Explorar o código

订单列表详情倒计时

chenrui %!s(int64=4) %!d(string=hai) anos
pai
achega
13e9aab46c
Modificáronse 2 ficheiros con 12 adicións e 13 borrados
  1. 5 8
      pages/order/order.vue
  2. 7 5
      pages/order/orderDetail.vue

+ 5 - 8
pages/order/order.vue

@@ -277,14 +277,11 @@
 						} else {
 							this.list = res.data.list || []
 						}
-						// let nowT = new Date().valueOf() // 现在时间戳
-						console.log(new Date(),'----当前时间')
-						let nowT = moment(new Date()).unix() // 当前时间戳
-						this.list.map(item=>{
-							// let orderT = new Date(item.orderTime).valueOf() // 下单时间戳
-							let orderT = moment(item.orderTime).unix() // 下单时间戳
-							let tt = ((1800 * 1000) - (nowT - orderT))/1000  // 距离30分钟支付 相差时间戳  
-							console.log(tt,'-------------tt')
+						const date1 = moment().toArray()  //  当前时间 数组形式
+						this.list.map(item=>{ 
+							const date2 = moment(item.orderTime).toDate()  //  下单时间  日期格式
+							const date3 = moment(date2).toArray()  //  下单时间  数组形式
+							const tt = 1800 - moment(date1).diff(moment(date3), 'seconds')//   距离30分钟支付   当前剩余秒数 = 1800秒 - 计算相差的秒数(当前时间-支付时间)
 							item.leftTimeT = tt > 0 ? tt : 0
 						})
 						this.total = res.data.count || 0

+ 7 - 5
pages/order/orderDetail.vue

@@ -154,11 +154,13 @@
 		methods: {
 			// 支付剩余时间
 			leftTimeFun() {
-				let nowT = moment(new Date()).unix() // 当前时间戳
-				let orderT = moment(this.orderInfo.orderTime).unix() // 下单时间戳
-				let tt = (1800 * 1000) - (nowT - orderT)   // 距离30分钟支付 相差时间戳
-				if (tt >0) {
-					this.leftTime =  parseInt(tt/(60*1000))
+				const date1 = moment().toArray()  //  当前时间 数组形式
+				const date2 = moment(this.orderInfo.orderTime).toDate()  //  下单时间  日期格式
+				const date3 = moment(date2).toArray()  //  下单时间  数组形式
+				const date4 = moment(date1).diff(moment(date3), 'seconds')//计算相差的秒数
+				const tt = 30 - Math.ceil(date4/60)  //向上取整
+				if (tt > 0) {
+					this.leftTime = tt
 				} else {
 					// this.getOrderDetail()
 					this.leftTime = '00'