clockstats.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <view class="page_view">
  3. <top-return text="打卡详情" color="#FFF"></top-return>
  4. <!-- 背景 -->
  5. <view class="bg_card"></view>
  6. <!-- 月统计卡片信息 -->
  7. <view class="card_view" style="margin-top: 140rpx;">
  8. <view class="card_item" style="width: 100%;">
  9. <view class="card_title" style="margin:10rpx 0 0 10rpx;">
  10. <!-- <view class="box_tag"></view> -->
  11. <view class="title">{{currentTodayData.month}}月 打卡汇总</view>
  12. </view>
  13. <view class="flex_row" style="justify-content: space-around;height: 180rpx;margin-bottom: 20rpx;">
  14. <view class="flex_cloumn" style="align-items: center;">
  15. <view class="number" style="color: #4169E1;">{{isClockStats}}</view>
  16. <view class="number-detail">打卡次数</view>
  17. </view>
  18. <view class="flex_cloumn" style="align-items: center;">
  19. <view class="number" style="color: #ff5959;">{{noClockStats}}</view>
  20. <view class="number-detail">缺卡次数</view>
  21. </view>
  22. <view class="flex_cloumn" style="align-items: center;">
  23. <view class="number"
  24. :style="{color: clockStatsQuality==='优秀'?'#4169E1':(clockStatsQuality === '较差'?'#ff5959':'#f9c752')}">
  25. {{clockStatsQuality}}
  26. </view>
  27. <view class="number-detail">出勤质量</view>
  28. </view>
  29. </view>
  30. </view>
  31. <!-- 打卡记录日历 -->
  32. <view class="card_item" style="width: 100%;">
  33. <view class="calendar_container">
  34. <zsyCalendar :sundayIndex="6" @chooseDate="chooseDate" @change="change" />
  35. </view>
  36. <view class="state-box">
  37. <view class="state"
  38. :style="{backgroundColor: clockState==='已打卡'?'#4169E1':(clockState === '未打卡'?'#ff5959':'#bebebe')}">
  39. <view class="state-text">{{clockState}}</view>
  40. </view>
  41. <view class="msg-box">
  42. <view class="flex">
  43. <text class="msg-text" style="font-weight: normal;font-size: 28rpx;">打卡时间:</text>
  44. <text class="msg-text">{{clockTime.replace('0','')}}</text>
  45. </view>
  46. <view class="flex">
  47. <text class="msg-text" style="font-weight: normal;font-size: 28rpx;">出勤效率:</text>
  48. <text class="msg-text"
  49. :style="{color: clockQuality==='优秀'?'#4169E1':(clockQuality === '良好'?'#f9c752':'#3B4144')}">{{clockQuality}}</text>
  50. </view>
  51. </view>
  52. <!-- 图片信息 -->
  53. <view class="image" v-if="currentTodayData.isAttend === 1"
  54. :style="{backgroundImage:`url(${imageWorkday})`}"></view>
  55. <view class="image" v-if="currentTodayData.isAttend === 7"
  56. :style="{backgroundImage:`url(${imageWeekend})`}"></view>
  57. <view class="image" v-if="currentTodayData.isAttend === 0"
  58. :style="{backgroundImage:`url(${imageNoAttend})`}"></view>
  59. <view class="image" v-if="currentTodayData.isAttend === -1"
  60. :style="{backgroundImage:`url(${imageNoArrive})`}"></view>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. import {
  68. mapState
  69. } from 'vuex'
  70. import zsyCalendar from '@/components/z-calendar/zsy-calendar.vue'
  71. export default {
  72. name: 'Calendar',
  73. components: {
  74. zsyCalendar
  75. },
  76. computed: {
  77. ...mapState('m_children', ['clockData']),
  78. },
  79. data() {
  80. return {
  81. //月打卡统计数据
  82. isClockStats: '',
  83. noClockStats: '',
  84. clockStatsQuality: '',
  85. //日打卡数据
  86. clockState: '',
  87. clockTime: '',
  88. clockQuality: '',
  89. //日历月份
  90. calendarMonth: '',
  91. //点击当日信息
  92. currentTodayData: '',
  93. //控制事件参数
  94. isFirst: false,
  95. //当日时间参数
  96. todayData: '',
  97. //图片
  98. imageWorkday: 'https://ouch-cdn2.icons8.com/z39mAYlsJUS2hKCBbkK_ktOIjma_qhkc5J0ANdyfiKU/rs:fit:912:912/czM6Ly9pY29uczgu/b3VjaC1wcm9kLmFz/c2V0cy9zdmcvMTA3/L2FlZjQ4NmM4LTAz/NTYtNGRhNS04ZWQ2/LTBhMGIzMzdhZjNm/Mi5zdmc.png',
  99. imageWeekend: 'https://ouch-cdn2.icons8.com/NJDdGibHzZkGZzgqe55ESzJ6_BrcgHO2bkz_vFG6PoY/rs:fit:912:912/czM6Ly9pY29uczgu/b3VjaC1wcm9kLmFz/c2V0cy9zdmcvNTg2/L2RlMmJhZDI4LTAz/NTQtNDMwNS1hNmQ2/LTU3Y2Y1ODJjNjc3/YS5zdmc.png',
  100. imageNoAttend: 'https://ouch-cdn2.icons8.com/ehPeP69ypvrLonk6YkqIzV_WfKM1G-Ls9J7PuZvxRr8/rs:fit:912:912/czM6Ly9pY29uczgu/b3VjaC1wcm9kLmFz/c2V0cy9zdmcvMzY3/L2QzZGNmODA5LTY3/ODUtNGFkOC1hOWVi/LWI4OWYyM2ZiMzNi/Yi5zdmc.png',
  101. imageNoArrive: 'https://ouch-cdn2.icons8.com/WfSBIzy4iTGDtprvhW0wA2S8lPNRoqeZqvFsNbKsraw/rs:fit:912:912/czM6Ly9pY29uczgu/b3VjaC1wcm9kLmFz/c2V0cy9zdmcvODQ3/LzI1NDY1ZDdhLTVj/NDEtNGIzMy1iN2Q1/LTRhYjgwOGU2NDk5/OS5zdmc.png'
  102. }
  103. },
  104. watch: {
  105. calendarMonth() {
  106. this.getClockStatsQuality()
  107. }
  108. },
  109. onLoad() {
  110. this.init()
  111. },
  112. methods: {
  113. init() {
  114. this.getClockStatsQuality()
  115. this.getTodayAttendance()
  116. },
  117. //判断本月出勤质量
  118. getClockStatsQuality() {
  119. this.clockStatsQuality = this.noClockStats / 30 <= 0.1 ? '优秀' : (this.noClockStats / 30 <= 0.2 ? '良好' :
  120. '较差')
  121. if (this.noClockStats === '暂无' && this.isClockStats === '暂无') {
  122. this.clockStatsQuality = '暂无'
  123. }
  124. },
  125. //今日打卡
  126. getTodayAttendance() {
  127. //获得当前时间时间戳
  128. let timeArr = (new Date()).format("yyyy-M-dd").split("-")
  129. let val = this.clockData.filter(x => x.year == timeArr[0] && x.month == timeArr[1] && x.date == timeArr[2])
  130. if (val.length === 0) {
  131. //出勤状况
  132. this.clockState = '未打卡',
  133. //打卡时间
  134. this.clockTime = '无记录',
  135. //出勤质量
  136. this.clockQuality = '无记录'
  137. } else {
  138. this.clockState = '已打卡'
  139. this.clockTime = val[0].time
  140. this.clockQuality = val[0].time <= '08:15' ? '优秀' : (val[0].time <= '08:25' ? '良好' : '较差')
  141. }
  142. },
  143. //选择日期
  144. chooseDate(dateInfo, dateIndex) {
  145. if (dateInfo.isAttend === 1) {
  146. this.clockState = '已打卡'
  147. this.clockTime = this.clockData.filter(x => x.date === dateInfo.date && x.month === dateInfo
  148. .month && x.year === x.year)[0].time
  149. this.clockQuality = this.clockTime <= '08:15' ? '优秀' : (this.clockTime <= '08:25' ?
  150. '良好' : '较差')
  151. }
  152. if (dateInfo.isAttend === 0) {
  153. this.clockState = '未打卡'
  154. this.clockTime = '无记录'
  155. this.clockQuality = '无记录'
  156. }
  157. if (dateInfo.isAttend === -1) {
  158. this.clockState = '时间未到'
  159. this.clockTime = '无记录'
  160. this.clockQuality = '无记录'
  161. }
  162. if (dateInfo.isAttend === 7) {
  163. this.clockState = '周末休息'
  164. this.clockTime = '无记录'
  165. this.clockQuality = '无记录'
  166. }
  167. },
  168. //选中日期改变回调
  169. change(e) {
  170. //存入当前时间
  171. if (this.isFirst === false) {
  172. this.todayData = e
  173. this.isFirst = true
  174. }
  175. //点击当日信息
  176. this.currentTodayData = e
  177. console.log("日历点击",this.currentTodayData);
  178. //日历月份
  179. this.calendarMonth = e.month
  180. //当前日历月份打卡数
  181. this.isClockStats = this.clockData.filter(x => x.month === e.month && x.year === e.year).length
  182. // 当前日历月天数
  183. let monthDays = new Date(e.year, e.month, 0).getDate()
  184. //在本年当前月之前
  185. if (e.year === this.todayData.year && e.month < this.todayData.month) {
  186. let weekendDates = 0
  187. for (let i = 1; i <= monthDays; i++) {
  188. if (new Date(`${e.year}-${e.month}-${i}`).getDay() === 0 ||
  189. new Date(`${e.year}-${e.month}-${i}`).getDay() === 6) {
  190. weekendDates++
  191. }
  192. }
  193. //当前日历月份未打卡数
  194. this.noClockStats = monthDays - this.isClockStats - weekendDates
  195. }
  196. //之前年份
  197. if (e.year < this.todayData.year) {
  198. let weekendDates = 0
  199. for (let i = 1; i <= monthDays; i++) {
  200. if (new Date(`${e.year}-${e.month}-${i}`).getDay() === 0 ||
  201. new Date(`${e.year}-${e.month}-${i}`).getDay() === 6) {
  202. weekendDates++
  203. }
  204. }
  205. //当前日历月份未打卡数
  206. this.noClockStats = monthDays - this.isClockStats - weekendDates
  207. }
  208. //在本月
  209. if (e.year === this.todayData.year && e.month === this.todayData.month) {
  210. let weekendDates = 0
  211. for (let i = 1; i <= this.todayData.date; i++) {
  212. if (new Date(`${e.year}-${e.month}-${i}`).getDay() === 0 ||
  213. new Date(`${e.year}-${e.month}-${i}`).getDay() === 6) {
  214. weekendDates++
  215. }
  216. }
  217. this.noClockStats = this.todayData.date - this.isClockStats - weekendDates
  218. }
  219. //在本年当月之后
  220. if (e.year === this.todayData.year && e.month > this.todayData.month) {
  221. this.noClockStats = '暂无'
  222. this.isClockStats = '暂无'
  223. }
  224. //之后年份
  225. if (e.year > this.todayData.year) {
  226. this.noClockStats = '暂无'
  227. this.isClockStats = '暂无'
  228. }
  229. },
  230. }
  231. }
  232. </script>
  233. <style lang="scss">
  234. .number {
  235. font-size: 50rpx;
  236. font-weight: bold;
  237. color: $title;
  238. }
  239. .number-detail {
  240. margin-top: 10rpx;
  241. font-size: 30rpx;
  242. color: $subtitle;
  243. }
  244. .state-box {
  245. display: flex;
  246. align-items: center;
  247. height: 200rpx;
  248. width: 100%;
  249. .state {
  250. display: flex;
  251. align-items: center;
  252. justify-content: center;
  253. border-radius: 100%;
  254. margin: 20rpx;
  255. height: 150rpx;
  256. width: 150rpx;
  257. .state-text {
  258. font-size: 32rpx;
  259. font-weight: bold;
  260. color: #FFF;
  261. }
  262. }
  263. .msg-box {
  264. display: flex;
  265. flex-direction: column;
  266. justify-content: space-around;
  267. height: 150rpx;
  268. width: auto;
  269. .msg-text {
  270. color: $title;
  271. font-weight: bold;
  272. font-size: 36rpx;
  273. margin-left: 15rpx;
  274. }
  275. }
  276. }
  277. .calendar_container {
  278. height: 100%;
  279. width: 100%;
  280. background-color: #FFF;
  281. margin: 0 auto;
  282. box-sizing: border-box;
  283. border-radius: $border-radius;
  284. }
  285. .image {
  286. margin-left: auto;
  287. margin-right: 20rpx;
  288. width: 200rpx;
  289. height: 200rpx;
  290. border-radius: $border-radius;
  291. background-size: 100%;
  292. background-repeat: no-repeat;
  293. }
  294. .box_tag{
  295. margin-right: 20rpx;
  296. height: 100%;
  297. width: 10rpx;
  298. background-color: $title;
  299. z-index: 99;
  300. }
  301. </style>