Browse Source

自动上架和下架

yuhongqi 4 tháng trước cách đây
mục cha
commit
df254f3148
1 tập tin đã thay đổi với 30 bổ sung24 xóa
  1. 30 24
      pages_course/videovip.vue

+ 30 - 24
pages_course/videovip.vue

@@ -94,7 +94,7 @@
 					</view>
 				</template>
 				<template v-if="currentId==1&&showTreatment==0 || isquestion&&showTreatment==0">
-					<goodsList ref="goodsList" :treatmentPackage="treatmentPackage" :urlOption="urlOption"></goodsList>
+					<goodsList ref="goodsList" :treatmentPackage="displayProductList" :urlOption="urlOption"></goodsList>
 				</template>
 			</view>
 		</scroll-view>
@@ -443,6 +443,8 @@
 				currentId: 0,
 				showTreatment: 1,
 				treatmentPackage: [],
+				// 商品栏展示列表(根据上架/下架时间过滤)
+				displayProductList: [],
 				// 商品卡片弹窗
 				cardPopup: false,
 				currentCardItem: null,
@@ -1080,17 +1082,11 @@
 						}
 					}
 					this.playTime = currentTime
-					this.updateCardPopup(currentTime)
+					this.updateProductAndCardDisplay(currentTime)
 				}
 			},
-			// 根据当前播放时间控制商品卡片展示
-			updateCardPopup(currentSec) {
-				if (this.treatmentPackage.length == 0) {
-					this.cardPopup = false
-					this.currentCardItem = null
-					return
-				}
-				let active = null
+			// 根据当前播放时间:1)扫描商品栏展示(上架/下架时间)2)控制商品卡片弹窗(弹出/关闭时间)
+			updateProductAndCardDisplay(currentSec) {
 				const toSeconds = (timeStr) => {
 					if (!timeStr || typeof timeStr !== 'string') return 0
 					const parts = timeStr.split(':')
@@ -1100,31 +1096,39 @@
 					const s = parseInt(parts[2], 10) || 0
 					return h * 3600 + m * 60 + s
 				}
+				if (this.treatmentPackage.length === 0) {
+					this.displayProductList = []
+					this.cardPopup = false
+					this.currentCardItem = null
+					return
+				}
+				const videoDuration = this.duration || 0
+				// 1. 商品栏展示:按上架/下架时间过滤
+				this.displayProductList = this.treatmentPackage.filter(item => {
+					const onShelfSec = (!item.onShelfTime || item.onShelfTime === '00:00:00') ? 0 : toSeconds(item.onShelfTime)
+					if (currentSec < onShelfSec) return false
+					if (!item.offShelfTime || item.offShelfTime === '00:00:00') return true
+					const offShelfSec = toSeconds(item.offShelfTime)
+					if (videoDuration > 0 && offShelfSec > videoDuration) return true
+					return currentSec < offShelfSec
+				})
+				// 2. 商品卡片弹窗:按弹出/关闭时间查找当前应展示的卡片
+				let activeCard = null
 				for (let i = 0; i < this.treatmentPackage.length; i++) {
 					const item = this.treatmentPackage[i]
 					const popupStr = item.cardPopupTime
 					const closeStr = item.cardCloseTime
-					// 默认 00:00:00 或未配置则不弹出
 					if (!popupStr || popupStr === '00:00:00') continue
 					const popupSec = toSeconds(popupStr)
 					if (!popupSec) continue
-					let closeSec = null
-					if (closeStr && closeStr !== '00:00:00') {
-						closeSec = toSeconds(closeStr)
-					}
+					const closeSec = (closeStr && closeStr !== '00:00:00') ? toSeconds(closeStr) : null
 					if (currentSec >= popupSec && (closeSec == null || currentSec < closeSec)) {
-						active = item
+						activeCard = item
 						break
 					}
 				}
-				if (active) {
-					this.cardPopup = true
-					this.currentCardItem = active
-					//console.log('active',active)
-				} else {
-					this.cardPopup = false
-					this.currentCardItem = null
-				}
+				this.cardPopup = !!activeCard
+				this.currentCardItem = activeCard
 			},
 			changeTime(that, e) {
 				that.playDurationSeek = 0
@@ -1347,6 +1351,8 @@
 								this.player.play();
 							}
 							this.updateTime();
+							// 初始扫描商品栏展示(根据上架/下架时间)
+							this.updateProductAndCardDisplay(this.playTime ?? this.playDuration ?? 0);
 							if (res.data.courseVideoDetails.questionBankList.length == 0) {
 								this.isquestion = true
 							} else {