index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. <template>
  2. <home-container :customStyle="{ background: 'none' }">
  3. <view class="container">
  4. <!-- 顶部tabs -->
  5. <h-tabs v-if="roles.includes('banzuzhang')" v-model="currentTab" :tabs="tabList" value-key="type"
  6. label-key="title" @change="handleTabChange" />
  7. <!-- 通道开放情况 -->
  8. <view class="card" :style="{ paddingBottom: currentTab !== 'all' ? '100rpx' : '24rpx' }">
  9. <view class="card-header">通道开放情况</view>
  10. <view class="chart-container">
  11. <view class="pie-chart" id="pieChart"></view>
  12. </view>
  13. <view v-if="currentTab === 'all'" style="margin-top: 120rpx;" class="bar-chart" id="barChart1"></view>
  14. </view>
  15. <!-- 人员情况 -->
  16. <view v-if="currentTab === 'all'" class="card">
  17. <view class="card-header">人员情况</view>
  18. <view class="bar-chart" id="barChart2"></view>
  19. </view>
  20. <!-- 明细情况 -->
  21. <view class="card-header" style="padding-left: 10rpx;">明细情况</view>
  22. <view class="card-detail">
  23. <uni-collapse v-if="isShowBarChart1">
  24. <uni-collapse-item v-for="(item, index) in terminlDetail" :key="index" :title="item.terminlName"
  25. :open="true">
  26. <view class="detail-content">
  27. <view v-if="item.region.length > 0">在岗班组</view>
  28. <view class="detail-row" v-for="(regionItem, i) in item.region" :key="i">
  29. <view class="detail-title">{{ regionItem.regionalName }}&nbsp;&nbsp;开放数量:{{
  30. regionItem.openChannelCount }}</view>
  31. <TableList :data="regionItem.detailList" :columns="[{
  32. props: 'channelName',
  33. title: '通道名称'
  34. }, {
  35. props: 'onDutyTeamName',
  36. title: '在岗班组'
  37. }, {
  38. props: 'onDutyTime',
  39. title: '上岗时间'
  40. }, {
  41. props: 'onDutyCount',
  42. title: '在岗人数'
  43. }]" />
  44. </view>
  45. <view v-if="item.waitList.length > 0" style="margin-bottom: 10rpx;">空闲班组</view>
  46. <TableList v-if="item.waitList.length > 0" :data="item.waitList" :columns="[{
  47. props: 'waitTeamName',
  48. title: '待岗班组'
  49. }, {
  50. props: 'waitCount',
  51. title: '待岗人数'
  52. }, {
  53. props: 'checkOutTime',
  54. title: '下通道时间'
  55. }]" />
  56. </view>
  57. </uni-collapse-item>
  58. </uni-collapse>
  59. <view v-else="!isShowBarChart1">
  60. <no-data text="暂无数据" icon-type="search" icon-size="60" icon-color="#C0C4CC" />
  61. </view>
  62. </view>
  63. </view>
  64. </home-container>
  65. </template>
  66. <script>
  67. import HomeContainer from "@/components/HomeContainer.vue";
  68. import TableList from "./components/TableList.vue";
  69. import * as echarts from 'echarts';
  70. import { getChannelStatistics } from '@/api/attendanceStatistics/attendanceStatistics';
  71. import HTabs from "@/components/h-tabs/h-tabs.vue";
  72. export default {
  73. components: { HomeContainer, TableList, HTabs },
  74. data() {
  75. return {
  76. currentTab: 'my', // 默认显示我的区域
  77. tabList: [
  78. {
  79. type: 'my',
  80. title: '我的区域'
  81. },
  82. {
  83. type: 'all',
  84. title: '全部区域'
  85. }
  86. ],
  87. terminlDetail: [],
  88. mainDetail: {},
  89. pieChart: null,
  90. barChart1: null,
  91. barChart2: null,
  92. roles: this.$store.state.user.roles
  93. }
  94. },
  95. computed: {
  96. isShowPieChart() {
  97. const values = Object.values(this.mainDetail || {});
  98. console.log('mainDetail values:', values, 'all empty check:', values.every(item => !item));
  99. return !values.every(item => !item);
  100. },
  101. isShowBarChart1() {
  102. return this.terminlDetail.length > 0;
  103. },
  104. },
  105. mounted() {
  106. this.fetchData("1");
  107. if (!this.roles.includes('banzuzhang')) {
  108. this.currentTab = 'all'
  109. }
  110. },
  111. methods: {
  112. handleTabChange(newValue, tab) {
  113. this.currentTab = newValue;
  114. this.fetchData(this.currentTab == 'my' ? "1" : "2")
  115. },
  116. async fetchData(status) {
  117. try {
  118. console.log('正在请求考勤统计数据,status:', status);
  119. const response = await getChannelStatistics(status);
  120. console.log('接口返回数据:', response);
  121. const { channelCount, maintainCount, onDutyCount, terminlDetail } = response;
  122. console.log('解析后的数据:', { channelCount, maintainCount, onDutyCount, terminlDetail });
  123. this.terminlDetail = terminlDetail || [];
  124. this.mainDetail = {
  125. channelCount: channelCount || 0,
  126. maintainCount: maintainCount || 0,
  127. onDutyCount: onDutyCount || 0,
  128. }
  129. console.log(this.mainDetail, 22)
  130. this.$nextTick(() => {
  131. this.initCharts();
  132. })
  133. } catch (e) {
  134. console.error('获取考勤数据失败', e);
  135. }
  136. },
  137. initCharts() {
  138. const pieDom = document.getElementById('pieChart');
  139. const barDom1 = document.getElementById('barChart1');
  140. const barDom2 = document.getElementById('barChart2');
  141. if (pieDom) {
  142. this.pieChart = echarts.init(pieDom);
  143. }
  144. if (barDom1) {
  145. this.barChart1 = echarts.init(barDom1);
  146. }
  147. if (barDom2) {
  148. this.barChart2 = echarts.init(barDom2);
  149. }
  150. this.$nextTick(() => {
  151. this.updateCharts();
  152. });
  153. },
  154. updateCharts() {
  155. // 在更新图表前先清空所有图表
  156. this.pieChart && this.pieChart.clear();
  157. this.barChart1 && this.barChart1.clear();
  158. this.barChart2 && this.barChart2.clear();
  159. let openRate = 0;
  160. let openData = 0;
  161. let closeData = 0;
  162. if (this.roles.includes('banzuzhang') && this.currentTab == 'my') {
  163. openData = this.terminlDetail.reduce((item, cur) => {
  164. return item + cur.onDutyChannelCount;
  165. }, 0);
  166. let allData = this.terminlDetail.reduce((item, cur) => {
  167. return item + cur.channelCount;
  168. }, 0);
  169. closeData = allData - openData;
  170. openRate = (openData / allData) * 100;
  171. } else {
  172. let allData = this.terminlDetail.reduce((item, cur) => {
  173. return item + cur.channelCount;
  174. }, 0);
  175. // openData = this.mainDetail.onDutyCount;
  176. openData = this.terminlDetail.reduce((item, cur) => {
  177. return item + cur.onDutyChannelCount;
  178. }, 0);
  179. openRate = (openData / allData) * 100;
  180. closeData = allData - openData;
  181. }
  182. // 检查数据是否有效
  183. const hasValidData = openData > 0 || closeData > 0;
  184. // 环形图配置
  185. this.pieChart && this.pieChart.setOption({
  186. series: [{
  187. type: 'pie',
  188. radius: ['55%', '70%'],
  189. avoidLabelOverlap: false,
  190. // label: { show: false },
  191. data: hasValidData ? [
  192. { value: openRate, name: '开放 ' + openData, itemStyle: { color: '#5972C0' } },
  193. { value: 100 - openRate, name: '未开放 ' + closeData, itemStyle: { color: 'rgba(89, 114, 192, 0.5)' } }
  194. ] : [],
  195. silent: !hasValidData // 无数据时禁用交互
  196. }],
  197. graphic: hasValidData ? [{
  198. type: 'text',
  199. left: 'center',
  200. top: '40%',
  201. style: {
  202. text: '开放率',
  203. font: 'normal 16px sans-serif',
  204. fill: '#333'
  205. }
  206. }, {
  207. type: 'text',
  208. left: 'center',
  209. top: '50%',
  210. style: {
  211. text: openRate.toFixed(2) + '%',
  212. font: 'bold 24px sans-serif',
  213. fill: '#333'
  214. }
  215. }] : [{
  216. // 无数据时显示提示
  217. type: 'text',
  218. left: 'center',
  219. top: 'center',
  220. style: {
  221. text: '暂无数据',
  222. font: '16px sans-serif',
  223. fill: '#999'
  224. }
  225. }]
  226. });
  227. let firstTerminal = 'T1航站楼';
  228. let secondTerminal = 'T2航站楼';
  229. let terminalName = [firstTerminal, secondTerminal]
  230. // 安全检查:确保 terminlDetail 存在且为数组
  231. let barT1 = this.terminlDetail && Array.isArray(this.terminlDetail)
  232. ? this.terminlDetail.filter(item => item.terminlName === firstTerminal)[0]
  233. : null;
  234. let barT2 = this.terminlDetail && Array.isArray(this.terminlDetail)
  235. ? this.terminlDetail.filter(item => item.terminlName === secondTerminal)[0]
  236. : null;
  237. let batT1Open = barT1?.onDutyChannelCount;//T1航站楼开放人数
  238. let batT2Open = barT2?.onDutyChannelCount;//T2航站楼开放人数
  239. let batT1Close = barT1 ? barT1.channelCount - barT1.onDutyChannelCount : 0;//T1航站楼未开放人数
  240. let batT2Close = barT2 ? barT2.channelCount - barT2.onDutyChannelCount : 0;//T2航站楼未开放人数
  241. console.log(batT1Open, batT2Open, "batT2Open")
  242. // 检查条形图数据是否有效
  243. const hasBarData = (batT1Open > 0 || batT1Close > 0 || batT2Open > 0 || batT2Close > 0);
  244. // 通道开放情况正负条形图
  245. if (this.currentTab === 'all') {
  246. this.barChart1 && this.barChart1.setOption({
  247. tooltip: {
  248. trigger: 'axis',
  249. axisPointer: { type: 'shadow' },
  250. formatter: function(params) {
  251. let result = params[0].name + '<br/>';
  252. params.forEach(function(item) {
  253. result += item.marker + ' ' + item.seriesName + ': ' + Math.abs(item.value) + '<br/>';
  254. });
  255. return result;
  256. }
  257. },
  258. legend: {
  259. data: ['开放', '未开放'],
  260. top: '15%'
  261. },
  262. grid: {
  263. left: '4%',
  264. right: '4%',
  265. bottom: '4%',
  266. containLabel: true,
  267. backgroundColor: 'transparent'
  268. },
  269. xAxis: {
  270. type: 'value',
  271. axisLine: { show: true },
  272. axisTick: { show: false },
  273. axisLabel: {
  274. show: false,
  275. formatter: function (value) {
  276. return Math.abs(value);
  277. }
  278. },
  279. splitLine: { show: false },
  280. min: function (value) {
  281. return value.min - (value.max - value.min) * 0.3;
  282. },
  283. max: function (value) {
  284. return value.max + (value.max - value.min) * 0.3;
  285. }
  286. },
  287. yAxis: {
  288. type: 'category',
  289. axisLine: { show: false },
  290. axisTick: { show: false },
  291. data: terminalName,
  292. splitLine: { show: false }
  293. },
  294. series: hasBarData ? [
  295. {
  296. name: '开放',
  297. type: 'bar',
  298. data: [-batT1Open, -batT2Open],
  299. stack: 'total',
  300. barWidth: '30%',
  301. itemStyle: { color: '#6E65F1' },
  302. label: {
  303. show: function (params) {
  304. return Math.abs(params.value) !== 0;
  305. },
  306. position: 'left',
  307. formatter: function (params) {
  308. return Math.abs(params.value) === 0 ? '' : Math.abs(params.value);
  309. }
  310. }
  311. },
  312. {
  313. name: '未开放',
  314. type: 'bar',
  315. stack: 'total',
  316. barWidth: '30%',
  317. data: [batT1Close, batT2Close],
  318. itemStyle: { color: '#D4D1FB' },
  319. label: {
  320. show: function (params) {
  321. return Math.abs(params.value) !== 0;
  322. },
  323. position: 'right',
  324. formatter: function (params) {
  325. return Math.abs(params.value) === 0 ? '' : Math.abs(params.value);
  326. }
  327. }
  328. }
  329. ] : [],
  330. graphic: !hasBarData ? [{
  331. // 无数据时显示提示
  332. type: 'text',
  333. left: 'center',
  334. top: 'center',
  335. style: {
  336. text: '暂无数据',
  337. font: '16px sans-serif',
  338. fill: '#999'
  339. }
  340. }] : []
  341. });
  342. }
  343. let batT1NormalPerson = barT1?.onDutyCount;//T1航站楼在岗人数
  344. let batT2NormalPerson = barT2?.onDutyCount;//T2航站楼在岗人数
  345. let batT1FreePerson = barT1 ? barT1.openChannelCount - barT1.onDutyCount : 0;//T1航站楼空闲人数
  346. let batT2FreePerson = barT2 ? barT2.openChannelCount - barT2.onDutyCount : 0;//T2航站楼空闲人数
  347. console.log(batT1NormalPerson, batT2NormalPerson, batT1FreePerson, batT2FreePerson, "batT2NormalPerson")
  348. // 检查条形图数据是否有效
  349. const hasBar2Data = (batT1NormalPerson > 0 || batT2NormalPerson > 0 || batT1FreePerson > 0 || batT2FreePerson > 0);
  350. // 人员情况正负条形图
  351. if (this.currentTab === 'all') {
  352. this.barChart2 && this.barChart2.setOption({
  353. tooltip: {
  354. trigger: 'axis',
  355. axisPointer: { type: 'shadow' },
  356. formatter: function(params) {
  357. let result = params[0].name + '<br/>';
  358. params.forEach(function(item) {
  359. result += item.marker + ' ' + item.seriesName + ': ' + Math.abs(item.value) + '<br/>';
  360. });
  361. return result;
  362. }
  363. },
  364. legend: { data: ['在岗人数', '空闲人数'], top: '15%' },
  365. grid: {
  366. left: '4%',
  367. right: '4%',
  368. bottom: '4%',
  369. containLabel: true,
  370. backgroundColor: 'transparent'
  371. },
  372. xAxis: {
  373. type: 'value',
  374. axisLine: { show: true },
  375. axisTick: { show: false },
  376. axisLabel: {
  377. show: false,
  378. formatter: function (value) {
  379. return Math.abs(value);
  380. }
  381. },
  382. splitLine: { show: false },
  383. min: function (value) {
  384. return value.min - (value.max - value.min) * 0.3;
  385. },
  386. max: function (value) {
  387. return value.max + (value.max - value.min) * 0.3;
  388. }
  389. },
  390. yAxis: {
  391. type: 'category',
  392. axisLine: { show: false },
  393. axisTick: { show: false },
  394. data: terminalName,
  395. splitLine: { show: false }
  396. },
  397. series: hasBar2Data ? [
  398. {
  399. name: '在岗人数',
  400. type: 'bar',
  401. data: [-batT1NormalPerson, -batT2NormalPerson],
  402. stack: 'total',
  403. barWidth: '30%',
  404. itemStyle: { color: '#6E65F1' },
  405. label: {
  406. show: true,
  407. position: 'left',
  408. formatter: function (params) {
  409. return Math.abs(params.value) === 0 ? '' : Math.abs(params.value);
  410. }
  411. }
  412. },
  413. {
  414. name: '空闲人数',
  415. type: 'bar',
  416. stack: 'total',
  417. barWidth: '30%',
  418. data: [batT1FreePerson, batT2FreePerson],
  419. itemStyle: { color: '#D4D1FB' },
  420. label: {
  421. show: true,
  422. position: 'right',
  423. formatter: function (params) {
  424. return Math.abs(params.value) === 0 ? '' : Math.abs(params.value);
  425. }
  426. }
  427. }
  428. ] : [],
  429. graphic: !hasBar2Data ? [{
  430. // 无数据时显示提示
  431. type: 'text',
  432. left: 'center',
  433. top: 'center',
  434. style: {
  435. text: '暂无数据',
  436. font: '16px sans-serif',
  437. fill: '#999'
  438. }
  439. }] : []
  440. });
  441. }
  442. }
  443. }
  444. }
  445. </script>
  446. <style lang="scss" scoped>
  447. .container {
  448. padding: 20rpx;
  449. display: flex;
  450. flex-direction: column;
  451. gap: 20rpx;
  452. background: none !important;
  453. }
  454. .card-detail {
  455. padding: 0;
  456. background: #fff;
  457. border-radius: 16rpx;
  458. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  459. }
  460. .card {
  461. background: #fff;
  462. border-radius: 16rpx;
  463. padding: 24rpx;
  464. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  465. }
  466. .card-header {
  467. font-size: 32rpx;
  468. font-weight: bold;
  469. margin-bottom: 20rpx;
  470. color: #333;
  471. }
  472. .chart-container {
  473. position: relative;
  474. height: 300rpx;
  475. margin-bottom: 20rpx;
  476. }
  477. .pie-chart,
  478. .bar-chart {
  479. width: 100% !important;
  480. height: 400rpx;
  481. }
  482. .open-rate {
  483. position: absolute;
  484. top: 50%;
  485. left: 50%;
  486. transform: translate(-50%, -50%);
  487. font-size: 28rpx;
  488. color: #666;
  489. }
  490. .detail-content {
  491. padding: 20rpx;
  492. }
  493. .detail-row {
  494. display: flex;
  495. justify-content: space-between;
  496. margin-bottom: 10rpx;
  497. font-size: 26rpx;
  498. color: #666;
  499. flex-direction: column;
  500. .detail-title {
  501. margin: 10rpx 0;
  502. color: #6E65F1;
  503. }
  504. }
  505. </style>