修正排序+筛选:总价/书价本地排序不调API+筛选改回标签选择+totalPrice含运费
This commit is contained in:
parent
0fd8db2523
commit
5a88e146fe
@ -212,9 +212,9 @@
|
|||||||
<view class="grid-item" v-for="(item, index) in sortedProductList.slice(0, 12)" :key="index">
|
<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>
|
<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-book-name">{{ item.bookName || '未知书名' }}</text>
|
||||||
<text class="grid-author">{{ item.author || item.shopName || '' }}</text>
|
<text class="grid-author">{{ item.author || '' }}</text>
|
||||||
<text class="grid-total-price">{{ item.totalPrice }}</text>
|
<text class="grid-total-price">¥{{ item.totalPrice.toFixed(2) }}</text>
|
||||||
<text class="grid-price-detail" v-if="item.shippingFee && item.shippingFee > 0">运{{ item.shippingFee }}</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-condition">{{ item.condition || '' }}</text>
|
||||||
<text class="grid-shop">{{ item.shopName || '' }}</text>
|
<text class="grid-shop">{{ item.shopName || '' }}</text>
|
||||||
</view>
|
</view>
|
||||||
@ -619,21 +619,31 @@
|
|||||||
<text class="popup-close" @click="showFilterPopup = false">✕</text>
|
<text class="popup-close" @click="showFilterPopup = false">✕</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="popup-body">
|
<view class="popup-body">
|
||||||
<view class="filter-group">
|
<view class="filter-group" v-if="filterPublishers.length > 0">
|
||||||
<text class="group-title">出版社</text>
|
<text class="group-title">出版社</text>
|
||||||
<input class="filter-search-input" v-model="filterPress" placeholder="输入出版社名称筛选" @input="onFilterPressInput" />
|
<view class="tag-list">
|
||||||
<view class="filter-suggest" v-if="filterPress && filterPressSuggestions.length > 0">
|
<view
|
||||||
<view class="suggest-item" v-for="(item, idx) in filterPressSuggestions" :key="'ps'+idx" @click="selectFilterPress(item)">
|
class="tag-item"
|
||||||
<text class="suggest-text">{{ item }}</text>
|
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>
|
||||||
</view>
|
</view>
|
||||||
<view class="filter-group">
|
<view class="filter-group" v-if="filterAuthors.length > 0">
|
||||||
<text class="group-title">作者</text>
|
<text class="group-title">作者</text>
|
||||||
<input class="filter-search-input" v-model="filterAuthor" placeholder="输入作者名称筛选" @input="onFilterAuthorInput" />
|
<view class="tag-list">
|
||||||
<view class="filter-suggest" v-if="filterAuthor && filterAuthorSuggestions.length > 0">
|
<view
|
||||||
<view class="suggest-item" v-for="(item, idx) in filterAuthorSuggestions" :key="'as'+idx" @click="selectFilterAuthor(item)">
|
class="tag-item"
|
||||||
<text class="suggest-text">{{ item }}</text>
|
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>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -783,8 +793,6 @@ export default {
|
|||||||
showFilterPopup: false,
|
showFilterPopup: false,
|
||||||
filterPress: '',
|
filterPress: '',
|
||||||
filterAuthor: '',
|
filterAuthor: '',
|
||||||
filterPressSuggestions: [],
|
|
||||||
filterAuthorSuggestions: [],
|
|
||||||
|
|
||||||
// 仓库弹窗
|
// 仓库弹窗
|
||||||
showWarehousePicker: false,
|
showWarehousePicker: false,
|
||||||
@ -855,12 +863,12 @@ export default {
|
|||||||
computed: {
|
computed: {
|
||||||
sortedProductList() {
|
sortedProductList() {
|
||||||
let list = [...this.productList]
|
let list = [...this.productList]
|
||||||
// 筛选(模糊匹配)
|
// 筛选(精确匹配,同zhizhu)
|
||||||
if (this.filterPress) {
|
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) {
|
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') {
|
if (this.sortBy === 'total') {
|
||||||
@ -979,11 +987,9 @@ export default {
|
|||||||
|
|
||||||
// 2. 搜索孔夫子 - 获取在售商品信息
|
// 2. 搜索孔夫子 - 获取在售商品信息
|
||||||
const phpsessid = this.kongfzToken || uni.getStorageSync('kongfz_phpsessid') || ''
|
const phpsessid = this.kongfzToken || uni.getStorageSync('kongfz_phpsessid') || ''
|
||||||
// 排序参数:5=价格低到高 7=综合
|
|
||||||
const sortType = this.sortBy !== 'total' && this.sortBy !== 'book' ? '' : '5'
|
|
||||||
// 并行请求:商品列表 + 品相统计(在售)+ 品相统计(已售)
|
// 并行请求:商品列表 + 品相统计(在售)+ 品相统计(已售)
|
||||||
Promise.all([
|
Promise.all([
|
||||||
searchProducts(keyword, { phpsessid, sortType }),
|
searchProducts(keyword, { phpsessid }),
|
||||||
searchFacet(keyword, { phpsessid, dataType: 0 }),
|
searchFacet(keyword, { phpsessid, dataType: 0 }),
|
||||||
searchFacet(keyword, { phpsessid, dataType: 1 })
|
searchFacet(keyword, { phpsessid, dataType: 1 })
|
||||||
]).then(([productsData, onSaleFacet, soldFacet]) => {
|
]).then(([productsData, onSaleFacet, soldFacet]) => {
|
||||||
@ -991,18 +997,23 @@ export default {
|
|||||||
if (productsData && productsData.total > 0) {
|
if (productsData && productsData.total > 0) {
|
||||||
// 在售商品列表(最多12条)
|
// 在售商品列表(最多12条)
|
||||||
const list = (productsData.list || []).slice(0, 12)
|
const list = (productsData.list || []).slice(0, 12)
|
||||||
this.productList = list.map(item => ({
|
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 || '',
|
image: item.imgBigUrl || '',
|
||||||
totalPrice: parseFloat((item.priceText || '0').replace(/[^\d.]/g, '')),
|
totalPrice: totalPrice,
|
||||||
bookPrice: parseFloat((item.priceText || '0').replace(/[^\d.]/g, '')),
|
bookPrice: cleanPrice,
|
||||||
shippingFee: item.postage && item.postage.shippingList && item.postage.shippingList.length > 0 ? parseFloat(item.postage.shippingList[0].shippingFee || 0) : 0,
|
shippingFee: shippingFee,
|
||||||
condition: item.qualityText || '',
|
condition: item.qualityText || '',
|
||||||
shopName: item.shopName || '',
|
shopName: item.shopName || '',
|
||||||
bookName: item.title || '',
|
bookName: item.title || '',
|
||||||
author: item.author || '',
|
author: item.author || '',
|
||||||
pubDate: item.pubDateText || '',
|
pubDate: item.pubDateText || '',
|
||||||
bookId: item.id || ''
|
bookId: item.id || ''
|
||||||
}))
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
// 市场统计:使用facet接口的真实数据(totalFound为准)
|
// 市场统计:使用facet接口的真实数据(totalFound为准)
|
||||||
this.marketData = {
|
this.marketData = {
|
||||||
@ -1214,10 +1225,9 @@ export default {
|
|||||||
this.searchISBN()
|
this.searchISBN()
|
||||||
},
|
},
|
||||||
|
|
||||||
// 排序 - 切换后重新请求孔夫子接口
|
// 排序 - 仅本地排序(不重新请求孔夫子接口)
|
||||||
sortProducts(by) {
|
sortProducts(by) {
|
||||||
this.sortBy = 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() {
|
submitUpload() {
|
||||||
if (this.isSubmitting) return
|
if (this.isSubmitting) return
|
||||||
@ -2166,57 +2154,6 @@ export default {
|
|||||||
color: #409eff;
|
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 {
|
.popup-footer {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 16rpx;
|
gap: 16rpx;
|
||||||
|
|||||||
@ -190,21 +190,17 @@ export function fetchItems(token, params = {}, onProgress) {
|
|||||||
* list中每项: {id, title, author, press, priceText, imgBigUrl, shopName, qualityText, pubDateText, postage}
|
* list中每项: {id, title, author, press, priceText, imgBigUrl, shopName, qualityText, pubDateText, postage}
|
||||||
*/
|
*/
|
||||||
export function searchProducts(keyword, options = {}) {
|
export function searchProducts(keyword, options = {}) {
|
||||||
const { phpsessid = '', page = 1, sortType = '' } = options
|
const { phpsessid = '', page = 1 } = options
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const reqData = {
|
uni.request({
|
||||||
|
url: 'https://search.kongfz.com/pc-gw/search-web/client/pc/product/keyword/list',
|
||||||
|
method: 'GET',
|
||||||
|
data: {
|
||||||
dataType: 0,
|
dataType: 0,
|
||||||
keyword: keyword,
|
keyword: keyword,
|
||||||
page: page,
|
page: page,
|
||||||
userArea: '13003000000'
|
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,
|
|
||||||
header: {
|
header: {
|
||||||
'Cookie': phpsessid ? `PHPSESSID=${phpsessid}` : ''
|
'Cookie': phpsessid ? `PHPSESSID=${phpsessid}` : ''
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user