Files
frontend-app/pages/rwa_package/dongjian/search.vue
T
2026-07-23 14:02:58 +08:00

264 lines
6.8 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view class="content">
<TopSafe bgColor="#fff"></TopSafe>
<view class="search-view">
<view class="head-view">
<u-icon size="30rpx" name="arrow-left" @click="onBack" color="#333"></u-icon>
<view class="search-box" :style="{ maxWidth: searchBoxMaxWidth + 'rpx' }">
<input class="input-view" v-model="searchInput" placeholder="请输入搜索关键词"></input>
<view class="search-btn flex-c" @click="onSearch">
<text class="text-32 text-white">搜索</text>
</view>
</view>
</view>
<view class="top-view mt-24">
<view class="flex-r-lr">
<text class="text-32 text-bold text-zu">搜索历史</text>
<u-icon size="40rpx" name="trash" @click="isDel = !isDel" color="#333"></u-icon>
</view>
<view class="history-view" v-if="historyList.length">
<view class="history-box flex-c mt-24 mr-32" v-for="(item,index) in historyList" :key="item">
<text class="text-24 text-fu line-h" @click="onText(item)" >{{item}}</text>
<u-icon size="32rpx" class="close-pos" v-if="isDel" @click="onDel(index)"
name="close-circle" color="#333"></u-icon>
</view>
</view>
<view class="history-on-data flex-c" v-else>
<text class="text-40 text-bold">暂无历史记录</text>
</view>
</view>
<view class="bottom-view">
<view class="bottom-head">
<text class="text-32 text-bold text-zu">商品展示</text>
</view>
<view class="bottom-scroll" v-if="dataList.length">
<ShopItem :obj="item" class="mt-24" @click="onJump(item)"
v-for="(item,index) in dataList" :key="item.id"></ShopItem>
</view>
<view class="bottom-scroll-no " v-else>
<text class="text-48 text-bold" style="margin-top:200rpx">暂无数据</text>
</view>
</view>
</view>
<DownPopup></DownPopup>
</view>
</template>
<script>
import { getUserInfo } from '@/api/auth.js';
import Header from '@/components/common/header.vue';
import TopSafe from '@/components/common/top-safe.nvue'
import DownPopup from '@/components/common/down-popup.vue';
import { searchList } from '@/api/product.js'
import ShopItem from './components/shop-item.vue'
import func from '@/utils/func.js';
export default {
components: { Header,TopSafe,DownPopup,ShopItem },
data() {
return {
searchInput:'',
historyList:[],
isDel:false,
dataList:[],
searchBoxMaxWidth: 0 // 搜索框最大宽度
};
},
onShow() {
this.init();
},
onLoad() {
// 获取胶囊按钮位置信息,计算搜索框最大宽度
this.calculateSearchBoxMaxWidth();
},
methods: {
init(){
let arr = uni.getStorageSync('history') || '';
if(arr){
this.historyList = arr.split(',');
}else{
this.historyList = [];
}
},
// 计算搜索框最大宽度,确保不与胶囊按钮重叠
calculateSearchBoxMaxWidth() {
// #ifdef MP-WEIXIN
const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
if (menuButtonInfo) {
const systemInfo = uni.getSystemInfoSync();
// 计算屏幕宽度减去左侧内边距和胶囊按钮左侧距离
// 左侧内边距32rpx转换为px
const leftPadding = 32 * (systemInfo.windowWidth / 750);
// 箭头图标宽度和间距约为30rpx + 24rpx = 54rpx
const arrowWidth = 54 * (systemInfo.windowWidth / 750);
// 计算搜索框最大宽度(px)
const maxWidthPx = menuButtonInfo.left - leftPadding - arrowWidth - 20; // 20px额外间距
// 转换为rpx
this.searchBoxMaxWidth = Math.ceil(maxWidthPx * (750 / systemInfo.windowWidth));
}
// #endif
},
onJump(item){
uni.navigateTo({
url: '/pages/other_package/productInfo/productInfo?id='+item.id,
})
},
onBack(){
uni.navigateBack();
},
onSearch(){
if(!this.searchInput){
return;
}
this.onAdd();
let params = {
keyword:this.searchInput
}
searchList(params).then((res)=>{
this.dataList = res.data;
console.log('res',res)
})
},
onDel(index){
this.historyList.splice(index,1);
this.onSave()
},
onAdd(){
if(this.searchInput){
let bool = false;
this.historyList.forEach(item=>{
if(item == this.searchInput){
bool = true;
}
})
if(!bool){
this.historyList.unshift(this.searchInput);
if(this.historyList.length > 15){
this.historyList.pop();
}
this.onSave();
}
}
},
onText(item){
this.searchInput = item;
},
onSave(){
if(this.historyList.length){
uni.setStorageSync('history',this.historyList.join(','));
}else{
uni.setStorageSync('history','');
}
}
}
}
</script>
<style lang="scss" scoped>
.search-view{
width:100%;
height:calc(100% - var(--status-bar-height));
display: flex;
flex-direction: column;
align-items: center;
box-sizing: border-box;
.top-view{
width:100%;
min-height:150rpx;
display: flex;
flex-direction: column;
padding: 0 32rpx;
box-sizing: border-box;
overflow-y: auto;
.history-on-data{
width:100%;
height:100%;
}
.history-view{
width:100%;
display: flex;
flex-wrap: wrap;
.history-box{
position: relative;
padding: 8rpx 22rpx;
box-sizing: border-box;
border-radius: 8rpx;
border:2rpx solid #7932FE;
.close-pos{
right:-20rpx;
position: absolute;
top:-40%;
}
}
}
}
.bottom-view{
width:100%;
flex:1;
display: flex;
flex-direction: column;
padding: 0 32rpx;
box-sizing: border-box;
.bottom-head{
height:50rpx;
display: flex;
}
.bottom-scroll{
width:100%;
height:calc(100vh - 50rpx - 324rpx - 4rpx - 88rpx - var(--status-bar-height));
overflow-y: auto;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.bottom-scroll-no{
width:100%;
display: flex;
flex-direction: column;
align-items: center;
}
}
.head-view{
width:100%;
height:118rpx;
min-height:118rpx;
display: flex;
flex-direction: row;
align-items: center;
padding: 0 32rpx;
box-sizing: border-box;
background-color: #fff;
.search-box{
/* 移除flex:1,使用固定最大宽度 */
height:84rpx;
min-height:16rpx;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
border-radius: 16rpx;
border:2rpx solid #7932FE;
margin-left:24rpx;
}
.search-btn{
width:156rpx;
height:100%;
border-radius: 16rpx;
background: linear-gradient( 270deg, #B164FB 0%, #7934F6 100%);
}
.input-view{
height:72rpx;
box-sizing: border-box;
padding: 0 7rpx !important;
border-radius: 36rpx;
margin-left:12rpx;
flex:1; /* 输入框在搜索框内自适应 */
}
}
}
</style>