From d6e3b7494c1d6a6d7e8d000258d0f38265cc5563 Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期日, 29 六月 2025 11:13:10 +0800
Subject: [PATCH] 视频发布商品搜索从第0页开始

---
 pages/commodity-square/commoditySquare.vue |  343 +++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 225 insertions(+), 118 deletions(-)

diff --git a/pages/commodity-square/commoditySquare.vue b/pages/commodity-square/commoditySquare.vue
index f903f36..2512eaa 100644
--- a/pages/commodity-square/commoditySquare.vue
+++ b/pages/commodity-square/commoditySquare.vue
@@ -1,21 +1,26 @@
 <template>
 	<view class="container">
+		<top-bar selectedTitleIndex="shop" textColor="black" @changeTab="topBarChange" class="topBar"></top-bar>
 		<input type="text" v-show="false" v-model="flushDom" />
-		<view class="commoditySquare">
+		<view class="search" :style="{marginTop: buttonHeight+'px',}">
+			<u-search class="nav-search" @blur='searchGoods' placeholder="鎼滅储鍟嗗搧" :show-action="false"></u-search>
+		</view>
+		<scroll-view class="scrollContainer"  :scroll-y="true" @scrolltolower="loadMoreData" >
+			<view class="commoditySquare">
 			<view class="left" style="width: 310rpx;">
 				<view class="commoditySquareItem" v-for="(item,index) in goodsList1"
 					@click="goToGoodsInfo('goodsList1',item.id)">
-					<video :src="item.goodsVideo" v-if="item.goodsVideo " v-show="item.show" :initial-time="0"
+					<!-- <video :src="item.goodsVideo" v-if="item.goodsVideo " v-show="item.show" :initial-time="0"
 						:controls="false" object-fit="contain" :show-play-btn="false" :show-center-play-btn="false"
 						@loadedmetadata="getvideoInfo($event,'goodsList1',index)" :ref="'video'+item.id"
-						:style="{width:item.width,height:item.height}"></video>
-					<image :src="item.thumbnail" v-if="item.goodsVideo ==null  || item.goodsVideo == ''"
+						:style="{width:item.width,height:item.height}"></video> -->
+					<image :src="item.thumbnail"
 						mode="aspectFill" class="goodsImg">
 					</image>
 					<view class="goodsInfo">
-						<view class="">{{item.goodsName}}</view>
+						<view class="goodsName">{{item.goodsName}}</view>
 						<view class="priceInfo">
-							<view class="">锟{item.price}}</view>
+							<view class="goodsPrice">锟{item.price}}</view>
 							<view class="">宸插敭: {{item.buyCount}}</view>
 						</view>
 					</view>
@@ -24,44 +29,44 @@
 			<view class="right" style="width: 310rpx;">
 				<view class="commoditySquareItem" v-for="(item,index) in goodsList2"
 					@click="goToGoodsInfo('goodsList2',item.id)">
-					<video :src="item.goodsVideo" v-if="item.goodsVideo " v-show="item.show" :initial-time="0"
+<!-- 					<video :src="item.goodsVideo" v-if="item.goodsVideo " v-show="item.show" :initial-time="0"
 						:controls="false" object-fit="contain" :show-play-btn="false" :show-center-play-btn="false"
 						@loadedmetadata="getvideoInfo($event,'goodsList2',index)" :ref="'video'+item.id"
-						:style="{width:item.width,height:item.height}"></video>
-					<image :src="item.thumbnail" v-if="item.goodsVideo ==null || item.goodsVideo == ''"
+						:style="{width:item.width,height:item.height}"></video> -->
+					<image :src="item.thumbnail"
 						mode="aspectFill" class="goodsImg">
 					</image>
 					<view class="goodsInfo">
-						<view class="">{{item.goodsName}}</view>
+						<view class="goodsName">{{item.goodsName}}</view>
 						<view class="priceInfo">
-							<view class="">锟{item.price}}</view>
+							<view class="goodsPrice">锟{item.price}}</view>
 							<view class="">宸插敭: {{item.buyCount}}</view>
 						</view>
 					</view>
 				</view>
 			</view>
 
