VUE获取当前日期的周日和周六

<template>
  <div>
      <div  @click="handleLast()">上一周</div>
       <div  @click="handleNext()">下一周</div>

      <el-calendar
        ref="monChild"
        v-model="value"
        :first-day-of-week="7"
        :range="[starttime, endtime]"
        style="height: 82px;"
      >
        <!-- 这里使用的是 2.5 slot 语法,对于新项目请使用 2.6 slot 语法-->
        <!-- slot="dateCell" -->
        <!-- slot-scope="{date, data}"> -->
        <template #dateCell="{ data }">
          <div
            :class="data.isSelected ? 'is-selected' : ''"
            @click="handleClick(data)"
          >
            <div style="line-height: 18px">
              {{ parseTime(data.day, "{d}") }}
            </div>
            <!-- 圆点显示 -->
            <div class="g-flexcenter">
              <div v-if="dateList.findIndex((res) => res.scheduleTime === data.day) !==-1" :class="data.isSelected? 'g-color-blue': 'g-color-blue'">
                ·
              </div>
            </div>
          </div>
        </template>
      </el-calendar>
    
  </div>
</template>

<script>

import dayjs from "dayjs";

export default {
  name: "",

  data() {
    return {
      value: new Date(), //选中的日期 默认当天
      starttime: "",
      endtime: "",
      timeLength: "", //时长
    };
  },

  
  created() {
    this.weekCheckingIn();
  },
  methods: {
    /**获取近一周的日期  开始周起始日,结束周结束日*/
    weekCheckingIn() {
      let now = new Date(this.value);
      let nowTime = now.getTime();
      let day = now.getDay() || 7; // 不加 || 7.周末会变成下周一
      let oneDayTime = 24 * 60 * 60 * 1000;
      let SundayTime = nowTime - day * oneDayTime; //显示周日
      let SaturdayTime = nowTime + (7 - day - 1) * oneDayTime; //显示周六
      this.starttime = dayjs(SundayTime).format("YYYY-MM-DD");
      this.endtime = dayjs(SaturdayTime).format("YYYY-MM-DD");
    },

    /**上一周 */
    handleLast() {
      const last = new Date(this.value);
      last.setDate(last.getDate() - 7); //日期相加减
      this.value = last;
      this.weekCheckingIn();
    },
    /**下一周 */
    handleNext() {
      const next = new Date(this.value);
      next.setDate(next.getDate() + 7);
      this.value = next;
      this.weekCheckingIn();
    },

   
    /**选中的日期 */
    handleClick(data) {
      this.value = data.day;
     //调详情列表
    
    },

    //给list添加一个字段timeLength
    // this.$set(item,'timeLength',(new Date(endTime) - new Date(startTime)) / (1000 * 60 * 60))

  },
};
</script>

  <style lang="scss" scoped>

::v-deep .el-calendar__header {
  display: none;
  font-size: 12px;
  padding: 10px 0px;
  .el-button--mini {
    padding: 2px 5px;
    border-radius: 3px;
  }
}
::v-deep .el-calendar__body {
  padding: 0;

  .el-calendar-table thead th {
    font-size: 12px;
    font-weight: 400;
    color: #8f959e;
    padding: 12px 0 8px !important;
  }
}

::v-deep .el-calendar-table .el-calendar-day {
  height: auto;
  padding: 5px;
 
}
::v-deep .el-calendar-table td.is-selected .el-calendar-day {
  height: 27px !important;
  width: 27px !important;
  background: none !important;
  background-color: #ebeefc !important;
  font-size: 14px !important;
  font-weight: bold !important;
  color: #ffffff !important;
  background: #3370ff !important;
}
::v-deep .el-calendar-table tr td {
  border: 0px;
  text-align: center;
  font-weight: bold !important;
}
::v-deep .el-calendar-table td.is-selected {
  display: flex;
  justify-content: center;
  background: #fff;

  .el-calendar-day {
    width: 34px;
    height: 31px;
    background: url("~@/assets/images/workbench/icon_date.png") no-repeat;
    background-size: 100% 100%;
    border-radius: 50%;
    // font-family: PingFang SC;
    font-weight: bold;
    color: #409eff;
  }
}
::v-deep .el-calendar-table td :hover {
  background: none;
  color: #409eff;
}
::v-deep .el-calendar-table td.is-selected :hover {
  border-radius: 50%;
}

</style>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值