search.vue 4.17 KB
<template>
  <div class="qulification_search_container">

    <div v-if="isSearch" class="search_bar">
      <van-field v-model="searchName" :placeholder="placeholdTxt" @input="inputChange">
        <template #label>
          <div class="select" :style="searchName && searchName!== '' ? 'opacity: 1' : 'opacity: 0.6'" @click="showSheet = true">
            <van-icon name="search" />
            <span class="qulification_type">{{qulificationType}}</span>
            <van-icon name="play" />
          </div>
        </template>
      </van-field>
    </div>
    <section v-else class="search_box">
      <span class="select" @click="showSheet = true">
        <van-icon name="search" />
        <span class="qulification_type">{{qulificationType}}</span>
        <van-icon name="play" />
      </span>
      <div class="visual_input" @click="toListSearch">
        <span>{{placeholdTxt}}</span>
      </div>
    </section>
    <van-action-sheet v-model="showSheet" :actions="actions" :cancel-text="$t('button.cancel')" close-on-click-action @select="onSelect" />
  </div>
</template>
<script>
export default {
  name: 'QulificationSearch',
  props: {
    isSearch: {
      type: Boolean,
      default: () => {
        return false
      }
    }
  },
  computed: {
    actions() {
      return [this.$t('qulification.searchAction').org, this.$t('qulification.searchAction').product ]
    }
  },
  data() {
    return {
      qulificationType: '',
      placeholdTxt: '',
      showSheet: false,
      searchName: ''
    }
  },
  created() {
    this.defaultInput()
  },
  methods: {
    defaultInput() {
      this.qulificationType = this.$t('qulification.searchAction').org.name
      this.placeholdTxt = this.$t('qulification.searchAction').org.placeholder
    },
    onSelect(item) {
      this.show = false;
      this.qulificationType = item.name;
      this.placeholdTxt = this.$t('qulification.searchAction')[item.key].placeholder
      this.$emit('select', item)
    },
    toListSearch() {
      this.$router.push({name: 'QulificationList'})
    },
    inputChange() {
      this.$emit('input', this.searchName)
    }
  }
}
</script>
<style lang="less" scoped>
.search_box {
  width: 384px;
  margin: 30px auto 25px;
  border-radius: 16px;
  background-color: rgba(246, 246, 246, 1);
  display: flex;
  font-size: 12px;
  .select {
    color: #999999;
    display: flex;
    align-items: center;
    padding: 10px 10px 10px 5px;
    .van-icon-search {
      margin: 0 11px;
      font-size: 12px;
    }
    .qulification_type {
      color: #333333;
      margin-right: 5px;
    }
    .van-icon-play {
      transform: rotate(90deg);
      -ms-transform: rotate(90deg); /* IE 9 */
      -moz-transform: rotate(90deg); /* Firefox */
      -webkit-transform: rotate(90deg); /* Safari 和 Chrome */
      -o-transform: rotate(90deg);
    }
  }
  .visual_input {
    // width: 285px;
    color: #999999;
    padding: 10px 0;
    overflow: hidden; /*超出部分隐藏*/
    white-space: nowrap; /*不换行*/
    text-overflow: ellipsis; /*超出部分文字以...显示*/
    span {
      padding-left: 15px;
      border-left: 0.5px solid #999999;
    }
  }
}

.search_bar {
  width: 384px;
  padding: 10px 15px;
  .van-cell {
    border-radius: 50px;
    background-color: rgba(255, 255, 255, 0.3);
    padding: 5px;
    line-height: 17px;
    ::v-deep .van-field__control {
      font-size: 12px;
      color: #ffffff;
    }
    ::v-deep input::-webkit-input-placeholder {
      color: rgba(255, 255, 255, 0.6);
    }
    ::v-deep input::-moz-input-placeholder {
      color: rgba(255, 255, 255, 0.6);
    }
    ::v-deep input::-ms-input-placeholder {
      color: rgba(255, 255, 255, 0.6);
    }
  }

  ::v-deep .van-field__label {
    width: auto;
  }

  .select {
    color: #ffffff;
    padding: 0 10px 0 5px;
    font-size: 12px;
    border-right: 0.5px solid #ffffff;
    .van-icon-search {
      margin: 0 11px;
    }
    .qulification_type {
      margin-right: 5px;
    }
    .van-icon-play {
      transform: rotate(90deg);
      -ms-transform: rotate(90deg); /* IE 9 */
      -moz-transform: rotate(90deg); /* Firefox */
      -webkit-transform: rotate(90deg); /* Safari 和 Chrome */
      -o-transform: rotate(90deg);
    }
  }
}
</style>