calendar.vue 10 KB

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