<template>
  <div class="data-range-container">
    <el-date-picker
      v-model="startDatePrivate"
      format="yyyy-MM-dd"
      value-format="yyyy-MM-dd"
      :picker-options="startDateOption"
      type="date"
      placeholder="选择日期">
    </el-date-picker>
    -
    <el-date-picker
      v-model="endDatePrivate"
      format="yyyy-MM-dd"
      value-format="yyyy-MM-dd"
      :picker-options="endDateOption"
      type="date"
      placeholder="选择日期">
    </el-date-picker>
  </div>
</template>

<script>
  export default {
    name: 'date-range',
    props: {
      startDate: '',
      endDate: ''
    },
    data() {
      return {
        startDatePrivate: '',
        endDatePrivate: '',
        startDateOption:{
          disabledDate: (time) => {
            let endTimeVal = this.endDateN;
            if (endTimeVal) {
              return time.getTime() > endTimeVal;
            }
          }
        },
        endDateOption:{
          disabledDate: (time) => {
            let startTimeVal = this.startDateN;
            if (startTimeVal) {
              return time.getTime() < startTimeVal;
            }
          }
        }
      }
    },
    computed: {
      startDateN: {
        get: function(){
          let date=this.startDatePrivate || '1900-01-01'
          date=date.replace(/-/g,'/')
          return (new Date(date)).getTime()
        },
      },
      endDateN: {
        get: function(){
          let date=this.endDatePrivate || '2200-01-01'
          date=date.replace(/-/g,'/')
          return (new Date(date)).getTime()
        },
      }
    },
    watch:{
      startDate(val) {
        this.startDatePrivate=val
      },

      endDate(val) {
        this.endDatePrivate=val
      },

      startDatePrivate(val) {
        this.$emit('update:startDate', val)
      },

      endDatePrivate(val) {
        this.$emit('update:endDate', val)
      }
    },
    mounted(){
      // console.log(this.total)
    },
    methods: {

    },
  }
</script>

<style scoped>
  .page-container{
    padding:30px 10px
  }
</style>
