feat: 单个物流查看

This commit is contained in:
2026-08-06 17:24:19 +08:00
parent 5f6358cb07
commit 811f87d385
8 changed files with 757 additions and 13 deletions
+601
View File
@@ -0,0 +1,601 @@
<template>
<uni-popup ref="popupRef" :type="popupType" background-color="transparent">
<view class="express-popup" :class="`express-popup--${popupType}`" @tap.stop>
<view class="express-popup__header">
<view>
<view class="express-popup__title">查看物流</view>
<view class="express-popup__order-no">订单号:{{ orderNo || '-' }}</view>
<view class="express-popup__tip">请选择要查看物流的商品</view>
</view>
<view class="express-popup__close" @tap.stop="handleClose">×</view>
</view>
<scroll-view scroll-y class="express-popup__content">
<view v-if="renderItems.length === 0" class="express-popup__empty">
暂无物流信息
</view>
<view
v-else
class="express-popup__item"
v-for="(item, index) in renderItems"
:key="item.itemKey || index"
>
<image class="express-popup__item-image" :src="item.picUrl" mode="aspectFill" />
<view class="express-popup__item-main">
<view class="express-popup__item-name lineTwo">{{ item.spuName }}</view>
<view class="express-popup__item-sku">{{ item.skuText || '-' }}</view>
<view class="express-popup__item-info">
<text class="express-popup__item-count">数量:x{{ item.count }}</text>
<text
v-if="item.logisticsNo"
class="express-popup__item-logistics"
>运单号:{{ item.logisticsNo }}</text>
</view>
<view class="express-popup__item-action">
<view
class="express-popup__btn express-popup__btn--primary"
@tap.stop="handleViewExpress(item)"
>
查看物流
</view>
</view>
</view>
</view>
</scroll-view>
</view>
</uni-popup>
</template>
<script setup>
import { computed, ref, watch } from 'vue';
import sheep from '@/sheep';
import { getAiOrderDelayRecords } from '@/sheep/api/ai';
const props = defineProps({
popupType: {
type: String,
default: 'bottom',
},
orderNo: {
type: String,
default: '',
},
orderData: {
type: Object,
default: () => ({}),
},
delayRecords: {
type: Array,
default: () => [],
},
orderId: {
type: [Number, String],
default: 0,
},
});
const emit = defineEmits(['close', 'view-express']);
const popupRef = ref();
const innerItems = ref([]);
const loadedRecords = ref([]);
const getFirstValidValue = (...values) =>
values.find((value) => value !== undefined && value !== null && String(value).trim() !== '') ?? '';
const hasValue = (value) => value !== undefined && value !== null && String(value).trim() !== '';
const formatSkuPropertyItem = (property) => {
const value = getFirstValidValue(
property?.valueName,
property?.value,
property?.specValue,
property?.attrValue,
property?.optionValue,
property?.propertyValue,
typeof property === 'string' ? property : '',
);
const name = getFirstValidValue(
property?.name,
property?.propertyName,
property?.specName,
property?.attrName,
property?.optionName,
property?.propertyKey,
'',
);
if (hasValue(name) && hasValue(value)) return `${name}:${value}`;
if (hasValue(value)) return String(value);
if (hasValue(name)) return String(name);
return '';
};
const formatSkuProperties = (properties) => {
if (!properties) return '';
if (typeof properties === 'string' && properties.trim()) return properties.trim();
if (Array.isArray(properties)) {
return properties.map(formatSkuPropertyItem).filter(Boolean).join(' ');
}
if (typeof properties === 'object') {
return Object.keys(properties)
.map((key) => {
const value = properties[key];
if (typeof value === 'object') return formatSkuPropertyItem(value);
return `${key}:${value}`;
})
.filter(Boolean)
.join(' ');
}
return '';
};
const resolveSpuItems = (data) => {
const items = Array.isArray(data?.items) ? data.items : [];
return items.flatMap((spu) => {
const subItems = Array.isArray(spu?.items) ? spu.items : [];
if (subItems.length > 0) {
return subItems.map((sub) => ({
...sub,
_spuName: getFirstValidValue(
spu?.spuName,
spu?.productName,
spu?.goodsName,
sub?.spuName,
sub?.productName,
sub?.goodsName,
),
_spuPic: getFirstValidValue(
spu?.picUrl,
spu?.imageUrl,
spu?.thumbUrl,
spu?.goodsPic,
sub?.picUrl,
sub?.imageUrl,
sub?.thumbUrl,
sub?.goodsPic,
),
_spuId: getFirstValidValue(spu?.spuId, spu?.productId, sub?.spuId, sub?.productId),
_skuText: getFirstValidValue(
sub?.skuProperties,
sub?.specInfo,
sub?.skuInfo,
sub?.skuText,
formatSkuProperties(sub?.skuProperties || sub?.specs || sub?.properties),
),
}));
}
return [
{
...spu,
_spuName: getFirstValidValue(spu?.spuName, spu?.productName, spu?.goodsName),
_spuPic: getFirstValidValue(
spu?.picUrl,
spu?.imageUrl,
spu?.thumbUrl,
spu?.goodsPic,
),
_spuId: getFirstValidValue(spu?.spuId, spu?.productId),
_skuText: getFirstValidValue(
spu?.skuProperties,
spu?.specInfo,
spu?.skuInfo,
spu?.skuText,
formatSkuProperties(spu?.skuProperties || spu?.specs || spu?.properties),
),
},
];
});
};
const resolveAllDelayRecords = () => {
if (Array.isArray(loadedRecords.value) && loadedRecords.value.length > 0) {
return loadedRecords.value.filter(Boolean);
}
const orderLevelRecords = Array.isArray(props.delayRecords)
? props.delayRecords
: Array.isArray(props.orderData?.delayRecords)
? props.orderData.delayRecords
: Array.isArray(props.orderData?.delayRecordList)
? props.orderData.delayRecordList
: [];
return orderLevelRecords.filter(Boolean);
};
const resolveCount = (record) =>
Number(
getFirstValidValue(
record?.count,
record?.num,
record?.quantity,
record?.number,
record?.totalCount,
1,
),
) || 1;
const resolveRecordOrderItemId = (record) =>
Number(
getFirstValidValue(
record?.orderItemId,
record?.orderItemVO?.id,
record?.orderItem?.id,
record?.itemId,
0,
),
) || 0;
const resolveRecordSkuText = (record) => {
const direct = getFirstValidValue(
record?.skuProperties,
record?.specInfo,
record?.skuText,
record?.skuInfo,
formatSkuProperties(record?.skuProperties || record?.specs || record?.properties),
);
if (direct) return direct;
const itemSpec = getFirstValidValue(
record?.orderItemVO?.skuProperties,
record?.orderItemVO?.specInfo,
record?.orderItem?.skuProperties,
record?.orderItem?.specInfo,
formatSkuProperties(record?.orderItemVO?.skuProperties || record?.orderItem?.specs),
);
return itemSpec;
};
const resolveRecordSpuName = (record) =>
getFirstValidValue(
record?.spuName,
record?.productName,
record?.goodsName,
record?.orderItemVO?.spuName,
record?.orderItem?.spuName,
record?.orderItemVO?.productName,
record?.orderItem?.productName,
);
const resolveRecordPicUrl = (record) =>
getFirstValidValue(
record?.picUrl,
record?.imageUrl,
record?.thumbUrl,
record?.goodsPic,
record?.orderItemVO?.picUrl,
record?.orderItem?.picUrl,
record?.orderItemVO?.imageUrl,
record?.orderItem?.imageUrl,
);
const resolveRecordLogisticsNo = (record) =>
getFirstValidValue(
record?.logisticsNo,
record?.waybillNo,
record?.trackingNo,
record?.expressNo,
record?.orderItemVO?.logisticsNo,
record?.orderItem?.logisticsNo,
);
const hasRecordLogistics = (record) => {
if (Number(record?.logisticsId) > 0) return true;
if (hasValue(resolveRecordLogisticsNo(record))) return true;
if (hasValue(record?.deliveryTime)) return true;
return false;
};
const buildExpressItemList = () => {
const records = resolveAllDelayRecords();
const expressRecords = records.filter((record) => {
const status = Number(record?.status);
return status === 3 && Number(record?.delayRecordId || record?.id) > 0;
});
if (expressRecords.length === 0) return [];
const spuItems = resolveSpuItems(props.orderData);
const findItemByOrderItemId = (id) =>
spuItems.find(
(sku) => Number(sku?.id || sku?.orderItemId || sku?.itemId || 0) === Number(id),
);
const findItemBySkuText = (text) =>
spuItems.find((sku) => {
const skuText = getFirstValidValue(
sku?.skuProperties,
sku?.specInfo,
sku?.skuInfo,
sku?.skuText,
formatSkuProperties(sku?.skuProperties || sku?.specs || sku?.properties),
);
return !!text && !!skuText && String(text).trim() === String(skuText).trim();
});
const singleSpu =
spuItems.length === 1
? spuItems[0]
: new Set(spuItems.map((s) => s?._spuId || s?._spuName)).size === 1
? spuItems[0]
: null;
return expressRecords.map((record, idx) => {
const orderItemId = resolveRecordOrderItemId(record);
const recordSku = resolveRecordSkuText(record);
let matched = orderItemId ? findItemByOrderItemId(orderItemId) : null;
if (!matched && recordSku) matched = findItemBySkuText(recordSku);
if (!matched && singleSpu) matched = singleSpu;
const count = resolveCount(record);
const spuName = matched
? getFirstValidValue(matched._spuName, matched?.spuName, matched?.productName)
: resolveRecordSpuName(record);
const picUrl = matched
? getFirstValidValue(matched._spuPic, matched?.picUrl, matched?.imageUrl)
: resolveRecordPicUrl(record);
const skuText = matched
? getFirstValidValue(
matched?._skuText,
matched?.skuProperties,
matched?.specInfo,
matched?.skuInfo,
matched?.skuText,
formatSkuProperties(matched?.skuProperties || matched?.specs || matched?.properties),
)
: recordSku;
const delayRecordId = Number(record?.delayRecordId || record?.id) || 0;
const logisticsNo = resolveRecordLogisticsNo(record);
return {
itemKey: `${delayRecordId}-${idx}`,
delayRecordId,
spuName: spuName || '商品信息',
skuText: skuText || '单规格',
picUrl: picUrl || '',
count,
logisticsNo,
};
});
};
const renderItems = computed(() => innerItems.value || []);
const open = async () => {
loadedRecords.value = [];
const oid = props.orderId || props.orderData?.id || props.orderData?.orderId;
if (oid) {
try {
const { code, data } = await getAiOrderDelayRecords({ orderId: oid });
if (code === 0 && Array.isArray(data)) {
loadedRecords.value = data;
}
} catch (e) {
loadedRecords.value = [];
}
}
innerItems.value = buildExpressItemList();
popupRef.value?.open?.();
};
const close = () => {
popupRef.value?.close?.();
};
const handleClose = () => {
emit('close');
close();
};
const handleViewExpress = (item) => {
const delayRecordId = Number(item?.delayRecordId) || 0;
if (!delayRecordId) {
uni.showToast({
title: '物流信息异常',
icon: 'none',
});
return;
}
const id = props.orderId || props.orderData?.id || props.orderData?.orderId;
if (!id) {
uni.showToast({
title: '订单信息异常',
icon: 'none',
});
return;
}
emit('view-express', {
id,
delayRecordId,
code: 2,
});
close();
const query = [
`id=${encodeURIComponent(id)}`,
`code=${encodeURIComponent(2)}`,
`delayRecordId=${encodeURIComponent(delayRecordId)}`,
].join('&');
const url = `/pages/order/express/log?${query}`;
uni.navigateTo({ url });
};
defineExpose({ open, close });
</script>
<style lang="scss" scoped>
.express-popup {
background: #ffffff;
box-sizing: border-box;
display: flex;
flex-direction: column;
&--bottom {
width: 100%;
max-height: 82vh;
border-radius: 24rpx 24rpx 0 0;
padding: 32rpx 32rpx calc(24rpx + env(safe-area-inset-bottom)) 32rpx;
overflow: hidden;
}
&--center {
width: 680rpx;
max-height: 78vh;
border-radius: 24rpx;
padding: 32rpx 32rpx 0 32rpx;
margin: 0 auto;
overflow: hidden;
}
&--center &__content {
max-height: 52vh;
}
&--center &__btn {
min-width: 160rpx;
}
&__header {
display: flex;
justify-content: space-between;
align-items: flex-start;
padding-bottom: 24rpx;
border-bottom: 1rpx solid #f2f2f2;
}
&__title {
font-size: 32rpx;
font-weight: 600;
color: #111827;
line-height: 44rpx;
}
&__order-no {
margin-top: 8rpx;
font-size: 24rpx;
color: #6b7280;
line-height: 32rpx;
}
&__tip {
margin-top: 8rpx;
font-size: 24rpx;
color: #f97316;
line-height: 32rpx;
}
&__close {
width: 48rpx;
height: 48rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 40rpx;
color: #9ca3af;
line-height: 1;
}
&__content {
flex: 1;
min-height: 0;
max-height: calc(82vh - 280rpx - env(safe-area-inset-bottom));
margin-top: 20rpx;
box-sizing: border-box;
}
&__empty {
padding: 80rpx 0;
text-align: center;
color: #9ca3af;
font-size: 26rpx;
}
&__item {
display: flex;
align-items: flex-start;
padding: 20rpx 0;
border-bottom: 1rpx solid #f2f2f2;
}
&__item-image {
flex-shrink: 0;
width: 140rpx;
height: 140rpx;
border-radius: 12rpx;
background: #f6f7fb;
margin-right: 20rpx;
}
&__item-main {
flex: 1;
min-width: 0;
padding-top: 4rpx;
display: flex;
flex-direction: column;
gap: 10rpx;
}
&__item-name {
font-size: 28rpx;
color: #111827;
line-height: 40rpx;
}
&__item-sku {
font-size: 24rpx;
color: #6b7280;
line-height: 32rpx;
background: #f6f7fb;
padding: 4rpx 12rpx;
border-radius: 8rpx;
align-self: flex-start;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
&__item-info {
display: flex;
flex-direction: column;
gap: 4rpx;
}
&__item-count {
font-size: 26rpx;
color: #111827;
font-weight: 500;
}
&__item-logistics {
font-size: 22rpx;
color: #6b7280;
}
&__item-action {
margin-top: 10rpx;
display: flex;
justify-content: flex-end;
}
&__btn {
min-width: 180rpx;
height: 60rpx;
line-height: 60rpx;
text-align: center;
border-radius: 30rpx;
font-size: 26rpx;
font-weight: 500;
padding: 0 24rpx;
}
&__btn--ghost {
border: 2rpx solid #e5e7eb;
color: #4b5563;
background: #ffffff;
}
&__btn--primary {
background: linear-gradient(135deg, #fa8735 0%, #fe3b48 100%);
color: #ffffff;
}
&__btn--disabled {
opacity: 0.6;
}
}
::v-deep .uni-popup {
background: transparent !important;
}
::v-deep .uni-popup__wrapper {
background: transparent !important;
}
::v-deep .uni-popup__wrapper-box {
background: transparent !important;
}
::v-deep .uni-popup__content {
background: transparent !important;
}
.express-popup--bottom ::v-deep .uni-popup__content,
.express-popup--bottom ::v-deep .uni-popup__wrapper-box {
border-radius: 24rpx 24rpx 0 0 !important;
overflow: hidden !important;
}
.express-popup--center ::v-deep .uni-popup__content,
.express-popup--center ::v-deep .uni-popup__wrapper-box {
border-radius: 24rpx !important;
overflow: hidden !important;
background: transparent !important;
}
</style>
+5 -2
View File
@@ -4,7 +4,7 @@
<view>{{ props.data.logisticsName }} {{ props.data.logisticsNo }}</view>
<view class="flex-center">
<view @click.stop="onCopy(props.data.logisticsNo)">复制</view>
<truckLine :data="props.data" :code="2" v-if="props.data.deliveryTime && props.data.logisticsNo"></truckLine>
<truckLine :data="props.data" :code="2" v-if="props.data.deliveryTime && props.data.logisticsNo" @openExpress="handleTruckLineOpenExpress"></truckLine>
</view>
</view>
@@ -156,7 +156,7 @@
import { fen2yuan, formatOrderStatus } from '@/sheep/hooks/useGoods';
import AfterSaleApi from '@/sheep/api/trade/afterSale';
import sheep from '@/sheep';
let emit = defineEmits(['getOrderDetail']);
let emit = defineEmits(['getOrderDetail', 'openExpress']);
const formatSkuProperties = (properties: any) => {
const list = Array.isArray(properties) ? properties : [];
return list
@@ -553,6 +553,9 @@
const onCopy = (text: any) => {
sheep.$helper.copyText(text);
};
const handleTruckLineOpenExpress = (payload: any) => {
emit('openExpress', payload);
};
</script>
<style scoped lang="scss">
+16
View File
@@ -126,6 +126,15 @@
@close="closeReceiveItemPopup"
@submit="handleReceiveItemSubmit"
/>
<ExpressListPopup
ref="expressListPopupRef"
popup-type="bottom"
:order-no="props.data.no || ''"
:order-data="props.data"
:delay-records="state.delayRecords"
:order-id="resolveAiOrderId(props.data)"
@close="closeExpressListPopup"
/>
</template>
<script setup>
import {
@@ -149,6 +158,7 @@
import AiOrderActionBar from '@/components/orderItem/AiOrderActionBar.vue';
import ShipmentPopup from '@/components/orderItem/ShipmentPopup.vue';
import ReceiveItemPopup from '@/components/orderItem/ReceiveItemPopup.vue';
import ExpressListPopup from '@/components/orderItem/ExpressListPopup.vue';
import AfterSaleApi from '@/sheep/api/trade/afterSale';
import sheep from '@/sheep';
import {
@@ -300,9 +310,11 @@
const nowShipmentPopupRef = ref();
const delayShipmentPopupRef = ref();
const receiveItemPopupRef = ref();
const expressListPopupRef = ref();
const closeNowShipmentPopup = () => {};
const closeDelayShipmentPopup = () => {};
const closeReceiveItemPopup = () => {};
const closeExpressListPopup = () => {};
const openDelayShipmentPopup = async (data) => {
const id = resolveAiOrderId(data);
if (!id) {
@@ -431,6 +443,10 @@
});
return;
}
if (isAiStoreOrder.value && !isPickUpOrder.value) {
expressListPopupRef.value?.open?.();
return;
}
proxy.utils.go('/pages/order/express/log', { id });
};
+5 -1
View File
@@ -27,10 +27,14 @@
default: 1, //1:商城订单 2:AI店铺订单 3:AI店铺赠送订单
}
});
const emit = defineEmits(['openExpress']);
let show = ref(false);
let list = ref([]);
const logistics = () => {
// 获取物流信息并显示弹窗
if (props.code === 2) {
emit('openExpress', { data: props.data, code: props.code });
return;
}
getData();
show.value = true;
};