<template>
  <a-time-picker
    v-model:value="dataValue"
    :value-format="valueFormat"
    :disabled="readonly || disabled"
    allowClear
    class="w-full"
    @change="dataValueChange"
    @click="dataValueClick"
    @blur="dataValueBlur"
    @focus="dataValueFocus"
    :placeholder="props.record?.placeholderContent || props.placeholder"
  ></a-time-picker>
</template>

<script setup name="FormTime">
import { ref, onMounted, watch } from 'vue';

const props = defineProps({
  value: {
    type: String,
    default: ''
  },
  //保存的值
  valueFormat: {
    type: String,
    default: 'HH:mm:ss'
  },
  //是否禁用
  disabled: {
    type: Boolean,
    default: false
  },
  record: {
    type: Object,
    default: {}
  },
  placeholder: {
    type: String,
    default: '请选择时间'
  },
  // 是否只读
  readonly: {
    type: Boolean,
    default: false
  }
});

const emits = defineEmits(['update:value', 'onBlur', 'onClick', 'onChange', 'onFocus']);

onMounted(() => {
  dataValue.value = props.value;
});

// 选中的值
const dataValue = ref('');

watch(
  () => props.value,
  val => {
    dataValue.value = val;
  },
  { deep: true }
);

// 更改值
const dataValueChange = () => {
  emits('update:value', dataValue.value);
  emits('onChange', props.record);
};
// 点击
const dataValueClick = () => {
  emits('onClick', props.record);
};
// 失去焦点
const dataValueBlur = () => {
  emits('onBlur', props.record);
};
// 获取焦点
const dataValueFocus = () => {
  emits('onFocus', props.record);
};
</script>

<style></style>
