feat: 为商城商品列表实现服务端筛选和分页功能,并调整积分显示逻辑。
This commit is contained in:
parent
9d25477cd3
commit
470094dc75
@ -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) {
|
||||||
|
|||||||
@ -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()
|
||||||
|
|||||||
@ -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())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user