<template>
  <van-dialog v-model:show="show" :show-confirm-button="false">
    <van-datetime-picker
      v-model="presentTime"
      type="date"
      :title="title"
      @cancel="onCancel"
      @confirm="onTimeConfirm"
    ></van-datetime-picker>
  </van-dialog>
</template>
<script setup>
import {ref, defineProps, onMounted, defineEmits, watch, computed} from "vue";
import { dateFormat } from "../utils/tools.js";
const props = defineProps({
  timeType: String,
});
const emits = defineEmits(["update:time"]);
const show = ref(true);
const presentTime = ref(new Date()); //选择器默认时间

const title = computed(() => {
  if (props.timeType == 'start') {
    return '选择开始日期'
  } else if (props.timeType == 'end') {
    return '选择结束日期'
  } else {
    return props.timeType
  }
})
function onTimeConfirm(val) {
  emits("update:time", dateFormat("", val));
}

function onCancel() {
  emits("update:cancelTime", "");
}
//确定选中的时间
</script>
<style lang="scss" scoped>
@import "../assets/styles/mixin.scss";
</style>
