bjdm_statistics.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. <template>
  2. <view class="statistics-page">
  3. <!-- 不在时间范围 -->
  4. <view v-if="isNotInTime" class="isNotInTime">
  5. <view class="isNotInTime-title">
  6. <Icon name="icon-naoling" size="97" color="#ff7e00" />
  7. 当前不在点名时段!
  8. </view>
  9. <view class="isNotInTime-content">
  10. <view class="isNotInTime-content-title">点名时段</view>
  11. <view v-for="item in NotInTime" class="isNotInTime-content-item">
  12. <view class="isNotInTime-content-item-icon">
  13. <Icon :name="item.icon" :size="item.iconSize" :color="item.iconColor" />
  14. </view>
  15. <view>
  16. <view>{{ item.title }}</view>
  17. <view>{{ item.range }}</view>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. <!-- Swiper 卡片容器 -->
  23. <swiper
  24. v-else
  25. class="grade-swiper"
  26. :current="currentIndex"
  27. :vertical="true"
  28. :previous-margin="currentIndex > 0 ? '30rpx' : '0'"
  29. :next-margin="currentIndex < njDataList.length - 1 ? '30rpx' : '0'"
  30. @change="handleSwiperChange"
  31. >
  32. <swiper-item
  33. v-for="(njData, index) in njDataList"
  34. :key="njData.njid"
  35. :class="{
  36. 'first-item': index === 0,
  37. 'last-item': index === njDataList.length - 1,
  38. 'middle-item': index > 0 && index < njDataList.length - 1
  39. }"
  40. >
  41. <view class="statistics-card">
  42. <!-- Top 部分 -->
  43. <view class="statistics-top">
  44. <view class="statistics-date"> {{ toChineseDateMonth(allData?.jkssj) || '5月20日' }} {{ getDayPeriod(allData?.jkssj) || '上午' }} </view>
  45. <view class="statistics-class"> {{ njData?.mc || '一年级' }} </view>
  46. <!-- 圆形进度条 -->
  47. <view class="progress-container">
  48. <view class="progress-circle" :style="getProgressCircleStyle(njData)">
  49. </view>
  50. </view>
  51. <view class="progress-legend">
  52. <view class="legend-item">
  53. <view class="legend-dot completed"></view>
  54. <text>已点名</text>
  55. </view>
  56. <view class="legend-item">
  57. <view class="legend-dot pending"></view>
  58. <text>未点名</text>
  59. </view>
  60. </view>
  61. </view>
  62. <!-- Bottom 部分 -->
  63. <view class="statistics-bottom">
  64. <view class="statistics-penal">
  65. <!-- 已全部点名完成的提示 -->
  66. <view v-if="isGradeAllChecked(njData)" class="statistics-all-checked">
  67. <view class="statistics-all-checked-title">点名情况</view>
  68. <view class="stats-section">
  69. <view class="stat-item">
  70. <text class="stat-label">出勤:</text>
  71. <text class="stat-value present">{{ (njData?.totalStudentCount || 0) - (ydmData.qjrs || 0) - (ydmData.kkrs || 0) }}人</text>
  72. </view>
  73. <view class="stat-item">
  74. <text class="stat-label">缺勤:</text>
  75. <text class="stat-value absent">{{ ydmData.kkrs || 0 }} 人</text>
  76. </view>
  77. <view class="stat-item">
  78. <text class="stat-label">请假:</text>
  79. <text class="stat-value absent">{{ ydmData.qjrs || 0 }} 人</text>
  80. </view>
  81. </view>
  82. </view>
  83. <!-- 未点名班级列表 -->
  84. <view v-else style="height: 100%;">
  85. <view style="display: flex;justify-content: space-between;color: #000000;font-weight: bold;font-size: 34rpx;margin: 20rpx 0 40rpx 0;">
  86. <view>未点名班级</view>
  87. <view><text :style="{ color: getProgressPercentage(njData) === 100 ? '' : '#df5548' }">{{ getCheckedCount(njData) }}</text>/{{ njData?.bjList?.length || 0 }}</view>
  88. </view>
  89. <view class="statistics-uncheck-list">
  90. <view v-for="item in getUnCheckedBjList(njData)" :key="item.bjid" class="list-item" @click="handleBjClick(item)">
  91. <view class="list-item-title">
  92. {{ item.mc }}
  93. </view>
  94. <view class="list-item-content">
  95. <view>{{ item.xm }}</view>
  96. <view>{{ item.grdh || '无' }}</view>
  97. </view>
  98. </view>
  99. </view>
  100. </view>
  101. </view>
  102. </view>
  103. </view>
  104. </swiper-item>
  105. </swiper>
  106. </view>
  107. </template>
  108. <script setup>
  109. import { ref, computed, onMounted, onUnmounted, nextTick, getCurrentInstance, defineExpose } from 'vue'
  110. import { kqjlApi } from '@/api/kqjl'
  111. import { formatDate, getDayPeriod, toChineseDateMonth } from '@/utils/date'
  112. import Icon from '@/components/icon/index.vue';
  113. const allData = ref() // 总数据(包含年级列表和班级列表)
  114. const njDataList = ref([]) // 按年级拆分后的数据列表
  115. const ydmData = ref() // 已经点名的年级数据
  116. const ydmInterval = ref()
  117. const isNotInTime = ref(false)
  118. // 滑动相关变量
  119. const currentIndex = ref(0) // 当前显示的年级索引
  120. const NotInTime = ref([
  121. {
  122. icon: 'icon-shangwu',
  123. iconColor: '#1296db',
  124. iconSize: 97,
  125. title: '上午',
  126. range:'6:00~12:00'
  127. },
  128. {
  129. icon: 'icon-xiawu',
  130. iconColor: '#dd9900',
  131. iconSize: 97,
  132. title: '下午',
  133. range:'13:40~16:00'
  134. },
  135. {
  136. icon: 'icon-night',
  137. iconColor: '#333333',
  138. iconSize: 97,
  139. title: '晚上',
  140. range:'18:30~21:00'
  141. }
  142. ])
  143. // 按年级拆分班级数据
  144. function organizeDataByGrade() {
  145. if (!allData.value?.njList || !allData.value?.bjList) {
  146. njDataList.value = []
  147. return
  148. }
  149. njDataList.value = allData.value.njList.map(nj => {
  150. const bjList = allData.value.bjList.filter(bj => bj.njm === nj.njm)
  151. return {
  152. ...nj,
  153. bjList,
  154. totalStudentCount: bjList.reduce((sum, bj) => sum + (bj.rs || 0), 0)
  155. }
  156. })
  157. }
  158. // 计算指定年级未点名的班级列表
  159. const getUnCheckedBjList = (njData) => {
  160. if (!njData?.bjList || !ydmData.value?.ydmBjList) {
  161. return njData?.bjList || []
  162. }
  163. // 已点名的班级ID数组
  164. const checkedBjIds = ydmData.value.ydmBjList.map(id => parseInt(id))
  165. // 筛选出未点名的班级
  166. return njData.bjList.filter(bj => !checkedBjIds.includes(bj.bjid))
  167. }
  168. // 获取指定年级已点名的班级数量
  169. const getCheckedCount = (njData) => {
  170. if (!njData?.bjList || !ydmData.value?.ydmBjList) {
  171. return 0
  172. }
  173. const checkedBjIds = ydmData.value.ydmBjList.map(id => parseInt(id))
  174. return njData.bjList.filter(bj => checkedBjIds.includes(bj.bjid)).length
  175. }
  176. // 计算指定年级是否全部点名完成
  177. const isGradeAllChecked = (njData) => {
  178. if (!njData?.bjList || !ydmData.value?.ydmBjList) {
  179. return false
  180. }
  181. const checkedCount = getCheckedCount(njData)
  182. // 只有当已点名班级数量大于0且等于该年级总班级数量时,才算全部完成
  183. return checkedCount > 0 && njData.bjList.length === checkedCount
  184. }
  185. // 计算指定年级的进度百分比
  186. const getProgressPercentage = (njData) => {
  187. if (!njData?.bjList || njData.bjList.length === 0) {
  188. return 0
  189. }
  190. const checkedBjIds = ydmData.value?.ydmBjList?.map(id => parseInt(id)) || []
  191. const checkedCount = njData.bjList.filter(bj => checkedBjIds.includes(bj.bjid)).length
  192. return Math.round((checkedCount / njData.bjList.length) * 100)
  193. }
  194. // 计算指定年级的圆形进度条样式
  195. const getProgressCircleStyle = (njData) => {
  196. const percentage = getProgressPercentage(njData)
  197. if (percentage === 0) {
  198. // 全红色
  199. return {
  200. background: '#df5548',
  201. color: '#333'
  202. }
  203. } else if (percentage === 100) {
  204. // 全绿色
  205. return {
  206. background: '#4db680',
  207. color: '#333'
  208. }
  209. } else {
  210. // 部分完成,在红绿交界处两边各添加透明边框
  211. const degrees = percentage * 3.6
  212. const borderWidth = 0.5 // 每侧透明边框宽度(角度)
  213. // 绿色区域的结束角度(减去边框)
  214. const greenEndDegree = degrees - borderWidth
  215. // 红色区域的开始角度(加上边框)
  216. const redStartDegree = degrees + borderWidth
  217. return {
  218. background: `conic-gradient(
  219. transparent 0deg ${borderWidth}deg,
  220. #4db680 ${borderWidth}deg ${greenEndDegree}deg,
  221. transparent ${greenEndDegree}deg ${redStartDegree}deg,
  222. #df5548 ${redStartDegree}deg ${360 - borderWidth}deg,
  223. transparent ${360 - borderWidth}deg 360deg
  224. )`,
  225. color: '#333'
  226. }
  227. }
  228. }
  229. function handleBjClick(bj) {
  230. console.log('点击了班级:', bj)
  231. if (bj.grdh) {
  232. uni.makePhoneCall({
  233. phoneNumber: bj.grdh,
  234. success: () => {
  235. console.log('拨号成功')
  236. },
  237. fail: (err) => {
  238. console.log('拨号失败', err)
  239. }
  240. })
  241. }
  242. }
  243. // Swiper 切换事件处理
  244. function handleSwiperChange(e) {
  245. currentIndex.value = e.detail.current
  246. }
  247. async function init() {
  248. const res = await kqjlApi.mp_njdmHomep_load()
  249. if (res.data.msg && res.data.msg.includes("不在点名时段")) {
  250. isNotInTime.value = true
  251. NotInTime.value[0].range = res.data.swsjd;
  252. NotInTime.value[1].range = res.data.xwsjd;
  253. NotInTime.value[2].range = res.data.wssjd;
  254. return
  255. }
  256. allData.value = res.data
  257. isNotInTime.value = false
  258. // 按年级拆分数据
  259. organizeDataByGrade()
  260. refreshLoad()
  261. // 先清理已存在的定时器,防止重复创建
  262. if (ydmInterval.value) {
  263. clearInterval(ydmInterval.value)
  264. ydmInterval.value = null
  265. }
  266. // 定时刷新
  267. ydmInterval.value = setInterval(() => {
  268. refreshLoad()
  269. }, 15000)
  270. }
  271. async function refreshLoad() {
  272. const res = await kqjlApi.mp_njdmHomep_refreshLoad({
  273. njmStr: allData.value.njmStr,
  274. jkssj: formatDate(allData.value.jkssj, 'yyyy-MM-dd HH:mm:ss'),
  275. jjssj: formatDate(allData.value.jjssj, 'yyyy-MM-dd HH:mm:ss')
  276. })
  277. ydmData.value = res.data
  278. // Mock 数据:模拟其中一个班级已经点名
  279. // ydmData.value.ydmBjList = ['40211', '40212'] // 模拟A班已点名
  280. console.log('已点名数据:', ydmData.value)
  281. // console.log('未点名班级:', unCheckedBjList.value)
  282. }
  283. // ============== 暴露给主容器的生命周期(供 pages/main/index.vue 调用) ==============
  284. function onLoad() {
  285. init()
  286. }
  287. function onShow() {
  288. console.log('统计图onShow')
  289. init()
  290. }
  291. function onHide() {
  292. // 可按需做暂存处理
  293. console.log('统计图onHide')
  294. if (ydmInterval.value) {
  295. clearInterval(ydmInterval.value)
  296. ydmInterval.value = null
  297. }
  298. }
  299. function onUnload() {
  300. // 可按需做清理处理
  301. console.log('onUnload')
  302. if (ydmInterval.value) {
  303. clearInterval(ydmInterval.value)
  304. ydmInterval.value = null
  305. }
  306. }
  307. defineExpose({ onLoad, onShow, onHide, onUnload })
  308. </script>
  309. <style scoped lang="less">
  310. .statistics-page {
  311. height: 100%;
  312. background: #f5f5f5;
  313. padding:0 20rpx;
  314. position: relative;
  315. box-sizing: border-box;
  316. }
  317. .grade-container {
  318. position: relative;
  319. height: 100vh;
  320. width: 100%;
  321. overflow: hidden;
  322. }
  323. .grade-content {
  324. position: relative;
  325. height: 100%;
  326. transition: transform 0.3s ease;
  327. }
  328. // Swiper 样式
  329. .grade-swiper {
  330. width: 100%;
  331. height: 100%;
  332. box-sizing: border-box;
  333. // swiper-item 控制间距
  334. swiper-item {
  335. box-sizing: border-box;
  336. display: flex;
  337. align-items: center;
  338. // 第一个 item:只有下内边距
  339. &.first-item {
  340. padding: 0 0 10rpx 0;
  341. }
  342. // 最后一个 item:只有上内边距
  343. &.last-item {
  344. padding: 10rpx 0 0 0;
  345. }
  346. // 中间 item:上下都有内边距
  347. &.middle-item {
  348. padding: 10rpx 0;
  349. }
  350. // 只有一个 item
  351. &.first-item.last-item {
  352. padding: 0;
  353. }
  354. }
  355. }
  356. .statistics-card {
  357. background: #fff;
  358. width: 100%;
  359. height: 100%;
  360. border-radius: 4rpx;
  361. padding: 20rpx;
  362. box-sizing: border-box;
  363. display: flex;
  364. flex-direction: column;
  365. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
  366. }
  367. .statistics-top {
  368. flex: 4;
  369. display: flex;
  370. flex-direction: column;
  371. justify-content: center;
  372. align-items: center;
  373. position: relative;
  374. }
  375. .statistics-bottom {
  376. flex: 6;
  377. display: flex;
  378. flex-direction: column;
  379. // padding: 0 0 20rpx;
  380. overflow: hidden;
  381. }
  382. .statistics-penal {
  383. background: #f9fafb;
  384. border-radius: 4rpx;
  385. width: 100%;
  386. height: 100%;
  387. padding: 32rpx;
  388. box-sizing: border-box;
  389. }
  390. .statistics-date {
  391. color: #333;
  392. font-weight: 500;
  393. font-size: 38rpx;
  394. text-align: center;
  395. margin-bottom: 10rpx;
  396. }
  397. .statistics-class {
  398. color: #333;
  399. font-size: 32rpx;
  400. font-weight: 500;
  401. text-align: center;
  402. }
  403. // 进度条样式
  404. .progress-container {
  405. display: flex;
  406. justify-content: center;
  407. margin: 20rpx 0 0;
  408. }
  409. .progress-circle {
  410. width: 350rpx;
  411. height: 350rpx;
  412. border-radius: 50%;
  413. display: flex;
  414. align-items: center;
  415. justify-content: center;
  416. position: relative;
  417. transition: all 0.3s ease;
  418. // 创建环形效果(中间透明)
  419. &::before {
  420. content: '';
  421. position: absolute;
  422. top: 60rpx;
  423. left: 60rpx;
  424. width: 230rpx;
  425. height: 230rpx;
  426. border-radius: 50%;
  427. background: #fff;
  428. z-index: 1;
  429. }
  430. }
  431. .progress-text {
  432. font-size: 32rpx;
  433. font-weight: bold;
  434. z-index: 2;
  435. position: relative;
  436. }
  437. .progress-legend {
  438. display: flex;
  439. justify-content: center;
  440. gap: 40rpx;
  441. margin: 20rpx 0;
  442. }
  443. .legend-item {
  444. display: flex;
  445. align-items: center;
  446. gap: 10rpx;
  447. color: #333;
  448. font-size: 28rpx;
  449. }
  450. .legend-dot {
  451. width: 50rpx;
  452. height: 20rpx;
  453. border-radius: 20rpx;
  454. &.completed {
  455. background: #4db680;
  456. }
  457. &.pending {
  458. background: #df5548;
  459. }
  460. }
  461. .statistics-uncheck-list {
  462. width: 100%;
  463. height: calc(100% - 94rpx);
  464. overflow-y: auto;
  465. display: flex;
  466. flex-direction: column;
  467. gap: 24rpx;
  468. .list-item {
  469. display: flex;
  470. justify-content: space-between;
  471. align-items: center;
  472. width: 100%;
  473. background: #ffffff;
  474. border-radius: 4rpx;
  475. border: 2rpx solid #edeef0;
  476. box-sizing: border-box;
  477. padding: 14rpx 32rpx;
  478. .list-item-title {
  479. font-size: 34rpx;
  480. font-weight: 500;
  481. color: #333333;
  482. margin-left: 10rpx;
  483. }
  484. .list-item-content {
  485. display: flex;
  486. flex-direction: column;
  487. align-items: flex-end;
  488. font-size: 30rpx;
  489. font-weight: 500;
  490. color: #333333;
  491. gap: 5rpx;
  492. }
  493. }
  494. }
  495. .statistics-all-checked {
  496. text-align: center;
  497. height: 100%;
  498. display: flex;
  499. flex-direction: column;
  500. justify-content: center;
  501. align-items: center;
  502. .statistics-all-checked-title {
  503. font-size: 38rpx;
  504. width: 80%;
  505. margin: 0 auto;
  506. border-bottom: 2rpx solid #e6e6e6;
  507. padding-bottom: 20rpx;
  508. }
  509. // 统计信息样式
  510. .stats-section {
  511. padding: 40rpx;
  512. display: flex;
  513. flex-direction: column;
  514. gap: 20rpx;
  515. width: 100%;
  516. .stat-item {
  517. display: flex;
  518. align-items: center;
  519. justify-content: center;
  520. font-size: 32rpx;
  521. color: #333;
  522. .stat-label {
  523. text-align: right;
  524. flex: 1;
  525. margin-right: 20rpx;
  526. }
  527. .stat-value {
  528. flex: 1;
  529. text-align: left;
  530. }
  531. }
  532. }
  533. }
  534. .isNotInTime {
  535. width: calc(100% - 40rpx);
  536. height: calc(100% - 40rpx);
  537. background: #fff;
  538. position: absolute;
  539. left: 50%;
  540. top: 50%;
  541. transform: translate(-50%, -50%);
  542. border-radius: 4rpx;
  543. border: 2rpx solid #ebecec;
  544. display: flex;
  545. flex-direction: column;
  546. padding: 20rpx;
  547. box-sizing: border-box;
  548. .isNotInTime-title {
  549. color: #333;
  550. font-weight: 500;
  551. font-size: 38rpx;
  552. text-align: center;
  553. flex: 3;
  554. display: flex;
  555. align-items: center;
  556. justify-content: center;
  557. gap: 30rpx;
  558. }
  559. .isNotInTime-content {
  560. flex: 7;
  561. border-radius: 4rpx;
  562. background: #f9fafb;
  563. padding: 0 30rpx;
  564. .isNotInTime-content-title {
  565. font-size: 36rpx;
  566. color: #333333;
  567. font-weight: 400;
  568. margin: 30rpx 0;
  569. }
  570. .isNotInTime-content-item {
  571. font-size: 36rpx;
  572. color: #333333;
  573. font-weight: 400;
  574. display: flex;
  575. align-items: center;
  576. justify-content: flex-start;
  577. background: #fff;
  578. padding: 20rpx 30rpx;
  579. box-sizing: border-box;
  580. border-radius: 4rpx;
  581. margin-bottom: 30rpx;
  582. gap: 30rpx;
  583. .isNotInTime-content-item-icon {
  584. width: 120rpx;
  585. text-align: center;
  586. }
  587. }
  588. }
  589. }
  590. </style>