index.vue 6.5 KB

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