<template>
  <div class="choose-day">
    <el-date-picker
        v-model="selectButton"
        type="month"
        placeholder="选择月"
        @change="dataSelect"
        value-format="YYYY-MM-DD"
        popper-class="choose-day-popper"
        :disabled-date="disabledDate"
    />
  </div>

</template>

<script setup>
const selectButton = ref('');
const emit = defineEmits(["update:modelValue", "select"]);
const disabledDate = (time) => {
  // return time.getTime() > Date.now()//不能选择之后的数据
  let curDate = (new Date()).toString() // 当前时间戳转为字符串
  let curDateYear = (new Date()).getFullYear() // 当前时间的年份
  let oneYearAgoDate = curDate.replace(curDateYear, curDateYear - 1)// 字符串年份替换为一年前
  let oneYear = new Date(oneYearAgoDate).getTime() //一年前字符串转为时间戳
  return time.getTime() >= Date.now() || time.getTime() < oneYear;
}
const dataSelect = (val) => {
  emit("update:modelValue", val);
  emit("select", val);
};
const clearData = () => {
  selectButton.value=''
}
defineExpose({
  clearData
})
</script>
