 <!--
   @Author: husanfeng
   @qq:1136014061
   @Date: 2018-09-21
   @Last Modified by: husanfeng
   @Last Modified time: 2018-09-21
 -->
<template> 
  <Input
    v-bind="$attrs"
    v-on="$listeners"
    :value="value"
    :icon="!disabled ? 'log-in' : ''"
    readonly
    @on-click.stop="handleIconClick"
    @click.native="handleInputClick"
    @mouseenter.native="handleInputMouseenter"
    @mouseleave.native="handleInputMouseleave"
    :clearable="!disabled"
    :disabled="disabled"
  ></Input>
</template>
<script>
import SelectSalesInfoEdit from "./list.vue";
export default {
  name: "SelectSalesInfo",
  components: {},
  props: {
    size: {
      type: String,
      default() {
        return "small";
      }
    },
    title: {
      type: String,
      default() {
        return "请选择业务员";
      }
    },

    value: {
      type: String,
      default() {
        return "";
      }
    },
    companyCode: {
      type: String,
      required: true
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data() {
    let showClose = !!this.value;
    return {
      showClose: showClose
    };
  },
  computed: { },
  created: function() {},
  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
      }
      if (e.target.tagName === "I" && this.showClose) {
        this.$emit("handleSelect");
        this.showClose = false;
      } else {
        new this.$pageModal(
          SelectSalesInfoEdit,
          {
            props: {
              title: this.title,
              _companyCode: this.companyCode
            }
          },
          data => {
            if (data) {
              this.$emit("handleSelect", data);
              this.showClose = false;
            }
          }
        );
      }
    }
  },
  watch: {},
  directives: {}
};
</script>  