index.vue 6.6 KB

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