feat: 优化收货清单固定头部交互

This commit is contained in:
zm2000 2026-04-20 18:26:04 +08:00
parent 5b7559953d
commit 518ceefb91
2 changed files with 214 additions and 7 deletions

View File

@ -26,7 +26,9 @@
@select="handleSelectDetail" @add="handleAddDetail" @delete="handleDeleteDetail"
@preview="handlePreviewImage" ref="detailContainerRef" @change="initData"
@tryGetStock="tryGetStock" @selectDetailChange="handleSelectDetailChange" @searchSpace="searchSpace" @print="handlePrint"/>
<receivingList v-else :receiving-data="receivingInfo" :detail-list="details"></receivingList>
<receivingList v-else :receiving-data="receivingInfo" :detail-list="details"
:fixed-header="true" :fixed-top="receivingListHeaderTop"
:fixed-mask-height="receivingListHeaderGap"></receivingList>
</view>
</view>
</view>
@ -75,6 +77,8 @@
return {
receivingId: null,
currentTab: 0,
receivingListHeaderTop: 0,
receivingListHeaderGap: 0,
qrcodeUrl: null,
showStockList: false,
showSpaceList:false,
@ -322,6 +326,23 @@
// Tab切换
handleTabChange(tab) {
this.currentTab = tab.index;
this.$nextTick(() => {
this.updateReceivingListHeaderTop();
});
},
updateReceivingListHeaderTop() {
const query = uni.createSelectorQuery().in(this);
query.select('.content-container').boundingClientRect();
query.exec(res => {
const contentRect = res && res[0];
if (!contentRect) {
return;
}
const headerGap = this.receivingListHeaderGap || uni.upx2px(20);
this.receivingListHeaderTop = contentRect.top + headerGap;
});
},
// DetailContainer事件处理
@ -751,6 +772,12 @@
this.receivingId = parseInt(options.id);
this.initData();
}
},
onReady() {
this.receivingListHeaderGap = uni.upx2px(20);
this.$nextTick(() => {
this.updateReceivingListHeaderTop();
});
}
};
</script>

View File

