From 5e8f70caf25beb34657f34a7ee06e1e1ff541cdb Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期六, 28 二月 2026 16:27:54 +0800
Subject: [PATCH] 合并

---
 mini-program/pages/search/search.vue |   67 +++++++++++++++++++++++++++++----
 1 files changed, 58 insertions(+), 9 deletions(-)

diff --git a/mini-program/pages/search/search.vue b/mini-program/pages/search/search.vue
index 2700b46..125ec50 100644
--- a/mini-program/pages/search/search.vue
+++ b/mini-program/pages/search/search.vue
@@ -2,18 +2,18 @@
 	<view class="box">
 		<view class="search">
 			<u-search placeholder="璇疯緭鍏ュ晢鍝佸悕绉版悳绱�" height="36" searchIconColor="#999999" borderColor="#EEEEEE"
-				bgColor="#F9F9FB" :showAction="false" v-model="goodsName" @search="search" />
+				bgColor="#F9F9FB" :showAction="false" v-model="goodsName" @search="search" @clear="goodsList = []" />
 		</view>
 		<view class="history" v-if="historyList && historyList.length > 0">
 			<view class="history-title">鍘嗗彶鎼滅储</view>
 			<view class="history-list">
-				<view class="history-list-item" v-for="(item, index) in historyList" :key="index">{{item.content}}</view>
+				<view class="history-list-item" v-for="(item, index) in historyList" :key="index" @click="seleContent(item.content)">{{item.content}}</view>
 			</view>
 		</view>
 		<template v-if="isSearch">
 			<view class="list">
 				<image class="list-notfund" v-if="goodsList.length === 0" src="/static/images/default_search@2x.png" mode="widthFix"></image>
-				<view class="commodity-item" v-for="(item, i) in goodsList" :key="i" v-else>
+				<view class="commodity-item" v-for="(item, i) in goodsList" :key="i" v-else @click="jumpDetails(item.id)">
 					<view class="commodity-item-image">
 						<image :src="item.imgurl" mode="widthFix"></image>
 					</view>
@@ -32,18 +32,21 @@
 						</view>
 						<view class="commodity-item-shou">
 							<text>宸插敭{{item.saleNum + item.realSaleNum}}</text>
-							<view class="commodity-item-shou-add">+</view>
+							<view class="commodity-item-shou-add" @click.stop="addCard(item)">+</view>
 						</view>
 					</view>
 				</view>
 			</view>
 		</template>
+		<Login ref="login" />
 	</view>
 </template>
 
 <script>
 	import { mapState } from 'vuex'
+	import Login from '@/components/login/login.vue'
 	export default {
+		components: { Login },
 		computed: {
 			...mapState(['userInfo'])
 		},
@@ -54,28 +57,64 @@
 				page: 1,
 				next: true,
 				isSearch: false,
-				historyList: []
+				historyList: [],
+				categoryId: null,
+				applicableBrandId: null
 			};
 		},
-		onLoad() {
+		onLoad(option) {
+			if (option.categoryId) {
+				this.categoryId = option.categoryId
+				this.isSearch = true
+				this.getGoodsList()
+			}
+			if (option.applicableBrandId) {
+				this.applicableBrandId = option.applicableBrandId
+				this.isSearch = true
+				this.getGoodsList()
+			}
 			this.gethistary()
 		},
 		onReachBottom() {
 			this.getGoodsList()
 		},
 		methods: {
+			addCard(e) {
+				if (!this.userInfo) {
+					this.$refs.login.open()
+					return
+				}
+				this.$u.api.addCart({
+					goodsId: e.id,
+					goodsSkuId: e.goodsSkuResponseList[0].id,
+					num: 1
+				}).then(res => {
+					if (res.code === 200) {
+						uni.showToast({ title: '娣诲姞鎴愬姛', icon: 'success' })
+					}
+				})
+			},
+			jumpDetails(id) {
+				uni.navigateTo({
+					url: '/pages/details/details?id=' + id
+				})
+			},
+			seleContent(val) {
+				this.goodsName = val
+				this.search()
+			},
 			gethistary() {
 				if (!this.userInfo) return
 				this.$u.api.searchHistoryList({
 					memberId: this.userInfo.id
 				}).then(res => {
 					if (res.code === 200) {
-						console.log(res)
 						this.historyList = res.data
 					}
 				})
 			},
 			search() {
+				if (!this.goodsName) return;
 				if (!this.isSearch) {
 					this.isSearch = true
 				}
@@ -92,10 +131,14 @@
 					model: {
 						type: 0,
 						sortInfo: 3,
-						goodsName: this.goodsName
+						goodsName: this.goodsName,
+						memberId: this.userInfo.id,
+						categoryId: this.categoryId,
+						applicableBrandId: this.applicableBrandId
 					}
 				}).then(res => {
 					if (res.code === 200) {
+						this.gethistary()
 						res.data.records.forEach(item => {
 							item.minPrice = item.minPrice.toFixed(2).split('.')
 						})
@@ -111,6 +154,11 @@
 	}
 </script>
 
+<style>
+	page {
+		background-color: #F9F9FB;
+	}
+</style>
 <style lang="scss" scoped>
 	.box {
 		width: 100%;
@@ -152,7 +200,7 @@
 					margin-right: 24rpx;
 					margin-bottom: 24rpx;
 					&:last-child {
-						margin: 0 !important;
+						margin-right: 0 !important;
 					}
 				}
 			}
@@ -180,6 +228,7 @@
 				.commodity-item-image {
 					width: 100%;
 					height: 336rpx;
+					overflow: hidden;
 					display: flex;
 					align-items: center;
 					justify-content: center;

--
Gitblit v1.9.3