index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <!-- 考勤统计(日历) -->
  3. <view class="attend-statistics">
  4. <u-navbar :placeholder="true" title="考勤统计" :autoBack="true">
  5. <template slot="right">
  6. <view @click="toggleType" class="dflex acenter">
  7. <image
  8. class="nav-right-icon"
  9. src="@/static/images/statistics/month.png"
  10. ></image>
  11. </view>
  12. </template>
  13. </u-navbar>
  14. <view class="content">
  15. <!-- 日历-->
  16. <view class="scroll-main">
  17. <view class="c-box">
  18. <view class="calendar-box">
  19. <uni-calendar
  20. class="uni-calendar--hook"
  21. :selected="selected"
  22. :date="selectDay.fulldate"
  23. :showMonth="false"
  24. @change="handleChange"
  25. @monthSwitch="monthSwitch"
  26. />
  27. </view>
  28. <view class="mt-10">
  29. <detailSteps
  30. :selectDay="selectDay"
  31. :key="detailsInfo.resultId"
  32. :detailsInfo="detailsInfo"
  33. ></detailSteps>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="footer">
  38. <c-button @click="goClock">
  39. <view class="dflex acenter">
  40. <image
  41. class="btn-icon"
  42. src="@/static/images/attendanceClock/clock-gray.png"
  43. ></image>
  44. 打卡
  45. </view>
  46. </c-button>
  47. <c-button type="primary">
  48. <view class="dflex acenter">
  49. <image
  50. class="btn-icon"
  51. src="@/static/images/attendanceClock/statistics-bai.png"
  52. ></image>
  53. 统计
  54. </view>
  55. </c-button>
  56. </view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import {
  62. getCalendarData,
  63. getStatistics,
  64. } from '@/api/attendanceClock/index.js';
  65. import detailSteps from '@/pages/attendanceClock/com/detail-steps.vue'; // 在考勤组
  66. export default {
  67. name: 'attendStatistics',
  68. components: {
  69. detailSteps,
  70. },
  71. data() {
  72. return {
  73. detailsInfo: {},
  74. selectMonth: '', // 选择的月份
  75. selectDay: {}, // 选择的天
  76. selected: [],
  77. };
  78. },
  79. onLoad() {
  80. const _date = new Date();
  81. this.selectMonth = uni.$u.timeFormat(_date, 'yyyy-mm');
  82. const today = uni.$u.timeFormat(new Date(), 'yyyy-mm-dd');
  83. this.selectDay = { fulldate: today }; // 选择的天
  84. this.getDetailData();
  85. },
  86. methods: {
  87. async getDetailData() {
  88. const data = await this.getDetailList(); // 根据月查询
  89. const today = uni.$u.timeFormat(new Date(), 'yyyy-mm-dd');
  90. const item = data.find((item) => item.numDate === today);
  91. this.selectDay = { ...item, fulldate: today };
  92. await this.getDayInfo(); // 根据日查询
  93. },
  94. toggleType() {
  95. uni.redirectTo({
  96. url: '/pages/attendanceClock/statistics/monthlyStatistics/index',
  97. });
  98. },
  99. goClock() {
  100. uni.redirectTo({ url: '/pages/attendanceClock/index' });
  101. },
  102. async getDetailList() {
  103. try {
  104. uni.$c.loading();
  105. const date = uni.$u.timeFormat(this.selectMonth, 'yyyy-mm');
  106. const { data } = await getCalendarData(date);
  107. uni.hideLoading();
  108. const types = {
  109. 0: 'success',
  110. 1: 'error',
  111. };
  112. this.selected = (data || []).map((item) => ({
  113. ...item,
  114. date: item.numDate,
  115. type: types[item.isNormal], //0正常 1异常
  116. }));
  117. return data;
  118. } catch (e) {
  119. uni.hideLoading();
  120. throw new Error(e);
  121. }
  122. },
  123. monthSwitch(e) {
  124. // 切换年月触发
  125. this.selectMonth = `${e.year}-${uni.$u.padZero(e.month)}`;
  126. this.getDetailList();
  127. },
  128. handleChange(e) {
  129. // 点击item触发
  130. this.selectDay = { ...e.extraInfo, fulldate: e.fulldate };
  131. this.getDayInfo();
  132. },
  133. async getDayInfo() {
  134. console.log(this.selectDay, 'selectDay');
  135. try {
  136. this.$c.loading();
  137. const { data } = await getStatistics(this.selectDay.fulldate);
  138. this.detailsInfo = data || {};
  139. uni.hideLoading();
  140. } catch (e) {
  141. uni.hideLoading();
  142. throw new Error(e);
  143. }
  144. },
  145. },
  146. };
  147. </script>
  148. <style scoped lang="scss">
  149. .attend-statistics {
  150. display: flex;
  151. flex-direction: column;
  152. .content {
  153. flex: 1;
  154. display: flex;
  155. flex-direction: column;
  156. .scroll-main {
  157. flex: 1;
  158. overflow-y: auto;
  159. position: relative;
  160. .c-box {
  161. position: absolute;
  162. width: 100%;
  163. top: 0;
  164. left: 0;
  165. padding: 30rpx;
  166. .calendar-box {
  167. background-color: #fff;
  168. border-radius: 6px;
  169. overflow: hidden;
  170. }
  171. }
  172. }
  173. .footer {
  174. display: flex;
  175. margin-bottom: 20rpx;
  176. .c-button {
  177. flex: 1;
  178. }
  179. .btn-icon {
  180. width: 32rpx;
  181. height: 32rpx;
  182. margin-right: 5px;
  183. }
  184. }
  185. }
  186. }
  187. .nav-right-icon {
  188. width: 23px;
  189. height: 26px;
  190. }
  191. </style>