@@ -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 : 82 vh ;
border - radius : 24 rpx 24 rpx 0 0 ;
padding : 32 rpx 32 rpx calc ( 24 rpx + env ( safe - area - inset - bottom ) ) 32 rpx ;
overflow : hidden ;
}
& -- center {
width : 680 rpx ;
max - height : 78 vh ;
border - radius : 24 rpx ;
padding : 32 rpx 32 rpx 0 32 rpx ;
margin : 0 auto ;
overflow : hidden ;
}
& -- center & _ _content {
max - height : 52 vh ;
}
& -- center & _ _btn {
min - width : 160 rpx ;
}
& _ _header {
display : flex ;
justify - content : space - between ;
align - items : flex - start ;
padding - bottom : 24 rpx ;
border - bottom : 1 rpx solid # f2f2f2 ;
}
& _ _title {
font - size : 32 rpx ;
font - weight : 600 ;
color : # 111827 ;
line - height : 44 rpx ;
}
& _ _order - no {
margin - top : 8 rpx ;
font - size : 24 rpx ;
color : # 6 b7280 ;
line - height : 32 rpx ;
}
& _ _tip {
margin - top : 8 rpx ;
font - size : 24 rpx ;
color : # f97316 ;
line - height : 32 rpx ;
}
& _ _close {
width : 48 rpx ;
height : 48 rpx ;
display : flex ;
align - items : center ;
justify - content : center ;
font - size : 40 rpx ;
color : # 9 ca3af ;
line - height : 1 ;
}
& _ _content {
flex : 1 ;
min - height : 0 ;
max - height : calc ( 82 vh - 280 rpx - env ( safe - area - inset - bottom ) ) ;
margin - top : 20 rpx ;
box - sizing : border - box ;
}
& _ _empty {
padding : 80 rpx 0 ;
text - align : center ;
color : # 9 ca3af ;
font - size : 26 rpx ;
}
& _ _item {
display : flex ;
align - items : flex - start ;
padding : 20 rpx 0 ;
border - bottom : 1 rpx solid # f2f2f2 ;
}
& _ _item - image {
flex - shrink : 0 ;
width : 140 rpx ;
height : 140 rpx ;
border - radius : 12 rpx ;
background : # f6f7fb ;
margin - right : 20 rpx ;
}
& _ _item - main {
flex : 1 ;
min - width : 0 ;
padding - top : 4 rpx ;
display : flex ;
flex - direction : column ;
gap : 10 rpx ;
}
& _ _item - name {
font - size : 28 rpx ;
color : # 111827 ;
line - height : 40 rpx ;
}
& _ _item - sku {
font - size : 24 rpx ;
color : # 6 b7280 ;
line - height : 32 rpx ;
background : # f6f7fb ;
padding : 4 rpx 12 rpx ;
border - radius : 8 rpx ;
align - self : flex - start ;
max - width : 100 % ;
overflow : hidden ;
text - overflow : ellipsis ;
white - space : nowrap ;
}
& _ _item - info {
display : flex ;
flex - direction : column ;
gap : 4 rpx ;
}
& _ _item - count {
font - size : 26 rpx ;
color : # 111827 ;
font - weight : 500 ;
}
& _ _item - logistics {
font - size : 22 rpx ;
color : # 6 b7280 ;
}
& _ _item - action {
margin - top : 10 rpx ;
display : flex ;
justify - content : flex - end ;
}
& _ _btn {
min - width : 180 rpx ;
height : 60 rpx ;
line - height : 60 rpx ;
text - align : center ;
border - radius : 30 rpx ;
font - size : 26 rpx ;
font - weight : 500 ;
padding : 0 24 rpx ;
}
& _ _btn -- ghost {
border : 2 rpx solid # e5e7eb ;
color : # 4 b5563 ;
background : # ffffff ;
}
& _ _btn -- primary {
background : linear - gradient ( 135 deg , # 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 : 24 rpx 24 rpx 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 : 24 rpx ! important ;
overflow : hidden ! important ;
background : transparent ! important ;
}
< / style >