gaoluyang
2026-03-02 8aff4f4bb7308c9875562a2b898a9a4a70c32329
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
<template>
  <div class="app-container">
    <div class="search_form">
      <div>
        <span class="search_title">发放季度:</span>
        <el-select
          style="width: 200px"
          v-model="searchForm.season"
          placeholder="请选择"
          @change="handleQuery"
          @clear="clearSeason"
          clearable
          :disabled="!!searchForm.issueDate"
        >
          <el-option
            v-for="item in jidu"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
 
        <span class="search_title ml10">发放月份:</span>
        <el-date-picker
          style="width: 200px"
          v-model="searchForm.issueDate"
          type="month"
          value-format="YYYY-MM-DD"
          format="YYYY-MM"
          placeholder="请选择月份"
          clearable
          @change="handleQuery"
          @clear="clearIssueDaten"
          :disabled="!!searchForm.season"
        />
 
        <el-button type="primary" style="margin-left: 10px" @click="handleQuery">
          搜索
        </el-button>
        <el-button style="margin-left: 10px" @click="resetHandleQuery">
          重置
        </el-button>
      </div>
      <div>
        <el-button @click="handleOut" icon="download">导出</el-button>
      </div>
    </div>
 
    <!-- 发放进度(图表模式) -->
    <el-row :gutter="20" class="progress-cards">
      <el-col :span="6">
        <el-card class="progress-card">
          <div class="pc-title">发放总数量</div>
          <div class="pc-value">{{ totalNum }}</div>
          <div class="pc-sub">已领 + 未领(含超时)</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="progress-card success">
          <div class="pc-title">已领取</div>
          <div class="pc-value">{{ adoptedNum }}</div>
          <div class="pc-sub">含超时已领取</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="progress-card warning">
          <div class="pc-title">未领取</div>
          <div class="pc-value">{{ unAdoptedNum }}</div>
          <div class="pc-sub">含超时未领取</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="progress-card info">
          <div class="pc-title">领取完成率</div>
          <div class="pc-value">{{ progressPercentVal }}%</div>
          <el-progress
            :percentage="progressPercentVal"
            :stroke-width="10"
            status="success"
          />
        </el-card>
      </el-col>
    </el-row>
 
    <el-row :gutter="20" class="charts-section">
      <el-col :span="12">
        <el-card class="chart-card" v-loading="statsLoading">
          <template #header>
            <div class="card-header">领取进度占比</div>
          </template>
          <div ref="pieChartRef" class="chart"></div>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card class="chart-card" v-loading="statsLoading">
          <template #header>
            <div class="card-header">进度分布(含超时)</div>
          </template>
          <div ref="barChartRef" class="chart"></div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>
 
<script setup>
import { ref, reactive, toRefs, onMounted, onUnmounted, computed, nextTick, getCurrentInstance } from 'vue'
import dayjs from 'dayjs'
import * as echarts from 'echarts'
import { progressTotal, progressPercent, progressDistribution } from '@/api/lavorissce/ledger'
import { ElMessageBox, ElMessage } from 'element-plus'
import { getCurrentMonth } from '@/utils/util'
 
const { proxy } = getCurrentInstance()
 
// 查询条件
const data = reactive({
  searchForm: {
    season: getCurrentMonth(),
    issueDate: '',
  },
})
const { searchForm } = toRefs(data)
 
// 季度选项
const jidu = ref([
  { value: '1', label: '第一季度' },
  { value: '2', label: '第二季度' },
  { value: '3', label: '第三季度' },
  { value: '4', label: '第四季度' },
])
 
// 进度统计(图表数据)
const statsLoading = ref(false)
// 发放进度-总计(来自 progressTotal 接口)
const totalData = ref({
  totalNum: 0,
  adoptedNum: 0,
  unAdoptedNum: 0,
  progressPercent: 0,
})
// 领取进度占比(来自 progressPercent 接口,饼图)
const percentData = ref([])
// 进度分布(来自 progressDistribution 接口,柱状图)
const distributionData = ref({
  ylqNum: 0,
  wlqNum: 0,
  csylqNum: 0,
  cswlqNum: 0,
})
 
