Commit 7bed1351 by liimin

feat(订单详情): 优化物流信息展示和交互功能

- 在TimeLine组件中新增电话拨打功能并优化样式
- 修复收货地址信息显示错误问题
- 重构Express组件物流状态处理逻辑
- 添加派件中状态并优化状态判断规则
- 优化物流信息为空时的默认显示内容
- 调整页面布局和样式细节
1 parent 8eda76e6
...@@ -5,10 +5,17 @@ Component({ ...@@ -5,10 +5,17 @@ Component({
nodes: { nodes: {
type: Array, type: Array,
value: [], value: [],
},
height:{
type:String,
value:'256rpx'
} }
}, },
methods: {
// 拨打电话
makePhoneCall(e) {
const phone = e.currentTarget.dataset.phone;
if (phone) {
wx.makePhoneCall({
phoneNumber: phone
});
}
}
}
}); });
\ No newline at end of file \ No newline at end of file
{ {
"component": true, "component": true,
"usingComponents": {} "usingComponents": {
"mp-html":"/components/mp-html/index"
}
} }
\ No newline at end of file \ No newline at end of file
/* 时间轴容器 */ /* 时间轴容器 */
.timeline-container { .timeline-container {
padding: 20rpx 0; // padding: 20rpx 0;
overflow-y: auto; overflow-y: auto;
} }
/* 时间轴节点 */ /* 时间轴节点 */
.timeline-node { .timeline-node {
position: relative; position: relative;
padding-bottom: 40rpx; padding-bottom: 32rpx;
display: flex; display: flex;
&:last-child { &:last-child {
...@@ -27,8 +27,8 @@ ...@@ -27,8 +27,8 @@
/* 时间轴节点点 */ /* 时间轴节点点 */
.timeline-node__dot { .timeline-node__dot {
width: 22rpx; width: 20rpx;
height: 22rpx; height: 20rpx;
background-color: #e8e8ea; background-color: #e8e8ea;
border-radius: 50%; border-radius: 50%;
z-index: 1; z-index: 1;
...@@ -116,8 +116,7 @@ ...@@ -116,8 +116,7 @@
/* 时间轴头部 */ /* 时间轴头部 */
.timeline-node__header { .timeline-node__header {
display: flex; display: flex;
margin-bottom: 16rpx; margin-bottom: 8rpx;
margin-bottom: 16rpx;
align-items: center; align-items: center;
gap: 20rpx; gap: 20rpx;
} }
...@@ -125,7 +124,7 @@ ...@@ -125,7 +124,7 @@
/* 时间轴标题 */ /* 时间轴标题 */
.timeline-node__title { .timeline-node__title {
font-weight: 500; font-weight: 500;
font-size: 28rpx; font-size: 32rpx;
margin-bottom: 8rpx; margin-bottom: 8rpx;
line-height: 1.4; line-height: 1.4;
} }
...@@ -159,3 +158,21 @@ ...@@ -159,3 +158,21 @@
color: #656566; color: #656566;
} }
} }
.phone-numbers {
margin-top: 8rpx;
}
.phone-number {
display: inline-block;
margin-right: 16rpx;
margin-top: 8rpx;
}
.phone-call-text {
color: #fff;
font-size: 24rpx;
background-color: var(--btnColor);
padding: 4rpx 12rpx;
border-radius: 24rpx;
}
\ No newline at end of file \ No newline at end of file
<!-- 时间轴组件 --> <!-- 时间轴组件 -->
<view class="timeline-container" style="height:{{height}}"> <view class="timeline-container">
<view wx:for="{{nodes}}" wx:key="index" class="timeline-node"> <view wx:for="{{nodes}}" wx:key="index" class="timeline-node">
<!-- 时间轴节点 --> <!-- 时间轴节点 -->
<view class="timeline-node__dot-wrapper"> <view class="timeline-node__dot-wrapper">
...@@ -15,7 +15,17 @@ ...@@ -15,7 +15,17 @@
<view wx:if="{{item.operateTime}}" class="timeline-node__time">{{item.operateTime}}</view> <view wx:if="{{item.operateTime}}" class="timeline-node__time">{{item.operateTime}}</view>
</view> </view>
<view class="timeline-node__tip"> <view class="timeline-node__tip">
{{item.content}} <view class="timeline-node__tip">
<rich-text nodes="{{item.content}}"></rich-text>
<!-- 手机号码点击区域 -->
<view wx:if="{{item.phones && item.phones.length > 0}}" class="phone-numbers">
<view wx:for="{{item.phones}}" wx:for-item="phone" wx:key="*this"
class="phone-number" bindtap="makePhoneCall" data-phone="{{phone}}">
<!-- <mp-icon icon="cellphone" color="var(--btnColor)" size="{{14}}"></mp-icon> -->
<text class="phone-call-text">拨打电话: {{phone}}</text>
</view>
</view>
</view>
</view> </view>
</view> </view>
</view> </view>
......
...@@ -4,6 +4,7 @@ const LOGISTICS_STATUS = { ...@@ -4,6 +4,7 @@ const LOGISTICS_STATUS = {
1002: "运输中", 1002: "运输中",
1003: "已签收", 1003: "已签收",
1004: "拒收", 1004: "拒收",
1005: "正在派件", // 新增状态
}; };
// 状态判断规则配置 // 状态判断规则配置
...@@ -19,34 +20,35 @@ const STATUS_RULES = [ ...@@ -19,34 +20,35 @@ const STATUS_RULES = [
statusDesc: "拒收", statusDesc: "拒收",
}, },
{ {
keywords: ["派件", "驿站", "暂存"], keywords: [
status: 1002, "正在派送",
statusDesc: "运输中", "正在派件",
"派送中",
"正在为您派送",
"派送",
"派件",
"派件中",
],
status: 1005,
statusDesc: "派件中",
}, },
{ {
keywords: ["转运中心", "发往", "到达"], keywords: ["驿站", "暂存", "已发往", "转运中心", "发往", "到达", "已到达"],
status: 1002, status: 1002,
statusDesc: "运输中", statusDesc: "运输中",
}, },
{ {
keywords: ["已收件", "揽收"], keywords: ["已收件", "揽收", "揽件"],
status: 1001,
statusDesc: "已揽件",
},
{
keywords: ["已发往"],
status: 1001, status: 1001,
statusDesc: "已揽件", statusDesc: "已揽件",
}, },
]; ];
Component({ Component({
properties: { properties: {
expressInfo: { expressInfo: {
type: Object, type: Object,
value: {}, value: {},
observer: function (val) { observer: function (val) {
if (!val) return;
this.processExpressInfo(val); this.processExpressInfo(val);
}, },
}, },
...@@ -54,6 +56,10 @@ Component({ ...@@ -54,6 +56,10 @@ Component({
type: Boolean, type: Boolean,
value: false, value: false,
}, },
receiver: {
type: String,
value: "",
},
}, },
data: { data: {
...@@ -89,20 +95,21 @@ Component({ ...@@ -89,20 +95,21 @@ Component({
* @returns {boolean} 是否显示该轨迹 * @returns {boolean} 是否显示该轨迹
*/ */
_shouldShowTrack(trackStatus, logisticsStatus) { _shouldShowTrack(trackStatus, logisticsStatus) {
return true;
const statusThresholds = { const statusThresholds = {
1000: 1000, // 待揽件 - 只显示收件相关记录 1000: 1000, // 待揽件 - 只显示收件相关记录
1001: 1001, // 已揽件 - 显示揽件和发往记录 1001: 1001, // 已揽件 - 显示揽件和发往记录
1002: 1002, // 运输中 - 显示所有运输中的记录 1002: 1002, // 运输中 - 显示所有运输中的记录
1003: 1003, // 已签收 - 显示所有记录 1003: 1003, // 已签收 - 显示所有记录
1004: 1004, // 拒收 - 显示所有记录 1004: 1004, // 拒收 - 显示所有记录
1005: 1005, // 正在派件 - 显示所有记录
}; };
const threshold = statusThresholds[logisticsStatus]; const threshold = statusThresholds[logisticsStatus];
return threshold !== undefined ? trackStatus <= threshold : true; return threshold !== undefined ? trackStatus <= threshold : true;
}, },
/** /**
* 处理物流轨迹数据 * 处理轨迹数据
* @param {Array} shipmentTrack - 原始轨迹数据 * @param {Array} shipmentTrack - 原始轨迹数据
* @param {number} logisticsStatus - 物流状态 * @param {number} logisticsStatus - 物流状态
* @returns {Array} 处理后的轨迹数据 * @returns {Array} 处理后的轨迹数据
...@@ -112,38 +119,62 @@ Component({ ...@@ -112,38 +119,62 @@ Component({
return []; return [];
} }
// 根据showAll决定显示数量 // 第一步:处理所有轨迹数据,获取状态和描述
const tracksToProcess = this.data.showAll const tracks = shipmentTrack
? shipmentTrack
: shipmentTrack.slice(0, 2);
return tracksToProcess
.map((track, index) => { .map((track, index) => {
const { content = "", operateTime = "" } = track; const { content = "", operateTime = "" } = track;
const isLast = index === 0;
// 根据内容判断状态 // 根据内容判断状态
const { status, statusDesc: initialStatusDesc } = const { status, statusDesc } =
this._determineStatusByContent(content); this._determineStatusByContent(content);
// 根据整体物流状态进行最终调整 // 提取手机号码
let finalStatusDesc = initialStatusDesc; const phoneRegex = /(1[3-9]\d{9}|0\d{2,3}[-]?\d{7,8})/g;
if (logisticsStatus < status) { const phones = [];
finalStatusDesc = `${LOGISTICS_STATUS[logisticsStatus]}(进行中)`; let match;
let contentCopy = content;
while ((match = phoneRegex.exec(content)) !== null) {
phones.push(match[1]);
} }
// 高亮手机号码和座机号码
const highlightedContent = content.replace(
phoneRegex,
'<span style="color: #fb8a32;">$1</span>'
);
return { return {
...track, ...track,
content, content: highlightedContent,
phones: phones, // 添加提取的手机号码数组
operateTime, operateTime,
type: isLast ? "active" : "", type: "",
status, status,
statusDesc: finalStatusDesc, statusDesc,
}; };
}) })
.filter((track) => .filter((track) =>
this._shouldShowTrack(track.status, logisticsStatus) this._shouldShowTrack(track.status, logisticsStatus)
); );
// 使用数组反转实现同一状态只显示最后一个的逻辑
// 1. 先反转数组
const reversedTracks = [...tracks].reverse();
// 2. 应用第一次出现状态显示,后续相同状态不显示的逻辑
let lastStatus = null;
const processedReversedTracks = reversedTracks.map((track) => {
const result = { ...track };
if (track.status === lastStatus && track.status === 1002) {
result.statusDesc = "";
result.type = "small";
} else {
lastStatus = track.status;
}
return result;
});
// 3. 再次反转数组,恢复原始顺序
return processedReversedTracks.reverse();
}, },
/** /**
...@@ -152,30 +183,104 @@ Component({ ...@@ -152,30 +183,104 @@ Component({
*/ */
processExpressInfo(expressInfo) { processExpressInfo(expressInfo) {
if (!expressInfo || typeof expressInfo !== "object") { if (!expressInfo || typeof expressInfo !== "object") {
wx.p.sentry.reportError(`快递信息异常:expressInfo参数无效`, {expressInfo}); wx.p.sentry.reportError(`快递信息异常:expressInfo参数无效`, {
expressInfo,
});
console.warn("Express组件: expressInfo参数无效"); console.warn("Express组件: expressInfo参数无效");
return; return;
} }
const { logisticsStatus, shipmentTrack, ...rest } = expressInfo; const {
logisticsStatus,
shipmentTrack,
expressName,
shipmentCode,
...rest
} = expressInfo;
// 验证必要字段 // 验证必要字段
if (typeof logisticsStatus !== "number") { if (typeof logisticsStatus !== "number") {
wx.p.sentry.reportError(`快递信息异常:logisticsStatus字段无效`, {expressInfo}); wx.p.sentry.reportError(`快递信息异常:logisticsStatus字段无效`, {
expressInfo,
});
console.warn("Express组件: logisticsStatus字段无效"); console.warn("Express组件: logisticsStatus字段无效");
return; return;
} }
const processedTrack = this.processShipmentTrack( // 创建默认轨迹对象
const statusDesc = LOGISTICS_STATUS[logisticsStatus] || "未知状态";
let defaultContent = "";
switch (logisticsStatus) {
case 1000:
defaultContent = `物流单号已生成,等待快递揽收。${
expressName ? `物流公司:${expressName}` : ""
}${shipmentCode ? `,运单号:${shipmentCode}` : ""}`;
break;
case 1001:
defaultContent = `包裹已被${
expressName || "快递公司"
}揽收,即将开始运输。`;
break;
case 1002:
defaultContent = `包裹正在运输中,请耐心等待。`;
break;
case 1003:
defaultContent = `包裹已签收,感谢您的购买。`;
break;
case 1004:
defaultContent = `包裹被拒收,请联系客服处理。`;
break;
default:
defaultContent = `包裹状态更新中,请稍后查看。`;
}
// 创建默认轨迹节点
const defaultTrackNode = {
content: defaultContent,
operateTime: "",
type: "normal",
status: logisticsStatus,
statusDesc: statusDesc,
};
// 处理正常轨迹数据
let normalTrackNodes = [];
if (
shipmentTrack &&
Array.isArray(shipmentTrack) &&
shipmentTrack.length > 0
) {
normalTrackNodes = this.processShipmentTrack(
shipmentTrack, shipmentTrack,
logisticsStatus logisticsStatus
); );
} else {
normalTrackNodes = [defaultTrackNode];
}
// 创建收货地址特殊节点
const receiverNode = {
content: this.data.receiver,
operateTime: "",
type: "special",
statusDesc: "收货地址",
};
// 合并节点:收货地址节点 + 默认轨迹节点 + 正常轨迹节点(如果有)
// 如果有正常轨迹节点,则将默认轨迹节点放在最后作为补充
// 如果没有正常轨迹节点,则只使用默认轨迹节点
let combinedTrack = [...normalTrackNodes, receiverNode];
if (!this.data.showAll) {
combinedTrack = combinedTrack.slice(0, 2);
}
combinedTrack[0].type = "active";
const logisticsData = { const logisticsData = {
...rest, ...rest,
expressName,
shipmentCode,
logisticsStatus, logisticsStatus,
logisticsStatusDesc: LOGISTICS_STATUS[logisticsStatus] || "未知状态", logisticsStatusDesc: LOGISTICS_STATUS[logisticsStatus] || "未知状态",
shipmentTrack: processedTrack, shipmentTrack: combinedTrack,
}; };
this.setData({ this.setData({
......
<!-- 时间轴 -->
<view class="item"> <view class="item">
<TimeLine nodes="{{logisticsData.shipmentTrack ||[]}}" height="{{height}}"/> <TimeLine nodes="{{logisticsData.shipmentTrack ||[]}}" height="{{height}}"/>
</view>
\ No newline at end of file \ No newline at end of file
</view>
\ No newline at end of file \ No newline at end of file
.express-container {
background-color: #fff;
border-radius: 12rpx;
overflow: hidden;
}
.express-info {
padding: 24rpx;
border-bottom: 1rpx solid #f5f5f5;
}
.express-status {
margin-bottom: 16rpx;
}
.status-text {
font-size: 32rpx;
font-weight: 500;
color: #333;
}
.express-detail {
display: flex;
flex-direction: column;
gap: 8rpx;
}
.express-name, .express-code {
font-size: 28rpx;
color: #666;
}
...@@ -6,7 +6,11 @@ Component({ ...@@ -6,7 +6,11 @@ Component({
}, },
expressInfo:{ expressInfo:{
type: Object, type: Object,
value: {} value: null
},
receiver:{
type: String,
value: '',
} }
}, },
}); });
\ No newline at end of file \ No newline at end of file
...@@ -31,5 +31,6 @@ ...@@ -31,5 +31,6 @@
width: 670rpx; width: 670rpx;
height: 2rpx; height: 2rpx;
background: #EFF0F2; background: #EFF0F2;
margin-bottom: 24rpx;
} }
} }
\ No newline at end of file \ No newline at end of file
<popup show="{{showExpress}}" show-close-button="{{true}}" showFooter="{{false}}" headerColor="#F7F7F7" title="物流详情" bindconfirm="onConfirmPopup"> <popup show="{{showExpress}}" show-close-button="{{true}}" showFooter="{{false}}" headerColor="#F7F7F7" title="物流详情" bindconfirm="onConfirmPopup">
<view class="popup-content"> <view class="popup-content" wx:if="{{expressInfo && receiver}}">
<Expressage expressInfo="{{expressInfo}}"></Expressage> <Expressage expressInfo="{{expressInfo}}"></Expressage>
<view class="line"></view> <view class="line"></view>
<Express expressInfo="{{expressInfo}}" showAll="{{true}}" /> <Express expressInfo="{{expressInfo}}" receiver="{{receiver}}" showAll="{{true}}" />
</view> </view>
</popup> </popup>
\ No newline at end of file \ No newline at end of file
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
<view class="item"> <view class="item">
<view class="label">收货地址:</view> <view class="label">收货地址:</view>
<view class="value">{{orderInfo.receiveAddress || ''}} <view class="value">{{orderInfo.receiveAddress || ''}}
<view class="value">{{orderInfo.receviveInfo || ''}}</view> <view class="value">{{orderInfo.receiveInfo || ''}}</view>
</view> </view>
</view> </view>
\ No newline at end of file \ No newline at end of file
...@@ -35,7 +35,7 @@ Page({ ...@@ -35,7 +35,7 @@ Page({
}, },
queryLogistics(subOrderCode) { queryLogistics(subOrderCode) {
wx.p.api.shopmallApi.queryLogistics({ subOrderCode }).then((data) => { wx.p.api.shopmallApi.queryLogistics({ subOrderCode }).then((data) => {
if(data.shipmentTrack&&data.shipmentTrack.length){ if(data&&data.expressCode){
this.setData({ this.setData({
logisticsInfo: data, logisticsInfo: data,
}) })
...@@ -57,29 +57,33 @@ Page({ ...@@ -57,29 +57,33 @@ Page({
receiveName, receiveName,
receiveMobile, receiveMobile,
} = data.receiveAddress; } = data.receiveAddress;
const receiveAddress = provinceName + cityName + countyName + address;
const receiveInfo = receiveName + receiveMobile;
this.setData({ this.setData({
orderInfo: { orderInfo: {
...data, ...data,
...this.data.orderInfo, ...this.data.orderInfo,
receiveAddress: provinceName + cityName + countyName + address, receiveAddress,
receviveInfo: receiveName + receiveMobile, receiveInfo,
}, },
}); receiver: `${receiveAddress}<br/>${receiveInfo}`,
if (data.expressName && this.data.orderInfo.goodsSource==GoodsSource.SELF) { // 如果有expressInfo也一并设置
this.setData({ ...(data.expressName && this.data.orderInfo.goodsSource == GoodsSource.SELF ? {
expressInfo: { expressInfo: {
expressName: data.expressName, expressName: data.expressName,
shipmentCode: data.expressNo, shipmentCode: data.expressNo,
},
});
} }
}).catch((err) => { } : {})
});
console.log(this.data)
})
.catch((err) => {
wx.p.sentry.reportError(`订单详情异常:${err.message}`, {subOrderCode,err}); wx.p.sentry.reportError(`订单详情异常:${err.message}`, {subOrderCode,err});
}) })
.finally(() => { .finally(() => {
wx.hideLoading(); wx.hideLoading();
}); });
}, },
showExpressPop() { showExpressPop() {
this.setData({ this.setData({
isShowExpressPop: true, isShowExpressPop: true,
......
...@@ -6,10 +6,13 @@ ...@@ -6,10 +6,13 @@
.express-detail{ .express-detail{
position: absolute; position: absolute;
right: 24rpx; right: 24rpx;
top:12rpx; top:0;
color: var(--btnColor); color: var(--btnColor);
font-weight: 400; font-weight: 400;
font-size: 24rpx; font-size: 24rpx;
display: flex;
align-items: center;
gap: 6rpx;
} }
} }
} }
......
...@@ -4,14 +4,15 @@ ...@@ -4,14 +4,15 @@
<Status title="{{Status.text}}" image="{{Status.image}}" tips="{{Status.tips}}"></Status> <Status title="{{Status.text}}" image="{{Status.image}}" tips="{{Status.tips}}"></Status>
</BlockBox> </BlockBox>
<!-- 云中鹤的有物流信息 --> <!-- 云中鹤的有物流信息 -->
<BlockBox wx:if="{{logisticsInfo}}"> <BlockBox wx:if="{{receiver && logisticsInfo}}">
<view class="express-box" bindtap="showExpressPop"> <view class="express-box" bindtap="showExpressPop">
<view class="express-detail"> <view class="express-detail">
物流详情 物流详情
<mp-icon icon="arrow" color="var(--btnColor)" size="{{11}}"></mp-icon> <mp-icon icon="arrow" color="var(--btnColor)" size="{{11}}"></mp-icon>
</view> </view>
<Express expressInfo="{{logisticsInfo}}" showAll="{{false}}"/> <Express expressInfo="{{logisticsInfo}}" receiver="{{receiver}}" showAll="{{false}}"/>
</view> </view>
<Expresspop showExpress="{{isShowExpressPop}}" expressInfo="{{logisticsInfo}}" receiver="{{receiver}}" />
</BlockBox> </BlockBox>
<!-- 自营商品展示快递信息 --> <!-- 自营商品展示快递信息 -->
<BlockBox wx:if="{{expressInfo}}"> <BlockBox wx:if="{{expressInfo}}">
...@@ -26,7 +27,6 @@ ...@@ -26,7 +27,6 @@
<!-- <BlockBox> <!-- <BlockBox>
<content item="{{orderInfo}}" /> <content item="{{orderInfo}}" />
</BlockBox> --> </BlockBox> -->
<Expresspop showExpress="{{isShowExpressPop}}" expressInfo="{{logisticsInfo}}" wx:if="{{logisticsInfo}}" />
</view> </view>
</block> </block>
<glsx-privacy appletName="积分商城"></glsx-privacy> <glsx-privacy appletName="积分商城"></glsx-privacy>
\ No newline at end of file \ No newline at end of file
...@@ -11,7 +11,7 @@ Component({ ...@@ -11,7 +11,7 @@ Component({
observer: function (v) { observer: function (v) {
v && this.getStatus(v); v && this.getStatus(v);
}, },
}, }
}, },
/** /**
...@@ -30,6 +30,6 @@ Component({ ...@@ -30,6 +30,6 @@ Component({
this.setData({ this.setData({
status: _order.text, status: _order.text,
}); });
}, }
}, }
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!