<template>
  <div class="wrapper">
    <div :span="5" class="left">
      <el-input
        placeholder="搜索文件"
        suffix-icon="el-icon-search"
        clearable
        size="mini"
      ></el-input>
      <div class="total">共计{{ markList.totalElements }}条数据</div>
      <el-row class="list">
        <el-col
          v-for="(item, index) in markList.records"
          :key="index"
          @click.native="handleClickArticle(item)"
        >
          <div v-if="item" class="item">
            <div class="item-left" :title="item.name">
              <svg-icon
                :icon-class="getIcon(item)"
                style="margin-right: 4px"
              ></svg-icon>
              <span>{{ item.name }}</span>
            </div>
            <div class="item-right">
              <i class="el-icon-more"></i>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
    <div :span="19" class="right">
      <div class="singleArticle" v-if="currentFile.name">
        <el-row class="info">
          <el-col :span="8" class="center">{{ currentFile.name }}</el-col>
          <el-col :span="8" class="center">{{ currentFile.author }}</el-col>
          <el-col :span="8" class="center"
            ><el-button type="text">查看原文</el-button></el-col
          >
        </el-row>

        <div>
          <el-card
            class="info"
            shadow="hover"
            v-for="(item, index) in mockNote.data"
            :key="index"
          >
            {{ item }}
          </el-card>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { getBookList, getBookMark } from "@/api/doc/bookMark";
import { mockNote } from "./mockNote";
export default {
  data() {
    return {
      markList: {
        records: [],
        pageNo: 1,
        pageSize: 10,
      },
      currentFile: {},
      mockNote,
    };
  },
  computed: {
    getIcon(row) {
      return (row) => {
        const { showType } = row;
        if (["doc", "docx", "word"].includes(row.showType)) {
          return "word";
        } else if (["pdf"].includes(row.showType)) {
          return "pdf-color";
        }
      };
    },
  },
  mounted() {
    this.loadBookMarkList();
  },
  methods: {
    async loadBookMarkList() {
      let res = await getBookList();
      console.log(res);
      if (res.result) {
        this.markList = res.result;
      }
    },
    // 点击文章
    async handleClickArticle(item) {
      this.currentFile = item;
      const { id, docSType } = this.currentFile;
      const params = {
        docId: id,
        docSType,
      };
      const res = await getBookMark(params);
      console.log(res);
    },
  },
};
</script>
<style lang="scss" scoped>
.wrapper,
.left,
.right {
  height: 100%;
}
.wrapper {
  display: flex;
}
.left {
  width: 300px;
  background-color: #f2f3f5;
  border-right: #fefefe;
  height: 100%;
  overflow: auto;
  padding: 16px 20px;
  .total {
    padding: 16px 0 0;
    font-size: 14px;
  }
  .list {
    font-size: 14px;
    padding: 16px 0;
    .item {
      cursor: pointer;
      padding: 8px;
      color: #333;
      display: flex;
      .item-left {
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
      }
      &:hover {
        background-color: #eaebed;
      }
    }
    .active {
      color: $theme-blue;
      background-color: #d6d8db;
    }
  }
}
.right {
  flex: 1;
  padding: 0 16px 16px;
  .info {
    padding: 16px;
    border-bottom: 1px solid #e7e7e7;
    margin-bottom: 8px;
    .center {
      display: flex;
      justify-content: center;
    }
  }
}
</style>
