From df7c8301893a767e5a70933db232ca679728718a Mon Sep 17 00:00:00 2001
From: hejianhao <15708179461@qq.com>
Date: 星期五, 03 四月 2026 11:14:29 +0800
Subject: [PATCH] feat(后备箱控制): 增加后备箱状态轮询机制

---
 src/robotaxi/pages/begin-route/components/calling-car.tsx |   70 +++++++++++++++++++++++++++++++----
 src/robotaxi/api/begin-route.ts                           |    9 ++++
 src/robotaxi/pages/operating-area/index.tsx               |    4 +-
 3 files changed, 73 insertions(+), 10 deletions(-)

diff --git a/src/robotaxi/api/begin-route.ts b/src/robotaxi/api/begin-route.ts
index fd15389..b17df8e 100644
--- a/src/robotaxi/api/begin-route.ts
+++ b/src/robotaxi/api/begin-route.ts
@@ -64,6 +64,15 @@
     }, true);
 }
 
+// 查询后备箱开启状态
+export const queryVehicleTrunkOpenStatus = async (payload) => {
+    return request({
+        url: _ROBOTAXI_HOST + '/vehicleConvoy/api/v1/mini-program/order/queryVehicleTrunkOpenStatus',
+        method: 'GET',
+        payload
+    }, true);
+}
+
 // 获取自动结束行程时间
 export const queryOrderFinishTime = async () => {
     return request({
diff --git a/src/robotaxi/pages/begin-route/components/calling-car.tsx b/src/robotaxi/pages/begin-route/components/calling-car.tsx
index 9c8ecf2..4726650 100644
--- a/src/robotaxi/pages/begin-route/components/calling-car.tsx
+++ b/src/robotaxi/pages/begin-route/components/calling-car.tsx
@@ -25,6 +25,7 @@
     setTemperature,
     unlockVehicle,
     queryTemperatureByOrderId,
+    queryVehicleTrunkOpenStatus,
     queryOrderFinishTime,
     queryFareBreakdown,
     submitOrderComment,
@@ -96,6 +97,7 @@
     const [showDetail, setShowDetail] = useState(false); // 是否显示费用明细
     const countdownTimerRef = useRef<any>(null); // 倒计时定时器引用
     const finishCountdownTimerRef = useRef<any>(null); // 结束倒计时定时器引用
+    const trunkPollTimerRef = useRef<any>(null); // 后备箱轮询定时器引用
     const tempTimerRef = useRef<any>(null); // 温度定时器引用
     const lastConfirmedTempRef = useRef<number>(); // 上一次确认的温度
     const countdownFinishedRef = useRef(false); // 倒计时是否结束
@@ -324,6 +326,9 @@
             if (finishCountdownTimerRef.current) {
                 clearTimeout(finishCountdownTimerRef.current);
             }
+            if (trunkPollTimerRef.current) {
+                clearTimeout(trunkPollTimerRef.current);
+            }
         };
     }, [tripStatus, estimatedWaitMinutes, orderId, finishCountdownEnabled]);
 
@@ -332,6 +337,9 @@
         return () => {
             if (tempTimerRef.current) {
                 clearTimeout(tempTimerRef.current);
+            }
+            if (trunkPollTimerRef.current) {
+                clearTimeout(trunkPollTimerRef.current);
             }
         };
     }, []);
