| | |
| | | doorType, |
| | | ...locationPayload |
| | | }).then((res: any) => { |
| | | const isFailure = res?.success === false || (typeof res?.code === 'number' && res.code !== 0); |
| | | if (isFailure) { |
| | | Taro.showToast({ |
| | | title: res?.msg || '解锁失败,请重试或联系客服', |
| | | icon: 'none' |
| | | }); |
| | | return; |
| | | } |
| | | if (doorType === 'trunk') { |
| | | const loadingText = trunkStatus ? '正在关闭后备箱' : '正在开启后备箱'; |
| | | Taro.showLoading({ title: loadingText, mask: true }); |
| | |
| | | const maxPolls = 3; |
| | | const pollInterval = 2000; // 2秒 |
| | | |
| | | const handlePollFail = () => { |
| | | pollCount++; |
| | | if (pollCount < maxPolls) { |
| | | trunkPollTimerRef.current = setTimeout(doPoll, pollInterval); |
| | | } else { |
| | | Taro.hideLoading(); |
| | | Taro.showToast({ |
| | | title: trunkStatus ? '关闭后备箱失败' : '开启后备箱失败', |
| | | icon: 'none' |
| | | }); |
| | | } |
| | | }; |
| | | |
| | | const doPoll = () => { |
| | | queryVehicleTrunkOpenStatus({ orderId: targetOrderId }).then((pollRes: any) => { |
| | | const data = pollRes?.data ?? pollRes?.result ?? pollRes; |
| | | const value = data?.stateMap?.trunkAjarCloseSt?.value; |
| | | const data = pollRes; |
| | | const rawValue = data?.stateMap?.trunkAjarCloseSt?.value; |
| | | |
| | | // 如果 data 或 value 为空,继续轮询 |
| | | if (!data || rawValue === undefined || rawValue === null || rawValue === '') { |
| | | handlePollFail(); |
| | | return; |
| | | } |
| | | |
| | | const value = String(rawValue); |
| | | |
| | | if (value === '0' || value === '1') { |
| | | // 0: 关闭, 1: 开启 |
| | |
| | | onSuccess?.(); |
| | | } else { |
| | | // 继续轮询 |
| | | pollCount++; |
| | | if (pollCount < maxPolls) { |
| | | trunkPollTimerRef.current = setTimeout(doPoll, pollInterval); |
| | | } else { |
| | | Taro.hideLoading(); |
| | | Taro.showToast({ |
| | | title: trunkStatus ? '关闭后备箱失败' : '开启后备箱失败', |
| | | icon: 'none' |
| | | }); |
| | | } |
| | | handlePollFail(); |
| | | } |
| | | }).catch(() => { |
| | | pollCount++; |
| | | if (pollCount < maxPolls) { |
| | | trunkPollTimerRef.current = setTimeout(doPoll, pollInterval); |
| | | } else { |
| | | Taro.hideLoading(); |
| | | Taro.showToast({ |
| | | title: trunkStatus ? '关闭后备箱失败' : '开启后备箱失败', |
| | | icon: 'none' |
| | | }); |
| | | } |
| | | handlePollFail(); |
| | | }); |
| | | }; |
| | | |