index.vue 5.4 KB

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