|
|
@@ -30,6 +30,11 @@ type InventoryDistributionResponse = {
|
|
|
|
|
|
type InventoryAgingResponse = Record<string, number>
|
|
|
|
|
|
+type InventoryAgingPoint = {
|
|
|
+ month: string
|
|
|
+ value: number
|
|
|
+}
|
|
|
+
|
|
|
type InventoryDetail = {
|
|
|
'1年以内': number
|
|
|
'3年以上': number
|
|
|
@@ -279,8 +284,8 @@ function getDistributionOption(
|
|
|
},
|
|
|
labelLine: {
|
|
|
show: true,
|
|
|
- length: layout.labelDistance,
|
|
|
- length2: layout.labelDistance,
|
|
|
+ // length: layout.labelDistance,
|
|
|
+ // length2: layout.labelDistance,
|
|
|
lineStyle: {
|
|
|
color: 'inherit'
|
|
|
}
|
|
|
@@ -307,8 +312,8 @@ function getDistributionOption(
|
|
|
},
|
|
|
labelLine: {
|
|
|
show: true,
|
|
|
- length: layout.labelDistance,
|
|
|
- length2: layout.labelDistance,
|
|
|
+ // length: layout.labelDistance,
|
|
|
+ // length2: layout.labelDistance,
|
|
|
lineStyle: {
|
|
|
color: 'inherit'
|
|
|
}
|
|
|
@@ -340,13 +345,30 @@ function initChart(
|
|
|
return nextChart
|
|
|
}
|
|
|
|
|
|
-function getInventoryAgingOption(data: InventoryAgingResponse): echarts.EChartsOption {
|
|
|
+function getInventoryAgingPoints(data: unknown): InventoryAgingPoint[] {
|
|
|
+ if (Array.isArray(data)) {
|
|
|
+ return data
|
|
|
+ .map((item: any) => ({
|
|
|
+ month: item?.month ?? item?.date ?? item?.fdate,
|
|
|
+ value: Number(item?.value ?? item?.amount ?? item?.overStockAmount)
|
|
|
+ }))
|
|
|
+ .filter((item) => /^\d{4}-\d{2}$/.test(item.month) && Number.isFinite(item.value))
|
|
|
+ .sort((itemA, itemB) => itemA.month.localeCompare(itemB.month))
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!data || typeof data !== 'object') return []
|
|
|
+
|
|
|
+ return Object.entries(data)
|
|
|
+ .map(([month, value]) => ({ month, value: Number(value) }))
|
|
|
+ .filter((item) => /^\d{4}-\d{2}$/.test(item.month) && Number.isFinite(item.value))
|
|
|
+ .sort((itemA, itemB) => itemA.month.localeCompare(itemB.month))
|
|
|
+}
|
|
|
+
|
|
|
+function getInventoryAgingOption(data: unknown): echarts.EChartsOption {
|
|
|
const layout = getChartLayout(trendChartRef)
|
|
|
- const entries = Object.entries(data)
|
|
|
- .filter(([month, value]) => /^\d{4}-\d{2}$/.test(month) && Number.isFinite(Number(value)))
|
|
|
- .sort(([monthA], [monthB]) => monthA.localeCompare(monthB))
|
|
|
- const months = entries.map(([month]) => month)
|
|
|
- const values = entries.map(([, value]) => yuanToWan(Number(value)))
|
|
|
+ const entries = getInventoryAgingPoints(data)
|
|
|
+ const months = entries.map(({ month }) => month)
|
|
|
+ const values = entries.map(({ value }) => yuanToWan(value))
|
|
|
|
|
|
return {
|
|
|
...ANIMATION,
|
|
|
@@ -489,16 +511,20 @@ async function requestInventoryAging() {
|
|
|
})
|
|
|
const data = response?.data?.data ?? response?.data ?? response
|
|
|
|
|
|
- if (
|
|
|
- data &&
|
|
|
- typeof data === 'object' &&
|
|
|
- Object.keys(data).some((month) => /^\d{4}-\d{2}$/.test(month))
|
|
|
- ) {
|
|
|
- inventoryAgingResult.value = data as InventoryAgingResponse
|
|
|
+ const points = getInventoryAgingPoints(data)
|
|
|
+
|
|
|
+ console.log('库存积压趋势数据', points)
|
|
|
+
|
|
|
+ if (points.length) {
|
|
|
+ inventoryAgingResult.value = Object.fromEntries(
|
|
|
+ points.map(({ month, value }) => [month, value])
|
|
|
+ )
|
|
|
nextTick(() => {
|
|
|
if (!trendChart) initTrendChart()
|
|
|
renderTrendChart()
|
|
|
})
|
|
|
+ } else if (trendChart) {
|
|
|
+ trendChart.setOption(getInventoryAgingOption({}), true)
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.error('获取库存积压趋势数据失败', error)
|
|
|
@@ -611,10 +637,26 @@ onUnmounted(() => {
|
|
|
<section class="inventory-detail-section">
|
|
|
<div class="inventory-detail-section__title">存货及变动情况</div>
|
|
|
<el-table :data="detailTableData" border class="inventory-detail-table" height="100%">
|
|
|
- <el-table-column prop="beginningInventory" label="年初存货" min-width="92" align="center" />
|
|
|
- <el-table-column prop="beginningOverStock" label="年初积压" min-width="92" align="center" />
|
|
|
- <el-table-column prop="endingInventory" label="期末库存" min-width="92" align="center" />
|
|
|
- <el-table-column prop="endingOverStock" label="期末积压" min-width="92" align="center" />
|
|
|
+ <el-table-column
|
|
|
+ prop="beginningInventory"
|
|
|
+ label="年初存货"
|
|
|
+ min-width="92"
|
|
|
+ align="center" />
|
|
|
+ <el-table-column
|
|
|
+ prop="beginningOverStock"
|
|
|
+ label="年初积压"
|
|
|
+ min-width="92"
|
|
|
+ align="center" />
|
|
|
+ <el-table-column
|
|
|
+ prop="endingInventory"
|
|
|
+ label="期末库存"
|
|
|
+ min-width="92"
|
|
|
+ align="center" />
|
|
|
+ <el-table-column
|
|
|
+ prop="endingOverStock"
|
|
|
+ label="期末积压"
|
|
|
+ min-width="92"
|
|
|
+ align="center" />
|
|
|
</el-table>
|
|
|
</section>
|
|
|
<section class="inventory-detail-section">
|