<template>
  <el-select
    v-show="isShow"
    class="selectTags"
    suffix-icon="el-icon-search"
    v-model="currentTag"
    filterable
    allow-create
    default-first-option
    clearable
    :remote="true"
    :remote-method="remoteSearch"
    @blur="addTags"
    ref="inputTag"
    placeholder="请输入Tag词">
    <el-option
      v-for="tag in searchTags"
      :key="tag"
      :label="tag"
      :value="tag">
    </el-option>
  </el-select>
</template>

<script>
export default {
  props: {
    tags: {
      type: Array
    },
    contentType: {
      type: String
    },
    show: {
      type: Boolean
    }
  },
  data() {
    return {
      searchTags: [],
      list: [],
      loading: true
    }
  },
  computed: {
    currentTag: {
      set(val) {
        if (val) {
          if (val && !this.tags.includes(val)) {
            this.tags.push(val)
          }
          this.$emit('update:tags', this.tags)
          this.isShow = false
        }
      },
      get(){
        return ''
      }
    },
    isShow: {
      set(val) {
        this.$emit('update:show', val)
      },
      get() {
        this.show && this.$refs['inputTag'].focus()
        return this.show
      }
    }
  },
  mounted() {
    this.list = this.searchTags
  },
  methods: {
    async remoteSearch(query) {
      let resp = await axios.get(`/ui/tagwords/search/${this.contentType}`, {params: { searchWord: encodeURI(query) }})
      if (resp.data.status === 1) {
        this.searchTags = resp.data.data
      }
    },
    addTags(val) {
      this.searchTag = val
    }
  }
}
</script>
<style scoped>
  .shadow_region {
    text-shadow: 0 1px 1px #3E6790;
    background-color: #e0e8f1;
  }

  .selfIcon {
    font-size: 20px;
    padding: 0 5px;
    cursor: pointer;
  }

  .content-form {
    height: 600px;
    overflow: auto;
  }

  .font-border {
    width: 20px;
    height: 16px;
    margin: 1px;
    text-align: center;
    border: 1px solid #bfcbd9;
    background-color: transparent;
    border-radius: 2px;
  }

  .font-border:hover {
    border: 1px solid #FFB820;
  }

  .active {
    background-color: #eed2c1;
    border-color: #b39;
  }

  .summary-font-counter {
    font-family: Constantia, Corbel;
    font-size: 26px;
    line-height: 12px;
    margin-right: 5px;
  }

  .letter-aside {
    position: fixed;
    right: 23px;
    top: 10.3rem;
  }

  .letter-aside ul {
    line-height: 1.4em;
    font-size: 14px;
    color: #bbb;
  }

  .letter-aside li {
    font-family: "Lucida Grande", 'Lucida Sans Unicode', Helvetica, Arial,
    sans-serif;
    font-size: 12px;

    text-align: center;
    cursor: pointer;
    list-style: none;
  }

  .letter-item .link {
    font-size: 14px;
    font-weight: bold;
    color: #2F3E46;
  }

  .letter-item>div {
    padding-right: 6%;
    padding-left: 6%;
    border-bottom: 1px solid #D2E2F9;
    margin-right: 10px;
    margin-left: 10px;
    line-height: 2em;
  }

  .letter-item>div:first-child {
    font-size: 16px;
    line-height: 2em;
    background: #D2E2F9;
    background-image: linear-gradient(#BCD0EB, #D2E2F9);
    margin-bottom: 2px;
    margin-right: 10px;
    margin-left: 10px;

  }

  .divider-current {
    background: #B6D6F4;
    background-image: linear-gradient(#9CC8F3, #B6D6F4);
  }

  .letter-item>div:first-child a {
    color: #fff;
    text-shadow: 0 1px 1px #3E6790;
  }

  .colors {
    color: #003399;
  }

  .upload-images {
    margin-top: -10px;
    margin-left: 8px;
  }

  .upload-images i {
    margin: 0 3px;
  }

  .el-input input {
    color: inherit !important;
    /*从父元素继承颜色*/
    text-decoration: inherit !important;
    /*从父元素继承下划线*/
  }

  .tag-dialog .el-dialog__body {
    height: 600px;
    overflow: auto;
  }
  .selectTags {
    width: 120px;
    vertical-align: bottom;
  }
</style>
<style>
  .selectTags .el-form-item .el-select .el-input__inner[readonly=readonly], .el-form-item .el-select .el-input--suffix .el-input__inner{
    height:32px !important;
  }
</style>