@@ -475,11 +483,57 @@
                 return;
             }
             if (doorType === 'trunk') {
-                Taro.showToast({
-                    title: trunkStatus ? '关闭成功' : '打开成功',
-                    icon: 'none'
-                });
-                onSuccess?.();
+                const loadingText = trunkStatus ? '正在关闭后备箱' : '正在开启后备箱';
+                Taro.showLoading({ title: loadingText, mask: true });
+
+                let pollCount = 0;
+                const maxPolls = 3;
+                const pollInterval = 2000; // 2秒
+
+                const doPoll = () => {
+                    queryVehicleTrunkOpenStatus({ orderId: targetOrderId }).then((pollRes: any) => {
+                        const data = pollRes?.data ?? pollRes?.result ?? pollRes;
+                        const value = data?.stateMap?.trunkAjarCloseSt?.value;
+                        
+                        if (value === '0' || value === '1') {
+                            // 0: 关闭, 1: 开启
+                            const isOpen = value === '1';
+                            setTrunkStatus(isOpen);
+                            Taro.hideLoading();
+                            Taro.showToast({
+                                title: isOpen ? '打开成功' : '关闭成功',
+                                icon: 'none'
+                            });
+                            onSuccess?.();
+                        } else {
+                            // 继续轮询
+                            pollCount++;
+                            if (pollCount < maxPolls) {
+                                trunkPollTimerRef.current = setTimeout(doPoll, pollInterval);
+                            } else {
+                                Taro.hideLoading();
+                                Taro.showToast({
+                                    title: trunkStatus ? '关闭后备箱失败' : '开启后备箱失败',
+                                    icon: 'none'
+                                });
+                            }
+                        }
+                    }).catch(() => {
+                        pollCount++;
+                        if (pollCount < maxPolls) {
+                            trunkPollTimerRef.current = setTimeout(doPoll, pollInterval);
+                        } else {
+                            Taro.hideLoading();
+                            Taro.showToast({
+                                title: trunkStatus ? '关闭后备箱失败' : '开启后备箱失败',
+                                icon: 'none'
+                            });
+                        }
+                    });
+                };
+
+                // 延迟2秒后开始第一次轮询
+                trunkPollTimerRef.current = setTimeout(doPoll, pollInterval);
             }
             if (doorType === 'door') {
                 Taro.showToast({
@@ -493,7 +547,7 @@
             }
         }).catch(() => {
             Taro.showToast({
-                title: res?.msg || '解锁失败,请重试或联系客服',
+                title: '解锁失败,请重试或联系客服',
                 icon: 'none'
             });
         });
@@ -601,7 +655,7 @@
                     {
                         tripStatus == 5 &&
                         <View className="car-card-arrive">
-                            <View className={`car-card-arrive-item ${trunkStatus && 'close-btn-item'}`} onClick={() => handleUnlock('trunk', () => setTrunkStatus((prev) => !prev))}>
+                            <View className={`car-card-arrive-item ${trunkStatus && 'close-btn-item'}`} onClick={() => handleUnlock('trunk')}>
                                 {
                                     trunkStatus ?
                                         <Image className="car-card-arrive-item-img" src={require('../../../assets/trunk-open.png')} />
@@ -763,7 +817,7 @@
                     <View className="car-card-reach-text">点击按钮开车门</View>
                     <Image className='car-card-reach-img' src='https://huishou-1323682843.cos.ap-nanjing.myqcloud.com/images/f4a18c3f-a2db-45e6-8967-1510355b5e3b.webp' />
                     <View className="car-card-reach-btn">
-                        <View className={`car-card-reach-btn-item ${trunkStatus && 'close-btn-item'}`} onClick={() => handleUnlock('trunk', () => setTrunkStatus((prev) => !prev))}>
+                        <View className={`car-card-reach-btn-item ${trunkStatus && 'close-btn-item'}`} onClick={() => handleUnlock('trunk')}>
                             {
                                 trunkStatus ?
                                     <Image className="car-card-reach-btn-item-img" src={require('../../../assets/trunk-open.png')} />
diff --git a/src/robotaxi/pages/operating-area/index.tsx b/src/robotaxi/pages/operating-area/index.tsx
index 436f195..738791c 100644
--- a/src/robotaxi/pages/operating-area/index.tsx
+++ b/src/robotaxi/pages/operating-area/index.tsx
@@ -342,13 +342,13 @@
 
   const renderOperatingTime = (info: any) => {
     if (!info?.rule) {
-      return `全天`;
+      return `工作日全天运营  周末全天运营`;
     }
 
     try {
       const rules = JSON.parse(info.rule);
       if (!Array.isArray(rules) || rules.length === 0) {
-        return `全天`;
+        return `工作日全天运营  周末全天运营`;
       }
 
       const getDayText = (typeStr: number[]) => {

--
Gitblit v1.7.1