feat:评价区改造

This commit is contained in:
2026-08-06 18:50:25 +08:00
parent 8225be60c6
commit aa20d121f7
13 changed files with 3323 additions and 1325 deletions
+371 -276
View File
@@ -1,276 +1,371 @@
<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">
<input class="input-view wx-width" v-model="searchInput"></input>
<!-- <u-input class="input-view wx-width"
v-model="searchInput"></u-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: [],
};
},
onShow() {
this.init();
},
methods: {
init() {
// this.isSignContract()
// this.getSignContract()
let arr = uni.getStorageSync('history') || '';
if (arr) {
this.historyList = arr.split(',');
} else {
this.historyList = [];
}
},
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;
/* #ifdef MP-WEIXIN */
padding-top: 80rpx !important;
height: auto !important;
min-height: calc(118rpx + 80rpx) !important;
/* #endif */
.search-box {
width: 100%;
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 30rpx !important;
border-radius: 36rpx;
margin-left: 12rpx;
flex: 1;
}
/* #ifdef MP-WEIXIN */
.wx-width {
width: 350rpx !important;
flex: none;
}
/* #endif */
}
}
</style>
<template>
<view class="page-container">
<!-- 顶部安全距离 -->
<TopSafe bgColor="#ffffff"></TopSafe>
<!-- 1. 自定义导航栏:左边返回箭头,中间“商品搜索”标题 -->
<view class="custom-navbar">
<view class="nav-back flex-c" @click="onBack">
<u-icon name="arrow-left" size="36rpx" color="#333333"></u-icon>
</view>
<view class="nav-title">商品搜索</view>
<view class="nav-right"></view>
</view>
<!-- 2. 搜索框部分:放大镜 + 输入框 + 右侧紫色搜索按钮 -->
<view class="search-bar-box">
<view class="search-inner">
<u-icon name="search" size="36rpx" color="#999999" class="search-icon"></u-icon>
<input
class="search-input"
v-model="searchInput"
placeholder="请输入商品关键字"
placeholder-style="color: #999999; font-size: 28rpx;"
confirm-type="search"
@confirm="onSearch"
/>
<view class="search-btn flex-c" @click="onSearch">
<text class="search-btn-text">搜索</text>
</view>
</view>
</view>
<!-- 3. 历史搜索部分 -->
<view class="history-container">
<view class="history-header flex-r-lr">
<text class="section-title">历史搜索</text>
<u-icon name="trash" size="38rpx" color="#999999" @click="toggleDel"></u-icon>
</view>
<!-- 历史记录标签列表 -->
<view class="history-tags flex-r" v-if="historyList.length">
<view
class="history-tag-item flex-r"
v-for="(item, index) in historyList"
:key="index"
@click="onText(item)"
>
<text class="tag-text">{{ item }}</text>
<u-icon
name="close-circle-fill"
size="28rpx"
color="#999999"
class="del-icon"
v-if="isDel"
@click.stop="onDel(index)"
></u-icon>
</view>
</view>
<!-- 无历史记录时显示 -->
<view class="history-empty" v-else>
<text class="empty-text">暂无搜索内容</text>
</view>
</view>
<!-- 4. 猜你喜欢部分 -->
<view class="recommend-container">
<view class="recommend-header">
<text class="section-title">猜你喜欢</text>
</view>
<!-- 猜你喜欢下面的列表按要求空着 -->
<view class="recommend-list">
<view class="product-grid" v-if="dataList && dataList.length">
<ShopItem
:obj="item"
class="product-item"
@click="onJump(item)"
v-for="item in dataList"
:key="item.id"
></ShopItem>
</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: [],
};
},
onShow() {
this.init();
},
methods: {
init() {
let arr = uni.getStorageSync('history') || '';
if (arr) {
this.historyList = arr.split(',').filter(item => item.trim() !== '');
} else {
this.historyList = [];
}
},
onJump(item) {
uni.navigateTo({
url: '/pages/other_package/productInfo/productInfo?id=' + item.id,
});
},
onBack() {
uni.navigateBack();
},
onSearch() {
if (!this.searchInput || !this.searchInput.trim()) {
return;
}
this.onAdd();
let params = {
keyword: this.searchInput.trim()
};
searchList(params).then((res) => {
this.dataList = res.data || [];
});
},
onDel(index) {
this.historyList.splice(index, 1);
this.onSave();
if (this.historyList.length === 0) {
this.isDel = false;
}
},
toggleDel() {
if (this.historyList.length > 0) {
this.isDel = !this.isDel;
}
},
onAdd() {
if (this.searchInput && this.searchInput.trim()) {
let val = this.searchInput.trim();
let index = this.historyList.indexOf(val);
if (index > -1) {
this.historyList.splice(index, 1);
}
this.historyList.unshift(val);
if (this.historyList.length > 15) {
this.historyList.pop();
}
this.onSave();
}
},
onText(item) {
this.searchInput = item;
this.onSearch();
},
onSave() {
if (this.historyList.length) {
uni.setStorageSync('history', this.historyList.join(','));
} else {
uni.setStorageSync('history', '');
}
}
}
};
</script>
<style lang="scss" scoped>
/* 避免全局 .content 的 align-items: center 导致元素全挤在中间 */
.page-container {
width: 750rpx;
min-width: 750rpx;
max-width: 100%;
min-height: 100vh;
background-color: #ffffff;
display: flex;
flex-direction: column;
align-items: stretch;
box-sizing: border-box;
}
/* 导航栏 */
.custom-navbar {
width: 100%;
height: 88rpx;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
padding: 0 32rpx;
box-sizing: border-box;
background-color: #ffffff;
position: relative;
.nav-back {
width: 60rpx;
height: 60rpx;
display: flex;
align-items: center;
justify-content: flex-start;
}
.nav-title {
font-size: 34rpx;
font-weight: bold;
color: #1a1a1a;
position: absolute;
left: 50%;
transform: translateX(-50%);
white-space: nowrap;
}
.nav-right {
width: 60rpx;
}
}
/* 搜索框 */
.search-bar-box {
width: 100%;
padding: 16rpx 32rpx;
box-sizing: border-box;
.search-inner {
width: 100%;
height: 80rpx;
background-color: #ffffff;
border-radius: 40rpx;
display: flex;
flex-direction: row;
align-items: center;
padding: 0 8rpx 0 28rpx;
box-sizing: border-box;
border: 2rpx solid #efefef;
.search-icon {
margin-right: 12rpx;
}
.search-input {
flex: 1;
height: 100%;
font-size: 28rpx;
color: #333333;
background: transparent;
border: none;
}
.search-btn {
height: 64rpx;
padding: 0 32rpx;
background: linear-gradient(270deg, #b164fb 0%, #7934f6 100%);
border-radius: 32rpx;
display: flex;
align-items: center;
justify-content: center;
.search-btn-text {
font-size: 28rpx;
color: #ffffff;
font-weight: 500;
}
}
}
}
/* 历史搜索 */
.history-container {
width: 100%;
padding: 32rpx 32rpx 16rpx 32rpx;
box-sizing: border-box;
.history-header {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
width: 100%;
.section-title {
font-size: 32rpx;
font-weight: bold;
color: #333333;
}
}
.history-tags {
display: flex;
flex-direction: row;
flex-wrap: wrap;
margin-top: 24rpx;
width: 100%;
.history-tag-item {
padding: 10rpx 28rpx;
background-color: #f5f5f7;
border-radius: 30rpx;
margin-right: 20rpx;
margin-bottom: 20rpx;
display: flex;
flex-direction: row;
align-items: center;
.tag-text {
font-size: 26rpx;
color: #666666;
}
.del-icon {
margin-left: 10rpx;
}
}
}
.history-empty {
margin-top: 16rpx;
width: 100%;
.empty-text {
font-size: 26rpx;
color: #999999;
}
}
}
/* 猜你喜欢 */
.recommend-container {
width: 100%;
padding: 32rpx 32rpx;
box-sizing: border-box;
.recommend-header {
width: 100%;
display: flex;
flex-direction: row;
align-items: center;
.section-title {
font-size: 32rpx;
font-weight: bold;
color: #333333;
}
}
.recommend-list {
width: 100%;
margin-top: 24rpx;
.product-grid {
width: 100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
}
}
}
</style>