feat: 为商城商品列表实现服务端筛选和分页功能,并调整积分显示逻辑。

This commit is contained in:
邹方成 2026-01-07 08:41:29 +08:00
parent 9d25477cd3
commit 470094dc75
3 changed files with 57 additions and 24 deletions

View File

@ -234,8 +234,16 @@ export function redeemItemCardByPoints(user_id, item_card_id, quantity = 1) {
return authRequest({ url: `/api/app/users/${user_id}/points/redeem-item-card`, method: 'POST', data: { item_card_id, quantity } })
}
export function getStoreItems(kind = 'product', page = 1, page_size = 20) {
return authRequest({ url: '/api/app/store/items', method: 'GET', data: { kind, page, page_size } })
export function getStoreItems(kind = 'product', page = 1, page_size = 20, filters = {}) {
const data = { kind, page, page_size }
if (filters.keyword) data.keyword = filters.keyword
if (filters.price_min !== undefined && filters.price_min !== null && filters.price_min !== '') {
data.price_min = parseInt(filters.price_min)
}
if (filters.price_max !== undefined && filters.price_max !== null && filters.price_max !== '') {
data.price_max = parseInt(filters.price_max)
}
return authRequest({ url: '/api/app/store/items', method: 'GET', data })
}
export function getTasks(page = 1, page_size = 20) {

View File

@ -779,10 +779,10 @@ export default {
return String(v || '').trim()
},
formatPoints(v) {
// * rate / 100
const n = Number(v) || 0
if (n === 0) return '0.0'
const f = n / 100
return f.toFixed(1)
return n.toFixed(1)
},
copyInviteCode() {
const code = this.getInviteCode()

View File

@ -290,7 +290,19 @@ async function loadItems(append = false) {
if (loading.value) return
loading.value = true
try {
const res = await getStoreItems(currentTab.value, page.value, pageSize)
//
const filters = {}
if (keyword.value && keyword.value.trim()) {
filters.keyword = keyword.value.trim()
}
if (priceMin.value !== '' && priceMin.value !== null) {
filters.price_min = priceMin.value
}
if (priceMax.value !== '' && priceMax.value !== null) {
filters.price_max = priceMax.value
}
const res = await getStoreItems(currentTab.value, page.value, pageSize, filters)
const list = res.list || res || []
const total = res.total || 0
const newItems = normalizeItems(list, currentTab.value)
@ -301,21 +313,12 @@ async function loadItems(append = false) {
allItems.value = newItems
}
// total
// 使
items.value = allItems.value
//
const totalPages = Math.ceil(total / pageSize)
//
if (page.value < totalPages) {
page.value++
//
loading.value = false // loading
await loadItems(true)
} else {
//
hasMore.value = false
}
applyFilters()
hasMore.value = page.value < totalPages
} catch (e) {
console.error(e)
hasMore.value = false
@ -350,14 +353,22 @@ function applyFilters() {
function applyPriceFilter() {
activePriceRange.value = 'custom'
applyFilters()
//
page.value = 1
hasMore.value = true
allItems.value = []
loadItems()
}
function resetPriceFilter() {
priceMin.value = ''
priceMax.value = ''
activePriceRange.value = 'all'
applyFilters()
//
page.value = 1
hasMore.value = true
allItems.value = []
loadItems()
}
function selectQuickPrice(range) {
@ -372,14 +383,24 @@ function selectQuickPrice(range) {
} else {
priceMax.value = ''
}
applyFilters()
//
page.value = 1
hasMore.value = true
allItems.value = []
loadItems()
}
function isRangeActive(range) {
return activePriceRange.value === range.key
}
function onSearchConfirm() { applyFilters() }
function onSearchConfirm() {
//
page.value = 1
hasMore.value = true
allItems.value = []
loadItems()
}
function onProductTap(p) {
if (p.kind === 'product') {
@ -458,7 +479,11 @@ onShow(() => {
})
onReachBottom(() => {
//
//
if (hasMore.value && !loading.value) {
page.value++
loadItems(true)
}
})
watch(keyword, () => applyFilters())