const totalNum = computed(() => Number(totalData.value.totalNum || 0))
const adoptedNum = computed(() => Number(totalData.value.adoptedNum || 0))
const unAdoptedNum = computed(() => Number(totalData.value.unAdoptedNum || 0))
const progressPercentVal = computed(() => Number(totalData.value.progressPercent ?? 0))
 
const pieChartRef = ref(null)
const barChartRef = ref(null)
let pieChart = null
let barChart = null
 
const resizeCharts = () => {
  pieChart?.resize()
  barChart?.resize()
}
 
const initChartsIfNeeded = async () => {
  await nextTick()
  if (pieChartRef.value && !pieChart) pieChart = echarts.init(pieChartRef.value)
  if (barChartRef.value && !barChart) barChart = echarts.init(barChartRef.value)
  renderCharts()
  window.addEventListener('resize', resizeCharts)
}
 
const renderCharts = () => {
  const s = distributionData.value
  const timelyAdopted = Number(s.ylqNum || 0)
  const timelyUnAdopted = Number(s.wlqNum || 0)
  const overtimeAdopted = Number(s.csylqNum || 0)
  const overtimeUnAdopted = Number(s.cswlqNum || 0)
 
  const colors = ['#67C23A', '#E6A23C']
  const pieData = percentData.value.length
    ? percentData.value.map((it, i) => ({
        ...it,
        itemStyle: it.itemStyle || { color: colors[i % colors.length] },
      }))
    : [
        { name: '已领取', value: adoptedNum.value, itemStyle: { color: '#67C23A' } },
        { name: '未领取', value: unAdoptedNum.value, itemStyle: { color: '#E6A23C' } },
      ]
 
  if (pieChart) {
    pieChart.setOption(
      {
        tooltip: { trigger: 'item', formatter: '{b}: {c} ({d}%)' },
        legend: { orient: 'vertical', left: 'left', top: 'middle' },
        series: [
          {
            name: '领取进度',
            type: 'pie',
            radius: ['45%', '72%'],
            center: ['60%', '50%'],
            label: { formatter: '{b}\n{c}' },
            data: pieData,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.3)',
              },
            },
          },
        ],
      },
      true,
    )
  }
 
  if (barChart) {
    barChart.setOption(
      {
        tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } },
        grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true },
        xAxis: { type: 'category', data: ['及时', '超时'] },
        yAxis: { type: 'value' },
        legend: { data: ['已领取', '未领取'] },
        series: [
          {
            name: '已领取',
            type: 'bar',
            stack: 'total',
            barWidth: 42,
            itemStyle: { color: '#67C23A' },
            data: [timelyAdopted, overtimeAdopted],
          },
          {
            name: '未领取',
            type: 'bar',
            stack: 'total',
            itemStyle: { color: '#F56C6C' },
            data: [timelyUnAdopted, overtimeUnAdopted],
          },
        ],
      },
      true,
    )
  }
}
 
const clearSeason = () => {
  searchForm.value.season = ''
  searchForm.value.issueDate = dayjs().format('YYYY-MM-DD')
}
 
const clearIssueDaten = () => {
  searchForm.value.issueDate = ''
  searchForm.value.season = getCurrentMonth()
}
 
const resetHandleQuery = () => {
  searchForm.value.issueDate = ''
  searchForm.value.season = getCurrentMonth()
  handleQuery()
}
 
// 查询
const handleQuery = async () => {
  await getStatistics()
}
 