-
 			<view class="openShowLeft" @click="showDrawer('showLeft')" v-if="!showLeft">
 				<uni-icons type="right" size="30"></uni-icons>
 			</view>
-			<uni-drawer ref="showLeft" mode="left" width="120" @change="change($event,'showLeft')"
-				class="navigationLeft">
-				<view class="typeNavigation">
+		</view>
+		<view style="display: flex;align-items: center;justify-content: center;margin-top: 20rpx;" v-if="canLoadMore">
+			娌℃湁鏇村鏁版嵁浜�.................</view>
+		</scroll-view>
+			<uni-drawer ref="showLeft" mode="left" width="120" height="80vh" :drawerTop="buttonHeight" @change="change($event,'showLeft')"
+				:cus-style="true" class="navigationLeft" :mask="false">
+				<scroll-view class="typeNavigation" :scroll-y="true" :show-scrollbar="false" >
 					<view class="typeNavigationItem" :class="{typeNavigationItemCheck:currentCategort ==item.id}"
 						@click="chooseCategory(item.id)" v-for="item in categoryList" :key="item.id">
 						{{item.name}}
 					</view>
-				</view>
+				</scroll-view>
 			</uni-drawer>
-		</view>
-		<view style="display: flex;align-items: center;justify-content: center;margin-top: 20rpx;" v-if="canLoadMore">
-			娌℃湁鏇村鏁版嵁浜�.................</view>
-		<custom-tabbar bgColor="#ffffff" selected="shop"></custom-tabbar>
 	</view>
 </template>
 
 <script>
+	import TopBar from "@/components/TopBar.vue";
 	import {
 		getCategoryList,
 		getGoodsList
@@ -70,8 +75,13 @@
 		getSTSToken
 	} from '@/api/common.js'
 	export default {
+		components: {TopBar},
 		data() {
 			return {
+				buttonHeight:0,
+				//璁板綍涓ゅ垪楂樺害
+				listHeight1: 0,
+				listHeight2: 0,
 				//鏄惁鏄剧ず鎵撳紑宸︿晶寮圭獥
 				showLeft: false,
 				//鍟嗗搧瀵艰埅鍒嗙被
@@ -90,6 +100,7 @@
 					pageSize: 12,
 					pageNumber: 1,
 					categoryId: null,
+					canFilter:true
 				},
 				//鍟嗗搧鍙屽垪鏄剧ず
 				goodsList1: [],
@@ -97,6 +108,27 @@
 			}
 		},
 		methods: {
+			topBarChange(titleObj) {
+				if (titleObj.index === 'home') {
+					uni.switchTab({
+						url: titleObj.pagePath
+					});
+				} else {
+					uni.redirectTo({
+						url: titleObj.pagePath
+					});
+				}
+			},
+			async searchGoods(keyWard) {
+				this.getGoodsParam.keyword = keyWard
+				this.getGoodsParam.pageNumber = 1
+				this.getGoodsParam.categoryId = ''
+				this.goodsList1 = []
+				this.goodsList2 = []
+				this.listHeight1 = 0;
+				this.listHeight2 = 0;
+				await this.getgoodsData();
+			},
 			confirm() {},
 			// 鎵撳紑绐楀彛
 			showDrawer(e) {
@@ -115,9 +147,24 @@
 				const height = e.detail.height;
 				this[arrName][index].width = 310 + 'rpx';
 				//璁$畻瀹介珮姣�
-				const videoHeight = 310 / (wight / height)
-				this[arrName][index].height = Math.floor(videoHeight) + 'rpx';
+				const videoHeight = Math.floor(310 / (wight / height))
+				this[arrName][index].height = videoHeight + 'rpx';
 				this[arrName][index].show = true;
+				//璁$畻闆嗗悎楂樺害
+				if (arrName === 'goodsList2') {
+					if (videoHeight > 300) {
+						this.listHeight2 += videoHeight;
+					} else if (videoHeight < 300) {
+						this.listHeight2 -= videoHeight;
+					}
+				}
+				if (arrName === 'goodsList1') {
+					if (videoHeight > 300) {
+						this.listHeight1 += videoHeight;
+					} else if (videoHeight < 300) {
+						this.listHeight1 -= videoHeight;
+					}
+				}
 				console.log(this[arrName][index].width, this[arrName][index].height)
 				this.flushDom = new Date();
 			},
@@ -127,37 +174,77 @@
 					url: `/pages/product/goods?id=${item.id}&goodsId=${item.goodsId}`
 				});
 			},
