<template>
  <van-popup
    :show="show"
    @close="onClose"
    position="bottom"
    round
    closeable
    :close-on-click-overlay="false"
  >
    <van-datetime-picker
      type="date"
      :value="currentDate"
      bind:change="onInput"
      @confirm="confirm1"
      @cancel="cancel"
      :min-date="minDate"
      :formatter="formatter"
    />
  </van-popup>
</template>

<script>
import vanPopup from "../../../../wxcomponents/weapp/dist/popup/index";
import vanDatetimePicker from "../../../../wxcomponents/weapp/dist/datetime-picker/index";
export default {
  components: {
    vanPopup,
    vanDatetimePicker,
  },
  data() {
    return {
      show: false,
      chooseIndex: null,
      currentDate: new Date().getTime(),
      minDate: new Date().getTime(),
      type: null,
      formatter(type, value) {
        if (type === "year") {
          return `${value}年`;
        }
        if (type === "month") {
          return `${value}月`;
        }
        return value;
      },
    };
  },
  methods: {
    cancel() {
      this.show = false;
    },
    onOpen(i, type) {
      this.chooseIndex = i;
      this.type = type;
      this.show = true;
    },
    formatTime(date) {
      date = new Date(date);
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      return [year, month, day].map(this.formatNumber).join("/");
    },

    onClose() {
      this.$emit(
        "getEndTime",
        this.chooseIndex,
        this.$common.transDate(this.currentDate),
        this.type
      );
      this.show = false;
    },
    confirm1(value) {
      //   this.currentDate = event.detail;
    },
  },
};
</script>

<style>
</style>