<template>
  <div style="display: flex">
    <div class="plate">
      <div class="breadcrumb">首页 / <span>搜索</span></div>
      <div class="iptBox">
        <el-input
          class="ipt"
          prefix-icon="el-icon-search"
          v-model="keyword"
          placeholder="请输入关键字"
          clearable
        ></el-input>
      </div>
      <div class="cont" v-for="(item, i) in list" :key="i">
        <div class="contFlex">
          <div class="contTitle">{{ item.name }}</div>
          <!-- <div class="" style="display: flex">
            <div class="contNumb">
              <i class="el-icon-download"></i>{{ item.downloadCount || 0 }}
            </div>
          </div> -->
          <el-tag type="success" v-if="item.type === 'service'" color="#FFF"
            >服务</el-tag
          >
          <el-tag type="primary" v-if="item.type === 'data'" color="#FFF"
            >数据</el-tag
          >
          <el-tag type="warn" v-if="item.type === 'literature'" color="#FFF"
            >文献</el-tag
          >
          <el-tag type="info" v-if="item.type === 'catalogue'" color="#FFF"
            >资源目录</el-tag
          >
          <el-tag type="danger" v-if="item.type === 'topic'" color="#FFF"
            >专题</el-tag
          >
        </div>
        <div class="contFlex on">
          <div>
            <div class="" style="display: flex; margin-bottom: 10px">
              <div class="contText">描述</div>
              <div class="contTxt">
                {{ item.remark }}
              </div>
            </div>
          </div>
          <div class="" style="display: flex">
            <!-- <el-button type="primary"
              >查看</el-button
            > -->
            <a class="view" :href="item.url" :target="item.target">查看详情</a>
          </div>
        </div>
      </div>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
        class="customer-pagination"
      />
    </div>
  </div>
</template>

<script>
import { parseQueryParam } from "@/utils/dxp";
import { searchList } from "@/api/customer/search";
export default {
  name: "Search",
  watch: {
    keyword: {
      handler(val) {
        this.queryParams.keyword = val;
        this.getList();
      },
    },
  },
  data() {
    return {
      keyword: "",
      queryParams: {
        keyword: null,
        pageNum: 1,
        pageSize: 4,
      },
      loading: false,
      list: [],
      total: 0,
    };
  },
  created() {
    // 获取参数
    const params = parseQueryParam(window.location.search);
    if (params.keyword) {
      this.keyword = decodeURIComponent(params.keyword);
      this.queryParams.keyword = this.keyword;
    } else {
      this.keyword = null;
      this.queryParams.keyword = null;
    }

    this.getList();
  },
  methods: {
    getList() {
      // if (!this.queryParams.keyword) {
      //   return;
      // }
      this.loading = true;
      searchList(this.queryParams).then((response) => {
        this.loading = false;
        this.list = response.rows;
        this.total = response.total;
      });
    },
  },
};
</script>

<style scoped lang="scss">
.left-tree {
  width: 270px;
  padding: 20px;
  box-shadow: 1px 0px 25px 0px rgba(0, 0, 0, 0.04);
  overflow: hidden;
}
.plate {
  padding: 20px 30px;
  box-sizing: border-box;
  width: 100%;
  background: #fafafa;
  min-height: 900px;

  .iptBox {
    width: 100%;
    background: #ffffff;
    box-shadow: 0px 2px 12px 0px rgba(159, 192, 255, 0.14);
    border-radius: 4px;
    padding: 30px;
    box-sizing: border-box;
    margin: 30px 0;

    .ipt {
      width: 340px;
      height: 42px;
    }
  }

  .cont {
    width: 100%;
    padding: 20px 30px;
    box-sizing: border-box;
    background: #ffffff;
    box-shadow: 0px 2px 12px 0px rgba(159, 192, 255, 0.14);
    border-radius: 4px;
    margin-bottom: 20px;

    .contFlex {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 20px;

      .contTitle {
        font-size: 20px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #333333;
      }

      .contNumb {
        font-size: 14px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #333333;
        margin-left: 30px;
      }

      .el-icon-view {
        color: #2866ff;
        margin-right: 10px;
      }

      .el-icon-download {
        color: #2866ff;
        margin-right: 10px;
      }

      .contText {
        width: 94px;
        font-size: 16px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #999999;
      }

      .contTxt {
        font-size: 16px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #666666;
      }
    }

    .contFlex.on {
      margin-bottom: 0;
    }
  }
}

.customer-pagination {
  background: none;
}

.file-item {
  margin-bottom: 20px;
  text-decoration: underline;
  color: #46a6ff;
}
.view {
  color: #1890ff;
}
</style>