+			//瑙﹀簳鑾峰彇鏁版嵁
+			async loadMoreData() {
+				if (this.getGoodsParam.pageNumber < this.maxPages) {
+					this.getGoodsParam.pageNumber++;
+					await this.getgoodsData()
+				} else {
+					this.canLoadMore = true;
+				}
+			
+			},
 			//鑾峰彇鍒嗙被瀵艰埅鏍�
 			async loadCategoryList() {
 				let list = await getCategoryList(0);
 				this.categoryList = list.data.result
 			},
+			async getgoodsData() {
+				const goodsList = await getGoodsList(this.getGoodsParam);
+				// const sts = await getSTSToken();
+				// const stsUrl = sts.data.data.endpoint
+				// // 澶勭悊鏁版嵁
+				// goodsList.data.result.records.forEach(item => {
+				// 	if (item.thumbnail !== '' && item.thumbnail !== null && item.thumbnail.indexOf('http') ===
+				// 		-1) {
+				// 		item.thumbnail = stsUrl + '/' + item.thumbnail
+				// 	}
+				// 	if (item.goodsVideo !== '' && item.goodsVideo !== null && item.goodsVideo.indexOf(
+				// 			'http') === -1) {
+				// 		item.goodsVideo = stsUrl + '/' + item.goodsVideo
+				// 	}
+				// })
+				//璁$畻涓や釜鏁扮粍鐨勯暱搴� 鐢ㄤ簬瑙e喅鐎戝竷娴佷袱杈归珮搴︿笉涓�鑷撮棶棰�
+				//骞冲垎缁欎袱涓暟缁�
+				const goodsSize = goodsList.data.result.records.length;
+				let middle = Math.ceil(goodsSize / 2);
+				//鍒ゆ柇閭d釜闆嗗悎闀垮害楂� 閲嶆柊鍒嗛厤闆嗗悎鏁版嵁
+				const diffHeight = this.listHeight1 - this.listHeight2;
+				//list1闀垮害澶т簬list2
+				if (diffHeight > 0) {
+					const needCount = Math.floor(diffHeight / 300)
+					if (needCount > 6) {
+						middle = 0;
+					} else {
+						middle -= needCount;
+					}
+				} else if(diffHeight < 0) {
+					const needCount = Math.abs(Math.floor(diffHeight / 300))
+					if (needCount > 6) {
+						middle += 6
+					} else {
+						middle = needCount;
+					}
+				}
+				this.goodsList1 = [...this.goodsList1, ...goodsList.data.result.records.slice(0, middle)];
+				this.goodsList2 = [...this.goodsList2, ...goodsList.data.result.records.slice(middle)];
+				this.maxPages = goodsList.data.result.pages
+
+				// if(this.listHeight1===0||this.listHeight2===0)}
+				this.listHeight1 += middle * 300;
+				this.listHeight2 += (goodsSize - middle) * 300
+			},
 			async chooseCategory(id) {
-				if (this.currentCategort === id) return
 				this.canLoadMore = false;
 				this.currentCategort = id
 				this.getGoodsParam.categoryId = id
 				this.getGoodsParam.keyword = ''
 				this.getGoodsParam.pageNumber = 1
-				const goodsList = await getGoodsList(this.getGoodsParam);
-				const sts = await getSTSToken();
-				const stsUrl = sts.data.data.endpoint
-				// 澶勭悊鏁版嵁
-				goodsList.data.result.records.forEach(item => {
-					if (item.thumbnail !== '' && item.thumbnail !== null && item.thumbnail.indexOf('http') ===
-						-1) {
-						item.thumbnail = stsUrl + '/' + item.thumbnail
-					}
-					if (item.goodsVideo !== '' && item.goodsVideo !== null && item.goodsVideo.indexOf(
-							'http') === -1) {
-						item.goodsVideo = stsUrl + '/' + item.goodsVideo
-					}
-				})
-				//骞冲垎缁欎袱涓暟缁�
-				const middle = Math.ceil(goodsList.data.result.records.length / 2);
-				this.goodsList1 = goodsList.data.result.records.slice(0, middle);
-				this.goodsList2 = goodsList.data.result.records.slice(middle);
-				this.maxPages = goodsList.data.result.pages
+				this.goodsList1 = [];
+				this.goodsList2 = [];
+				this.listHeight1 = 0;
+				this.listHeight2 = 0;
+				await this.getgoodsData();
 				console.log(this.maxPages)
 			}
 		},
