Commit 7bed1351 by liimin

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

- 在TimeLine组件中新增电话拨打功能并优化样式
- 修复收货地址信息显示错误问题
- 重构Express组件物流状态处理逻辑
- 添加派件中状态并优化状态判断规则
- 优化物流信息为空时的默认显示内容
- 调整页面布局和样式细节
1 parent 8eda76e6
......@@ -5,10 +5,17 @@ Component({
nodes: {
type: Array,
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
{
"component": true,
"usingComponents": {}
"usingComponents": {
"mp-html":"/components/mp-html/index"
}
}
\ No newline at end of file
/* 时间轴容器 */
.timeline-container {
padding: 20rpx 0;
// padding: 20rpx 0;
overflow-y: auto;
}
/* 时间轴节点 */
.timeline-node {
position: relative;
padding-bottom: 40rpx;
padding-bottom: 32rpx;
display: flex;
&:last-child {
......@@ -27,8 +27,8 @@
/* 时间轴节点点 */
.timeline-node__dot {
width: 22rpx;
height: 22rpx;
width: 20rpx;
height: 20rpx;
background-color: #e8e8ea;
border-radius: 50%;
z-index: 1;
......@@ -116,8 +116,7 @@
/* 时间轴头部 */
.timeline-node__header {
display: flex;
margin-bottom: 16rpx;
margin-bottom: 16rpx;
margin-bottom: 8rpx;
align-items: center;
gap: 20rpx;
}
......@@ -125,7 +124,7 @@
/* 时间轴标题 */
.timeline-node__title {
font-weight: 500;
font-size: 28rpx;
font-size: 32rpx;
margin-bottom: 8rpx;
line-height: 1.4;
}
......@@ -158,4 +157,22 @@
.timeline-node__tip {
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
<!-- 时间轴组件 -->
<view class="timeline-container" style="height:{{height}}">
<view class="timeline-container">
<view wx:for="{{nodes}}" wx:key="index" class="timeline-node">
<!-- 时间轴节点 -->
<view class="timeline-node__dot-wrapper">
......@@ -15,7 +15,17 @@
<view wx:if="{{item.operateTime}}" class="timeline-node__time">{{item.operateTime}}</view>
</view>
<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>
......
......@@ -4,6 +4,7 @@ const LOGISTICS_STATUS = {
1002: "运输中",
1003: "已签收",
1004: "拒收",
1005: "正在派件", // 新增状态
};
// 状态判断规则配置
......@@ -19,34 +20,35 @@ const STATUS_RULES = [
statusDesc: "拒收",
},
{
keywords: ["派件", "驿站", "暂存"],
status: 1002,
statusDesc: "运输中",
keywords: [
"正在派送",
"正在派件",
"派送中",
"正在为您派送",
"派送",
"派件",
"派件中",
],
status: 1005,
statusDesc: "派件中",
},
{
keywords: ["转运中心", "发往", "到达"],
keywords: ["驿站", "暂存", "已发往", "转运中心", "发往", "到达", "已到达"],
status: 1002,
statusDesc: "运输中",
},
{
keywords: ["已收件", "揽收"],
status: 1001,
statusDesc: "已揽件",
},
{
keywords: ["已发往"],
keywords: ["已收件", "揽收", "揽件"],
status: 1001,
statusDesc: "已揽件",
},
];
Component({
properties: {
expressInfo: {
type: Object,
value: {},
observer: function (val) {
if (!val) return;
this.processExpressInfo(val);
},
},
......@@ -54,6 +56,10 @@ Component({
type: Boolean,
value: false,
},
receiver: {
type: String,
value: "",
},
},
data: {
......@@ -89,20 +95,21 @@ Component({
* @returns {boolean} 是否显示该轨迹
*/
_shouldShowTrack(trackStatus, logisticsStatus) {
return true;
const statusThresholds = {
1000: 1000, // 待揽件 - 只显示收件相关记录
1001: 1001, // 已揽件 - 显示揽件和发往记录
1002: 1002, // 运输中 - 显示所有运输中的记录
1003: 1003, // 已签收 - 显示所有记录
1004: 1004, // 拒收 - 显示所有记录
1005: 1005, // 正在派件 - 显示所有记录
};
const threshold = statusThresholds[logisticsStatus];
return threshold !== undefined ? trackStatus <= threshold : true;
},
/**
* 处理物流轨迹数据
* 处理轨迹数据
* @param {Array} shipmentTrack - 原始轨迹数据
* @param {number} logisticsStatus - 物流状态
* @returns {Array} 处理后的轨迹数据
......@@ -112,38 +119,62 @@ Component({
return [];
}
// 根据showAll决定显示数量
const tracksToProcess = this.data.showAll
? shipmentTrack
: shipmentTrack.slice(0, 2);
return tracksToProcess
// 第一步:处理所有轨迹数据,获取状态和描述
const tracks = shipmentTrack
.map((track, index) => {
const { content = "", operateTime = "" } = track;
const isLast = index === 0;
// 根据内容判断状态
const { status, statusDesc: initialStatusDesc } =
const { status, statusDesc } =
this._determineStatusByContent(content);
// 根据整体物流状态进行最终调整
let finalStatusDesc = initialStatusDesc;
if (logisticsStatus < status) {
finalStatusDesc = `${LOGISTICS_STATUS[logisticsStatus]}(进行中)`;
// 提取手机号码
const phoneRegex = /(1[3-9]\d{9}|0\d{2,3}[-]?\d{7,8})/g;
const phones = [];
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 {
...track,
content,
content: highlightedContent,
phones: phones, // 添加提取的手机号码数组
operateTime,
type: isLast ? "active" : "",
type: "",
status,
statusDesc: finalStatusDesc,
statusDesc,
};
})
.filter((track) =>
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({
*/
processExpressInfo(expressInfo) {
if (!expressInfo || typeof expressInfo !== "object") {
wx.p.sentry.reportError(`快递信息异常:expressInfo参数无效`, {expressInfo});
wx.p.sentry.reportError(`快递信息异常:expressInfo参数无效`, {
expressInfo,
});
console.warn("Express组件: expressInfo参数无效");
return;
}
const { logisticsStatus, shipmentTrack, ...rest } = expressInfo;
const {
logisticsStatus,
shipmentTrack,
expressName,
shipmentCode,
...rest
} = expressInfo;
// 验证必要字段
if (typeof logisticsStatus !== "number") {
wx.p.sentry.reportError(`快递信息异常:logisticsStatus字段无效`, {expressInfo});
wx.p.sentry.reportError(`快递信息异常:logisticsStatus字段无效`, {
expressInfo,
});
console.warn("Express组件: logisticsStatus字段无效");
return;
}
const processedTrack = this.processShipmentTrack(
shipmentTrack,
logisticsStatus
);
// 创建默认轨迹对象
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,
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 = {
...rest,
expressName,
shipmentCode,
logisticsStatus,
logisticsStatusDesc: LOGISTICS_STATUS[logisticsStatus] || "未知状态",
shipmentTrack: processedTrack,
shipmentTrack: combinedTrack,
};
this.setData({
......
<view class="item">
<TimeLine nodes="{{logisticsData.shipmentTrack ||[]}}" height="{{height}}"/>
</view>
\ No newline at end of file
<!-- 时间轴 -->
<view class="item">
<TimeLine nodes="{{logisticsData.shipmentTrack ||[]}}" height="{{height}}"/>
</view>
\ 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({
},
expressInfo:{
type: Object,
value: {}
value: null
},
receiver:{
type: String,
value: '',
}
},
});
\ No newline at end of file
......@@ -31,5 +31,6 @@
width: 670rpx;
height: 2rpx;
background: #EFF0F2;
margin-bottom: 24rpx;
}
}
\ No newline at end of file
<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>
<view class="line"></view>
<Express expressInfo="{{expressInfo}}" showAll="{{true}}" />
<Express expressInfo="{{expressInfo}}" receiver="{{receiver}}" showAll="{{true}}" />
</view>
</popup>
\ No newline at end of file
......@@ -2,6 +2,6 @@
<view class="item">
<view class="label">收货地址:</view>
<view class="value">{{orderInfo.receiveAddress || ''}}
<view class="value">{{orderInfo.receviveInfo || ''}}</view>
<view class="value">{{orderInfo.receiveInfo || ''}}</view>
</view>
</view>
\ No newline at end of file
......@@ -35,7 +35,7 @@ Page({
},
queryLogistics(subOrderCode) {
wx.p.api.shopmallApi.queryLogistics({ subOrderCode }).then((data) => {
if(data.shipmentTrack&&data.shipmentTrack.length){
if(data&&data.expressCode){
this.setData({
logisticsInfo: data,
})
......@@ -45,41 +45,45 @@ Page({
});
},
getOrderDetail(subOrderCode) {
wx.p.wxApi.showLoading("加载中...");
wx.p.api.shopmallApi
.getOrderDetail({ subOrderCode })
.then((data) => {
let {
provinceName,
cityName,
countyName,
address,
receiveName,
receiveMobile,
} = data.receiveAddress;
this.setData({
orderInfo: {
...data,
...this.data.orderInfo,
receiveAddress: provinceName + cityName + countyName + address,
receviveInfo: receiveName + receiveMobile,
},
});
if (data.expressName && this.data.orderInfo.goodsSource==GoodsSource.SELF) {
this.setData({
expressInfo: {
expressName: data.expressName,
shipmentCode: data.expressNo,
},
});
}
}).catch((err) => {
wx.p.sentry.reportError(`订单详情异常:${err.message}`, {subOrderCode,err});
})
.finally(() => {
wx.hideLoading();
wx.p.wxApi.showLoading("加载中...");
wx.p.api.shopmallApi
.getOrderDetail({ subOrderCode })
.then((data) => {
let {
provinceName,
cityName,
countyName,
address,
receiveName,
receiveMobile,
} = data.receiveAddress;
const receiveAddress = provinceName + cityName + countyName + address;
const receiveInfo = receiveName + receiveMobile;
this.setData({
orderInfo: {
...data,
...this.data.orderInfo,
receiveAddress,
receiveInfo,
},
receiver: `${receiveAddress}<br/>${receiveInfo}`,
// 如果有expressInfo也一并设置
...(data.expressName && this.data.orderInfo.goodsSource == GoodsSource.SELF ? {
expressInfo: {
expressName: data.expressName,
shipmentCode: data.expressNo,
}
} : {})
});
},
console.log(this.data)
})
.catch((err) => {
wx.p.sentry.reportError(`订单详情异常:${err.message}`, {subOrderCode,err});
})
.finally(() => {
wx.hideLoading();
});
},
showExpressPop() {
this.setData({
isShowExpressPop: true,
......
......@@ -6,10 +6,13 @@
.express-detail{
position: absolute;
right: 24rpx;
top:12rpx;
top:0;
color: var(--btnColor);
font-weight: 400;
font-size: 24rpx;
display: flex;
align-items: center;
gap: 6rpx;
}
}
}
......
......@@ -4,14 +4,15 @@
<Status title="{{Status.text}}" image="{{Status.image}}" tips="{{Status.tips}}"></Status>
</BlockBox>
<!-- 云中鹤的有物流信息 -->
<BlockBox wx:if="{{logisticsInfo}}">
<BlockBox wx:if="{{receiver && logisticsInfo}}">
<view class="express-box" bindtap="showExpressPop">
<view class="express-detail">
物流详情
<mp-icon icon="arrow" color="var(--btnColor)" size="{{11}}"></mp-icon>
</view>
<Express expressInfo="{{logisticsInfo}}" showAll="{{false}}"/>
<Express expressInfo="{{logisticsInfo}}" receiver="{{receiver}}" showAll="{{false}}"/>
</view>
<Expresspop showExpress="{{isShowExpressPop}}" expressInfo="{{logisticsInfo}}" receiver="{{receiver}}" />
</BlockBox>
<!-- 自营商品展示快递信息 -->
<BlockBox wx:if="{{expressInfo}}">
......@@ -26,7 +27,6 @@
<!-- <BlockBox>
<content item="{{orderInfo}}" />
</BlockBox> -->
<Expresspop showExpress="{{isShowExpressPop}}" expressInfo="{{logisticsInfo}}" wx:if="{{logisticsInfo}}" />
</view>
</block>
<glsx-privacy appletName="积分商城"></glsx-privacy>
\ No newline at end of file
......@@ -11,7 +11,7 @@ Component({
observer: function (v) {
v && this.getStatus(v);
},
},
}
},
/**
......@@ -30,6 +30,6 @@ Component({
this.setData({
status: _order.text,
});
},
},
}
}
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!