<template>
  <el-date-picker
    ref="dateRef"
    :type="props.type"
    :placeholder="props.placeholder"
    value-format="YYYY-MM-DD"
    class="datePicker"
    :popper-class="!props.isNeedTime ? '' : 'popperClass'"
    :teleported="true"
    :disabled-date="disabledDate"
  />
</template>
<script lang="ts" setup>
const dateRef = ref(null)
const props = withDefaults(
  defineProps<{
    placeholder?: string
    type?: string
    isNeedTime?: boolean
    rowData?: unknown
    isrowDate?: boolean
    newDisableDate?: (...arg: unknown[]) => boolean
  }>(),
  {
    placeholder: '请选择日期',
    type: 'date',
    isNeedTime: false,
    isrowDate: false,
    rowData: undefined,
    newDisableDate: undefined,
  },
)
// 用于存储动态的禁用日期逻辑
function disabledDate(time: Date) {
  if (props.isrowDate && props.newDisableDate) {
    return props.newDisableDate(time, props.rowData)
  }
}
</script>
<style lang="scss" scoped>
.popperClass .el-time-spinner__wrapper {
  width: 100% !important;
}
.popperClass .el-scrollbar:nth-of-type(2) {
  display: none !important;
}
</style>