@@ -165,57 +252,15 @@
 			this.showDrawer('showLeft')
 		},
 		async onLoad() {
+			// 鑾峰彇鐘舵�佹爮楂樺害
+			const systemInfo = uni.getSystemInfoSync();
+			this.buttonHeight = systemInfo.statusBarHeight +40;
+			console.log('-------------------------------->',this.buttonHeight)
 			await this.loadCategoryList();
 			this.getGoodsParam.pageNumber = 1
 			this.getGoodsParam.categoryId = ""
 			this.getGoodsParam.keyword = ""
-			const goodsList = await getGoodsList(this.getGoodsParam);
-			const sts = await getSTSToken();
-			const stsUrl = sts.data.data.endpoint
-			// 澶勭悊鏁版嵁
-			goodsList.data.result.records.forEach(item => {
-				if (item.thumbnail !== '' && item.thumbnail !== null && item.thumbnail.indexOf('http') ===
-					-1) {
-					item.thumbnail = stsUrl + '/' + item.thumbnail
-				}
-				if (item.goodsVideo !== '' && item.goodsVideo !== null && item.goodsVideo.indexOf(
-						'http') === -1) {
-					item.goodsVideo = stsUrl + '/' + item.goodsVideo
-				}
-			})
-			//骞冲垎缁欎袱涓暟缁�
-			const middle = Math.ceil(goodsList.data.result.records.length / 2);
-			this.goodsList1 = goodsList.data.result.records.slice(0, middle);
-			this.goodsList2 = goodsList.data.result.records.slice(middle);
-			this.maxPages = goodsList.data.result.pages
-			console.log(this.maxPages)
-		},
-		async onReachBottom() {
-			if (this.getGoodsParam.pageNumber < this.maxPages) {
-				this.getGoodsParam.pageNumber++;
-				const goodsList = await getGoodsList(this.getGoodsParam);
-				const sts = await getSTSToken();
-				const stsUrl = sts.data.data.endpoint
-				// 澶勭悊鏁版嵁
-				goodsList.data.result.records.forEach(item => {
-					if (item.thumbnail !== '' && item.thumbnail !== null && item.thumbnail.indexOf('http') ===
-						-1) {
-						item.thumbnail = stsUrl + '/' + item.thumbnail
-					}
-					if (item.goodsVideo !== '' && item.goodsVideo !== null && item.goodsVideo.indexOf(
-							'http') === -1) {
-						item.goodsVideo = stsUrl + '/' + item.goodsVideo
-					}
-				})
-				//骞冲垎缁欎袱涓暟缁�
-				const middle = Math.ceil(goodsList.data.result.records.length / 2);
-				this.goodsList1 = [...this.goodsList1, ...goodsList.data.result.records.slice(0, middle)];
-				this.goodsList2 = [...this.goodsList2, ...goodsList.data.result.records.slice(middle)];
-				this.maxPages = goodsList.data.result.pages
-			} else {
-				this.canLoadMore = true;
-			}
-
+			await this.getgoodsData()
 		}
 	}
 </script>
@@ -224,16 +269,27 @@
 	.container {
 		width: 750rpx;
 		padding-bottom: 64rpx;
+		height: 100vh;
+		overflow: hidden;
 	}
 
 	.commoditySquare {
 		width: 750rpx;
-		position: relative;
 		box-sizing: border-box;
 		display: flex;
 		justify-content: space-around;
+		height: 100%;
 	}
