<template>
  <div id="top-header">
    <div class="timers">
      {{ dateYear }} {{ dateWeek }} {{ dateDay }}
    </div>
    <div class="center-title">项目施工数据概览</div>

    <div class="top-header-select">
      <el-select v-model="value" placeholder="请选择" @change="changeProject">
        <el-option
          v-for="item in projectOption"
          :key="item.abbreviation"
          :label="item.title"
          :value="item.title">
        </el-option>
      </el-select>
    </div>
  </div>
</template>

<script>
import { formatTime } from "@/utils/index.js";

export default {
	name: 'TopHeader',

	props: {
		projectOption: {
			type: Array,
			default: []
		},

		defaultValue: {
			type: String,
			default: ''
		}
	},

	data() {
		return {
			timing: null,
			dateDay: null,
			dateYear: null,
			dateWeek: null,
			weekday: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],

			value: ''
		}
	},

	methods: {
		timeFn() {
			this.timing = setInterval(() => {
				this.dateDay = formatTime(new Date(), "HH: mm: ss");
				this.dateYear = formatTime(new Date(), "yyyy-MM-dd");
				this.dateWeek = this.weekday[new Date().getDay()];
			}, 1000);
		},

		changeProject() {
			console.log(this.value);
			this.$emit('handleChangeProject', this.value);
		}
	},

	mounted() {
		this.timeFn()
		this.value = this.defaultValue
	},

	beforeDestroy() {
		clearInterval(this.timing);
	}
}
</script>

<style lang="scss">
#top-header {
  position: relative;
  width: 100%;
  height: 80px;
  display: flex;
  justify-content: space-between;
  flex-shrink: 0;
  background: url(../assets/img/title.png) no-repeat;
  background-size: 100% 100%;

  .center-title {
    position: absolute;
    font-size: 26px;
    font-weight: bold;
    left: 50%;
    transform: translateX(-50%);
    line-height: 80px;
  }

  .timers {
    font-size: 16px;
    font-weight: bold;

    position: absolute;
    left: 8%;
    bottom: 24px;
  }

  .top-header-select {
    position: absolute;
    right: 8%;
    bottom: 20px;
    background: rgba(47,85,151,.58) !important;
    color: #fff;
    .el-select,
    .el-input__inner {
      background: transparent;
      border: none;
      color: #fff;
    }
  }
}
</style>
