index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <view class="box">
  3. <div class="week">
  4. <div class="w_pre" v-for="(pre,idx) in weekList" :key="idx">{{pre}}</div>
  5. </div>
  6. <div class="date">
  7. <div class="d_pre" v-for="(pre,idx) in calendarList" :key="idx" @tap="selectDay(pre,idx)">
  8. <div class="day" :class="{'dq':pre.iscurrentday,'select':pre.select,'wd':pre.isweekday}">{{pre.day}}</div>
  9. <div class="status" :class="{'zc':pre.status===0,'yc':pre.status===1}" v-if="pre.status<2"></div>
  10. </div>
  11. </div>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. data(){
  17. return {
  18. weekList:['一','二','三','四','五','六','日'],
  19. year:new Date().getFullYear(),
  20. month:new Date().getMonth()+1,
  21. calendarList:[],
  22. clockList:[]
  23. }
  24. },
  25. // created() {
  26. // this.getDataByMonth(this.year,this.month);
  27. // },
  28. methods:{
  29. getDataByMonth(year,month){
  30. const daysInMonth = new Date(year, month, 0).getDate();
  31. let calendar = [];
  32. for (let day = 1; day <= daysInMonth; day++) {
  33. let date = new Date(year, month - 1, day); // 注意月份从0开始
  34. let nyr = `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
  35. calendar.push({
  36. nyr,
  37. year,
  38. month,
  39. day,
  40. week: date.getDay()||7,
  41. isweekday:(date.getDay()||7)<6,
  42. iscurrentday:nyr==new Date().Format('yyyy-MM-dd')
  43. });
  44. }
  45. let qlist = this.insertDays(year,month,calendar);
  46. let hlist = this.appendDays(year,month,calendar);
  47. let list = qlist.concat(calendar).concat(hlist);
  48. this.calendarList = JSON.parse(JSON.stringify(list));
  49. this.calendarList.forEach((c,i)=>{
  50. this.$set(this.calendarList[i],'select',false);
  51. let t = this.clockList.find(l=>l.attendanceDate==c.nyr);
  52. if(t&&c.month==month){
  53. this.$set(this.calendarList[i],'status',t?.isLeave===0?0:1);
  54. this.$set(this.calendarList[i],'id',t?.id);
  55. }
  56. else this.$set(this.calendarList[i],'status',2);
  57. })
  58. },
  59. insertDays(year,month,calendar){
  60. let week = calendar[0].week;
  61. if(week==1) return []
  62. let qyear = month==1?(year-1):year;
  63. let qmonth = month==1?12:month-1;
  64. let daysInMonth = new Date(qyear, qmonth, 0).getDate();
  65. let list = [];
  66. for (let day = daysInMonth-week+2; day <= daysInMonth; day++) {
  67. let date = new Date(qyear, qmonth - 1, day);
  68. list.push({
  69. nyr: `${qyear}-${String(qmonth).padStart(2, '0')}-${String(day).padStart(2, '0')}`,
  70. year:qyear,
  71. month:qmonth,
  72. day,
  73. week: date.getDay()||7
  74. });
  75. }
  76. return list
  77. },
  78. appendDays(year,month,calendar){
  79. let week = calendar[calendar.length-1].week;
  80. if(week==7) return []
  81. let hyear = month==12?(year+1):year;
  82. let hmonth = month==12?1:month+1;
  83. let daysInMonth = new Date(hyear, hmonth, 0).getDate();
  84. let list = [];
  85. for (let day = 1; day <= 7-week; day++) {
  86. let date = new Date(hyear, hmonth - 1, day);
  87. list.push({
  88. nyr: `${hyear}-${String(hmonth).padStart(2, '0')}-${String(day).padStart(2, '0')}`,
  89. year:hyear,
  90. month:hmonth,
  91. day,
  92. week: date.getDay()||7
  93. });
  94. }
  95. return list
  96. },
  97. async selectDay(pre,idx){
  98. let info = {
  99. iswd:pre.isweekday,
  100. clockTimes:0,
  101. workHours:0,
  102. sbTime:'',
  103. xbTime:'',
  104. status:0
  105. }
  106. if(pre.id){
  107. let res = await this.$api.get('/wms/outsourced/attendance/'+pre?.id||'');
  108. if(res.data.code!==0) return this.$showToast(res.data.msg)
  109. let d = res.data.data;
  110. info.clockTimes = d.isLeave===0?2:((d.isLeave===1||d.isLeave===2)?1:0);
  111. info.workHours = d.workingHours;
  112. info.sbTime = (d.isLeave===0||d.isLeave===2)?d.checkInTime:'';
  113. info.xbTime = (d.isLeave===0||d.isLeave===1)?d.clockOutTime:'';
  114. info.status = 1;
  115. }
  116. this.$emit('selectInfo',info);
  117. if(pre?.month==this.month){
  118. this.calendarList.forEach((c,i)=>{
  119. this.$set(this.calendarList[i],'select',i===idx);
  120. })
  121. }else{
  122. this.$emit('selectDay',pre);
  123. }
  124. }
  125. }
  126. }
  127. </script>
  128. <style scoped lang="less">
  129. .box{
  130. .week{
  131. display: flex;
  132. .w_pre{
  133. width: calc(100% / 7);
  134. font-family: PingFangSC, PingFang SC;
  135. font-weight: 400;
  136. font-size: 28rpx;
  137. color: #9D9D9D;
  138. line-height: 72rpx;
  139. text-align: center;
  140. }
  141. }
  142. .date{
  143. display: flex;
  144. flex-wrap: wrap;
  145. .d_pre{
  146. width: calc(100% / 7);
  147. display: flex;
  148. flex-direction: column;
  149. align-items: center;
  150. padding: 15rpx 0;
  151. .day{
  152. width: 64rpx;
  153. height: 64rpx;
  154. border-radius: 16rpx;
  155. background: #FFFFFF;
  156. font-family: PingFangSC, PingFang SC;
  157. font-weight: 400;
  158. font-size: 28rpx;
  159. color: #9D9D9D;
  160. line-height: 64rpx;
  161. text-align: center;
  162. &.wd{
  163. color: #1D2129;
  164. }
  165. &.dq{
  166. color: #2E69EB;
  167. font-weight: bold;
  168. background: rgba(46,105,235,0.1);
  169. }
  170. &.select{
  171. color: #FFFFFF;
  172. font-weight: bold;
  173. background: #2E69EB;
  174. }
  175. }
  176. .status{
  177. width: 10rpx;
  178. height: 10rpx;
  179. border-radius: 50%;
  180. margin-top: 5rpx;
  181. &.zc{
  182. background: #2E69EB;
  183. }
  184. &.yc{
  185. background: #FEA400;
  186. }
  187. }
  188. }
  189. }
  190. }
  191. </style>