<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="getFileIcon(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="single-article">
        <el-row class="info">
          <el-col :span="16">
            <el-row>
              <el-col class="info-title">
                {{ currentFile.name }}
              </el-col>
              <el-col>
                <span class="info-author">
                  作者： {{ currentFile.author }}
                </span>
                <el-button type="text">查看原文</el-button>
              </el-col>
            </el-row>
          </el-col>
        </el-row>

        <div class="card-group">
          <el-card
            class="card-item"
            shadow="hover"
            v-for="(item, index) in mockNote.data"
            :key="index"
          >
            <div class="oprations">
              <el-link type="primary"><i class="el-icon-edit"></i></el-link>
              <el-link type="danger"><i class="el-icon-delete"></i></el-link>
            </div>
            <div class="bookmark">
              <span>
                <svg-icon :icon-class="getNoteTypeIcon(item.type)" />
                {{ item.subject }}:
              </span>
              <span> {{ item.bookmarkContent }}</span>
            </div>
            <div class="source">
              <span>
                <svg-icon icon-class="source" />
                来源：
              </span>
              <span>{{ item.docName }}</span>
            </div>
          </el-card>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { getBookMarkList, getBookMark } from "@/api/doc/bookMark";
import { mockNote } from "./mockNote";
export default {
  data() {
    return {
      markList: {
        records: [],
        pageNo: 1,
        pageSize: 10,
      },
      currentFile: {},
      mockNote,
    };
  },
  computed: {
    getFileIcon(row) {
      return (row) => {
        const { showType } = row;
        if (["doc", "docx", "word"].includes(row.showType)) {
          return "word";
        } else if (["pdf"].includes(row.showType)) {
          return "pdf-color";
        }
      };
    },
    getNoteTypeIcon(type) {
      return (type) => {
        return type ? type : "underline";
      };
    },
  },
  mounted() {
    this.loadBookMarkList();
  },
  methods: {
    async loadBookMarkList() {
      let res = await getBookMarkList();
      console.log(res);
      if (res.data) {
        this.markList = res.data;
      }
    },
    // 点击文章
    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;
  // 单篇文章
  .single-article {
    //文章基本信息
    .info {
      padding: 16px;
      margin-bottom: 8px;
      .info-title {
        color: #333;
        font-size: 18px;
        font-weight: bold;
      }
      .info-author {
        margin-right: 18px;
      }
    }
    .card-group {
      .card-item {
        font-size: 14px;
        margin-bottom: 16px;
        .oprations {
          display: flex;
          justify-content: flex-end;
        }
        .bookmark {
          .svg-icon {
            color: $theme-blue;
          }
        }
        .source {
          .svg-icon {
            color: $danger;
          }
        }
      }
    }
  }
}
</style>
