input 失去焦点隐藏div

  <div class="search" ref="slicerBtn">
      <svg-icon class="search_icon" class-name="search-icon" icon-class="search"/>
      <el-input placeholder="Search" v-model="search"></el-input><!--@keyup.enter.native="Getsearchs" -->
      <div class="search_Main" v-show="show" v-loading="loding" ref="slicer">
        <div v-for="(item,index) in options" :key="index">
          <div class="search-title" :style="'color:'+color[index].c">{{item.type}}</div>
           <div v-if="item.list.length == 0" class="grey search-text"> &nbsp;&nbsp;&nbsp;no results</div>
          <div class="search-item" v-for="(ele,i) in item.list" :key="i" v-if="i<5 || color[index].xh" @click="GetSearchItem(ele)">
            <div class="search-size" :style="'background:'+color[index].c">{{color[index].s}}</div>{{ele.name}}
          </div>
          <div class="showmore" v-if="item.list.length>5 && !color[index].xh" @click="Showmore(index)">Show more</div>
        </div>
      </div>
  </div>


  created(){
    document.addEventListener('click',(e)=>{
        if(this.show)
        if(!this.$refs.slicer.contains(e.target) && !this.$refs.slicerBtn.contains(e.target)){
            this.show = false;
            this.search = '';
        }
    })
  },
  data(){
     search: '',
	loding: false,
	options: [{type: "Report", list:[]},{type: "Application", list:[]},{type: "Tags", list:[]},{type: "Department", list:[]}],
	color:[{s:'R',c:'#3A87AD',xh:false},{s:'A',c:'#A48800',xh:false},{s:'T',c:'#FFA500',xh:false}{s:'D',c:'#9E072E',xh:false}],
	},

  watch: {
    search: {
      immediate: true,
      deep: true,
      handler(newValue, oldValue) {
        if(newValue.length>=2){
          this.Getsearchs();
        };
        if(!newValue.length){
          this.show = false;
          this.color = [{s:'R',c:'#3A87AD',xh:false},{s:'A',c:'#A48800',xh:false},{s:'T',c:'#FFA500',xh:false},{s:'D',c:'#9E072E',xh:false}];
       
        }
      }
    }
  },

  methods: {
    GetSearchItem(ele){
    // 隐藏
        this.$nextTick(()=> {
          this.search = '';
          this.show = false;
        })
    },
 Showmore(index){
      this.color[index].xh = !this.color[index].xh
    },
  },
    Getsearchs() {
      this.show = true;
      this.loding = true;
      handSearch(this.search,this.num).then(res => {
        let arr = [{type: "Report", list:[]},{type: "Application", list:[]},{type: "Tags", list:[]},{type: "Department", list:[]}]
          if(res.data == null) {
            this.options = [{type: "Report", list:[{name: 111,type: 'app}]},{type: "Application", list:[]},{type: "Tags", list:[]},{type: "Department", list:[]}];
          } else {
            this.options = res.data;
          }
          this.loding = false;
      }).catch(error => {

      });
    },


<style lang="scss" scoped>
.search_Main{
  z-index: 100;
  border-radius:0 0 5px 5px;
  position: absolute;
  background: #fff;
  border: 1px solid #eee;
  left: 0;
  top: 35px;
  width: 100%;
  max-height:340px;
  overflow-y: auto;
}
.search-title{
  padding:5px 10px;
  font-size: 12px;
  font-weight: bold;
}
.search-item{
  font-size: 12px;
  padding:5px 10px;
  display: flex;
  align-items: center;
}
.search-item:hover{
  background: #ededed;
  cursor: pointer;
}

.search-text {
  font-size: 12px;
}
.search-item .search-size{
  height: 20px;
  width:20px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  margin-right: 10px;
  font-size: 12px;
}
.showmore{
  font-style: oblique;
  font-size: 10px;
  color: #818080;
  padding: 10px 10px;
  cursor: pointer;
}
.search {
  position: relative;
 >>> .el-input__inner {
    width:  270px;
    padding-left: 45px;
    border-radius: 5px;
  }


}

  .search_icon {
    font-size: 18px;
    position: absolute;
    top: 10px;
    left: 10px;
    cursor: pointer;
    z-index: 1;
  }


.header-search {
  font-size: 0 !important;

  .search-icon {
    cursor: pointer;
    font-size: 18px;
    vertical-align: middle;
  }

  .header-search-select {
    font-size: 18px;
    transition: width 0.2s;
    width: 0;
    overflow: hidden;
    background: transparent;
    border-radius: 0;
    display: inline-block;
    vertical-align: middle;

    /deep/ .el-input__inner {
      // border-radius: 0;
      border-radius: 10%, 10% ,10%, 10%;
      border: 0;
      padding-left: 15px;
      padding-right: 0;
      box-shadow: none !important;
      border-bottom: 1px solid #d9d9d9;
      vertical-align: middle;
    }
  }

  &.show {
    .header-search-select {
      width: 210px;
      margin-right: 10px;
    }
  }
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值