const getStatistics = async () => {
  statsLoading.value = true
  const params = { ...searchForm.value }
  try {
    const [totalRes, percentRes, distRes] = await Promise.all([
      progressTotal(params),
      progressPercent(params),
      progressDistribution(params),
    ])
 
    const d = totalRes?.data || {}
    totalData.value = {
      totalNum: d.total ?? 0,
      adoptedNum: d.adopted ?? 0,
      unAdoptedNum: d.notAdopted ?? 0,
      progressPercent: d.adoptedPercent ?? 0,
    }
 
    const p = percentRes?.data || {}
    if (Array.isArray(p)) {
      percentData.value = p
    } else if (p.data && Array.isArray(p.data)) {
      percentData.value = p.data
    } else if (p.adopted != null || p.notAdopted != null) {
      percentData.value = [
        { name: '已领取', value: Number(p.adopted || 0), itemStyle: { color: '#67C23A' } },
        { name: '未领取', value: Number(p.notAdopted || 0), itemStyle: { color: '#E6A23C' } },
      ]
    } else {
      percentData.value = []
    }
 
    const dist = distRes?.data || {}
    // 后端返回示例:{ series: [[2,14],[0,0]] }
    // 约定:series[0] = [及时已领, 及时未领],series[1] = [超时已领, 超时未领]
    if (
      Array.isArray(dist.series) &&
      dist.series.length >= 2 &&
      Array.isArray(dist.series[0]) &&
      Array.isArray(dist.series[1]) &&
      dist.series[0].length >= 2 &&
      dist.series[1].length >= 2
    ) {
      distributionData.value = {
        ylqNum: Number(dist.series[0][0] ?? 0),
        wlqNum: Number(dist.series[0][1] ?? 0),
        csylqNum: Number(dist.series[1][0] ?? 0),
        cswlqNum: Number(dist.series[1][1] ?? 0),
      }
    } else {
      // 兼容其它返回字段命名
      distributionData.value = {
        ylqNum: Number(dist.ylqNum ?? dist.timelyAdopted ?? 0),
        wlqNum: Number(dist.wlqNum ?? dist.timelyUnAdopted ?? 0),
        csylqNum: Number(dist.csylqNum ?? dist.overtimeAdopted ?? 0),
        cswlqNum: Number(dist.cswlqNum ?? dist.overtimeUnAdopted ?? 0),
      }
    }
 
    await initChartsIfNeeded()
  } catch (e) {
    totalData.value = { totalNum: 0, adoptedNum: 0, unAdoptedNum: 0, progressPercent: 0 }
    percentData.value = []
    distributionData.value = { ylqNum: 0, wlqNum: 0, csylqNum: 0, cswlqNum: 0 }
    renderCharts()
  } finally {
    statsLoading.value = false
  }
}
 
// 导出
const handleOut = () => {
  ElMessageBox.confirm('选中的内容将被导出,是否确认导出?', '导出', {
    confirmButtonText: '确认',
    cancelButtonText: '取消',
    type: 'warning',
  })
    .then(() => {
      proxy.download(
        '/lavorIssue/exportCopy',
        {
          season: searchForm.value.season,
          issueDate: searchForm.value.issueDate,
        },
        '劳保发放报表.xlsx',
      )
    })
    .catch(() => {
      ElMessage.info('已取消')
    })
}
 
onMounted(() => {
  handleQuery()
})
 
onUnmounted(() => {
  window.removeEventListener('resize', resizeCharts)
  if (pieChart) {
    pieChart.dispose()
    pieChart = null
  }
  if (barChart) {
    barChart.dispose()
    barChart = null
  }
})
</script>
 
<style scoped>
.progress-cards {
  margin: 14px 0 18px;
}
.progress-card :deep(.el-card__body) {
  padding: 16px;
}
.pc-title {
  color: #606266;
  font-size: 13px;
  margin-bottom: 8px;
}
.pc-value {
  font-size: 28px;
  font-weight: 700;
  color: #303133;
  line-height: 1.2;
  margin-bottom: 6px;
}
.pc-sub {
  color: #909399;
  font-size: 12px;
}
 
.charts-section {
  margin-bottom: 12px;
}
.chart-card :deep(.el-card__body) {
  padding: 12px 16px 16px;
}
.card-header {
  font-weight: 600;
  color: #303133;
}
.chart {
  height: 320px;
  width: 100%;
}
.dynamic-table-container {
  width: 100%;
}
 
.pagination-container {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}
 
::deep(.el-table .el-table__header-wrapper th) {
  background-color: #f0f1f5 !important;
  color: #333333;
  font-weight: 600;
}
 
::deep(.el-table .el-table__body-wrapper td) {
  padding: 8px 0;
}
 
::deep(.el-select) {
  width: 100%;
}
 
::deep(.el-input) {
  width: 100%;
}
</style>