 <!--
   @Author: husanfeng
   @qq:1136014061
   @Date: 2018-09-21
   @Last Modified by: husanfeng
   @Last Modified time: 2018-09-21
 -->
<template>
  <!-- <div class="close-div">
    <Input :size="size" ref="ipt" :value="value" @input="handleInput" icon="log-in" @click.native="showList" readonly></Input>
    <Icon type="close" class="close-btn" @click.native="clean" v-show="isShowCloseIcon"></Icon>
  </div>-->
  <Input
    v-bind="$attrs"
    v-on="$listeners"
    :value="value"
    :icon="showClose ? 'ios-close-circle':'log-in'"
    readonly
    @on-click.stop="handleIconClick"
    @click.native="handleInputClick"
    @mouseenter.native="handleInputMouseenter"
    @mouseleave.native="handleInputMouseleave"
    :clearable="showClose"
  ></Input>
</template>
<script>
import SelectVendorEdit from "./list.vue";
export default {
  name: "SelectVendor",
  components: {},
  props: {
    size: {
      type: String,
      default() {
        return "small";
      }
    },
    title: {
      type: String,
      default() {
        return "请选择客户";
      }
    },

    value: {
      type: String,
      default() {
        return "";
      }
    }
  },
  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 (e.target.tagName === "I" && this.showClose) {
        this.$emit("handleSelect");
        this.showClose = false;
      } else {
        new this.$pageModal(
          SelectCustomerEdit,
          {
            props: {
              title: this.title
            }
          },
          data => {
            if (data) {
              this.$emit("handleSelect", data);
              this.showClose = false;
            }
          }
        );
      }
    }
  },
  watch: {},
  directives: {}
};
</script>
<style lang='less' scoped>
.close-div {
  width: 100%;
  position: relative;
  display: inline-block;
  .close-btn {
    position: absolute;
    right: 20px;
    top: 50%;
    margin-top: -7px;
    font-size: 14px;
    color: #ff0000;
    display: none;
    cursor: pointer;
  }
  &:hover {
    .close-btn {
      display: inline-block;
      background: #fff;
    }
  }
}
</style>