艺术家
2025-06-09 7c129cb1793c51db134afef96dc099b62144dca3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
 
<template>
  <el-card style="border-radius: 0" :body-style="{ padding: '1rem 2rem' }" v-loading="loading">
    <template #header>
      <div style="display: flex;align-items: center;">
        <div style="font-weight: bold; font-size: 1.2rem">物料来源统计</div>
        <div style="flex: 1;display: flex;justify-content: space-around;margin-left: 3rem;">
          <template v-for="i in goodsSourceList" :key="i.value">
            <div @click="handleSelect(i.value)" :class="i.value == id ? 'selected' : ''" class="no-select">{{ i.label }}
            </div>
          </template>
        </div>
      </div>
    </template>
    <div style="height: 4rem;background-color: #f5f5f5;display: flex;box-sizing: border-box;padding: 0.6rem;">
      <div
        style="border-right: 1px solid #ccc;flex: 1;display: flex;flex-direction: column;justify-content: space-between;">
        <div style="color: black;font-weight: bold;text-align: center;">{{ info.sumCount }}</div>
        <div style="color: black;text-align: center;">数据总量</div>
      </div>
      <div style="border-right: 1px solid #ccc;flex: 1;">
        <div style="color: black;font-weight: bold;text-align: center;">{{ info.monthAddCount }}</div>
        <div style="color: black;text-align: center;">新增量</div>
      </div>
      <div style="flex: 1;">
        <div style="color: black;font-weight: bold;text-align: center;">{{ info.printCount }}</div>
        <div style="color: black;text-align: center;">打印总量</div>
      </div>
    </div>
    <div ref="chartDom" style="height: 21rem; width: 100%"></div>
  </el-card>
</template>
 
<script setup>
import { ref, onMounted, onUnmounted, nextTick } from "vue";
import { goodsSourceList } from "../../utils";
// 引入echarts
import * as echarts from "echarts";
import { GetGoodsSourceDistApi } from "../../api/dashboard";
import { ElLoading } from 'element-plus'
const loading=ref(true)
const id = ref(1)
const xData = ref([])
const monthAddCountData = ref([])
const monthSumCountData= ref([])
const printSumCountData = ref([])
const info = ref({
  monthAddCount: 0,
  printCount: 0,
  sourceName: "0",
  sumCount: 0
})
 
 
 
const handleSelect = (data) => {
  id.value = data
  GetGoodsSourceDistApi(id.value).then(res => {
    info.value = res.data.sourceObj[0]
    xData.value = res.data.monthGoodsObj.map(i=>i.monthNow)
    monthAddCountData.value = res.data.monthGoodsObj.map(i=>i.monthAddCount)
    monthSumCountData.value = res.data.monthGoodsObj.map(i=>i.monthSumCount)
    printSumCountData.value = res.data.monthGoodsObj.map(i=>i.printSumCount)
    initChart()
  })
}
 
// 创建一个响应式引用来保存DOM元素
const chartDom = ref(null);
let chartInstance = null;
 
 
 
// 初始化ECharts实例并设置配置项(这里以折线图为例,但可灵活替换)
onMounted(async () => {
  await GetGoodsSourceDistApi(id.value).then(res => {
    info.value = res.data.sourceObj[0]
    xData.value = res.data.monthGoodsObj.map(i=>i.monthNow)
    monthAddCountData.value = res.data.monthGoodsObj.map(i=>i.monthAddCount)
    monthSumCountData.value = res.data.monthGoodsObj.map(i=>i.monthSumCount)
    printSumCountData.value = res.data.monthGoodsObj.map(i=>i.printSumCount)
  })
  await nextTick(); // 确保DOM已经渲染完成
  initChart();
});
 
const initChart = () => {
  chartInstance = echarts.init(chartDom.value);
  const option = {
    tooltip: {
      trigger: 'axis'
    },
    legend: {
      data: ['数据总量', '新增量', '打印总量'],
      // right: "0%",
      top: "2%",
      center: "center",
    },
    grid: {
      left: '0%',
      right: '4%',
      bottom: '0%',
      top: "15%",
      containLabel: true
    },
 
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: xData.value
    },
    yAxis: {
      type: 'value',
      minInterval:1,
    },
    series: [
      {
        name: '数据总量',
        type: 'line',
        stack: 'Total',
        smooth: true,
        color: "#0099ff",
        data: monthSumCountData.value
      },
      {
        name: '新增量',
        type: 'line',
        smooth: true,
        color: "#009966",
        data: monthAddCountData.value
      },
      {
        name: '打印总量',
        type: 'line',
        smooth: true,
        color: "#ff9900",
        data: printSumCountData.value
      }
    ]
  };
  chartInstance.setOption(option);
  nextTick(() => {
    loading.value = false
  })
}
 
// 销毁ECharts实例
onUnmounted(() => {
  if (chartInstance != null && chartInstance.dispose) {
    chartInstance.dispose();
  }
});
 
//窗口大小变化重绘echart
window.onresize = function () {
  if (chartInstance != null && chartInstance.resize) {
    chartInstance.resize();
  }
};
</script>
 
<style scoped lang="less">
.no-select {
  text-align: center;
  color: black;
  font-size: 1.1rem;
  cursor: pointer;
  flex: 1;
  padding: 0.1rem 0;
  transition: all 0.3s;
}
 
.selected {
  background-color: #105b84;
  color: white;
}
</style>