<template>
  <div>
    <el-date-picker
      v-model="time"
      type="daterange"
      start-placeholder="开始日期"
      end-placeholder="结束日期"
      @change="timeChange">
    </el-date-picker>
  </div>
</template>

<script>
export default {
  name: 'TimeSelect',
  data() {
    return {
      start:'',
      over:'',
      time:''
    };
  },
  computed:{
  },
  watch:{
  },
  methods: {
    timeChange(e) {
      if(!e) {
        this.$emit('clearSelect')
        return
      } 
      let result = e.map(item => {
        return this.changeTimeFormat(item.getTime())
      })   
      this.$emit('timeChange',result)
    },
    changeTimeFormat(time) {
      var date = new Date(time);
      var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
      var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
      return date.getFullYear() + "-" + month + "-" + currentDate
    }
  },
}
</script>

<style scoped>

</style>
