TimeDate.vue 4.17 KB
<!-- 日期时间 - 选择器 -->
<template>
  <div class="time-selector">
    <div class="time-selector-header">
      <p>邀约日历</p>
      <p>2020年</p>
    </div>
    <div class="time-selector-container">
      <template class="date-left-tips">
        <div class="date-tips-time">
          <p>上午9:00</p>
          <p>中午12:00</p>
          <p>晚上18:00</p>
        </div>
        <p class="date-y-line" />
      </template>
      <el-button icon="el-icon-d-arrow-left"
                 type="text"
                 class="arrow-left-icon"
                 :disabled="currentWeek === 1"
                 @click="handleWeek(false)" />
      <template>
        <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 === 0">
                  <div>
                    <p>1、客户姓名,时间,项目</p>
                    <p>2、客户姓名,时间,项目</p>
                    <p>余位数:8</p>
                  </div>
                  <el-button :class="{'col-width': true, 'hour-template': true, 'status-full': info.status === 2, 'status-remain': info.status === 1 }"
                             slot="reference"
                             @click="handleAppoint(item, infoIndex)">
                    {{ appointStatusList[info.status] }}</el-button>
                </el-popover>
              </p>
            </span>
          </div>
        </div>
        <p class="date-x-line" />
        <div class="date-picker">
          <div class="wrapper"
               v-for="(item, index) in dateList.slice(currentWeek * 7 - 7, currentWeek * 7)"
               :key="index">
            <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>
      </template>
      <el-button icon="el-icon-d-arrow-right"
                 type="text"
                 :disabled="currentWeek === 5"
                 @click="handleWeek(true)" />
    </div>
  </div>
</template>

<script>
import { appointDays } from '@/common/format'
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>