<template>
    <el-date-picker
        v-model="content"
        :type="type"
        range-separator="-"
        start-placeholder="开始时间"
        end-placeholder="结束时间"
        value-format="YYYY-MM-DD HH:mm:ss"
        clearable
        @change="change"
    ></el-date-picker>
</template>

<script lang="ts" setup>
import { withDefaults, computed } from 'vue'

/* Props S */
const props = withDefaults(
    defineProps<{
        startTime?: string
        endTime?: string
        type?: string
    }>(),
    {
        startTime: '',
        endTime: '',
        type: 'datetimerange'
    }
)
const emit = defineEmits(['update:startTime', 'update:endTime', 'change'])

const change = (e: any)=>{
    emit('change', e)
}

const content = computed<any>({
    get: () => {
        return [props.startTime, props.endTime]
    },
    set: (value: Event | any) => {
        if (value === null) {
            emit('update:startTime', '')
            emit('update:endTime', '')
        } else {
            emit('update:startTime', value[0])
            emit('update:endTime', value[1])
        }
    }
})
</script>
