<template>
  <a-input-password
    v-model:value="dataValue"
    :disabled="readonly || disabled"
    allowClear
    @change="dataValueChange"
    @click="dataValueClick"
    @blur="dataValueBlur"
    @focus="dataValueFocus"
    @input="dataValueInput"
    autocomplete="new-password"
    :placeholder="props.record?.placeholderContent || placeholder"
  ></a-input-password>
</template>

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

const props = defineProps({
  value: {
    type: String,
    default: ''
  },
  //是否禁用
  disabled: {
    type: Boolean,
    default: false
  },
  record: {
    type: Object,
    default: {}
  },
  placeholder: {
    type: String,
    default: '请输入密码'
  },
  // 是否只读
  readonly: {
    type: Boolean,
    default: false
  }
});

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

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

// 选中的值
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);
};
// 输入
const dataValueInput = () => {
  emits('onInput', props.record);
};
</script>

<style></style>
