fix: 商品列表页加载库存数据

This commit is contained in:
Agent
2026-03-27 10:26:55 +00:00
parent 781cca9a15
commit b9a8a6dd71

View File

@@ -64,6 +64,7 @@
<script>
import productApi from '@/api/product'
import stockApi from '@/api/stock'
export default {
data() {
@@ -89,6 +90,12 @@ export default {
this.loadProducts()
}
},
onPullDownRefresh() {
this.page = 1
this.loadProducts().then(() => {
uni.stopPullDownRefresh()
})
},
methods: {
async loadCategories() {
try {
@@ -115,12 +122,28 @@ export default {
this.products = [...this.products, ...list]
}
this.hasMore = list.length >= this.pageSize
// 加载库存数据
this.loadStocks()
} catch (e) {
console.error(e)
} finally {
this.loading = false
}
},
async loadStocks() {
try {
const res = await stockApi.getStockList({ page: 1, pageSize: 500 })
const stockList = res.records || []
const stockMap = {}
stockList.forEach(item => {
stockMap[item.productId] = item.quantity || 0
})
this.stocks = stockMap
} catch (e) {
console.error('加载库存失败', e)
}
},
selectCategory(id) {
this.categoryId = id
this.page = 1