123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- <template>
- <div class="sample-statistics">
- <!-- Top: Statistics & Time Filter -->
- <el-row :gutter="20" class="top-bar">
- <el-col :span="12">
- <div class="stat-box">
- <div class="stat-title">样本统计</div>
- <!-- <div class="stat-value">{{ totalSamples }}</div> -->
- </div>
- </el-col>
- <el-col :span="12" class="filter-col">
- <el-select v-model="selectedRange" placeholder="选择时间范围" @change="onRangeChange" size="small">
- <el-option label="近24小时" value="1"></el-option>
- <el-option label="近3天(72小时)" value="2"></el-option>
- <el-option label="近7天" value="3"></el-option>
- <el-option label="近30天" value="4"></el-option>
- </el-select>
- </el-col>
- </el-row>
- <!-- Middle: Line Chart -->
- <div class="chart-section">
- <div ref="lineChart" class="line-chart"></div>
- </div>
- <!-- Bottom: Pie Charts -->
- <el-row :gutter="20" class="pie-row">
- <el-col :span="12">
- <div class="pie-title">样本类型占比</div>
- <div ref="typePieChart" class="pie-chart"></div>
- </el-col>
- <el-col :span="12">
- <div class="pie-title">检出物占比</div>
- <div ref="detectedPieChart" class="pie-chart"></div>
- </el-col>
- </el-row>
- </div>
- </template>
- <script>
- import * as echarts from 'echarts';
- import {getjcwzbInfo, getyblxtjInfo, getybtjInfo} from '@/api/statistics/report';
- export default {
- name: 'SampleStatistics',
- data() {
- return {
- selectedRange: '1',
- totalSamples: 1234,
- lineChart: null,
- typePieChart: null,
- detectedPieChart: null,
- lineData: [],
- typePieData: [],
- detectedPieData: [],
- }
- },
- mounted() {
- this.initCharts()
- this.fetchData()
- },
- methods: {
- onRangeChange() {
- this.fetchData()
- },
- async fetchData() {
- const response = await getjcwzbInfo(this.selectedRange)
- if (response.data ) {
- let arr = []
- for(let k in response.data) {
- arr.push({
- name: k,
- value: response.data[k]
- })
- }
- this.detectedPieData = [...arr];
- }
- const res = await getyblxtjInfo(this.selectedRange)
- if (res.data ) {
- let arr = []
- for(let k in res.data) {
- arr.push({
- name: k,
- value: res.data[k]
- })
- }
- this.typePieData = [...arr];
- }
- const result = await getybtjInfo(this.selectedRange)
- const analysisData = []
- const adoptionData = []
- // 生成日期
- const xData = []
- if (result.data ) {
- result.data.forEach(item => {
- analysisData.push(item.fxl)
- adoptionData.push(item.ybl)
- xData.push(item.hour)
- })
- }
- // 模拟数据,根据selectedRange更新
- // const now = new Date()
- // let days = 1
- // if (this.selectedRange === '2') days = 3
- // if (this.selectedRange === '3') days = 7
- // if (this.selectedRange === '4') days = 30
- // for (let i = days - 1; i >= 0; i--) {
- // const d = new Date(now)
- // d.setDate(now.getDate() - i)
- // xData.push(`${d.getMonth() + 1}-${d.getDate()}`)
- // analysisData.push(Math.floor(Math.random() * 100 + 100))
- // adoptionData.push(Math.floor(Math.random() * 80 + 50))
- // }
- this.lineData = { xData, analysisData, adoptionData }
- // // 饼图数据
- // this.typePieData = [
- // { value: 335, name: '血液' },
- // { value: 310, name: '尿液' },
- // { value: 234, name: '唾液' },
- // { value: 135, name: '其他' }
- // ]
- // this.detectedPieData = [
- // { value: 400, name: '物质A' },
- // { value: 335, name: '物质B' },
- // { value: 310, name: '物质C' },
- // { value: 234, name: '其他' }
- // ]
- // this.totalSamples = analysisData.reduce((a, b) => a + b, 0)
- this.updateCharts()
- },
- initCharts() {
- this.lineChart = echarts.init(this.$refs.lineChart)
- this.typePieChart = echarts.init(this.$refs.typePieChart)
- this.detectedPieChart = echarts.init(this.$refs.detectedPieChart)
- },
- updateCharts() {
- // 折线图
- this.lineChart.setOption({
- tooltip: { trigger: 'axis' },
- legend: { data: ['数据分析量', '收样量'] },
- xAxis: { type: 'category', data: this.lineData.xData },
- yAxis: { type: 'value', name: '数量' },
- series: [
- {
- name: '数据分析量',
- type: 'line',
- smooth: true,
- data: this.lineData.analysisData
- },
- {
- name: '收样量',
- type: 'line',
- smooth: true,
- data: this.lineData.adoptionData
- }
- ]
- })
- // 样本类型饼图
- this.typePieChart.setOption({
- tooltip: { trigger: 'item' },
- legend: { bottom: 0 },
- series: [
- {
- name: '样本类型',
- type: 'pie',
- radius: '60%',
- data: this.typePieData,
- emphasis: {
- itemStyle: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)' }
- }
- }
- ]
- })
- // 检出物饼图
- this.detectedPieChart.setOption({
- tooltip: { trigger: 'item' },
- legend: { bottom: 0 },
- series: [
- {
- name: '检出物',
- type: 'pie',
- radius: '60%',
- data: this.detectedPieData,
- emphasis: {
- itemStyle: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)' }
- }
- }
- ]
- })
- }
- }
- }
- </script>
- <style scoped>
- .sample-statistics {
- padding: 24px;
- background: #fff;
- }
- .top-bar {
- margin-bottom: 24px;
- align-items: center;
- }
- .stat-box {
- display: flex;
- flex-direction: column;
- justify-content: center;
- height: 60px;
- }
- .stat-title {
- font-size: 16px;
- color: #888;
- }
- .stat-value {
- font-size: 28px;
- font-weight: bold;
- color: #409EFF;
- }
- .filter-col {
- display: flex;
- align-items: center;
- justify-content: flex-end;
- }
- .chart-section {
- margin-bottom: 24px;
- }
- .line-chart {
- width: 100%;
- height: 320px;
- }
- .pie-row {
- margin-top: 12px;
- }
- .pie-chart {
- width: 100%;
- height: 260px;
- }
- .pie-title {
- text-align: center;
- font-size: 16px;
- margin-bottom: 8px;
- color: #333;
- }
- </style>
|