checkIn.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  1. <template>
  2. <page-meta root-font-size="system" />
  3. <view class="attendance-page">
  4. <view class="header">
  5. <text class="title">我的考勤记录</text>
  6. <picker mode="selector" :range="timeRanges" @change="onTimeRangeChange">
  7. <view class="picker">
  8. {{ selectedTimeRange }}/切换
  9. </view>
  10. </picker>
  11. </view>
  12. <!-- 今日签到信息区域 -->
  13. <view class="todayCheckIn" v-if="todayInfoShow">
  14. <view class="check-in-container">
  15. <text class="todayAttTitle">今日签到信息</text>
  16. <text class="exceptionText" v-if="lackCardState" @click="toBuKa">处理异常</text>
  17. <view class="info-row">
  18. <view>
  19. <text class="ygoa_icon icon-date"></text>
  20. <text class="value">日期:</text>
  21. </view>
  22. <text class="label">{{ todayData.day }}</text>
  23. </view>
  24. <view class="info-row">
  25. <view>
  26. <text class="ygoa-icon icon-day"></text>
  27. <text class="value" v-if="!clockMultiple">晨签时间:</text>
  28. <text class="value" v-if="clockMultiple">早上签到:</text>
  29. </view>
  30. <view>
  31. <text class="label">{{ todayData.startTime || '未打卡' }}</text>
  32. <text class="att_status">{{todayData.startStatus}}</text>
  33. </view>
  34. </view>
  35. <view class="info-row" v-if="clockMultiple">
  36. <view>
  37. <text class="ygoa-icon icon-day"></text>
  38. <text class="value">早上签退:</text>
  39. </view>
  40. <view>
  41. <text class="label">{{ todayData.endTimeAm || '未打卡' }}</text>
  42. <text class="att_status">{{todayData.endStatusForAm}}</text>
  43. </view>
  44. </view>
  45. <view class="info-row" v-if="clockMultiple">
  46. <view>
  47. <text class="ygoa-icon icon-night"></text>
  48. <text class="value">下午签到:</text>
  49. </view>
  50. <view>
  51. <text class="label">{{ todayData.startTimePm || '未打卡' }}</text>
  52. <text class="att_status">{{todayData.startStatusForPm}}</text>
  53. </view>
  54. </view>
  55. <view class="info-row">
  56. <view>
  57. <text class="ygoa-icon icon-night"></text>
  58. <text class="value" v-if="!clockMultiple">晚签时间:</text>
  59. <text class="value" v-if="clockMultiple">下午签退:</text>
  60. </view>
  61. <view>
  62. <text class="label">{{ todayData.endTime || '未打卡' }}</text>
  63. <text class="att_status">{{todayData.endStatus}}</text>
  64. </view>
  65. </view>
  66. </view>
  67. <!-- 分界线 -->
  68. <view class="divider"></view>
  69. <!-- 打卡记录 -->
  70. <!-- <view class="container">
  71. <view class="header">
  72. <text class="clockRecordTitle">打卡记录</text>
  73. </view>
  74. <view class="content" style="height: 41vh;">
  75. <z-paging :fixed="false" :default-page-size="pSize" default-page-no="1" @query="queryData" ref="paging">
  76. <view class="clockRecord" v-for="clockRecord in clockRecords" :key="clockRecord.date">
  77. <text class="date">{{ clockRecord.date }}</text>
  78. <view class="shifts">
  79. <view class="shift">
  80. <text class="shift-label">晨签:</text>
  81. <text class="shift-time">{{ clockRecord.morning||'没有该记录'}}</text>
  82. </view>
  83. <view class="shift">
  84. <text class="shift-label">晚签:</text>
  85. <text class="shift-time">{{ clockRecord.evening ||'没有该记录'}}</text>
  86. </view>
  87. </view>
  88. </view>
  89. </z-paging>
  90. </view>
  91. </view> -->
  92. <!-- 日历板块 -->
  93. <template>
  94. <view class="calendar-content">
  95. <view>
  96. <uni-calendar class="uni-calendar--hook" :selected="calenderData" :showMonth="true" @change="changeDate"
  97. @monthSwitch="monthSwitch" />
  98. </view>
  99. </view>
  100. </template>
  101. </view>
  102. <!-- 周,月数据统计区域 -->
  103. <view class="statistics" v-if="chartShow">
  104. <view class="statistic-card">
  105. <view class="statistic-title">{{ selectedTimeRange }}考勤统计</view>
  106. <view class="statistic-item">
  107. <view>
  108. <text class="ygoa_icon icon-attendance"></text>
  109. <text class="label">出勤:</text>
  110. </view>
  111. <text class="value">{{ attendanceCount }}</text>
  112. </view>
  113. <view class="statistic-item">
  114. <view>
  115. <text class="ygoa_icon icon-goOut"></text>
  116. <text class="label">外出:</text>
  117. </view>
  118. <text class="value">{{ goOutCount }}</text>
  119. </view>
  120. <view class="statistic-item">
  121. <view>
  122. <text class="ygoa_icon icon-late"></text>
  123. <text class="label">迟到:</text>
  124. </view>
  125. <text class="value">{{ lateCount }}</text>
  126. </view>
  127. <view class="statistic-item">
  128. <view>
  129. <text class="ygoa_icon icon-leaveEarly"></text>
  130. <text class="label">早退:</text>
  131. </view>
  132. <text class="value">{{ leaveEarlyCount }}</text>
  133. </view>
  134. <view class="statistic-item">
  135. <view>
  136. <text class="ygoa_icon icon-absenteeism"></text>
  137. <text class="label">缺勤:</text>
  138. </view>
  139. <text class="value">{{ absenteeismCount }}</text>
  140. </view>
  141. </view>
  142. </view>
  143. <!-- 图表区域 -->
  144. <view class="chart-container" v-if="chartShow">
  145. <view class="">
  146. <text class="chart-title">考勤趋势图</text>
  147. <view class="charts-box">
  148. <qiun-data-charts :type="chartsType" :opts="opts" :chartData="chartData" />
  149. </view>
  150. </view>
  151. </view>
  152. </view>
  153. </template>
  154. <script setup lang="ts">
  155. import {ref,onMounted,reactive} from 'vue';
  156. import { getProcessList } from '@/api/work.js'
  157. import {checkAttendance,getMyTotalCount,getMyQDQtAttendance,getMyTotalMonthCount} from '@/api/mine.js'
  158. import {useUserStore} from '@/store/user.js';
  159. import { useConfigStore } from '@/store/config'
  160. import $tab from '@/plugins/tab.js'
  161. import config from '@/config.js';
  162. const userStore = useUserStore();
  163. //考勤规则数据
  164. const configStore = useConfigStore();
  165. // 创建一个响应式对象记录今天的考勤数据
  166. const todayData = reactive({
  167. day: '', // 当前日期
  168. startTime: '', // 晨签到时间
  169. startStatus:'',//晨签状态
  170. endTime: '', // 晚签到时间
  171. endStatus:'',//晚签状态
  172. endTimeAm: '',//早上下班签退时间
  173. endStatusForAm:'',//早上下班签退状态
  174. startTimePm: '', // 下午上班签到时间
  175. startStatusForPm:'',//下午上班签到状态
  176. })
  177. // 控制今日签到信息和图表显示的状态
  178. const todayInfoShow = ref(true) // 今日签到信息是否显示
  179. const chartShow = ref(false) // 图表是否显示
  180. // 图表类型的响应式引用
  181. const chartsType = ref('')
  182. // 图表要填充的数据
  183. const chartData = ref({})
  184. // 图表配置选项
  185. const opts = ref({
  186. color: ["#EE6666", "#FAC858", "#FC8452", "#73C0DE", "#3CA272", "#1890FF", "#91CB74", "#9A60B4",
  187. "#ea7ccc"
  188. ], // 设定图表颜色
  189. padding: [15, 15, 0, 5],
  190. enableScroll: false, // 滚动
  191. legend: {}, // 图例设置
  192. xAxis: {
  193. disableGrid: true ,// 禁用网格线
  194. // scrollShow: true,
  195. },
  196. yAxis: {
  197. data: [{
  198. min: 0 // y轴最小值
  199. }]
  200. },
  201. extra: {
  202. column: {
  203. type: "group",
  204. width: 30,
  205. activeBgColor: "#000000",
  206. activeBgOpacity: 0.08
  207. }
  208. }
  209. });
  210. // 时间范围选择数组
  211. const timeRanges = ref(['日', '周', '月']);
  212. const selectedTimeRange = ref('日'); // 初始化选择的时间范围为“日”
  213. // 考勤相关统计数据
  214. const attendanceCount = ref(0); // 出勤次数
  215. const goOutCount = ref(0); // 外出次数
  216. const lateCount = ref(0); // 迟到次数
  217. const leaveEarlyCount = ref(0); // 早退次数
  218. const absenteeismCount = ref(0); // 缺勤次数
  219. //用户id
  220. const userId = userStore.user.useId; //拿到用户id
  221. //当前周的周一日期
  222. const thisMondayDate = ref('');
  223. const clockMultiple = ref(false)
  224. if(config.clock && config.clock == 'multiple'){
  225. clockMultiple.value = true;
  226. }else{
  227. clockMultiple.value = false;
  228. }
  229. onMounted(() => {
  230. initAttData(); //初始化日考勤数据
  231. });
  232. //初始化考勤数据
  233. function initAttData() {
  234. const nowDate = new Date();
  235. todayData.day = formatDate(nowDate);
  236. getthisMondayDate(nowDate);
  237. getDayAttData();
  238. initCalenderData();
  239. }
  240. //格式化日期
  241. function formatDate(date) {
  242. const year = date.getFullYear(); // 获取年份
  243. const month = date.getMonth() + 1; // 获取月份
  244. const day = date.getDate(); // 获取日期
  245. // 格式化月份和日期为两位数
  246. const formattedMonth = month < 10 ? '0' + month : month;
  247. const formattedDay = day < 10 ? '0' + day : day;
  248. return `${year}-${formattedMonth}-${formattedDay}`;
  249. }
  250. //获取日考勤数据
  251. function getDayAttData() {
  252. const params = {
  253. universalid: userId,
  254. rizi: todayData.day
  255. }
  256. checkAttendance(params).then(res => {
  257. if ("success" == res.returnMsg) {
  258. //数据初始化
  259. todayData.startTime = ''
  260. todayData.endTime = ''
  261. todayData.startTimePm = ''
  262. todayData.endTimeAm = ''
  263. todayData.startStatus=''
  264. todayData.endStatus=''
  265. todayData.startStatusForPm=''
  266. todayData.endStatusForAm=''
  267. if (res.returnParams.list.length == 0) {
  268. return
  269. }
  270. const attList = res.returnParams.list;
  271. let time1;
  272. let time2;
  273. let time3;
  274. let time4;
  275. const filteredRecord1 = attList.filter(item => item.att_type_id === '1');
  276. if (filteredRecord1.length > 0) {
  277. time1 = filteredRecord1.reduce((latest, current) => {
  278. const latestTime = new Date(latest.att_time);
  279. const currentTime = new Date(current.att_time);
  280. return (currentTime < latestTime) ? current : latest;
  281. });
  282. }
  283. //上午下班,取最大时间的那个
  284. const filteredRecord3 = attList.filter(item => item.att_type_id === '7');
  285. if (filteredRecord3.length > 0) {
  286. time3 = filteredRecord3.reduce((latest, current) => {
  287. const latestTime = new Date(latest.att_time);
  288. const currentTime = new Date(current.att_time);
  289. return (currentTime > latestTime) ? current : latest;
  290. });
  291. }
  292. //下午上班,取最小时间
  293. const filteredRecord4 = attList.filter(item => item.att_type_id === '8');
  294. if (filteredRecord4.length > 0) {
  295. time4 = filteredRecord4.reduce((latest, current) => {
  296. const latestTime = new Date(latest.att_time);
  297. const currentTime = new Date(current.att_time);
  298. return (currentTime < latestTime) ? current : latest;
  299. });
  300. }
  301. //拿到所有签退数据后,取最大时间的那个
  302. const filteredRecord2 = attList.filter(item => item.att_type_id === '2');
  303. if (filteredRecord2.length > 0) {
  304. time2 = filteredRecord2.reduce((latest, current) => {
  305. const latestTime = new Date(latest.att_time);
  306. const currentTime = new Date(current.att_time);
  307. return (currentTime > latestTime) ? current : latest;
  308. });
  309. }
  310. if (time1 !== undefined) {
  311. todayData.startTime = time1.att_time.split(' ')[1];
  312. if(subOneMinute(todayData.startTime)>=configStore.signInTimeRange[0][1]){
  313. todayData.startStatus='(迟到)'
  314. }
  315. }
  316. if (time3 !== undefined) {
  317. todayData.endTimeAm = time3.att_time.split(' ')[1];
  318. if(todayData.endTimeAm<configStore.signOutTimeRange[0][0]){
  319. todayData.endStatusForAm='(早退)'
  320. }
  321. }
  322. if (time4 !== undefined) {
  323. todayData.startTimePm = time4.att_time.split(' ')[1];
  324. if(subOneMinute(todayData.startTimePm)>=configStore.signInTimeRange[1][1]){
  325. todayData.startStatusForPm='(迟到)'
  326. }
  327. }
  328. if (time2 !== undefined) {
  329. todayData.endTime = time2.att_time.split(' ')[1];
  330. if(todayData.endTime<configStore.signOutTimeRange[1][0]){
  331. todayData.endStatus='(早退)'
  332. }
  333. }
  334. }
  335. })
  336. }
  337. //减一分钟
  338. function subOneMinute(timeStr) {
  339. // 将时间字符串转换为 Date 对象
  340. const [hours, minutes, seconds] = timeStr.split(':').map(Number);
  341. const date = new Date();
  342. date.setHours(hours, minutes, seconds, 0); // 设置时间为给定的时分秒
  343. // 减去一分钟
  344. date.setMinutes(date.getMinutes() - 1);
  345. return date.toTimeString().slice(0, 8);
  346. }
  347. //打卡历史记录(日历版)
  348. //日历表数据
  349. const calenderData = ref([])
  350. // 初始化此月日历数据
  351. function initCalenderData() {
  352. const params = {
  353. type: 2, //设置时间区间
  354. universalid: userId,
  355. ks_att_time: todayData.day.slice(0, 8) + '01',
  356. js_att_time: todayData.day,
  357. pSize: parseInt(todayData.day.slice(8, 10), 10),//当前天数
  358. p: 1
  359. }
  360. getCalenderData(params)
  361. }
  362. //日历数据的刷新
  363. function getCalenderData(params){
  364. getMyQDQtAttendance(params).then(({ returnParams }) => {
  365. //定义一个数组用于接收日历data
  366. const thisCalenderData=[]
  367. returnParams.list.forEach(item => {
  368. if ((!item.type.includes('1') || !item.type.includes('2'))&&item.att_date.slice(0, 10)!==todayData.day) {
  369. const calenderDataInfo = {
  370. date: item.att_date.slice(0, 10),
  371. info: '缺卡'
  372. }
  373. thisCalenderData.push(calenderDataInfo)
  374. }
  375. });
  376. calenderData.value=thisCalenderData
  377. })
  378. }
  379. const lackCardState=ref(false)//缺卡异常处理状态
  380. //日历点击日期切换事件
  381. function changeDate(e) {
  382. // console.log('changeDate: ',e);
  383. // console.log("3:calenderData.value " + JSON.stringify(calenderData.value));
  384. if(config.companyCode && config.companyCode == 'yg'){
  385. lackCardState.value = !!e.extraInfo.info;//!!转布尔值
  386. }
  387. todayData.day = e.fulldate
  388. getDayAttData()
  389. }
  390. //补卡页面跳转
  391. function toBuKa(){
  392. const bukaType=todayData.startTime?'下班':'上班'
  393. getProcessList(userStore.user.useId, userStore.user.unitId).then(res => {
  394. const { modelName, modelId, control } = res.returnParams.fList.find(item => item.modelName === "补卡申请")
  395. $tab.navigateTo('/pages/work/edit/index?modelName=' + modelName + '&modelId=' + modelId + '&control=' + control+'&bukaDate='+todayData.day+'&bukaType='+bukaType)
  396. })
  397. // $tab.switchTab('/pages/work/index?bukaDate='+todayData.day+'&bukaType='+bukaType)
  398. }
  399. //传入年份月份,返回此月天数
  400. function getDaysInMonth(year, month) {
  401. const date = new Date(year, month - 1, 1);
  402. // 将日期设置为下一个月的第0天,即当前月的最后一天
  403. date.setMonth(date.getMonth() + 1);
  404. date.setDate(0);
  405. // 返回当前月的最后一天的日期,即该月的天数
  406. return date.getDate();
  407. }
  408. //月份切换事件
  409. function monthSwitch(e) {
  410. const days=getDaysInMonth(e.year,e.month);
  411. //月份小于10前面补零
  412. const month = String(e.month).padStart(2, '0');
  413. const params = {
  414. type: 2, //设置时间区间
  415. universalid: userId,
  416. ks_att_time: e.year+'-'+month+'-' + '01',
  417. js_att_time: e.year+'-'+month+'-' +days,
  418. pSize: days,
  419. p: 1
  420. }
  421. getCalenderData(params);
  422. }
  423. // //打卡历史记录(下拉刷新版)
  424. // const paging = ref(null)
  425. // const pSize = ref(5)
  426. // function complete(list, total, pageNo) {
  427. // if (pageNo == 1) {
  428. // paging.value.complete(list);
  429. // return
  430. // }
  431. // // 防止重复获取最后一次信息
  432. // if (pSize.value * pageNo < total) {
  433. // paging.value.complete(list)
  434. // } else {
  435. // paging.value.complete([])
  436. // }
  437. // }
  438. // //日考勤历史记录
  439. // const clockRecords = ref([])
  440. // const totalPage = ref(0)
  441. // //获取日考勤历史(下拉刷新)
  442. // function getDayAttHistory() {
  443. // const params = {
  444. // type: 1, //不设时间区间
  445. // universalid: userId,
  446. // ks_att_time: '',
  447. // js_att_time: '',
  448. // pSize: pSize.value,
  449. // p: 1
  450. // }
  451. // getMyQDQtAttendance(params).then(({ returnParams }) => {
  452. // totalPage.value = Math.ceil(returnParams.total / pSize.value)
  453. // const list = returnParams.list.map(item => {
  454. // return {
  455. // date: item.att_date.substring(0, 10),
  456. // morning: item.time.split(',')[item.type.split(',').indexOf("1")],
  457. // evening: item.time.split(',')[item.type.split(',').indexOf("2")],
  458. // }
  459. // });
  460. // clockRecords.value = list;
  461. // complete(clockRecords.value, returnParams.total, returnParams.current)
  462. // })
  463. // }
  464. // // 刷新
  465. // function queryData(pageNo, pSize, queryType) {
  466. // switch (queryType) {
  467. // case 0: // 下拉刷新
  468. // case 1: // 初始加载
  469. // getDayAttHistory()
  470. // break
  471. // case 3: // 上拉加载
  472. // scrollQuery(pageNo, pSize)
  473. // break
  474. // default: // 默认刷新
  475. // getDayAttHistory()
  476. // break
  477. // }
  478. // }
  479. // //上拉加载事件
  480. // function scrollQuery(pageNo, pSize) {
  481. // const params = {
  482. // type: 1, //不设时间区间
  483. // universalid: userId,
  484. // ks_att_time: '',
  485. // js_att_time: '',
  486. // pSize: pSize,
  487. // p: pageNo
  488. // }
  489. // getMyQDQtAttendance(params).then(({ returnParams }) => {
  490. // const list = returnParams.list.map(item => {
  491. // return {
  492. // date: item.att_date.substring(0, 10),
  493. // morning: item.time.split(',')[item.type.split(',').indexOf("1")],
  494. // evening: item.time.split(',')[item.type.split(',').indexOf("2")],
  495. // }
  496. // });
  497. // if (pageNo <= totalPage.value) {
  498. // clockRecords.value.push(...list);
  499. // }
  500. // complete(list, returnParams.total, pageNo)
  501. // })
  502. // }
  503. // 日周月时间范围切换事件
  504. function onTimeRangeChange(event) {
  505. const selectedIndex = event.detail.value;
  506. selectedTimeRange.value = timeRanges.value[selectedIndex]; // 设置选择的时间范围(日周月)
  507. // 根据选择的时间范围更新展示内容
  508. switch (selectedTimeRange.value) {
  509. case '日':
  510. getDayAttData();
  511. showDay(); // 显示今日考勤
  512. break;
  513. case '周':
  514. chartsType.value = 'pie'; // 设置图表类型为饼图
  515. fetchWeekAttData().then(message => {
  516. // console.log(message);
  517. showWeekAndMonth();
  518. updateChart(message);
  519. })
  520. .catch(error => {
  521. console.error(error);
  522. });
  523. break;
  524. case '月':
  525. chartsType.value = 'column'; // 设置图表类型为柱状图
  526. fetchMonthAttData();
  527. showWeekAndMonth();
  528. // fetchMonthAttData().then(message => {
  529. // console.log('message', message);
  530. // showWeekAndMonth();
  531. // updateChart(message);
  532. // })
  533. // .catch(error => {
  534. // console.error(error);
  535. // });
  536. break;
  537. }
  538. };
  539. // 显示今日考勤数据
  540. function showDay() {
  541. todayInfoShow.value = true; // 显示今日签到信息
  542. chartShow.value = false; // 隐藏图表
  543. }
  544. // 显示周或者月考勤
  545. function showWeekAndMonth() {
  546. todayInfoShow.value = false; // 隐藏今日签到信息
  547. chartShow.value = true; // 显示图表
  548. }
  549. //计算本周周一日期
  550. function getthisMondayDate(today) {
  551. const dayOfWeek = today.getDay(); // 0 (周日) 到 6 (周六)
  552. const dayOfMonth = today.getDate();
  553. // 计算本周周一的日期
  554. const offset = dayOfWeek === 0 ? -6 : 1; // 如果今天是周日,则偏移量为-6,否则为1
  555. const thisMonday = new Date(today);
  556. thisMonday.setDate(dayOfMonth - dayOfWeek + offset);
  557. thisMondayDate.value = formatDate(thisMonday);
  558. }
  559. //获取周考勤记录
  560. function fetchWeekAttData() {
  561. return new Promise((resolve, reject) => {
  562. const params = {
  563. staffId: userId,
  564. start_date: thisMondayDate.value,
  565. end_date: todayData.day
  566. }
  567. getMyTotalCount(params).then(res => {
  568. const myWeekAttData = res.returnParams;
  569. const mockData = {
  570. series: [{
  571. data: [
  572. {
  573. "name": "缺勤",
  574. "value": myWeekAttData.type6,
  575. "labelText": "缺勤:" + myWeekAttData.type6 + "次"
  576. },
  577. {
  578. "name": "迟到",
  579. "value": myWeekAttData.type4,
  580. "labelText": "迟到:" + myWeekAttData.type4 + "次"
  581. },
  582. {
  583. "name": "早退",
  584. "value": myWeekAttData.type5,
  585. "labelText": "早退:" + myWeekAttData.type5 + "次"
  586. },
  587. {
  588. "name": "出勤",
  589. "value": myWeekAttData.attDays,
  590. "labelText": "出勤:" + myWeekAttData.attDays + "次"
  591. },
  592. {
  593. "name": "外出",
  594. "value": myWeekAttData.type2,
  595. "labelText": "外出:" + myWeekAttData.type2 + "次"
  596. },
  597. {
  598. "name": "公休",
  599. "value": myWeekAttData.type1,
  600. "labelText": "公休:" + myWeekAttData.type1 + "次"
  601. },
  602. // {
  603. // "name": "未排班",
  604. // "value": myWeekAttData.type3,
  605. // "labelText": "未排班:" + myWeekAttData.type3 + "次"
  606. // }
  607. ]
  608. }],
  609. };
  610. // const weekData = mockData.series[0].data;
  611. attendanceCount.value = myWeekAttData.attDays;
  612. goOutCount.value = myWeekAttData.type2;
  613. lateCount.value = myWeekAttData.type4;
  614. leaveEarlyCount.value = myWeekAttData.type5;
  615. absenteeismCount.value = myWeekAttData.type6;
  616. resolve(mockData)
  617. }).catch(error => {
  618. reject(error)
  619. })
  620. })
  621. }
  622. // 获取月考勤记录
  623. function fetchMonthAttData() {
  624. //数据初始化
  625. attendanceCount.value = 0;
  626. goOutCount.value = 0;
  627. lateCount.value = 0;
  628. leaveEarlyCount.value = 0;
  629. absenteeismCount.value = 0;
  630. const params = {
  631. staffId: userId,
  632. now_date: todayData.day
  633. }
  634. getMyTotalMonthCount(params).then(res=>{
  635. const myMonthAttData = res.returnParams;
  636. let data1 = []; // 收集 type6 的值
  637. let data2 = []; // 收集 type4 的值
  638. let data3 = []; // 收集 type5 的值
  639. // console.log('attendanceCount: ',attendanceCount.value);
  640. // 遍历 myMonthAttData 并收集指定类型的值
  641. myMonthAttData.forEach(item => {
  642. data1.push(item.type6);
  643. data2.push(item.type4);
  644. data3.push(item.type5);
  645. attendanceCount.value += item.attDays;
  646. goOutCount.value += item.type2;
  647. lateCount.value += item.type4;
  648. leaveEarlyCount.value += item.type5;
  649. absenteeismCount.value += item.type6;
  650. });
  651. // 定义一个常量数组生成器
  652. const generateWeekArray = n => Array.from({ length: n }, (_, i) => `第${i + 1}周`);
  653. let categoriesArr=generateWeekArray(myMonthAttData.length)
  654. // console.log(categoriesArr);
  655. const mockData = {
  656. categories:  categoriesArr,
  657. series: [{
  658. name: "缺勤",
  659. data: data1
  660. }, {
  661. name: "迟到",
  662. data: data2
  663. }, {
  664. name: "早退",
  665. data: data3
  666. }]
  667. };
  668. updateChart(mockData)
  669. })
  670. }
  671. // //获取六天前的日期
  672. // function getSixDaysAgo(dateStr) {
  673. // const date = new Date(dateStr);
  674. // date.setDate(date.getDate() - 6);
  675. // return date.toISOString().split('T')[0]; // 返回格式为'YYYY-MM-DD'的字符串
  676. // }
  677. // //获取一天前的日期
  678. // function getOneDaysAgo(dateStr) {
  679. // const date = new Date(dateStr);
  680. // date.setDate(date.getDate() - 1);
  681. // return date.toISOString().split('T')[0]; // 返回格式为'YYYY-MM-DD'的字符串
  682. // }
  683. // 更新图表数据
  684. function updateChart(res) {
  685. chartData.value = JSON.parse(JSON.stringify(res)); // 更新图表数据
  686. }
  687. </script>
  688. <style lang="scss" scoped>
  689. // @import "@/static/font/ygoa/iconfont.css";
  690. .ygoa_icon {
  691. margin-right: 0.5rem;
  692. font-size: calc(2rem + 0px) !important;
  693. vertical-align: middle;
  694. /* 确保图标与文本竖直居中 */
  695. }
  696. .attendance-page {
  697. padding: 20px;
  698. background-color: #f9f9f9;
  699. ::v-deep .calendar-content {
  700. margin: -20px;
  701. margin-top: 20px;
  702. .uni-calendar__header {
  703. .uni-calendar__header-text {
  704. font-size: calc(14px + .5*(1rem - 16px)) !important;
  705. }
  706. .uni-calendar__backtoday {
  707. padding: 2px 8px 2px 10px !important;
  708. font-size: calc(0.75rem + 0px) !important;
  709. }
  710. }
  711. .uni-calendar__box {
  712. .uni-calendar__weeks {
  713. .uni-calendar__weeks-day {
  714. .uni-calendar__weeks-day-text {
  715. font-size: calc(14px + .5*(1rem - 16px)) !important;
  716. }
  717. }
  718. .uni-calendar__weeks-item {
  719. .uni-calendar-item__weeks-box-item {
  720. .uni-calendar-item__weeks-box-circle {
  721. width: calc(8px + .5*(1rem - 16px)) !important;
  722. height: calc(8px + .5*(1rem - 16px)) !important;
  723. top: calc(5px - .25*(1rem - 16px)) !important;
  724. right: calc(5px - .25*(1rem - 16px)) !important;
  725. }
  726. .uni-calendar-item__weeks-box-text {
  727. font-size: calc(14px + .5*(1rem - 16px)) !important;
  728. }
  729. .uni-calendar-item__weeks-lunar-text {
  730. font-size: calc(12px + .5*(1rem - 16px)) !important;
  731. }
  732. }
  733. }
  734. }
  735. }
  736. }
  737. }
  738. .header {
  739. display: flex;
  740. justify-content: space-between;
  741. align-items: center;
  742. margin-bottom: 20px;
  743. .clockRecordTitle {
  744. font-size: calc(1.25rem + 0px) !important;
  745. margin: auto;
  746. }
  747. }
  748. .title {
  749. font-size: calc(1.5rem + 0px) !important;
  750. font-weight: bold;
  751. color: #333;
  752. }
  753. .picker {
  754. border: 1px solid #3498db;
  755. border-radius: 5px;
  756. padding: 10px;
  757. background-color: #ecf6fc;
  758. color: #3498db;
  759. }
  760. .statistics {
  761. // display: flex;
  762. justify-content: center;
  763. }
  764. .statistic-card {
  765. background: white;
  766. border-radius: 10px;
  767. padding: 20px;
  768. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  769. /* width: 100%; */
  770. max-width: 600px;
  771. }
  772. .statistic-title {
  773. text-align: center;
  774. font-size: calc(1.25rem + 0px) !important;
  775. font-weight: bold;
  776. color: #333;
  777. }
  778. .statistic-item {
  779. display: flex;
  780. justify-content: space-between;
  781. border-bottom: 1px solid #eee;
  782. padding: 10px 0;
  783. }
  784. .label {
  785. color: #666;
  786. }
  787. .value {
  788. font-size: calc(1.125rem + 0px) !important;
  789. font-weight: bold;
  790. line-height: calc(2rem + 0px) !important;
  791. color: #333;
  792. }
  793. .label {
  794. font-size: calc(1rem + 0px) !important;
  795. line-height: calc(2rem + 0px) !important;
  796. }
  797. .chart-container {
  798. margin-top: 20px;
  799. }
  800. .chart-title {
  801. font-size: calc(1.25rem + 0px) !important;
  802. font-weight: bold;
  803. text-align: center;
  804. margin-bottom: 10px;
  805. color: #333;
  806. }
  807. .charts-box {
  808. width: 100%;
  809. height: 300px;
  810. }
  811. .todayCheckIn {
  812. background-color: #ffffff;
  813. padding: 20px;
  814. margin: auto -20px; //抵消父级padding
  815. box-sizing: border-box;
  816. border-radius: 10px;
  817. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  818. }
  819. .check-in-container {
  820. width: 100%;
  821. height: 100%;
  822. display: flex;
  823. flex-direction: column;
  824. align-items: center;
  825. justify-content: center;
  826. position: relative;
  827. .exceptionText{
  828. position: absolute;
  829. top: 10px;
  830. right: 10px;
  831. color: blue;
  832. text-decoration: underline;
  833. }
  834. }
  835. .todayAttTitle {
  836. font-size: calc(1.375rem + 0px) !important;
  837. font-weight: bold;
  838. margin-bottom: 20px;
  839. }
  840. .info-row {
  841. width: 100%;
  842. display: flex;
  843. align-items: center;
  844. justify-content: space-between;
  845. margin-bottom: 10px;
  846. .att_status{
  847. color: red;
  848. }
  849. }
  850. .icon {
  851. width: 50rpx;
  852. height: 50rpx;
  853. margin-right: 20rpx;
  854. vertical-align: middle;
  855. /* 确保图标与文本竖直居中 */
  856. }
  857. .clockRecord {
  858. margin-bottom: 20px;
  859. padding: 10px;
  860. border: 1px solid #ccc;
  861. border-radius: 8px;
  862. }
  863. .date {
  864. font-size: 16px;
  865. font-weight: bold;
  866. margin-bottom: 5px;
  867. }
  868. .name {
  869. font-size: 14px;
  870. color: #666;
  871. margin-bottom: 10px;
  872. }
  873. .divider {
  874. border-bottom: 5px dashed #ccc; //虚线
  875. margin: 10px 0;
  876. }
  877. .shift-label {
  878. font-size: 14px;
  879. color: #333;
  880. }
  881. .shift-time {
  882. font-size: 14px;
  883. color: #333;
  884. }
  885. </style>