<template>
  <div class="main-list">
    <ul v-if="list.length">
      <li v-for="item in list" :key="item.id" @click="onClick">{{item.title}}</li>
    </ul>
    <template v-else>
      <slot name="empty">
        <div class="empty">暂时没有内容哦，换个搜索词试试吧～</div>
      </slot>
    </template>
  </div>
</template>

<script>
import * as api from '@/api/course.js'
export default {
  name: 'TagList',
  props: {
    params: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      list: [],
      requestParams: {}
    }
  },
  watch: {
    params: {
      immediate: true,
      handler(value) {
        this.requestParams = Object.assign({}, this.requestParams, value)
      }
    }
  },
  methods: {
    getList() {
      api.getTagSearchList(this.requestParams).then(response => {
        this.list = response
      })
    },
    // 刷新
    refresh() {
      this.getList()
    },
    onClick() {
      window.alert('开发中')
      // this.$router.push({ name: 'courseLearnItem', params: { id } })
    }
  },
  beforeMount() {
    this.getList()
  }
}
</script>

<style lang="scss" scoped>
.main-list li {
  padding: 0.3rem 0;
  font-size: 0.3rem;
  color: #222;
  border-bottom: 1px solid #f1f1f1;
}
</style>
