<template>
  <el-time-picker
    class="ps-date-picker"
    v-model="inputValue"
    :value-format="valueFormat"
    :type="type"
    :placeholder="placeholder"
    :disabled="disabled"
    :id="id"
    v-bind="$attrs"
    @change="operaChange"
    ref="elementRef"
  >
  </el-time-picker>
</template>

<script>
export default {
  name: "PsDatetimePicker",
  props: {
    value: null,
    type: {
      type: String,
      default: "date",
    },
    placeholder: {
      type: String,
      default: null,
    },
    disabled: {
      type: Boolean,
      default: false,
    },
    valueFormat: {
      type: String,
      default: 'yyyy-MM-dd HH:mm:ss'
    },
    id: { type: String, default: "" }
  },
  //处理v-model语法糖的emit事件
  model: {
    prop: 'value',
    event: 'handler'
  },
  watch: {
    value: {
      handler(val) {
        this.inputValue = val
      },
      immediate: true
    }
  },
  data() {
    return {
      inputValue: null,
    };
  },
  created() {

  },
  mounted() {
  },
  methods: {
    operaChange(val) {
      this.$emit('change', val)
      this.$emit('handler', val)
    },
    blur() {
      this.$refs.elementRef.blur();
    }
  },
};
</script>
