index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. clockTimes:0,
  100. workHours:0,
  101. sbTime:'',
  102. xbTime:'',
  103. status:0
  104. }
  105. if(pre.id){
  106. let res = await this.$api.get('/wms/outsourced/attendance/'+pre?.id||'');
  107. if(res.data.code!==0) return this.$showToast(res.data.msg)
  108. let d = res.data.data;
  109. info.clockTimes = d.isLeave===0?2:((d.isLeave===1||d.isLeave===2)?1:0);
  110. info.workHours = d.workingHours;
  111. info.sbTime = (d.isLeave===0||d.isLeave===2)?d.checkInTime:'';
  112. info.xbTime = (d.isLeave===0||d.isLeave===1)?d.clockOutTime:'';
  113. info.status = 1;
  114. }
  115. this.$emit('selectInfo',info);
  116. if(pre?.month==this.month){
  117. this.calendarList.forEach((c,i)=>{
  118. this.$set(this.calendarList[i],'select',i===idx);
  119. })
  120. }else{
  121. this.$emit('selectDay',pre);
  122. }
  123. }
  124. }
  125. }
  126. </script>
  127. <style scoped lang="less">
  128. .box{
  129. .week{
  130. display: flex;
  131. .w_pre{
  132. width: calc(100% / 7);
  133. font-family: PingFangSC, PingFang SC;
  134. font-weight: 400;
  135. font-size: 28rpx;
  136. color: #9D9D9D;
  137. line-height: 72rpx;
  138. text-align: center;
  139. }
  140. }
  141. .date{
  142. display: flex;
  143. flex-wrap: wrap;
  144. .d_pre{
  145. width: calc(100% / 7);
  146. display: flex;
  147. flex-direction: column;
  148. align-items: center;
  149. padding: 15rpx 0;
  150. .day{
  151. width: 64rpx;
  152. height: 64rpx;
  153. border-radius: 16rpx;
  154. background: #FFFFFF;
  155. font-family: PingFangSC, PingFang SC;
  156. font-weight: 400;
  157. font-size: 28rpx;
  158. color: #9D9D9D;
  159. line-height: 64rpx;
  160. text-align: center;
  161. &.wd{
  162. color: #1D2129;
  163. }
  164. &.dq{
  165. color: #2E69EB;
  166. font-weight: bold;
  167. background: rgba(46,105,235,0.1);
  168. }
  169. &.select{
  170. color: #FFFFFF;
  171. font-weight: bold;
  172. background: #2E69EB;
  173. }
  174. }
  175. .status{
  176. width: 10rpx;
  177. height: 10rpx;
  178. border-radius: 50%;
  179. margin-top: 5rpx;
  180. &.zc{
  181. background: #2E69EB;
  182. }
  183. &.yc{
  184. background: #FEA400;
  185. }
  186. }
  187. }
  188. }
  189. }
  190. </style>