From ec77c6dd50d31d51a2ab7fd2fdc821b15ed80ced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=9C=B1?= <2671189764@qq.com> Date: Tue, 13 May 2025 17:06:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=A7=A3=E5=AF=86=E4=BC=98?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E5=AF=B9=E6=8E=A5=E5=AE=9E=E6=97=B6=E8=AE=A1?= =?UTF-8?q?=E8=B4=B9=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ebike-user/pages/user/home/home.vue | 139 ++++++++++++++++++++-------- 1 file changed, 100 insertions(+), 39 deletions(-) diff --git a/ebike-user/pages/user/home/home.vue b/ebike-user/pages/user/home/home.vue index 64a32c3..46130e7 100644 --- a/ebike-user/pages/user/home/home.vue +++ b/ebike-user/pages/user/home/home.vue @@ -51,11 +51,11 @@ -
+
{ + map.getLoalcation(res => { const { latitude, longitude @@ -213,12 +214,12 @@ } arrBikeData = data || []; const arrData = markers.value || []; - arrBikeData.map((item,index) => { + arrBikeData.map((item, index) => { const { longitude, latitude } = item; - arrData.push( map.addMarker(index, longitude, latitude, "mapbike.png", + arrData.push(map.addMarker(index, longitude, latitude, "mapbike.png", true)); }) markers.value = arrData; @@ -232,7 +233,7 @@ // latitude, // longitude // }; - + // }, // fail(res) { @@ -353,17 +354,42 @@ return; } showOrder.value = true; - if(tempLock==1){ + if (status == 0) { + // 获取订单信息 + getOrderInfo(bikeCode); + order.value.bikecode = bikeCode; + // 设置 intervalId 变量来保存定时器 ID + const intervalId = setInterval(() => { + // 更新订单时间 + order.value.time = timeDifference(createdAt); + console.log(order.value.time); // 输出更新时间 + if (!showOrder.value) { // 如果 showOrder 为 false,停止轮询 + clearInterval(intervalId); // 使用 intervalId 来停止轮询 + } + }, 1000); + } + if (tempLock == 1) { getTracking(); return; } + getTracking(); // if (!orderTimer) { // orderTimer = setInterval(getTracking, 100000); // } }) } - + const getOrderInfo = (bikeCode) => { + const params = { + "userId": oUser.userId, + "bikeCode": bikeCode + } + callOrdereApi("userOrders/costCalculation", params).then(res => { + if (res.code == 200) { + order.value.money = res.data; + } + }) + } //轨迹 function getTracking() { const { @@ -403,7 +429,7 @@ latitude: latGCJ02 } }); - + const startPoint = ridePoint.split(","); const lng = startPoint[0]; const lat = startPoint[1]; @@ -413,7 +439,9 @@ } const arrMakers = markers.value || []; arrPoints.splice(0, 0, start); - let indexStart = findIndex(arrMakers, {pointStart}); + let indexStart = findIndex(arrMakers, { + pointStart + }); indexStart = indexStart == -1 ? arrMakers.length : indexStart; arrMakers[indexStart] = map.addMarker(pointStart, lng, lat, "start.png"); if (data && data.length > 0) { @@ -465,10 +493,10 @@ data } = res; showModelMessage(message) - if(code==200){ - if(orderTimer) { + if (code == 200) { + if (orderTimer) { clearInterval(orderTimer); - orderTimer=null; + orderTimer = null; } orderState.value = 1; } @@ -479,31 +507,33 @@ function endRiding() { checkBikeEnding(); } - - function checkBikeEnding(callback){ + + function checkBikeEnding(callback) { const { bikeCode } = orderData; - const params={bikeCode} + const params = { + bikeCode + } //运营区和停车区检查 - const arrMethod=[callOrdereApi("userOrders/checkBikeInOperation", params, "get") - ,callOrdereApi("userOrders/checkBikeInParking", params, "get")] - Promise.all(arrMethod).then(([res1,res2])=>{ - if(res1.code!=200){ + const arrMethod = [callOrdereApi("userOrders/checkBikeInOperation", params, "get"), callOrdereApi( + "userOrders/checkBikeInParking", params, "get")] + Promise.all(arrMethod).then(([res1, res2]) => { + if (res1.code != 200) { showModelMessage(res1.message); return; } - if(res2.code!=200){ + if (res2.code != 200) { showModelMessage(res2.message); return; } doneRide(); }); } - + //完成骑行 - function doneRide(){ + function doneRide() { const { userId } = oUser; @@ -548,10 +578,10 @@ data } = res; showModelMessage(message) - if(code==200){ - if(orderTimer) { + if (code == 200) { + if (orderTimer) { clearInterval(orderTimer); - orderTimer=null; + orderTimer = null; } orderState.value = 0; } @@ -568,13 +598,13 @@ const { markerId } = e.detail; - if(markerId==pointEnd || markerId==pointStart){ + if (markerId == pointEnd || markerId == pointStart) { return; } - bikeData.value=arrBikeData[markerId]; + bikeData.value = arrBikeData[markerId]; showBikeInfo.value = true; showTools.value = false; - showOrderPay.value=false; + showOrderPay.value = false; } //关闭车辆信息 @@ -583,7 +613,7 @@ showTools.value = true; } - onMounted(()=>{ + onMounted(() => { const instance = getCurrentInstance(); oMap = uni.createMapContext("mapRef", { this: instance.proxy @@ -591,9 +621,9 @@ getLoalcationData(); }) onShow(() => { - oUser = JSON.parse(jkcBaseDecode(uni.getStorageSync("wechat_user"))); - console.log("7777777777777777777777","oUser", oUser) - + if (uni.getStorageSync("wechat_user")) { + oUser = JSON.parse(jkcBaseDecode(uni.getStorageSync("wechat_user"))); + } const { userId } = oUser; @@ -604,8 +634,39 @@ }); onUnload(() => { - console.log("9999999999999999999", "onUnload",orderTimer); + console.log("9999999999999999999", "onUnload", orderTimer); }) + + function parseDate(createTime) { + // 将日期字符串转换为 iOS 支持的格式 + createTime = createTime.replace(" ", "T"); // 将空格替换为 "T",使其符合 "yyyy-MM-ddTHH:mm:ss" 格式 + return new Date(createTime); // 返回新的 Date 对象 + } + + function timeDifference(createTime) { + const currentTime = new Date(); + const createDate = parseDate(createTime); // 使用转换后的日期字符串 + const diffInSeconds = Math.floor((currentTime - createDate) / 1000); + + if (diffInSeconds < 60) return `${diffInSeconds}秒`; + + const diffInMinutes = Math.floor(diffInSeconds / 60); + if (diffInMinutes < 60) { + const remainingSeconds = diffInSeconds % 60; + return `${diffInMinutes}分钟 ${remainingSeconds}秒`; + } + + const diffInHours = Math.floor(diffInMinutes / 60); + if (diffInHours < 24) { + const remainingMinutes = diffInMinutes % 60; + const remainingSeconds = diffInSeconds % 60; + return `${diffInHours}小时 ${remainingMinutes}分钟 ${remainingSeconds}秒`; + } + + const diffInDays = Math.floor(diffInHours / 24); + return `${diffInDays}天 ${diffInHours % 24}小时 ${diffInMinutes % 60}分钟 ${diffInSeconds % 60}秒`; + } +