Express.js
4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
const LOGISTICS_STATUS = {
1000: "待揽件",
1001: "已揽件",
1002: "运输中",
1003: "已签收",
1004: "拒收",
};
// 状态判断规则配置
const STATUS_RULES = [
{
keywords: ["已签收", "签收人"],
status: 1003,
statusDesc: "已签收",
},
{
keywords: ["拒收", "退回"],
status: 1004,
statusDesc: "拒收",
},
{
keywords: ["派件", "驿站", "暂存"],
status: 1002,
statusDesc: "运输中",
},
{
keywords: ["转运中心", "发往", "到达"],
status: 1002,
statusDesc: "运输中",
},
{
keywords: ["已收件", "揽收"],
status: 1001,
statusDesc: "已揽件",
},
{
keywords: ["已发往"],
status: 1001,
statusDesc: "已揽件",
},
];
Component({
properties: {
expressInfo: {
type: Object,
value: {},
observer: function (val) {
if (!val) return;
this.processExpressInfo(val);
},
},
showAll: {
type: Boolean,
value: false,
},
},
data: {
logisticsData: {},
},
methods: {
/**
* 根据内容判断物流状态
* @param {string} content - 物流轨迹内容
* @returns {Object} 包含status和statusDesc的对象
*/
_determineStatusByContent(content) {
if (!content || typeof content !== "string") {
return { status: 1000, statusDesc: "待揽件" };
}
for (const rule of STATUS_RULES) {
if (rule.keywords.some((keyword) => content.includes(keyword))) {
return {
status: rule.status,
statusDesc: rule.statusDesc,
};
}
}
return { status: 1000, statusDesc: "待揽件" };
},
/**
* 根据物流状态过滤轨迹
* @param {number} trackStatus - 轨迹状态
* @param {number} logisticsStatus - 整体物流状态
* @returns {boolean} 是否显示该轨迹
*/
_shouldShowTrack(trackStatus, logisticsStatus) {
const statusThresholds = {
1000: 1000, // 待揽件 - 只显示收件相关记录
1001: 1001, // 已揽件 - 显示揽件和发往记录
1002: 1002, // 运输中 - 显示所有运输中的记录
1003: 1003, // 已签收 - 显示所有记录
1004: 1004, // 拒收 - 显示所有记录
};
const threshold = statusThresholds[logisticsStatus];
return threshold !== undefined ? trackStatus <= threshold : true;
},
/**
* 处理物流轨迹数据
* @param {Array} shipmentTrack - 原始轨迹数据
* @param {number} logisticsStatus - 物流状态
* @returns {Array} 处理后的轨迹数据
*/
processShipmentTrack(shipmentTrack, logisticsStatus) {
if (!Array.isArray(shipmentTrack) || shipmentTrack.length === 0) {
return [];
}
// 根据showAll决定显示数量
const tracksToProcess = this.data.showAll
? shipmentTrack
: shipmentTrack.slice(0, 2);
return tracksToProcess
.map((track, index) => {
const { content = "", operateTime = "" } = track;
const isLast = index === 0;
// 根据内容判断状态
const { status, statusDesc: initialStatusDesc } =
this._determineStatusByContent(content);
// 根据整体物流状态进行最终调整
let finalStatusDesc = initialStatusDesc;
if (logisticsStatus < status) {
finalStatusDesc = `${LOGISTICS_STATUS[logisticsStatus]}(进行中)`;
}
return {
...track,
content,
operateTime,
type: isLast ? "active" : "",
status,
statusDesc: finalStatusDesc,
};
})
.filter((track) =>
this._shouldShowTrack(track.status, logisticsStatus)
);
},
/**
* 处理快递信息
* @param {Object} expressInfo - 快递信息对象
*/
processExpressInfo(expressInfo) {
if (!expressInfo || typeof expressInfo !== "object") {
wx.p.sentry.reportError(`快递信息异常:expressInfo参数无效`, {expressInfo});
console.warn("Express组件: expressInfo参数无效");
return;
}
const { logisticsStatus, shipmentTrack, ...rest } = expressInfo;
// 验证必要字段
if (typeof logisticsStatus !== "number") {
wx.p.sentry.reportError(`快递信息异常:logisticsStatus字段无效`, {expressInfo});
console.warn("Express组件: logisticsStatus字段无效");
return;
}
const processedTrack = this.processShipmentTrack(
shipmentTrack,
logisticsStatus
);
const logisticsData = {
...rest,
logisticsStatus,
logisticsStatusDesc: LOGISTICS_STATUS[logisticsStatus] || "未知状态",
shipmentTrack: processedTrack,
};
this.setData({
logisticsData,
});
},
},
});