<template>
  <!--来源浏览-->
  <el-dialog title="选择来源" :visible.sync="mySourceFlag" size="tiny" class="tag-dialog" @open="getSources">
    <el-form>
      <el-form-item label="通过名称查询：">
        <el-input v-model="searchWord" style="width:180px" @change="search"></el-input>
      </el-form-item>
      <el-form-item label="最近使用过的：">
        {{sources}}
      </el-form-item>
    </el-form>

    <div v-loading="sourceLoading">
      <div v-for="item in selectsources" :key="item.index" class="letter-item">
        <div>
          <a :id="item.letter">{{item.letter}}</a>
        </div>
        <div v-for="i in item.sources" :key="i.index">
          <a class="link" @click="sourceClick(i.source)">{{i.source}}</a>
        </div>
      </div>
      <aside class="letter-aside">
        <ul>
          <li @click="naver(letter)" v-for="letter in letters" :key="letter.index">{{letter}}</li>
        </ul>
      </aside>
    </div>
  </el-dialog>
</template>
<script>
export default {
  props: ['contentType', 'sourceFlag', 'sourceCallBack'],
  data() {
    return {
      selectsources: [],
      searchWord: '',
      sources: '',
      letters: ['#', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],
      sourceLoading: false

    }
  },
  computed: {
    mySourceFlag: {
      set(val) {
        this.$emit('update:sourceFlag', val)
      },
      get() {
        return this.sourceFlag
      }
    }
  },
  methods: {
    async getSources() {
      let resp = await axios.get('/ui/sourcewords/init', { searchWord: this.searchWord })
      if (resp.data.status === 1) {
        this.selectsources = resp.data.data
      }
    },
    search() {

    },
    sourceClick(val) {
      this.$emit('sourceCallBack', val)
      this.mySourceFlag = false
    },
    naver(id) {
      try { throw document.getElementById(id).scrollIntoView() } catch (e) { }
    }

  }

}
</script>
<style scoped>
  .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;
  }
</style>
