<template>
  <div :class="$style.searchrate">
    <a-card :bordered="false" title="个人常用">
      <a-list item-layout="horizontal" :data-source="hotListData">
        <a-list-item slot="renderItem" slot-scope="item, index" @click="click(item)">
          <span :class="$style.num">{{ index + 1 }}</span>
          <span>{{ item }}</span>
        </a-list-item>
      </a-list>
    </a-card>
  </div>
</template>

<script>
import KmKnowledageService from '../km-knowledage-service'

import components from './_import-components/km-fullsearch-rate-import'
export default {
  name: 'KmFullsearchRate',
  components,
  data() {
    return {
      hotListData: [],
    }
  },
  mounted() {
    this.getHotList()
  },
  methods: {
    getHotList() {
      KmKnowledageService.getHotserch().then((res) => {
        if (res.data.length > 0) {
          res.data.forEach((item, index) => {
            if (item === '请输入搜索内容') {
              res.data.splice(index, 1)
            }
          })
          this.hotListData = res.data
        }
      })
    },
    click(item) {
      this.$emit('onSearch', item, 'searchText')
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
$color-a: #9094a2;
$color-b: #f82b44;
$color-c: #f96300;
$color-d: #fac572;
.searchrate {
  width: 210px;
  max-width: 230px;
  margin-right: 1rem;
  margin-left: 1rem;
  .num {
    display: inline-block;
    width: 20px;
    height: 20px;
    margin-right: 10px;
    line-height: 1.125;
    color: $color-a;
    text-align: center;
    border: 1px solid $color-a;
    border-radius: 10px;
  }
  :global(.ant-list) {
    :global(.ant-list-item) {
      justify-content: flex-start;
      cursor: pointer;
      &:first-child {
        .num {
          color: $color-b;
          border-color: $color-b;
        }
      }
      &:nth-child(2) {
        .num {
          color: $color-c;
          border-color: $color-c;
        }
      }
      &:nth-child(3) {
        .num {
          color: $color-d;
          border-color: $color-d;
        }
      }
    }
  }
}
</style>
