浏览代码

瑞恒看板库存模块

yanghao 2 周之前
父节点
当前提交
29d6a76063
共有 2 个文件被更改,包括 128 次插入9 次删除
  1. 68 0
      src/views/pms/stat/rhkb/data.json
  2. 60 9
      src/views/pms/stat/rhkb/inventorySituation.vue

+ 68 - 0
src/views/pms/stat/rhkb/data.json

@@ -0,0 +1,68 @@
+{
+  "totalInventory": 36392625,
+  "totalOverStock": 13570778,
+  "factoryNameOverStockPair": {
+    "新疆科瑞氮气工厂": 176738,
+    "瑞恒新疆": 9331039,
+    "瑞恒兴域": 4063001
+  },
+  "factoryNameInventoryPair": {
+    "新疆科瑞氮气工厂": 176738,
+    "瑞恒新疆": 20297592,
+    "瑞恒兴域": 15918295
+  },
+  "storageNameOverStockPair": {
+    "6006-3001": 7344717,
+    "6000-7001": 0,
+    "6006-1001": 319134,
+    "6006-3004": 628908,
+    "6006-3002": 662088,
+    "6006-3003": 376192,
+    "6000-null": 99812,
+    "6000-3008": 27986,
+    "6000-1002": 1441498,
+    "6000-1003": 589,
+    "6000-3004": 102024,
+    "6000-1004": 326682,
+    "6000-3007": 178674,
+    "6000-3006": 1692,
+    "6000-1005": 265905,
+    "6000-3001": 50439,
+    "6000-3003": 0,
+    "6000-3002": 10299,
+    "6000-1001": 1557401,
+    "6000-6002": 0,
+    "6000-8002": 0,
+    "6000-8001": 0,
+    "6006-6000": 0,
+    "5010-3009": 93527,
+    "5010-1002": 83211
+  },
+  "storageNameInventoryPair": {
+    "6006-3001": 14121779,
+    "6000-7001": 737776,
+    "6006-1001": 699665,
+    "6006-3004": 2960010,
+    "6006-3002": 1810637,
+    "6006-3003": 394306,
+    "6000-null": 99812,
+    "6000-3008": 46357,
+    "6000-1002": 2297667,
+    "6000-1003": 4398,
+    "6000-3004": 102024,
+    "6000-1004": 1231117,
+    "6000-3007": 516405,
+    "6000-3006": 27200,
+    "6000-1005": 527621,
+    "6000-3001": 251052,
+    "6000-3003": 6605752,
+    "6000-3002": 16121,
+    "6000-1001": 2637684,
+    "6000-6002": 670540,
+    "6000-8002": 45968,
+    "6000-8001": 100801,
+    "6006-6000": 311195,
+    "5010-3009": 93527,
+    "5010-1002": 83211
+  }
+}

+ 60 - 9
src/views/pms/stat/rhkb/inventorySituation.vue

@@ -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)
   }
   }