文件
xionggeshop/xgsc.gynhc.com_wx/pages/public/search.vue
2026-09-14 17:24:53 +08:00

360 行
8.0 KiB
Vue

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<template>
<view class="search-page">
<!-- 搜索栏 -->
<view class="search-page__head">
<u-search
v-model="searchVal"
:focus="autoFocus"
margin="0"
placeholder="搜索臻选好酒"
height="72"
bg-color="#FFFFFF"
border-color="#EEEEEE"
color="#2C2C2C"
placeholder-color="#999999"
action-text="搜索"
:action-style="searchActionStyle"
:input-style="searchInputStyle"
@search="onSearch"
@custom="onSearch"
@clear="clearSearch"
></u-search>
</view>
<scroll-view scroll-y class="search-page__body">
<!-- 空态引导(无历史时) -->
<view v-if="!historyTag.length" class="search-empty">
<view class="search-empty__icon-wrap">
<u-icon name="search" size="44" color="#1677FF"></u-icon>
</view>
<text class="search-empty__title">发现臻选好酒</text>
<text class="search-empty__desc">输入关键词,或点击下方热门搜索快速查找</text>
</view>
<!-- 热门搜索 -->
<view class="search-section">
<view class="search-section__head">
<view class="search-section__title-wrap">
<u-icon name="tags-fill" size="32" color="#1677FF"></u-icon>
<text class="search-section__title">热门搜索</text>
</view>
</view>
<view class="search-tags">
<button
v-for="(item, index) in hotKeywords"
:key="index"
class="search-tag search-tag--hot u-reset-button"
hover-class="search-tag--pressed"
@tap="onSearch(item)"
>
<text v-if="index < 3" class="search-tag__badge">热</text>
<text class="search-tag__text u-ellipsis-1">{{ item }}</text>
</button>
</view>
</view>
<!-- 快捷分类 -->
<view class="search-section">
<view class="search-section__head">
<view class="search-section__title-wrap">
<u-icon name="grid-fill" size="32" color="#1677FF"></u-icon>
<text class="search-section__title">快捷分类</text>
</view>
</view>
<view class="search-quick">
<view
v-for="(item, index) in quickCategories"
:key="index"
class="search-quick__item"
hover-class="search-quick__item--pressed"
@tap="onQuickSearch(item)"
>
<text class="search-quick__label">{{ item.label }}</text>
<u-icon name="arrow-right" size="24" color="#CCCCCC"></u-icon>
</view>
</view>
</view>
<!-- 搜索历史 -->
<view v-if="historyTag.length" class="search-section">
<view class="search-section__head">
<view class="search-section__title-wrap">
<u-icon name="clock-fill" size="32" color="#999999"></u-icon>
<text class="search-section__title">搜索历史</text>
</view>
<button class="search-section__action u-reset-button" hover-class="search-section__action--pressed" @tap="showModal = true">
<u-icon name="trash" size="28" color="#999999"></u-icon>
<text>清空</text>
</button>
</view>
<view class="search-tags">
<button
v-for="(item, index) in historyTag"
:key="index"
class="search-tag search-tag--history u-reset-button"
hover-class="search-tag--pressed"
@tap="onSearch(item)"
>
<text class="search-tag__text u-ellipsis-1">{{ item }}</text>
</button>
</view>
</view>
<view class="search-page__safe-bottom"></view>
</scroll-view>
<u-modal
ref="uModal"
v-model="showModal"
:show-cancel-button="true"
confirm-color="#1677FF"
cancel-color="#666666"
@confirm="clearSearchHistory"
confirm-text="清除"
cancel-text="取消"
content="是否清除历史搜索记录?"
title="提示"
></u-modal>
</view>
</template>
<script>
const HOT_KEYWORDS = ['雄戈小酒', '礼盒装', '品鉴装', '酱香型', '单瓶装', '商务宴请'];
export default {
data() {
return {
searchVal: '',
historyTag: [],
showModal: false,
autoFocus: true,
hotKeywords: HOT_KEYWORDS,
quickCategories: [
{ label: '雄戈系列', keyword: '雄戈系列' },
{ label: '白酒', keyword: '白酒' },
{ label: '礼盒装', keyword: '礼盒装' },
{ label: '品鉴装', keyword: '品鉴装' },
{ label: '单瓶装', keyword: '单瓶装' },
{ label: '商务宴请', keyword: '商务宴请' }
],
searchActionStyle: {
color: '#1677FF',
fontSize: '28rpx',
fontWeight: '600',
width: '100rpx'
},
searchInputStyle: {
fontSize: '28rpx'
}
};
},
onShow() {
this.historyTag = uni.getStorageSync('searchHistoryArr') ? JSON.parse(uni.getStorageSync('searchHistoryArr')) : [];
},
methods: {
onSearch(keyword) {
const kw = (typeof keyword === 'string' ? keyword : this.searchVal).trim();
if (!kw) {
uni.showToast({ title: '请输入搜索关键词', icon: 'none' });
return;
}
if (!this.historyTag.includes(kw)) {
const next = [kw, ...this.historyTag].slice(0, 10);
this.historyTag = next;
uni.setStorageSync('searchHistoryArr', JSON.stringify(next));
}
this.$Router.push({
path: '/pages/goods/list',
query: { keywords: kw }
});
this.searchVal = '';
},
onQuickSearch(item) {
this.onSearch(item.keyword);
},
clearSearch() {
this.searchVal = '';
},
clearSearchHistory() {
this.historyTag = [];
uni.removeStorageSync('searchHistoryArr');
}
}
};
</script>
<style lang="scss" scoped>
.search-page {
min-height: 100vh;
background: $brand-page-bg;
display: flex;
flex-direction: column;
}
.search-page__head {
padding: $brand-page-gutter;
padding-bottom: 16rpx;
background: $brand-page-bg;
position: sticky;
top: 0;
z-index: 10;
}
.search-page__body {
flex: 1;
height: 0;
padding: 0 $brand-page-gutter;
box-sizing: border-box;
}
.search-page__safe-bottom {
height: calc(env(safe-area-inset-bottom) + 32rpx);
}
.search-empty {
@include brand-card;
padding: 48rpx 32rpx;
margin-bottom: $brand-section-gap;
text-align: center;
}
.search-empty__icon-wrap {
width: 96rpx;
height: 96rpx;
margin: 0 auto 24rpx;
border-radius: 50%;
background: $brand-gold-light;
display: flex;
align-items: center;
justify-content: center;
}
.search-empty__title {
display: block;
font-size: 32rpx;
font-weight: 600;
color: $brand-text;
margin-bottom: 12rpx;
}
.search-empty__desc {
display: block;
font-size: 26rpx;
color: $brand-text-muted;
line-height: 1.5;
}
.search-section {
margin-bottom: $brand-section-gap;
}
.search-section__head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 24rpx;
}
.search-section__title-wrap {
display: flex;
align-items: center;
gap: 12rpx;
}
.search-section__title {
font-size: 30rpx;
font-weight: 600;
color: $brand-text;
}
.search-section__action {
display: flex;
align-items: center;
gap: 8rpx;
font-size: 26rpx;
color: $brand-text-muted;
padding: 8rpx 0;
min-height: 64rpx;
}
.search-section__action--pressed {
opacity: 0.65;
}
.search-tags {
display: flex;
flex-wrap: wrap;
gap: 16rpx;
}
.search-tag {
display: inline-flex;
align-items: center;
max-width: 100%;
padding: 0 24rpx;
min-height: 64rpx;
border-radius: 999rpx;
font-size: 26rpx;
line-height: 1.2;
}
.search-tag--hot {
background: $brand-gold-light;
border: 1rpx solid rgba(22, 119, 255, 0.35);
color: $brand-text;
}
.search-tag--history {
background: #FFFFFF;
border: 1rpx solid $brand-border;
color: $brand-text;
box-shadow: $brand-shadow;
}
.search-tag--pressed {
opacity: 0.72;
transform: scale(0.98);
}
.search-tag__badge {
flex-shrink: 0;
margin-right: 8rpx;
padding: 2rpx 10rpx;
border-radius: 8rpx;
font-size: 20rpx;
font-weight: 600;
color: #FFFFFF;
background: linear-gradient(90deg, #1677FF, #4096FF);
}
.search-tag__text {
max-width: 420rpx;
}
.search-quick {
@include brand-card;
overflow: hidden;
}
.search-quick__item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 28rpx 24rpx;
border-bottom: 1rpx solid $brand-border;
&:last-child {
border-bottom: none;
}
}
.search-quick__item--pressed {
background: rgba(245, 239, 228, 0.45);
}
.search-quick__label {
font-size: 28rpx;
color: $brand-text;
}
</style>