fix: 商品列表页加载库存数据
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user