Files
gao-customer-h5/src/pages/product/component/ProductStockMovementChart.vue
T
2026-09-23 15:43:31 +08:00

78 lines
2.3 KiB
Vue

<template>
<date-range-chart-card
title="库存变动"
caption="预占与释放不计入实际出入库"
:date-text-list="dateTextList"
:option="buildOption"
:loading="loading"
height="17rem"
/>
</template>
<script setup lang="ts">
import type { EChartsOption } from "echarts";
import DateRangeChartCard from "@/components/DateRangeChartCard.vue";
import type { GaoProductStockMovementDailyStatView } from "@/types/GaoChart";
import { buildAxisChartOption, getDailyItem, getNumber } from "@/pages/product/component/chartUtils";
import { buildRestDayMarkArea, useRestDayCalendar } from "@/pages/store/component/useRestDayCalendar";
defineOptions({
name: "ProductStockMovementChart"
});
const props = defineProps<{
dateTextList: string[];
list: GaoProductStockMovementDailyStatView[];
loading: boolean;
}>();
const dateTextList = computed(() => props.dateTextList);
const { restDaySet } = useRestDayCalendar(dateTextList);
function buildOption(visibleDateTextList: string[]): EChartsOption {
const labelList = visibleDateTextList.map(item => item.slice(5));
return {
...buildAxisChartOption(labelList),
xAxis: {
type: "category",
data: labelList,
axisLine: { onZero: true },
axisTick: { show: false },
axisLabel: { color: "#52607a", interval: "auto", hideOverlap: true }
},
series: [
{
name: "入库",
type: "bar",
stack: "stock-movement",
markArea: buildRestDayMarkArea(visibleDateTextList, restDaySet.value, window.innerWidth - 32),
data: visibleDateTextList.map(dateText => Math.abs(getNumber(getDailyItem(props.list, dateText)?.inQuantity)))
},
{
name: "出库",
type: "bar",
stack: "stock-movement",
data: visibleDateTextList.map(dateText => -Math.abs(getNumber(getDailyItem(props.list, dateText)?.outQuantity)))
},
{
name: "库存净变化",
type: "line",
smooth: true,
data: visibleDateTextList.map(dateText => getNumber(getDailyItem(props.list, dateText)?.netOnHandQuantity))
},
{
name: "新增预占",
type: "line",
data: visibleDateTextList.map(dateText => Math.abs(getNumber(getDailyItem(props.list, dateText)?.reserveQuantity)))
},
{
name: "释放预占",
type: "line",
data: visibleDateTextList.map(dateText => -Math.abs(getNumber(getDailyItem(props.list, dateText)?.releaseQuantity)))
}
]
};
}
</script>