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 } }) 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) { export function getStoreItems(kind = 'product', page = 1, page_size = 20, filters = {}) {
return authRequest({ url: '/api/app/store/items', method: 'GET', data: { kind, page, page_size } }) 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) { export function getTasks(page = 1, page_size = 20) {

View File

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

View File

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