<template>
  <div>
    <Input
      v-bind="$attrs"
      :value="formatVal"
      :icon="!disabled ? 'md-log-in' : ''"
      readonly
      :placeholder="placeholder"
      :clearable="!disabled"
      :disabled="disabled"
      v-on="$listeners"
      @on-click.stop="handleIconClick"
      @click.native="handleInputClick"
      @mouseenter.native="handleInputMouseenter"
      @mouseleave.native="handleInputMouseleave"
    ></Input>
  </div>
</template>

<script>
export default {
  name: 'CommonSelectInput',
  components: {},
  directives: {},
  props: {
    placeholder: {
      type: String,
      default() {
        return '';
      }
    },
    value: {
      type: String,
      default() {
        return '';
      }
    },
    coaCodeType: {
      type: String,
      default() {
        return '';
      }
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      showClose: false
    };
  },
  computed: {
    formatVal: {
      get() {
        return this.value;
      },
      set(val) {
        this.formatVal = val;
      }
    }
  },
  watch: {},
  created() {},
  beforeMount: function() {},
  mounted: function() {},
  beforeDestroy: function() {},
  destroyed: function() {},
  methods: {
    handleInputMouseenter() {
      if (this.value) {
        this.showClose = true;
      }
    },
    handleInputMouseleave() {
      this.showClose = false;
    },
    handleIconClick(e) {
      this.handleInputClick(e);
    },
    handleInputClick(e) {
      if (this.disabled) {
        return false;
      }
      if (e.target.tagName === 'I' && this.showClose) {
        this.$emit('handleSelect', 'close');
        this.showClose = false;
      } else {
        this.$emit('handleSelect', 'select');
      }
    }
  }
};
</script>
