fix: 商品列表页加载库存数据
This commit is contained in:
@@ -64,6 +64,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import productApi from '@/api/product'
|
import productApi from '@/api/product'
|
||||||
|
import stockApi from '@/api/stock'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
@@ -89,6 +90,12 @@ export default {
|
|||||||
this.loadProducts()
|
this.loadProducts()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onPullDownRefresh() {
|
||||||
|
this.page = 1
|
||||||
|
this.loadProducts().then(() => {
|
||||||
|
uni.stopPullDownRefresh()
|
||||||
|
})
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async loadCategories() {
|
async loadCategories() {
|
||||||
try {
|
try {
|
||||||
@@ -115,12 +122,28 @@ export default {
|
|||||||
this.products = [...this.products, ...list]
|
this.products = [...this.products, ...list]
|
||||||
}
|
}
|
||||||
this.hasMore = list.length >= this.pageSize
|
this.hasMore = list.length >= this.pageSize
|
||||||
|
|
||||||
|
// 加载库存数据
|
||||||
|
this.loadStocks()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
} finally {
|
} finally {
|
||||||
this.loading = false
|
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) {
|
selectCategory(id) {
|
||||||
this.categoryId = id
|
this.categoryId = id
|
||||||
this.page = 1
|
this.page = 1
|
||||||
|
|||||||
Reference in New Issue
Block a user