<template>
  <!-- 快速查看 -->
  <div class="matter-page flex flexc">
    <!-- 头部 -->
    <Header>
      <div slot="title" class="title">快速查看</div>
    </Header>
    <!-- 主体 -->
    <div class="main flex1 flex">
      <LeftMenus @click="changeDept"></LeftMenus>
      <div class="right flex1 flex flexc">
        <!-- 搜索 -->
        <PageTop>
          <div slot="count" class="count">
            共计<span class="data-count" v-format="'#,##0'">{{
              matterTotal
            }}</span
            >件事项
          </div>
          <SearchBox
            slot="search-right"
            width="834px"
            v-model="searchVal"
            @click="handleSearch"
          ></SearchBox>
        </PageTop>
        <!-- 事项列表 -->
        <div class="matter-box flex1">
          <div class="matter-list" v-if="matterList.length">
            <div
              class="matter-item"
              v-for="v in matterList"
              :key="v.id"
              @click="handleCheck(v)"
            >
              <div v-if="v.isRecommend" class="hot-icon flex jcc aic">
                <i class="iconfont icon-hot"></i>
                <span>热门</span>
              </div>
              <div
                class="for-short"
                :class="{ isRecommend: v.isRecommend }"
                v-html="v.matterName"
              ></div>
              <div class="name">
                <span class="matter-fullName">事项全称</span
                >{{ v.matterFullName }}
              </div>
            </div>
          </div>
          <el-empty class="empty" :image-size="200" v-else></el-empty>
          <!-- 分页 -->
          <div class="tac">
            <el-pagination
              prev-text="上一页"
              next-text="下一页"
              hide-on-single-page
              layout="prev,next"
              :total="matterTotal"
              :current-page="current"
              :page-size="size"
              @current-change="changePage"
            >
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
    <!-- 材料列表 -->
    <MateralsList
      :matterInfo="matterInfo"
      :visible.sync="visible"
    ></MateralsList>
  </div>
</template>

<script>
import Header from "@/components/Header.vue";
import LeftMenus from "./components/LeftMenus.vue";
import PageTop from "@/components/PageTop.vue";
import SearchBox from "@/components/SearchBox.vue";
import MateralsList from "../../components/MateralsList.vue";
import { getWriteMatterList } from "@/api";

export default {
  components: {
    Header,
    LeftMenus,
    PageTop,
    SearchBox,
    MateralsList,
  },
  data() {
    return {
      current: 1,
      size: 12,
      matterInfo: {},
      visible: false,
      searchVal: "",
      deptCode: "",
      matterTotal: 0,
      materals: {},
      matterList: [],
    };
  },
  created() {
    this.getWriteMatterList();
  },
  watch: {
    searchVal(newVal) {
      if (newVal === "") {
        this.current = 1;
        this.getWriteMatterList();
      }
    },
  },
  methods: {
    // 获取事项列表
    async getWriteMatterList() {
      let res = await getWriteMatterList({
        page: this.current,
        size: this.size,
        deptCode: this.deptCode,
        matterName: this.searchVal,
        isTerminal: 1,
      });
      let { total, data } = res.data.data;
      this.matterList = data;
      this.matterTotal = total;
    },
    // 切换部门
    changeDept(deptCode) {
      this.deptCode = deptCode;
      this.current = 1;
      this.getWriteMatterList();
    },
    // 搜索
    handleSearch() {
      this.current = 1;
      this.getWriteMatterList();
    },
    // 分页
    changePage(cur) {
      this.current = cur;
      this.getWriteMatterList();
    },
    handleCheck(row) {
      this.matterInfo = row;
      this.visible = true;
    },
    // 重置搜索
    // handleClear() {
    //   this.searchVal = "";
    // },
  },
};
</script>

<style lang="less" scoped>
.matter-page {
  width: 100%;
  height: 100%;
  background-color: #f5f5f5;
}

.main {
  width: 100%;
  height: 100%;
  margin-top: 10px;

  .right {
    height: 100%;
    padding: 0px 40px;
    padding-bottom: 20px;

    .data-count {
      color: var(--main-assist-color3);
    }
  }

  .matter-box {
    width: 1540px;
    height: 800px;
    padding: 30px;
    background: #ffffff;
    border-radius: 16px;
    position: relative;
    .empty {
      position: absolute;
      left: 0;
      top: 0;
      right: 0;
      bottom: 0;
    }
    .matter-list {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      &::after {
        content: "";
        width: 474px;
        border: 1px solid transparent;
      }
    }

    .matter-item {
      width: 474px;
      height: 150px;
      margin-bottom: 30px;
      padding: 20px;
      background: #f7fafd;
      border-radius: 16px;
      cursor: pointer;
      position: relative;
      .hot-icon {
        width: 87px;
        height: 36px;
        background: linear-gradient(87deg, #fdba6b, #f15800);
        border-radius: 0px 16px 0px 9px;
        font-size: 20px;
        font-family: Source Han Sans CN;
        color: #ffffff;
        position: absolute;
        top: 0px;
        right: 0px;
        .icon-hot {
          margin-right: 4px;
          font-size: 20px;
          color: #ffe96d;
        }
      }
      .for-short {
        margin-bottom: 10px;
        font-size: 24px;
        font-weight: 500;
        line-height: 36px;
        color: #333333;
        letter-spacing: 1px;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1;
        overflow: hidden;
      }
      .isRecommend {
        max-width: 340px;
      }
      .name {
        margin-bottom: 10px;
        font-size: 18px;
        font-family: Source Han Sans CN;
        color: #888888;
        line-height: 24px;
        letter-spacing: 1px;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
      }

      .materials {
        font-size: 18px;
        font-family: Source Han Sans CN;
        color: #333333;
        line-height: 30px;
        .count {
          color: #2878ff;
        }
      }
    }

    :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>