feat(selfop): show customer names and filter sales and turnover
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { computed, ref } from 'vue'
|
||||
import { analyticsApi } from './api/analytics'
|
||||
import { contextParams } from './state'
|
||||
import type { OwnerOption, QueryContext } from './types'
|
||||
|
||||
export function useOwnerDirectory() {
|
||||
const owners = ref<OwnerOption[]>([]), error = ref('')
|
||||
let loaded = '', generation = 0
|
||||
const options = computed(() => owners.value.map(owner => ({ value: owner.customerCode, label: owner.customerName ? `${owner.customerName} (${owner.customerCode})` : owner.customerCode })))
|
||||
async function load(context: QueryContext, warehouseCode: string, signal?: AbortSignal) {
|
||||
const key = `${warehouseCode}|${context.queryAsOf}`
|
||||
if (key === loaded) return
|
||||
const request = ++generation
|
||||
try {
|
||||
const result = await analyticsApi.ownerDirectory({ sourceAccount: 'lingxing-primary', warehouseCode, ...contextParams(context) }, signal)
|
||||
if (request !== generation || signal?.aborted) return
|
||||
owners.value = result; loaded = key; error.value = ''
|
||||
} catch {
|
||||
if (request !== generation || signal?.aborted) return
|
||||
owners.value = []; loaded = ''; error.value = '客户名称选项读取失败,请刷新重试'
|
||||
}
|
||||
}
|
||||
return { options, error, load }
|
||||
}
|
||||
Reference in New Issue
Block a user