@ -1,16 +1,23 @@
<template>
<scroll-view style="height: 100%;" scroll-y>
<scroll-view style="height: 100%;" scroll-y :scroll-top="scrollTopValue"
:scroll-with-animation="scrollWithAnimation" @scroll="handleScroll">
<!-- 收货单基本信息 -->
<view class="receiving-info-card">
<view class="info-header">
<view v-if="showHeaderMask" class="info-header-top-mask" :style="infoHeaderMaskStyle"></view>
<view class="info-header" :class="{ collapsed: !infoExpanded, fixed: fixedHeader }"
:style="infoHeaderStyle" @click="toggleInfoExpanded">
<text class="receiving-number">{{ receivingInfo.receiving_number }}</text>
<view class="status-badge" :class="receivingInfo.status">
<text>{{ getStatusText(receivingInfo.status) }}</text>
<view class="header-right">
<view class="status-badge" :class="receivingInfo.status">
<text>{{ getStatusText(receivingInfo.status) }}</text>
</view>
<text class="fold-icon">{{ infoExpanded ? '∧' : '∨' }}</text>
</view>
</view>
<view v-if="fixedHeader" class="info-header-placeholder" :class="{ collapsed: !infoExpanded }"></view>
<view class="info-content">
<view v-show="infoExpanded" class="info-content">
<view class="info-item">
<text class="label">货主:</text>
<text class="value">{{ receivingInfo.store_name }}</text>
@ -191,13 +198,36 @@
scrollHeight: {
type: String,
default: 'calc(100vh - 700rpx)'
},
// 是否固定到整页顶部
fixedHeader: {
type: Boolean,
default: false
},
// 固定头部距离顶部的偏移量(px)
fixedTop: {
type: [Number, String],
default: 0
},
// 头部上边距遮罩高度(px)
fixedMaskHeight: {
type: [Number, String],
default: 0
}
},
data() {
return {
receivingInfo: {},
details: []
details: [],
infoExpanded: true,
scrollTopValue: 0,
currentScrollTop: 0,
scrollWithAnimation: true,
expandTimer: null
}
},
@ -234,6 +264,47 @@
// 总数量(计算属性)
totalQuantity() {
return this.details.reduce((sum, item) => sum + (item.actual_quantity || 0), 0)
},
showHeaderMask() {
if (!this.fixedHeader) {
return false
}
const maskHeight = Number(this.fixedMaskHeight)
return Number.isFinite(maskHeight) ? maskHeight > 0 : !!this.fixedMaskHeight
},
infoHeaderStyle() {
if (!this.fixedHeader) {
return {}
}
const topValue = typeof this.fixedTop === 'number' ? `${this.fixedTop}px` : this.fixedTop
return {
top: topValue
}
},
infoHeaderMaskStyle() {
if (!this.showHeaderMask) {
return {}
}
if (typeof this.fixedTop === 'number' && typeof this.fixedMaskHeight === 'number') {
const topValue = Math.max(this.fixedTop - this.fixedMaskHeight, 0)
return {
top: `${topValue}px`,
height: `${this.fixedMaskHeight}px`
}
}
const topValue = `calc(${this.fixedTop} - ${this.fixedMaskHeight})`
const heightValue = typeof this.fixedMaskHeight === 'number' ? `${this.fixedMaskHeight}px` : this.fixedMaskHeight
return {
top: topValue,
height: heightValue
}
}
},
@ -338,6 +409,56 @@
})
},
// 切换收货单基本信息展开状态
toggleInfoExpanded() {
const nextExpanded = !this.infoExpanded
if (this.expandTimer) {
clearTimeout(this.expandTimer)
this.expandTimer = null
}
if (!nextExpanded) {
this.infoExpanded = false
return
}
if (this.currentScrollTop > 2) {
this.scrollWithAnimation = true
this.scrollTopValue = Math.ceil(this.currentScrollTop)
this.$nextTick(() => {
this.scrollTopValue = 0
})
this.expandTimer = setTimeout(() => {
this.currentScrollTop = 0
this.infoExpanded = true
this.expandTimer = null
}, 260)
return
}
if (this.currentScrollTop > 0) {
this.scrollWithAnimation = false
this.scrollTopValue = 0
this.expandTimer = setTimeout(() => {
this.currentScrollTop = 0
this.infoExpanded = true
this.$nextTick(() => {
this.scrollWithAnimation = true
})
this.expandTimer = null
}, 20)
return
}
this.infoExpanded = true
},
handleScroll(event) {
this.currentScrollTop = Number(event?.detail?.scrollTop || 0)
},
// 添加商品
handleAdd() {
this.$emit('add-goods', this.receivingInfo.id)
@ -379,16 +500,40 @@
display: flex;
justify-content: space-between;
align-items: center;
background-color: #fff;
margin-bottom: 30rpx;
padding-bottom: 20rpx;
border-bottom: 1rpx solid #f0f0f0;
&.fixed {
position: fixed;
left: 40rpx;
right: 40rpx;
z-index: 200;
margin-bottom: 0;
padding: 18rpx 30rpx;
min-height: 76rpx;
border-radius: 12rpx;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
}
&.collapsed {
margin-bottom: 0;
border-bottom: none;
}
.receiving-number {
font-size: 32rpx;
font-weight: bold;
color: #333;
}
.header-right {
display: flex;
align-items: center;
gap: 16rpx;
}
.status-badge {
padding: 8rpx 20rpx;
border-radius: 20rpx;
@ -410,6 +555,41 @@
color: #ff4d4f;
}
}
.fold-icon {
font-size: 34rpx;
line-height: 1;
color: #606266;
}
}
.info-header-top-mask {
position: fixed;
left: 40rpx;
right: 40rpx;
z-index: 199;
background-color: #fff;
pointer-events: none;
&::after {
content: '';
position: absolute;
left: 0;
right: 0;
bottom: -14rpx;
height: 14rpx;
background: linear-gradient(180deg, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 100%);
}
}
.info-header-placeholder {
height: 76rpx;
margin-bottom: 24rpx;
&.collapsed {
height: 76rpx;
margin-bottom: 0;
}
}
.info-content {