<script setup>
import {ref} from "vue";

const {type} = defineProps({
    type: {
        type: Number,
        default: 2
    }
});

let promise, resolve, reject;

const value = ref();
const DateTimeRef = ref();
const open = () => {
    const {promise: _promise, resolve: _resolve, reject: _reject} = Promise.withResolvers();

    promise = _promise;
    resolve = _resolve;
    reject = _reject;

    DateTimeRef.value.show();
    return promise;
}

const success = ({result}) => {
    value.value = result;
    resolve(result);
}

const cancel = () => {
    reject("取消了选择");
}

defineExpose({
    open,
});
</script>

<template>
    <tui-datetime ref="DateTimeRef" :type="type" @confirm="success" @cancel="cancel"></tui-datetime>
</template>

<style scoped lang="scss">

</style>
