|
@@ -22,9 +22,19 @@ type InventoryItem = {
|
|
|
mayBacklogAmount: number
|
|
mayBacklogAmount: number
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+type InventoryDistributionResponse = {
|
|
|
|
|
+ totalInventory: number
|
|
|
|
|
+ totalOverStock: number
|
|
|
|
|
+ factoryNameOverStockPair: Record<string, number>
|
|
|
|
|
+ factoryNameInventoryPair: Record<string, number>
|
|
|
|
|
+ storageNameOverStockPair?: Record<string, number>
|
|
|
|
|
+ storageNameInventoryPair?: Record<string, number>
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
const activePanel = ref<ActivePanel>('distribution')
|
|
const activePanel = ref<ActivePanel>('distribution')
|
|
|
const DEFAULT_DATE = dayjs().subtract(1, 'day').format('YYYY-MM-DD')
|
|
const DEFAULT_DATE = dayjs().subtract(1, 'day').format('YYYY-MM-DD')
|
|
|
const selectedDate = inject<Ref<string>>('rhKbInventoryDate', ref(DEFAULT_DATE))
|
|
const selectedDate = inject<Ref<string>>('rhKbInventoryDate', ref(DEFAULT_DATE))
|
|
|
|
|
+const inventoryResult = ref<InventoryDistributionResponse | null>(null)
|
|
|
const distributionChartRef = ref<HTMLDivElement>()
|
|
const distributionChartRef = ref<HTMLDivElement>()
|
|
|
const trendChartRef = ref<HTMLDivElement>()
|
|
const trendChartRef = ref<HTMLDivElement>()
|
|
|
|
|
|
|
@@ -101,6 +111,22 @@ function formatAmount(value: number) {
|
|
|
return Number(value || 0).toFixed(2)
|
|
return Number(value || 0).toFixed(2)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function getFactoryInventoryData(data: InventoryDistributionResponse | null): InventoryItem[] {
|
|
|
|
|
+ if (!data) return inventoryData
|
|
|
|
|
+
|
|
|
|
|
+ const factoryNames = new Set([
|
|
|
|
|
+ ...Object.keys(data.factoryNameInventoryPair || {}),
|
|
|
|
|
+ ...Object.keys(data.factoryNameOverStockPair || {})
|
|
|
|
|
+ ])
|
|
|
|
|
+
|
|
|
|
|
+ return [...factoryNames].map((project) => ({
|
|
|
|
|
+ project,
|
|
|
|
|
+ mayInventoryAmount: yuanToWan(data.factoryNameInventoryPair?.[project] || 0),
|
|
|
|
|
+ yearBeginningBacklog: 0,
|
|
|
|
|
+ mayBacklogAmount: yuanToWan(data.factoryNameOverStockPair?.[project] || 0)
|
|
|
|
|
+ }))
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function getChartLayout(chartRef: Ref<HTMLDivElement | undefined>) {
|
|
function getChartLayout(chartRef: Ref<HTMLDivElement | undefined>) {
|
|
|
const { clientWidth = 0, clientHeight = 0 } = chartRef.value ?? {}
|
|
const { clientWidth = 0, clientHeight = 0 } = chartRef.value ?? {}
|
|
|
const compact = clientHeight > 0 && (clientHeight < 210 || clientWidth < 520)
|
|
const compact = clientHeight > 0 && (clientHeight < 210 || clientWidth < 520)
|
|
@@ -135,10 +161,19 @@ function getChartLayout(chartRef: Ref<HTMLDivElement | undefined>) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function getDistributionOption(data: InventoryItem[]): echarts.EChartsOption {
|
|
|
|
|
|
|
+function getDistributionOption(
|
|
|
|
|
+ data: InventoryItem[],
|
|
|
|
|
+ totals?: Pick<InventoryDistributionResponse, 'totalInventory' | 'totalOverStock'>
|
|
|
|
|
+): echarts.EChartsOption {
|
|
|
const layout = getChartLayout(distributionChartRef)
|
|
const layout = getChartLayout(distributionChartRef)
|
|
|
- const inventoryTotal = data.reduce((total, item) => total + item.mayInventoryAmount, 0)
|
|
|
|
|
- const backlogTotal = data.reduce((total, item) => total + item.mayBacklogAmount, 0)
|
|
|
|
|
|
|
+ const inventoryTotal =
|
|
|
|
|
+ totals?.totalInventory != null
|
|
|
|
|
+ ? yuanToWan(totals.totalInventory)
|
|
|
|
|
+ : data.reduce((total, item) => total + item.mayInventoryAmount, 0)
|
|
|
|
|
+ const backlogTotal =
|
|
|
|
|
+ totals?.totalOverStock != null
|
|
|
|
|
+ ? yuanToWan(totals.totalOverStock)
|
|
|
|
|
+ : data.reduce((total, item) => total + item.mayBacklogAmount, 0)
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
...ANIMATION,
|
|
...ANIMATION,
|
|
@@ -403,23 +438,32 @@ function initChart(
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function renderDistributionChart() {
|
|
function renderDistributionChart() {
|
|
|
- distributionChart?.setOption(getDistributionOption(inventoryData), true)
|
|
|
|
|
|
|
+ const data = getFactoryInventoryData(inventoryResult.value)
|
|
|
|
|
+ distributionChart?.setOption(
|
|
|
|
|
+ getDistributionOption(data, inventoryResult.value || undefined),
|
|
|
|
|
+ true
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function renderTrendChart() {
|
|
function renderTrendChart() {
|
|
|
- trendChart?.setOption(getTrendOption(inventoryData), true)
|
|
|
|
|
|
|
+ trendChart?.setOption(getTrendOption(getFactoryInventoryData(inventoryResult.value)), true)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function initDistributionChart() {
|
|
function initDistributionChart() {
|
|
|
|
|
+ const data = getFactoryInventoryData(inventoryResult.value)
|
|
|
distributionChart = initChart(
|
|
distributionChart = initChart(
|
|
|
distributionChartRef,
|
|
distributionChartRef,
|
|
|
distributionChart,
|
|
distributionChart,
|
|
|
- getDistributionOption(inventoryData)
|
|
|
|
|
|
|
+ getDistributionOption(data, inventoryResult.value || undefined)
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function initTrendChart() {
|
|
function initTrendChart() {
|
|
|
- trendChart = initChart(trendChartRef, trendChart, getTrendOption(inventoryData))
|
|
|
|
|
|
|
+ trendChart = initChart(
|
|
|
|
|
+ trendChartRef,
|
|
|
|
|
+ trendChart,
|
|
|
|
|
+ getTrendOption(getFactoryInventoryData(inventoryResult.value))
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function resizeCharts() {
|
|
function resizeCharts() {
|
|
@@ -440,10 +484,17 @@ async function requestInventoryDistribution() {
|
|
|
if (deptId.value === null || !selectedDate.value) return
|
|
if (deptId.value === null || !selectedDate.value) return
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- await IotStatApi.getInventoryDistribution({
|
|
|
|
|
|
|
+ const response = await IotStatApi.getInventoryDistribution({
|
|
|
fdate: selectedDate.value,
|
|
fdate: selectedDate.value,
|
|
|
- dept: 157
|
|
|
|
|
|
|
+ dept: '157'
|
|
|
})
|
|
})
|
|
|
|
|
+ const data = response
|
|
|
|
|
+
|
|
|
|
|
+ if (data && typeof data === 'object') {
|
|
|
|
|
+ inventoryResult.value = data as InventoryDistributionResponse
|
|
|
|
|
+ renderDistributionChart()
|
|
|
|
|
+ renderTrendChart()
|
|
|
|
|
+ }
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.error('获取库存分布数据失败', error)
|
|
console.error('获取库存分布数据失败', error)
|
|
|
}
|
|
}
|