import React, { useState, useEffect } from 'react' import { View, Text, ScrollView } from '@tarojs/components' import Taro from '@tarojs/taro' import { Button } from '@nutui/nutui-react-taro' import { queryLogistics, formatLogisticsStatus, EXPRESS_COMPANIES } from '@/api/shop/shopLogistics' import type { LogisticsInfo, LogisticsTrack } from '@/api/shop/shopLogistics' import Loading from '@/components/common/Loading' import EmptyState from '@/components/common/EmptyState' definePageConfig({ navigationBarTitleText: '物流详情', }) const LogisticsPage: React.FC = () => { const { orderId, expressNo, expressCompany } = Taro.getCurrentInstance().router?.params || {} const [loading, setLoading] = useState(true) const [logisticsInfo, setLogisticsInfo] = useState(null) const [trackList, setTrackList] = useState([]) useEffect(() => { loadLogistics() }, []) const loadLogistics = async () => { setLoading(true) try { // 必须传入参数 if (!expressNo || !expressCompany) { Taro.showToast({ title: '缺少物流参数', icon: 'none' }) setLoading(false) return } const res = await queryLogistics({ orderId, expressNo, expressCompany, }) if (res?.data) { setLogisticsInfo(res.data.logisticsInfo) setTrackList(res.data.trackList) } } catch (err) { console.error('加载物流信息失败', err) Taro.showToast({ title: '加载失败', icon: 'none' }) } finally { setLoading(false) } } // 复制单号 const copyExpressNo = () => { if (logisticsInfo?.expressNo) { Taro.setClipboardData({ data: logisticsInfo.expressNo, success: () => { Taro.showToast({ title: '单号已复制', icon: 'success' }) }, }) } } // 联系快递员(模拟) const contactRider = () => { Taro.makePhoneCall({ phoneNumber: '400-811-1111', fail: () => { Taro.showToast({ title: '拨打失败', icon: 'none' }) }, }) } // 格式化时间 const formatTime = (time: string) => { if (!time) return '' const date = new Date(time) const month = String(date.getMonth() + 1).padStart(2, '0') const day = String(date.getDate()).padStart(2, '0') const hours = String(date.getHours()).padStart(2, '0') const minutes = String(date.getMinutes()).padStart(2, '0') return `${month}-${day} ${hours}:${minutes}` } // 格式化日期 const formatDate = (time: string) => { if (!time) return '' const date = new Date(time) return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}` } if (loading) { return } if (!logisticsInfo) { return ( ) } const statusInfo = formatLogisticsStatus(logisticsInfo.status) return ( {/* 快递信息卡片 */} {/* 快递logo */} 📦 {logisticsInfo.expressCompanyName} {statusInfo.text} 运单号: {logisticsInfo.expressNo} 复制 {/* 预计送达 */} {logisticsInfo.estimatedTime && ( 预计送达: {formatDate(logisticsInfo.estimatedTime)} 24:00 前 )} {/* 当前状态 */} {statusInfo.icon} {logisticsInfo.status} {logisticsInfo.currentLocation && ( 当前位于: {logisticsInfo.currentLocation} )} 更新时间: {formatTime(logisticsInfo.updateTime)} {/* 收货人信息 */} {logisticsInfo.receiverInfo && ( 收货信息 {logisticsInfo.receiverInfo.name} {logisticsInfo.receiverInfo.phone} {logisticsInfo.receiverInfo.address} )} {/* 物流轨迹 */} 物流详情 {/* 竖线 */} {trackList.map((item, idx) => ( {/* 圆点 */} {item.isCompleted && idx !== 0 ? ( ) : !item.isCompleted ? ( ) : null} {/* 内容 */} {item.status} {formatTime(item.time)} {item.description} {item.location} ))} {/* 温馨提示 */} 温馨提示 1. 快递在运输过程中可能存在延迟,请耐心等待{'\n'} 2. 如有疑问可联系快递公司客服{'\n'} 3. 签收前请检查包裹是否完好 {/* 底部操作 */} ) } export default LogisticsPage