修正排序+筛选:总价/书价本地排序不调API+筛选改回标签选择+totalPrice含运费

This commit is contained in:
97694732@qq.com 2026-06-03 16:49:30 +08:00
parent 0fd8db2523
commit 5a88e146fe
2 changed files with 52 additions and 119 deletions

View File

@ -212,9 +212,9 @@
<view class="grid-item" v-for="(item, index) in sortedProductList.slice(0, 12)" :key="index">
<image class="grid-image" :src="item.image" mode="aspectFill" @click="previewProductImage(index)" v-if="item.image"></image>
<text class="grid-book-name">{{ item.bookName || '未知书名' }}</text>
<text class="grid-author">{{ item.author || item.shopName || '' }}</text>
<text class="grid-total-price">{{ item.totalPrice }}</text>
<text class="grid-price-detail" v-if="item.shippingFee && item.shippingFee > 0">{{ item.shippingFee }}</text>
<text class="grid-author">{{ item.author || '' }}</text>
<text class="grid-total-price">¥{{ item.totalPrice.toFixed(2) }}</text>
<text class="grid-price-detail" v-if="item.shippingFee > 0">¥{{ item.bookPrice.toFixed(2) }}+¥{{ item.shippingFee.toFixed(2) }}</text>
<text class="grid-condition">{{ item.condition || '' }}</text>
<text class="grid-shop">{{ item.shopName || '' }}</text>
</view>
@ -619,21 +619,31 @@
<text class="popup-close" @click="showFilterPopup = false"></text>
</view>
<view class="popup-body">
<view class="filter-group">
<view class="filter-group" v-if="filterPublishers.length > 0">
<text class="group-title">出版社</text>
<input class="filter-search-input" v-model="filterPress" placeholder="输入出版社名称筛选" @input="onFilterPressInput" />
<view class="filter-suggest" v-if="filterPress && filterPressSuggestions.length > 0">
<view class="suggest-item" v-for="(item, idx) in filterPressSuggestions" :key="'ps'+idx" @click="selectFilterPress(item)">
<text class="suggest-text">{{ item }}</text>
<view class="tag-list">
<view
class="tag-item"
v-for="(item, index) in filterPublishers"
:key="'p'+index"
:class="{ active: filterPress === item }"
@click="filterPress = filterPress === item ? '' : item"
>
<text class="tag-text">{{ item }}</text>
</view>
</view>
</view>
<view class="filter-group">
<view class="filter-group" v-if="filterAuthors.length > 0">
<text class="group-title">作者</text>
<input class="filter-search-input" v-model="filterAuthor" placeholder="输入作者名称筛选" @input="onFilterAuthorInput" />
<view class="filter-suggest" v-if="filterAuthor && filterAuthorSuggestions.length > 0">
<view class="suggest-item" v-for="(item, idx) in filterAuthorSuggestions" :key="'as'+idx" @click="selectFilterAuthor(item)">
<text class="suggest-text">{{ item }}</text>
<view class="tag-list">
<view
class="tag-item"
v-for="(item, index) in filterAuthors"
:key="'a'+index"
:class="{ active: filterAuthor === item }"
@click="filterAuthor = filterAuthor === item ? '' : item"
>
<text class="tag-text">{{ item }}</text>
</view>
</view>
</view>
@ -783,8 +793,6 @@ export default {
showFilterPopup: false,
filterPress: '',
filterAuthor: '',
filterPressSuggestions: [],
filterAuthorSuggestions: [],
//
showWarehousePicker: false,
@ -855,12 +863,12 @@ export default {
computed: {
sortedProductList() {
let list = [...this.productList]
//
// zhizhu
if (this.filterPress) {
list = list.filter(item => (item.shopName || '').toLowerCase().includes(this.filterPress.toLowerCase()))
list = list.filter(item => item.shopName === this.filterPress)
}
if (this.filterAuthor) {
list = list.filter(item => (item.author || '').toLowerCase().includes(this.filterAuthor.toLowerCase()))
list = list.filter(item => item.author === this.filterAuthor)
}
//
if (this.sortBy === 'total') {
@ -979,11 +987,9 @@ export default {
// 2. -
const phpsessid = this.kongfzToken || uni.getStorageSync('kongfz_phpsessid') || ''
// 5= 7=
const sortType = this.sortBy !== 'total' && this.sortBy !== 'book' ? '' : '5'
// + +
Promise.all([
searchProducts(keyword, { phpsessid, sortType }),
searchProducts(keyword, { phpsessid }),
searchFacet(keyword, { phpsessid, dataType: 0 }),
searchFacet(keyword, { phpsessid, dataType: 1 })
]).then(([productsData, onSaleFacet, soldFacet]) => {
@ -991,18 +997,23 @@ export default {
if (productsData && productsData.total > 0) {
// 12
const list = (productsData.list || []).slice(0, 12)
this.productList = list.map(item => ({
image: item.imgBigUrl || '',
totalPrice: parseFloat((item.priceText || '0').replace(/[^\d.]/g, '')),
bookPrice: parseFloat((item.priceText || '0').replace(/[^\d.]/g, '')),
shippingFee: item.postage && item.postage.shippingList && item.postage.shippingList.length > 0 ? parseFloat(item.postage.shippingList[0].shippingFee || 0) : 0,
condition: item.qualityText || '',
shopName: item.shopName || '',
bookName: item.title || '',
author: item.author || '',
pubDate: item.pubDateText || '',
bookId: item.id || ''
}))
this.productList = list.map(item => {
const cleanPrice = parseFloat((item.priceText || '0').replace(/[^\d.]/g, ''))
const shippingFee = item.postage && item.postage.shippingList && item.postage.shippingList.length > 0 ? parseFloat(item.postage.shippingList[0].shippingFee || 0) : 0
const totalPrice = Number((cleanPrice + shippingFee).toFixed(2))
return {
image: item.imgBigUrl || '',
totalPrice: totalPrice,
bookPrice: cleanPrice,
shippingFee: shippingFee,
condition: item.qualityText || '',
shopName: item.shopName || '',
bookName: item.title || '',
author: item.author || '',
pubDate: item.pubDateText || '',
bookId: item.id || ''
}
})
}
// 使facettotalFound
this.marketData = {
@ -1214,10 +1225,9 @@ export default {
this.searchISBN()
},
// -
// -
sortProducts(by) {
this.sortBy = by
this.searchISBN()
},
//
@ -1252,28 +1262,6 @@ export default {
}
},
// -
onFilterPressInput() {
const kw = this.filterPress.toLowerCase()
this.filterPressSuggestions = this.filterPublishers.filter(p => p.toLowerCase().includes(kw)).slice(0, 10)
},
selectFilterPress(val) {
this.filterPress = val
this.filterPressSuggestions = []
},
// -
onFilterAuthorInput() {
const kw = this.filterAuthor.toLowerCase()
this.filterAuthorSuggestions = this.filterAuthors.filter(a => a.toLowerCase().includes(kw)).slice(0, 10)
},
selectFilterAuthor(val) {
this.filterAuthor = val
this.filterAuthorSuggestions = []
},
//
submitUpload() {
if (this.isSubmitting) return
@ -2166,57 +2154,6 @@ export default {
color: #409eff;
}
/* 筛选弹窗 - 搜索输入框 */
.filter-search-input {
background: #f5f6fa;
border: 2rpx solid #dcdfe6;
border-radius: 8rpx;
height: 64rpx;
padding: 0 16rpx;
font-size: 26rpx;
color: #303133;
width: 100%;
box-sizing: border-box;
-webkit-appearance: none;
appearance: none;
}
.filter-search-input:focus {
border-color: #409eff;
outline: none;
}
.filter-search-input::placeholder {
color: #c0c4cc;
}
.filter-suggest {
background: #ffffff;
border: 2rpx solid #e4e7ed;
border-radius: 8rpx;
margin-top: 6rpx;
max-height: 300rpx;
overflow-y: auto;
}
.suggest-item {
padding: 16rpx 20rpx;
border-bottom: 2rpx solid #f0f2f5;
}
.suggest-item:last-child {
border-bottom: none;
}
.suggest-text {
font-size: 26rpx;
color: #303133;
}
.suggest-item:active {
background-color: #ecf5ff;
}
.popup-footer {
display: flex;
gap: 16rpx;

View File

@ -190,21 +190,17 @@ export function fetchItems(token, params = {}, onProgress) {
* list中每项: {id, title, author, press, priceText, imgBigUrl, shopName, qualityText, pubDateText, postage}
*/
export function searchProducts(keyword, options = {}) {
const { phpsessid = '', page = 1, sortType = '' } = options
const { phpsessid = '', page = 1 } = options
return new Promise((resolve, reject) => {
const reqData = {
dataType: 0,
keyword: keyword,
page: page,
userArea: '13003000000'
}
if (sortType) {
reqData.sortType = sortType
}
uni.request({
url: 'https://search.kongfz.com/pc-gw/search-web/client/pc/product/keyword/list',
method: 'GET',
data: reqData,
data: {
dataType: 0,
keyword: keyword,
page: page,
userArea: '13003000000'
},
header: {
'Cookie': phpsessid ? `PHPSESSID=${phpsessid}` : ''
},