<template>
  <div class="list">
    <div class="serch-wrapper">
      <div class="search">
        <input
          type="text"
          v-model="keyword"
          placeholder="请输入内容进行搜索"
          class=""
          @keyup.enter="getList()"
        />
        <img
          src="../../assets/img/search.png"
          class="hand"
          @click="getList()"
        />
      </div>
    </div>
    <div class="empty" v-if="tipList.length == 0">暂无数据</div>
    <div class="wrapper">
      <div
        class="tip"
        v-for="item in tipList"
        :key="item.id"
        @click="tipClick(item.url?item.url:('/popularScience/detail?id=' + item.id))"
      >
        <img :src="item.image" />
        <div class="info hand">
          <div class="title clamp">{{ item.title }}</div>
          <div class="content clamp">{{ item.synopsis }}</div>
          <div class="num">{{ item.visit }}人已观看</div>
        </div>
      </div>
      <el-pagination
        layout="prev, pager, next"
        :total="total"
        background
        prev-text="上一页"
        next-text="下一页"
        @current-change="currentChange"
        :page-size="7"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { splist, getArtList } from "../../request/api.js";

export default {
  data() {
    return {
      tipList: [],
      alllist: [],
      total: 0,
      page: 1,
      limit: 7,
      keyword: "",
    };
  },
  created() {
    this.getAllList();
  },
  methods: {
    tipClick(url) {
		if(url.indexOf('http') != -1) {
			window.open(url)
		}else {
			this.$router.push(url);
		}
      // this.$router.push("/popularScience/detail?id=" + id);
    },
    //分页页码改变触发事件
    currentChange(e) {
      this.page = e;
      this.getList();
    },
    getAllList() {
      let obj = this;
      let data = {
        page: this.page,
        limit: this.limit,
      };
      getArtList({
        ifyid: 1,
        page: obj.page,
        limit: obj.limit,
        key: obj.keyword,
      }).then(({ data }) => {
        obj.total = data.count;
        obj.tipList = data.list;
		console.log( obj.tipList,' obj.tipList+++++')
      });
    },
    getList() {
      let obj = this;
      if (obj.keyword) {
        obj.page = 1;
      }
    //   let data = {
    //     page: this.page,
    //     limit: this.limit,
    //     name: this.keyword,
    //   };
     getArtList({
        ifyid: 1,
        page: obj.page,
        limit: obj.limit,
        key: obj.keyword,
      }).then(({ data }) => {
        obj.tipList = data.list;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.list {
  position: relative;
}
.empty {
  text-align: center;
  color: #999;
  height: 400px;
  line-height: 400px;
}
.tip {
  width: 815px;
  height: 127px;
  border-bottom: 1px solid #f2f2f2;
  display: flex;
  align-items: center;
  img {
    width: 155px;
    height: 98px;
  }
  .info {
    padding-left: 16px;
    .title {
      padding-top: 5px;
      width: 200px;
      // height: 19px;

      font-size: 18px;
      font-family: PingFang SC;
      font-weight: bold;
      color: #333333;
    }
    .content {
      width: 491px;
      height: 16px;
      font-size: 16px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #999999;
      line-height: 1;
      padding-top: 11px;
    }
    .num {
      margin-top: 24px;
      height: 16px;
      font-size: 16px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #999999;
      line-height: 27px;
      text-align: right;
    }
  }
}
/deep/ .el-pagination {
  margin-top: 50px;
  text-align: center;
}
.serch-wrapper {
  display: flex;
  height: 33px;
  position: absolute;
  top: -80px;
  right: -50px;

  .search {
    padding-left: 13px;
    padding-right: 13px;
    width: 295px;
    height: 33px;
    line-height: 33px;
    background: #ffffff;
    border: 1px solid #cccccc;
    border-radius: 10px;
    // margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;

    input {
      width: 235px;
      font-size: 16px;
      font-family: PingFang SC;
      font-weight: bold;
      outline: none;
      border: none;
    }

    img {
      width: 20px;
      height: 20px;
    }
  }
}
</style>
