支持按账号商品监控库存抢购
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { ref, computed } from 'vue'
|
||||
import { useToast } from './useToast'
|
||||
import { useActivity } from './useActivity'
|
||||
import { LoadProducts } from '@wails/go/app/App'
|
||||
import { LoadProducts, LoadProductsForAccounts } from '@wails/go/app/App'
|
||||
|
||||
export interface Product {
|
||||
commodityId: string
|
||||
@@ -63,21 +63,39 @@ export function useProducts() {
|
||||
products.value.find(p => p.commodityId === selectedProductId.value)
|
||||
)
|
||||
|
||||
const applyProductPayload = (data: ProductPayload, showToastMsg: boolean) => {
|
||||
products.value = Array.isArray(data.products) ? data.products : []
|
||||
productInfo.value = data
|
||||
|
||||
if (selectedProductId.value && !products.value.some(p => p.commodityId === selectedProductId.value)) {
|
||||
clearSelection()
|
||||
}
|
||||
|
||||
if (showToastMsg) {
|
||||
showToast('商品已刷新', `共 ${products.value.length} 个`, 'success')
|
||||
}
|
||||
}
|
||||
|
||||
const loadProducts = async (showToastMsg = true) => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await LoadProducts(true)
|
||||
products.value = Array.isArray(data.products) ? data.products : []
|
||||
productInfo.value = data
|
||||
applyProductPayload(data, showToastMsg)
|
||||
} catch (e: any) {
|
||||
products.value = []
|
||||
productInfo.value = null
|
||||
clearSelection()
|
||||
showToast('商品刷新失败', e.message, 'error')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 如果选中的商品不存在了,清空选择
|
||||
if (selectedProductId.value && !products.value.some(p => p.commodityId === selectedProductId.value)) {
|
||||
clearSelection()
|
||||
}
|
||||
|
||||
if (showToastMsg) {
|
||||
showToast('商品已刷新', `共 ${products.value.length} 个`, 'success')
|
||||
}
|
||||
const loadProductsForAccounts = async (accountNames: string[], showToastMsg = true) => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await LoadProductsForAccounts(accountNames)
|
||||
applyProductPayload(data, showToastMsg)
|
||||
} catch (e: any) {
|
||||
products.value = []
|
||||
productInfo.value = null
|
||||
@@ -134,6 +152,7 @@ export function useProducts() {
|
||||
loading,
|
||||
xiaodianTab,
|
||||
loadProducts,
|
||||
loadProductsForAccounts,
|
||||
selectProduct,
|
||||
clearSelection,
|
||||
setSearch,
|
||||
|
||||
Reference in New Issue
Block a user