-
+	.scrollContainer{
+		overflow: hidden;
+		height: 1224rpx;
+		-webkit-overflow-scrolling: touch;
+	}
+	.scrollContainer::-webkit-scrollbar {
+	  display: none; /* Chrome/Safari绛� */
+	  width: 0 !important; /* 鍏煎iOS */
+	  height: 0 !important;
+	}
 	.left {
 		box-sizing: border-box;
 	}
@@ -265,8 +321,16 @@
 
 	.openShowLeft {
 		position: fixed;
-		top: 30rpx;
+		top: 200rpx;
 		left: 0;
+		align-items: center;
+		justify-content: flex-start;
+		background-color: #b6b6b6;
+		opacity: 0.8;
+		z-index: 999;
+		height: 70rpx;
+		width: 50rpx;
+		border-radius: 0 50% 50% 0;
 	}
 
 	.navigationLeft {
@@ -277,34 +341,36 @@
 	}
 
 
-	.scroll-view {
-		/* #ifndef APP-NVUE */
-		width: 100%;
-		height: 100%;
-		/* #endif */
-		flex: 1
-	}
+	// .scroll-view {
+	// 	/* #ifndef APP-NVUE */
+	// 	width: 100%;
+	// 	height: 100%;
+	// 	/* #endif */
+	// 	flex: 1
+	// }
 
-	.priceInfo {
-		margin-top: 10rpx;
-		display: flex;
-		justify-content: space-around;
-	}
+	// .priceInfo {
+	// 	margin-top: 10rpx;
+	// 	display: flex;
+	// 	justify-content: space-around;
+	// }
 
 	// 澶勭悊鎶藉眽鍐呭婊氬姩
-	.scroll-view-box {
-		flex: 1;
-		position: absolute;
-		top: 0;
-		right: 0;
-		bottom: 0;
-		left: 0;
-	}
+	// .scroll-view-box {
+	// 	flex: 1;
+	// 	position: absolute;
+	// 	top: 0;
+	// 	right: 0;
+	// 	bottom: 0;
+	// 	left: 0;
+	// }
 
 
 	.typeNavigation {
+		box-sizing: border-box;
 		padding: 10rpx;
-		position: relative;
+		height: 100%;
+		// position: relative;
 	}
 
 	.typeNavigationItem {
@@ -312,13 +378,12 @@
 		font-size: 28rpx;
 		color: black;
 		margin-top: 10rpx;
-		border-radius: 12rpx;
-		border: 1rpx solid gray;
 	}
 
 	.typeNavigationItemCheck {
-		background-color: #42b993;
-		color: #fff;
+		color: #ef321e;
+		font-size: 32rpx;
+		font-weight: bold;
 		border: 0;
 	}
 
@@ -327,4 +392,46 @@
 		top: 20rpx;
 		right: 0;
 	}
-</style>
\ No newline at end of file
+
+	.nav-search {
+		padding-left: 30rpx !important;
+		padding-right: 20rpx !important;
+		// position: fixed;
+		// top: 0;
+		// width: 500rpx;
+		// z-index: 9999;
+	}
+	.goodsInfo{
+		margin-top: 10rpx;
+		box-sizing: border-box;
+		width: 100%;
+		display: flex;
+		flex-direction: column;
+	}
+	.goodsName{
+		display: -webkit-box;
+		-webkit-box-orient: vertical;
+		-webkit-line-clamp: 1;
+		height: 32rpx;
+		overflow: hidden;
+		text-overflow: ellipsis;
+		text-align: center;
+		vertical-align: middle;
+	}
+	.priceInfo{
+		margin-top: 10rpx;
+		display: flex;
+		align-items: center;
+		justify-content: space-between;
+	}
+	.goodsPrice{
+		color: red;
+		font-weight: bold;
+	}
+	.topBar {
+		position: fixed;
+		top: 20rpx;
+		left: 20rpx;
+		z-index: 1000
+	}
+</style>

--
Gitblit v1.8.0