<template>
  <el-date-picker
    class="h34"
    @change="timeAdd(1)"
    v-model="productionDate"
    type="monthrange"
    value-format="yyyy-MM"
    align="right"
    :picker-options="pickerOptions"
    :range-separator="$t('OrderList.zhi')"
    :clearable="((clearable==false||clearable)&&!isQueryHistoryData)?clearable:true"
  ></el-date-picker>
</template>
<script>
  export default {
    props:['dateTime','clearable'],
    data() {
      return {
        productionDate: [],
        pickerOptions: {
          shortcuts: [{
            text: this.$t('objFill.v101.FinancialModule.benyue'),
            onClick(picker) {
              picker.$emit('pick', [new Date(), new Date()]);
            }
          }, {
            text: this.$t('objFill.v101.FinancialModule.jinnianzj'),
            onClick(picker) {
              const end = new Date();
              const start = new Date(new Date().getFullYear(), 0);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: this.$t('objFill.v101.FinancialModule.zuijinlgy'),
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setMonth(start.getMonth() - 6);
              picker.$emit('pick', [start, end]);
            }
          }],
          onPick: ({ maxDate, minDate }) => {
            this.choiceDate = minDate.getTime();
            if (maxDate) {
              this.choiceDate = "";
            }
          },
          disabledDate: time => {
            if (!this.isQueryHistoryData) {
              let endTime = this.TourDateRestrictions()
              return time && endTime.getTime() >= time.getTime();
              // return true;
            } else {
              // if (this.choiceDate) {
              //   const one = 365 * 24 * 3600 * 1000;
              //   const minTime = this.choiceDate - one;
              //   const maxTime = this.choiceDate + one;
              //   return time.getTime() < minTime || time.getTime() > maxTime;
              // }
            }
          }
        },
        startDate: '',
        endDate: '',
        isQueryHistoryData: false
      }
    },
    created() {

    },
    mounted() {
      this.GetSupperOrderEditAuth()
    },
    watch: {
      dateTime:{
        handler(n,o){
          this.productionDate = this.dateTime
        },
        deep:false,
        immediate: true,
      }
    },
    methods: {
      timeAdd(type) {
        // 日期格式
        if (type === 1) {
          if (!this.productionDate) {
            this.startDate = "";
            this.endDate = "";
            this.$emit('change',this.startDate,this.endDate)
            return;
          }

          this.startDate = this.productionDate[0];
          this.endDate = this.productionDate[1];
          this.$emit('change',this.startDate,this.endDate)
        }
      },
      GetSupperOrderEditAuth() {
        var actionCode = this.$AuthCode.isQueryHistoryData;
        this.CheckUserAuth(actionCode, res => {
          if (res.data.resultCode == 1 && res.data.data == 1) {
            this.isQueryHistoryData = true;
          }
        });
      },
    }
  }
</script>