TimeDate.vue 3.2 KB
<!-- 日期时间 - 选择器 -->
<template>
  <div class="time-selector">
    <el-button icon="el-icon-d-arrow-left" type="text" :disabled="currentWeek === 1" @click="handleWeek(false)"></el-button>
    <div class="date-picker">
      <div
        class="wrapper"
        v-for="(item, index) in dateList.slice(currentWeek * 7 - 7, currentWeek * 7)"
        :key="index"
      >
        <span>
          <p
            v-for="(info, infoIndex) in appointData[index].infoList"
            :key="infoIndex"
          >
            <el-popover
              placement="bottom-start"
              title=""
              width="200"
              open-delay="600"
              trigger="hover"
              :disabled="info.status !== 1"
            >
              <div>
                <p>1、客户姓名,时间,项目</p>
                <p>2、客户姓名,时间,项目</p>
                <p>余位数:8</p>
              </div>
              <el-button
                class="col-width hour-block"
                slot="reference"
                :disabled="((item.date == new Date().toLocaleDateString()) && (+hoursList[infoIndex].hour.split(':')[0] <= new Date().getHours())) || (info.status === 2)"
                @click="handleAppoint(item, infoIndex)"
              >{{appointStatusList[info.status]}}</el-button>
            </el-popover>
          </p>
        </span>
        <el-button
          type="text"
          :class="{'date-btn': true, 'col-width': true, 'active': item.active}"
          @click="handleSelectDate(index)"
        >
          <p>{{item.date.split('/')[1] + '.' + item.date.split('/')[2]}}</p>
          <p>{{weekList[item.week]}}</p>
        </el-button>
      </div>
    </div>
    <el-button icon="el-icon-d-arrow-right" type="text" :disabled="currentWeek === 5" @click="handleWeek(true)"></el-button>
  </div>
</template>

<script>
import { appointDays } from '@/common/constants'
export default {
  name: 'TimeDate',
  data() {
    return {
      // 7天为一个周期,预约时间为35天,一共5个周期,当前周期
      currentWeek: 1,
      // 日期
      dateIndex: 0,
      weekList: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
      dateList: new Array(appointDays).fill(null).map((item, index) => {
        var date = new Date(new Date().setDate(new Date().getDate() + index))
        return {
          date: date.toLocaleDateString(),
          week: date.getDay(),
          active: !index
        }
      }),
      // 时间
      appointStatusList: ['空', '余', '满']
    }
  },

  props: {
    appointData: {
      type: Array,
      default: () => []
    },
    hoursList: {
      type: Array,
      default: () => []
    }
  },

  mounted() { },

  methods: {
    // 日期选择
    handleSelectDate(currentIndex) {
      this.dateList[this.dateIndex].active = false
      this.dateIndex = currentIndex
      this.dateList[currentIndex].active = true
    },
    handleAppoint(date, hourIndex) {
      this.$emit('handleAppoint', { date: date.date, hour: this.hoursList[hourIndex].hour })
    },
    handleWeek(isAdd) {
      isAdd ? this.currentWeek++ : this.currentWeek--
    }
  }
}

</script>
<style lang="scss" scoped>
@import './css/timeDateStyle.scss';
</style>