TimeDate.vue 4.13 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 class="arrow-left-icon"
                 icon="el-icon-d-arrow-left"
                 type="text"
                 :disabled="currentWeek === 1"
                 @click="handleWeek(false)" />
      <template>
        <div class="date-picker">
          <div v-for="(item, index) in dateList.slice(currentWeek * 7 - 7, currentWeek * 7)"
               :key="index"
               class="wrapper">
            <span>
              <p v-for="(info, infoIndex) in appointData[index].infoList"
                 :key="infoIndex">
                <el-popover open-delay="600"
                            placement="bottom-start"
                            title=""
                            trigger="hover"
                            width="200"
                            :disabled="info.status === 0">
                  <div>
                    <p>1、客户姓名,时间,项目</p>
                    <p>2、客户姓名,时间,项目</p>
                    <p>余位数:8</p>
                  </div>
                  <el-button slot="reference"
                             class="col-width hour-template"
                             :class="{ 'status-full': info.status === 2, 'status-remain': info.status === 1 }"
                             @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 v-for="(item, index) in dateList.slice(currentWeek * 7 - 7, currentWeek * 7)"
               :key="index"
               class="wrapper">
            <el-button class="date-btn col-width"
                       type="text"
                       :class="{ 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",

	props: {
		appointData: {
			type: Array,
			default: () => [],
		},
		hoursList: {
			type: Array,
			default: () => [],
		},
	},
	data() {
		return {
			// 7天为一个周期,预约时间为35天,一共5个周期,当前周期
			currentWeek: 1,
			// 日期
			dateIndex: 0,
			weekList: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
			dateList: new Array(appointDays).fill(null).map((item, index) => {
				let date = new Date(new Date().setDate(new Date().getDate() + index));
				return {
					date: date.toLocaleDateString(),
					week: date.getDay(),
					active: !index,
				};
			}),
			// 时间
			appointStatusList: ["空", "余", "满"],
		};
	},

	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>