|
|
@@ -1,27 +1,33 @@
|
|
|
<!--
|
|
|
商品列表页
|
|
|
- 从店铺首页金刚区进入;支持搜索、分页触底加载、筛选弹窗(配送占位/价格/分类/场景)
|
|
|
+ 从店铺首页金刚区进入,或从首页搜索框带 searchText 进入(回填搜索框并按关键词搜索);
|
|
|
+ 支持搜索、分页触底加载、筛选弹窗(配送占位/价格/分类/场景)
|
|
|
按钮配色与店铺首页统一:#FF4D6D / linear-gradient(135deg, #FF8FA3, #FF4D6D)
|
|
|
右侧购物车:单规格直接加购,多规格跳转详情选规格(与首页 goodsSection 一致)
|
|
|
左下角悬浮购物车:展示当前店铺购物车数量,点击跳转 pages/home/cart
|
|
|
-->
|
|
|
<template>
|
|
|
<view class="goods-list-page">
|
|
|
- <!-- 搜索栏 -->
|
|
|
+ <!-- 搜索栏:搜索按钮在输入框内,仅点击搜索/键盘确认才请求;筛选仍在框外 -->
|
|
|
<view class="search-bar">
|
|
|
<view class="search-input-wrap">
|
|
|
- <app-search-module
|
|
|
- v-model="searchText"
|
|
|
+ <input
|
|
|
+ class="search-field"
|
|
|
+ type="text"
|
|
|
+ confirm-type="search"
|
|
|
+ :value="searchText"
|
|
|
placeholder="请输入搜索商品名称"
|
|
|
- :height="66"
|
|
|
- :fontSize="28"
|
|
|
- backColor="#fff"
|
|
|
- @input="onSearchInput"
|
|
|
- @search="doSearch"
|
|
|
+ placeholder-class="search-ph"
|
|
|
+ @input="onKeywordInput"
|
|
|
+ @confirm="doSearch"
|
|
|
/>
|
|
|
+ <view class="search-btn" @click="doSearch">搜索</view>
|
|
|
+ </view>
|
|
|
+ <view class="filter-btn" @click="openFilter">
|
|
|
+ 筛选
|
|
|
+ <!-- 弹窗内有已生效的选中项时显示圆点,提醒当前列表处于筛选中 -->
|
|
|
+ <view v-if="hasActiveFilter" class="filter-dot"></view>
|
|
|
</view>
|
|
|
- <view class="search-btn" @click="doSearch">搜索</view>
|
|
|
- <view class="filter-btn" @click="openFilter">筛选</view>
|
|
|
</view>
|
|
|
|
|
|
<!-- 商品列表 -->
|
|
|
@@ -160,6 +166,7 @@
|
|
|
<view class="filter-scroll-space"></view>
|
|
|
</scroll-view>
|
|
|
<view class="filter-footer">
|
|
|
+ <view class="clear-btn" @click="clearFilterDraft">清空</view>
|
|
|
<view class="confirm-btn" @click="confirmFilter">确认</view>
|
|
|
</view>
|
|
|
</view>
|
|
|
@@ -168,12 +175,12 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import AppSearchModule from '@/components/item/module/app-search'
|
|
|
import AppWrapperEmpty from '@/components/app-wrapper-empty'
|
|
|
import BottomPopup from '@/components/plugin/bottom-popup'
|
|
|
import { getClass, getList, getUseCaseList } from '@/api/category'
|
|
|
import { list } from '@/mixins'
|
|
|
import productMins from '@/mixins/cgProduct'
|
|
|
+import { parseFilterIds, takeGoodsListFilter, isIdInList } from '@/utils/goodsListFilter'
|
|
|
|
|
|
const PRICE_PRESETS = [
|
|
|
{ key: 'lt50', label: '50元以下', min: '', max: '50' },
|
|
|
@@ -202,7 +209,6 @@ const emptyDraft = () => ({
|
|
|
export default {
|
|
|
name: 'goodsList',
|
|
|
components: {
|
|
|
- AppSearchModule,
|
|
|
AppWrapperEmpty,
|
|
|
BottomPopup
|
|
|
},
|
|
|
@@ -213,13 +219,13 @@ export default {
|
|
|
pageType: 'cg',
|
|
|
autoLoad: false,
|
|
|
searchText: '',
|
|
|
- searchTimer: null,
|
|
|
filterShow: false,
|
|
|
categoryOptions: [],
|
|
|
useCaseOptions: [],
|
|
|
deliveryOptions: DELIVERY_OPTIONS,
|
|
|
pricePresets: PRICE_PRESETS,
|
|
|
// 已生效的筛选条件;goodsIds 仅由路由 filterType=2 带入,不在筛选弹窗中编辑
|
|
|
+ routeFilterApplied: false,
|
|
|
filters: {
|
|
|
categoryIds: [],
|
|
|
useCaseIds: [],
|
|
|
@@ -244,6 +250,29 @@ export default {
|
|
|
/** 角标文案:超过 99 显示 99+ */
|
|
|
cartBadgeText() {
|
|
|
return this.cartBadgeCount > 99 ? '99+' : String(this.cartBadgeCount)
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 筛选按钮是否显示圆点
|
|
|
+ * 只看弹窗里能勾选的项(配送/价格/分类/场景);goodsIds 是轮播带入、面板里看不到,不算
|
|
|
+ */
|
|
|
+ hasActiveFilter() {
|
|
|
+ const f = this.filters || {}
|
|
|
+ if (f.delivery) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ if (f.minPrice !== '' && f.minPrice != null) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ if (f.maxPrice !== '' && f.maxPrice != null) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ if (f.categoryIds && f.categoryIds.length) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ if (f.useCaseIds && f.useCaseIds.length) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
}
|
|
|
},
|
|
|
/** 从详情/购物车返回时刷新角标,避免仍显示旧数量 */
|
|
|
@@ -282,13 +311,30 @@ export default {
|
|
|
})
|
|
|
},
|
|
|
/**
|
|
|
- * 解析路由带入的 filterType / filterValue
|
|
|
- * type=2 商品ID列表、type=3 分类、type=4 场景(首页轮播/金刚区跳转)
|
|
|
+ * 解析路由带入的筛选与搜索关键词
|
|
|
+ * searchText:首页搜索框跳转带入,回填搜索框并参与首次列表请求
|
|
|
+ * filterType=2 商品ID列表、type=3 分类、type=4 场景(首页轮播/金刚区跳转)
|
|
|
+ * 多 ID 优先用跳转前写入的缓存:微信可能截断 URL 里的逗号,导致筛选分类无法高亮
|
|
|
*/
|
|
|
applyRouteFilter() {
|
|
|
- const type = parseInt((this.option && this.option.filterType) || 0, 10)
|
|
|
- const value = (this.option && this.option.filterValue) ? String(this.option.filterValue) : ''
|
|
|
- const ids = value.split(',').map((s) => s.trim()).filter(Boolean)
|
|
|
+ // 首页搜索跳转:回填关键词,init 随后 loadGoods 会带上 searchText
|
|
|
+ const keyword = (this.option && this.option.searchText) ? String(this.option.searchText) : ''
|
|
|
+ if (keyword) {
|
|
|
+ this.searchText = keyword
|
|
|
+ }
|
|
|
+ // 登录回调可能二次 init,避免缓存已被消费后用残缺 URL 把多分类冲掉
|
|
|
+ if (this.routeFilterApplied) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.routeFilterApplied = true
|
|
|
+ let type = parseInt((this.option && this.option.filterType) || 0, 10)
|
|
|
+ let ids = parseFilterIds((this.option && this.option.filterValue) || '')
|
|
|
+ const cached = takeGoodsListFilter()
|
|
|
+ // 搜索进入不套用分类缓存,避免误带到搜索结果;缓存 ID 更多时覆盖被截断的路由
|
|
|
+ if (cached && cached.ids.length && !keyword && (!ids.length || cached.ids.length >= ids.length)) {
|
|
|
+ type = cached.filterType || type
|
|
|
+ ids = cached.ids
|
|
|
+ }
|
|
|
if (type === 2 && ids.length) {
|
|
|
this.filters.goodsIds = ids
|
|
|
} else if (type === 3 && ids.length) {
|
|
|
@@ -347,20 +393,17 @@ export default {
|
|
|
this.list.finished = true
|
|
|
})
|
|
|
},
|
|
|
- onSearchInput() {
|
|
|
- if (this.searchTimer) {
|
|
|
- clearTimeout(this.searchTimer)
|
|
|
- this.searchTimer = null
|
|
|
- }
|
|
|
- this.searchTimer = setTimeout(() => {
|
|
|
- this.doSearch()
|
|
|
- }, 600)
|
|
|
+ /**
|
|
|
+ * 只同步输入框文案,不发请求
|
|
|
+ * 避免边输入边搜;真正搜索由搜索按钮 / 键盘确认触发
|
|
|
+ */
|
|
|
+ onKeywordInput(e) {
|
|
|
+ this.searchText = (e && e.detail && e.detail.value != null) ? e.detail.value : ''
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 点击搜索按钮或键盘确认后才重置分页并按当前关键词拉列表
|
|
|
+ */
|
|
|
doSearch() {
|
|
|
- if (this.searchTimer) {
|
|
|
- clearTimeout(this.searchTimer)
|
|
|
- this.searchTimer = null
|
|
|
- }
|
|
|
this.resetList()
|
|
|
this.loadGoods()
|
|
|
},
|
|
|
@@ -371,8 +414,8 @@ export default {
|
|
|
pricePreset: presetKey,
|
|
|
customMin: presetKey ? '' : (this.filters.minPrice === '' || this.filters.minPrice == null ? '' : String(this.filters.minPrice)),
|
|
|
customMax: presetKey ? '' : (this.filters.maxPrice === '' || this.filters.maxPrice == null ? '' : String(this.filters.maxPrice)),
|
|
|
- categoryIds: [...this.filters.categoryIds],
|
|
|
- useCaseIds: [...this.filters.useCaseIds]
|
|
|
+ categoryIds: this.filters.categoryIds.map(String),
|
|
|
+ useCaseIds: this.filters.useCaseIds.map(String)
|
|
|
}
|
|
|
this.filterShow = true
|
|
|
},
|
|
|
@@ -402,8 +445,11 @@ export default {
|
|
|
this.draft.pricePreset = ''
|
|
|
}
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 分类是否勾选:接口 id 可能是数字,路由解析后是字符串,统一转字符串再比
|
|
|
+ */
|
|
|
isCategoryChecked(id) {
|
|
|
- return this.draft.categoryIds.indexOf(String(id)) > -1
|
|
|
+ return isIdInList(this.draft.categoryIds, id)
|
|
|
},
|
|
|
toggleCategory(id) {
|
|
|
const key = String(id)
|
|
|
@@ -414,8 +460,11 @@ export default {
|
|
|
this.draft.categoryIds.push(key)
|
|
|
}
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 场景是否勾选:与分类相同,避免数字/字符串不一致导致不高亮
|
|
|
+ */
|
|
|
isUseCaseChecked(id) {
|
|
|
- return this.draft.useCaseIds.indexOf(String(id)) > -1
|
|
|
+ return isIdInList(this.draft.useCaseIds, id)
|
|
|
},
|
|
|
toggleUseCase(id) {
|
|
|
const key = String(id)
|
|
|
@@ -426,6 +475,13 @@ export default {
|
|
|
this.draft.useCaseIds.push(key)
|
|
|
}
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 清空弹窗草稿中的全部可选项(配送/价格/分类/场景)
|
|
|
+ * 只改草稿,不关弹窗、不立刻请求;点确认后才生效,避免误触直接打乱列表
|
|
|
+ */
|
|
|
+ clearFilterDraft() {
|
|
|
+ this.draft = emptyDraft()
|
|
|
+ },
|
|
|
confirmFilter() {
|
|
|
let minPrice = ''
|
|
|
let maxPrice = ''
|
|
|
@@ -517,12 +573,6 @@ export default {
|
|
|
if (!this.list.finished) {
|
|
|
await this.loadGoods()
|
|
|
}
|
|
|
- },
|
|
|
- beforeDestroy() {
|
|
|
- if (this.searchTimer) {
|
|
|
- clearTimeout(this.searchTimer)
|
|
|
- this.searchTimer = null
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
|
@@ -586,25 +636,60 @@ export default {
|
|
|
.search-input-wrap {
|
|
|
flex: 1;
|
|
|
min-width: 0;
|
|
|
+ height: 64upx;
|
|
|
+ padding: 4upx 4upx 4upx 24upx;
|
|
|
border: 1upx solid #e5e5e5;
|
|
|
border-radius: 32upx;
|
|
|
- overflow: hidden;
|
|
|
+ background: #fff;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+}
|
|
|
+
|
|
|
+.search-field {
|
|
|
+ flex: 1;
|
|
|
+ min-width: 0;
|
|
|
+ height: 100%;
|
|
|
+ font-size: 26upx;
|
|
|
+ color: #333;
|
|
|
+}
|
|
|
+
|
|
|
+.search-ph {
|
|
|
+ font-size: 26upx;
|
|
|
+ color: #999;
|
|
|
}
|
|
|
|
|
|
.search-btn,
|
|
|
.filter-btn {
|
|
|
flex-shrink: 0;
|
|
|
- margin-left: 12upx;
|
|
|
padding: 0 28upx;
|
|
|
- height: 64upx;
|
|
|
- line-height: 64upx;
|
|
|
+ height: 56upx;
|
|
|
+ line-height: 56upx;
|
|
|
font-size: 26upx;
|
|
|
color: #fff;
|
|
|
background: linear-gradient(135deg, #FF8FA3, #FF4D6D);
|
|
|
- border-radius: 32upx;
|
|
|
+ border-radius: 28upx;
|
|
|
text-align: center;
|
|
|
}
|
|
|
|
|
|
+.filter-btn {
|
|
|
+ position: relative;
|
|
|
+ margin-left: 12upx;
|
|
|
+ height: 64upx;
|
|
|
+ line-height: 64upx;
|
|
|
+ border-radius: 32upx;
|
|
|
+}
|
|
|
+
|
|
|
+/* 有筛选条件时的白点:衬在粉色按钮上更醒目,无选中项时不渲染 */
|
|
|
+.filter-dot {
|
|
|
+ position: absolute;
|
|
|
+ top: 10upx;
|
|
|
+ right: 10upx;
|
|
|
+ width: 14upx;
|
|
|
+ height: 14upx;
|
|
|
+ border-radius: 50%;
|
|
|
+ background: #fff;
|
|
|
+}
|
|
|
+
|
|
|
.card-list {
|
|
|
padding: 20upx;
|
|
|
}
|
|
|
@@ -860,19 +945,34 @@ export default {
|
|
|
|
|
|
.filter-footer {
|
|
|
flex-shrink: 0;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
padding: 20upx 30upx;
|
|
|
padding-bottom: calc(20upx + env(safe-area-inset-bottom));
|
|
|
background: #fff;
|
|
|
}
|
|
|
|
|
|
+.clear-btn,
|
|
|
.confirm-btn {
|
|
|
+ flex: 1;
|
|
|
height: 88upx;
|
|
|
line-height: 88upx;
|
|
|
text-align: center;
|
|
|
font-size: 32upx;
|
|
|
font-weight: 600;
|
|
|
+ border-radius: 44upx;
|
|
|
+ box-sizing: border-box;
|
|
|
+}
|
|
|
+
|
|
|
+.clear-btn {
|
|
|
+ margin-right: 20upx;
|
|
|
+ color: #FF4D6D;
|
|
|
+ background: #fff;
|
|
|
+ border: 2upx solid #FF4D6D;
|
|
|
+}
|
|
|
+
|
|
|
+.confirm-btn {
|
|
|
color: #fff;
|
|
|
background: linear-gradient(135deg, #FF8FA3, #FF4D6D);
|
|
|
- border-radius: 44upx;
|
|
|
}
|
|
|
</style>
|