Files
gao-customer-h5/src/pages/product/component/ProductSalesTrendChart.vue
T
2026-09-23 16:12:09 +08:00

87 lines
2.4 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 { GaoProductSalesDailyStatView } from "@/types/GaoChart";
import { buildAxisChartOption, getDailyItem, getNumber } from "@/pages/product/component/chartUtils";
import { buildRestDayMarkArea, useRestDayCalendar } from "@/pages/store/component/useRestDayCalendar";
defineOptions({
name: "ProductSalesTrendChart"
});
const props = defineProps<{
dateTextList: string[];
list: GaoProductSalesDailyStatView[];
loading: boolean;
}>();
const dateTextList = computed(() => props.dateTextList);
const { restDaySet } = useRestDayCalendar(dateTextList);
function buildOption(visibleDateTextList: string[], chartWidth: number): EChartsOption {
const labelList = visibleDateTextList.map(item => item.slice(5));
return {
...buildAxisChartOption(labelList),
xAxis: {
type: "category",
data: labelList,
axisTick: { show: true, length: 0, interval: 0 },
axisLabel: { color: "#52607a", interval: "auto", hideOverlap: true }
},
yAxis: [
{
type: "value",
name: "基础单位",
minInterval: 1,
axisLabel: { color: "#52607a" },
splitLine: { lineStyle: { color: "rgba(148, 163, 184, .2)" } }
},
{
type: "value",
name: "订单",
position: "right",
minInterval: 1,
axisLabel: { color: "#52607a" },
splitLine: { show: false }
}
],
series: [
{
name: "直接销量",
type: "bar",
stack: "quantity",
yAxisIndex: 0,
markArea: buildRestDayMarkArea(visibleDateTextList, restDaySet.value, chartWidth),
data: visibleDateTextList.map(dateText => getNumber(getDailyItem(props.list, dateText)?.directBaseQuantity))
},
{
name: "套餐权益",
type: "bar",
stack: "quantity",
yAxisIndex: 0,
data: visibleDateTextList.map(dateText => getNumber(getDailyItem(props.list, dateText)?.packageBaseQuantity))
},
{
name: "订单数",
type: "line",
smooth: true,
yAxisIndex: 1,
data: visibleDateTextList.map(dateText => getNumber(getDailyItem(props.list, dateText)?.orderCount))
}
]
};
}
</script>