|
|
@@ -65,6 +65,22 @@
|
|
|
</view>
|
|
|
</scroll-view>
|
|
|
|
|
|
+ <!-- 排序栏:综合 / 价格↑ / 价格↓ -->
|
|
|
+ <view class="sort-bar">
|
|
|
+ <view
|
|
|
+ :class="['sort-item', sortType === 'default' ? 'active' : '']"
|
|
|
+ @click="onSortSelect('default')"
|
|
|
+ >综合</view>
|
|
|
+ <view
|
|
|
+ :class="['sort-item', sortType === 'price_asc' ? 'active' : '']"
|
|
|
+ @click="onSortSelect('price_asc')"
|
|
|
+ >价格↑</view>
|
|
|
+ <view
|
|
|
+ :class="['sort-item', sortType === 'price_desc' ? 'active' : '']"
|
|
|
+ @click="onSortSelect('price_desc')"
|
|
|
+ >价格↓</view>
|
|
|
+ </view>
|
|
|
+
|
|
|
<!-- 商品列表 -->
|
|
|
<scroll-view
|
|
|
scroll-y
|
|
|
@@ -161,6 +177,7 @@ export default {
|
|
|
categories: [],
|
|
|
currentCat1: null,
|
|
|
currentCat2: null,
|
|
|
+ sortType: 'default',
|
|
|
products: [],
|
|
|
page: 1,
|
|
|
size: 20,
|
|
|
@@ -218,6 +235,19 @@ export default {
|
|
|
this.noMore = false
|
|
|
this.loadProducts()
|
|
|
},
|
|
|
+ buildSort() {
|
|
|
+ if (this.sortType === 'price_asc') return [{ column: 'price', order: 'asc' }]
|
|
|
+ if (this.sortType === 'price_desc') return [{ column: 'price', order: 'desc' }]
|
|
|
+ return []
|
|
|
+ },
|
|
|
+ onSortSelect(type) {
|
|
|
+ if (type === this.sortType) return
|
|
|
+ this.sortType = type
|
|
|
+ this.page = 1
|
|
|
+ this.products = []
|
|
|
+ this.noMore = false
|
|
|
+ this.loadProducts()
|
|
|
+ },
|
|
|
loadProducts() {
|
|
|
if (this.loading) return
|
|
|
this.loading = true
|
|
|
@@ -227,6 +257,8 @@ export default {
|
|
|
} else if (this.currentCat1) {
|
|
|
params.categoryId = this.currentCat1.id
|
|
|
}
|
|
|
+ const sort = this.buildSort()
|
|
|
+ if (sort.length) params.sort = sort
|
|
|
productList(params).then(res => {
|
|
|
this.loading = false
|
|
|
this.refreshing = false
|
|
|
@@ -261,6 +293,8 @@ export default {
|
|
|
} else if (this.currentCat1) {
|
|
|
params.categoryId = this.currentCat1.id
|
|
|
}
|
|
|
+ const sort = this.buildSort()
|
|
|
+ if (sort.length) params.sort = sort
|
|
|
productList(params).then(res => {
|
|
|
this.loadingMore = false
|
|
|
if (res.code === 200 && res.data) {
|
|
|
@@ -553,6 +587,28 @@ export default {
|
|
|
color: $app-surface;
|
|
|
}
|
|
|
|
|
|
+/* ==================== 排序栏 ==================== */
|
|
|
+.sort-bar {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ gap: $uni-space-lg;
|
|
|
+ padding: $uni-space-sm $uni-space-lg;
|
|
|
+ margin-bottom: $uni-space-sm;
|
|
|
+ background: $app-surface;
|
|
|
+ border-bottom: 1rpx solid $facade-hairline-2;
|
|
|
+}
|
|
|
+.sort-item {
|
|
|
+ display: inline-block;
|
|
|
+ padding: $uni-space-2xs $uni-space-xs;
|
|
|
+ font-size: calc(26rpx * var(--font-scale, 1));
|
|
|
+ color: $facade-text-body;
|
|
|
+ border-radius: $uni-space-xs;
|
|
|
+}
|
|
|
+.sort-item.active {
|
|
|
+ color: $facade-violet;
|
|
|
+ font-weight: 600;
|
|
|
+}
|
|
|
+
|
|
|
/* ==================== 商品列表 ==================== */
|
|
|
.product-list {
|
|
|
flex: 1;
|