index.vue 6.5 KB

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