<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 + 1 }}</span
          >个文件夹
        </div>
        <SearchBox
          slot="search-right"
          width="834px"
          placeholder="输入文件夹关键字搜索"
          @click="handleSearch"
          v-model="searchVal"
        ></SearchBox>
      </PageTop>
      <!-- 事项文件夹 -->
      <div class="folder-box flex1">
        <div class="folder-list">
          <div class="folder-item" @click="handleCheck({})">
            <div class="folder-img-box flex aic jcc">
              <i class="iconfont icon-folder"></i>
            </div>
            <p class="folder-name tac">所有</p>
          </div>
          <div
            class="folder-item"
            v-for="v in folderList"
            :key="v.id"
            @click="handleCheck(v)"
          >
            <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="tac">
          <el-pagination
            prev-text="上一页"
            next-text="下一页"
            layout="prev,next"
            :total="total"
            hide-on-single-page
            :current-page="current"
            :page-size="size"
            @current-change="changePage"
          >
          </el-pagination>
        </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 {
  getMatterFolderList,
  getMaterialsList,
  getSampleformMatterInfo,
} from "@/api";
import { mapMutations } from "vuex";
export default {
  components: {
    Header,
    PageTop,
    SearchBox,
    MateralsList,
    YEmpty,
  },
  data() {
    return {
      row: 4,
      searchVal: "",
      total: 0,
      current: 1,
      size: 16,
      matterInfo: {},
      folderList: [],
      visible: false,
    };
  },
  created() {
    this.getMatterFolderList();
  },
  watch: {
    searchVal(newVal) {
      if (newVal === "") {
        this.current = 1;
        this.getMatterFolderList();
      }
    },
  },
  methods: {
    ...mapMutations(["SET_operTime"]),
    // 获取事项分类
    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();
    },
    // 分页
    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;
          let time = this.$moment().format("YYYY-MM-DD HH:mm:ss");
          this.SET_operTime(time);
          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 {
    display: flex;
    flex-wrap: wrap;
    gap: 40px 115px;
  }

  .folder-item {
    display: flex;
    flex-direction: column;
    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 {
      font-family: Source Han Sans CN;
      font-weight: 500;
      font-size: 24px;
      color: #333333;
    }
  }
}
:deep(.btn-prev) {
  margin-right: 80px;
}
:deep(.btn-prev),
:deep(.btn-next) {
  width: 78px;
  height: 25px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: var(--main-theme-color);
  line-height: 28px;
  span {
    font-size: 28px;
  }
}
</style>
