<template>
  <div class="search-page flex flexc">
    <Header>
      <div slot="title" class="title">快速查看</div>
    </Header>
    <div class="main flex1 flex flexc">
      <PageTop>
        <div slot="count" class="count">
          共计<span class="data-count">{{ total }}</span
          >个文件夹
        </div>
        <SearchBox
          slot="search-right"
          width="834px"
          placeholder="输入文件夹关键字搜索"
          @click="handleSearch"
          v-model="searchVal"
        ></SearchBox>
      </PageTop>
      <!-- 事项文件夹 -->
      <div class="folder-box">
        <div class="folder-list" v-if="folderList.length || !isSearch">
          <div class="folder-item" @click="handleCheck({})" v-if="!isSearch">
            <div class="folder-img-box flex aic jcc">
              <i class="el-icon-more"></i>
            </div>
            <p class="folder-name tac">全部</p>
          </div>
          <div
            class="folder-item"
            v-for="v in folderList"
            :key="v.id"
            @click="handleCheck(v)"
            v-onEvent="{
              eventName: '点击',
              eventCode: 'Click',
              businessCode: 'check_matter_category',
              businessName: '查看事项分类',
              routers: $route,
            }"
          >
            <div class="folder-img-box flex aic jcc">
              <i class="iconfont icon-folder"></i>
            </div>
            <p class="folder-name tac">
              {{ v.categoryName }}
            </p>
          </div>
        </div>
        <YEmpty v-else width="200" text="暂无数据"></YEmpty>
        <!-- 分页 -->
        <div class="pagination">
          <YPagination
            :total="total"
            :hideOnSinglePage="true"
            :current="current"
            :size="size"
            @change="changePage"
          >
          </YPagination>
        </div>
      </div>
    </div>
    <!-- 材料列表 -->
    <MateralsList
      :matterInfo="matterInfo"
      :visible.sync="visible"
    ></MateralsList>
  </div>
</template>

<script>
import Header from "@/components/Header.vue";
import PageTop from "@/components/PageTop.vue";
import SearchBox from "@/components/SearchBox.vue";
import MateralsList from "@/components/MateralsList.vue";
import YEmpty from "@/components/YEmpty.vue";
import YPagination from "@/components/YPagination.vue";
import {
  getMatterFolderList,
  getMaterialsList,
  getSampleformMatterInfo,
} from "@/api";
export default {
  components: {
    Header,
    PageTop,
    SearchBox,
    MateralsList,
    YEmpty,
    YPagination,
  },
  data() {
    return {
      row: 4,
      searchVal: "",
      isSearch: false,
      total: 0,
      current: 1,
      size: 18,
      matterInfo: {},
      folderList: [],
      visible: false,
    };
  },
  created() {
    this.getMatterFolderList();
  },
  watch: {
    searchVal(newVal) {
      if (newVal === "") {
        this.current = 1;
        this.getMatterFolderList();
        this.isSearch = false;
      }
    },
  },
  methods: {
    // 获取事项分类
    async getMatterFolderList() {
      let res = await getMatterFolderList({
        page: this.current,
        size: this.size,
        matterId: this.$route.query.matterId,
        categoryName: `%${this.searchVal}%`,
      });
      if (res.data.code == 1) {
        let { data, total } = res.data.data;
        this.total = total;
        this.folderList = data;
      }
    },

    // 搜索
    handleSearch() {
      this.current = 1;
      this.getMatterFolderList();
      if (this.searchVal) {
        this.isSearch = true;
      }
    },
    // 分页
    changePage(cur) {
      this.current = cur;
      this.getMatterFolderList();
    },
    // 查看
    async handleCheck(row) {
      let res = await getSampleformMatterInfo({
        id: this.$route.query.matterId,
      });
      if (res.data.code == 1) {
        let { data } = res.data;
        let result = await getMaterialsList({
          categoryId: row.id,
          matterId: this.$route.query.matterId,
          page: 1,
          size: -1,
        });
        if (result.data.code == 1) {
          data.matterDatumList = result.data.data.data;
          this.matterInfo = data;
          this.matterInfo = data;
          this.visible = true;
        }
      }
    },
  },
};
</script>

<style lang="less" scoped>
.search-page {
  width: 100%;
  height: 100%;
  background-color: #f5f5f5;
}
.main {
  padding: 0px 40px;
  padding-bottom: 30px;
  .data-count {
    color: #ff0000;
  }
}
.folder-box {
  width: 1840px;
  height: 800px;
  padding: 30px;
  padding-bottom: 10px;
  background: #ffffff;
  border-radius: 16px;
  position: relative;
  .empty {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
  }
  .folder-list {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 40px 115px;
  }

  .folder-item {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
    gap: 20px;
    cursor: pointer;
    .folder-img-box {
      width: 134px;
      height: 129px;
      background-color: rgba(250, 147, 45, 0.1);
      border-radius: 16px;
      i {
        font-size: 90px;
        color: #fca134;
      }
    }
    .folder-name {
      width: 100%;
      font-family: Source Han Sans CN;
      font-weight: 500;
      font-size: 24px;
      color: #333333;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
}
.pagination {
  margin-top: 50px;
}
</style>
