<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">{{ matterTotal }}</span
          >件事项
          <!-- ，<span class="data-count">{{ matterDatumTotal }}</span
          >份表单 -->
        </div>
        <SearchBox
          slot="search"
          width="834px"
          @click="handleSearch"
          v-model="searchVal"
        ></SearchBox>
      </PageTop>
      <!-- 事项列表 -->
      <div class="matter-box flex1">
        <div class="matter-list" v-if="matterList.length">
          <div
            class="matter-item"
            v-for="matter in matterList"
            :key="matter.id"
            @click="handleCheck(matter)"
          >
            <div class="for-short" v-html="matter.matterName"></div>
            <div class="name">
              {{ matter.matterFullName }}
            </div>
            <div
              class="materials flex aic"
              v-for="(item, index) in matter.matterDatumList"
              :key="item.id"
            >
              <i class="iconfont icon-dot"></i>
              <span
                class="material-name"
                :class="{
                  isMore: index === 2 && matter.matterDatumList.length > 3,
                }"
              >
                {{ item.materiaFullName }}
              </span>
              <span v-if="index === 2 && matter.matterDatumList.length > 3">
                等
                <span class="count">
                  {{
                    `${
                      v.matterDatumList && matter.matterDatumList.length
                    }份材料`
                  }}
                </span>
              </span>
            </div>
          </div>
          <div
            class="list"
            v-for="item in row - (matterList.length % row)"
            v-show="matterList.length % row > 0"
            :key="'list' + item"
          ></div>
        </div>
        <el-empty :image-size="200" v-else></el-empty>
        <!-- 分页 -->
        <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 { getWriteMatterList } from "@/api";
export default {
  components: {
    Header,
    PageTop,
    SearchBox,
    MateralsList,
  },
  data() {
    return {
      row: 4,
      searchVal: this.$route.query.val,
      total: 0,
      current: 1,
      size: 12,
      matterInfo: {},
      visible: false,
      matterTotal: 0,
      matterDatumTotal: 0,
      matterList: [], // 事项列表
      matterDatumList: [], // 所有材料列表
    };
  },
  created() {
    this.getWriteMatterList();
    // this.getAllmaterials();
  },
  watch: {
    searchVal(newVal) {
      if (newVal === "") {
        this.current = 1;
        this.getWriteMatterList();
      }
    },
  },
  methods: {
    // 获取事项列表
    async getWriteMatterList() {
      let res = await getWriteMatterList({
        page: this.current,
        size: this.size,
        isTerminal: 1,
        matterName: this.searchVal,
      });
      let { total, matterDatumTotal, data } = res.data.data;
      this.matterList = data;
      this.matterTotal = total;
      this.matterDatumTotal = matterDatumTotal;
      console.log(data);
    },
    // 搜索
    handleSearch() {
      this.current = 1;
      this.getWriteMatterList();
    },
    // 分页
    changePage(cur) {
      this.current = cur;
      this.getWriteMatterList();
    },
    // 查看
    handleCheck(row) {
      this.matterInfo = row;
      this.visible = true;
    },
  },
};
</script>

<style lang="less" scoped>
.search-page {
  width: 100%;
  height: 100%;
  background-color: #f5f5f5;
}
.main {
  padding: 0px 40px;
  padding-bottom: 40px;
  .data-count {
    color: #ff0000;
  }
}
.matter-box {
  width: 100%;
  padding: 30px;
  background: #ffffff;
  border-radius: 16px;
  .matter-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
  }
  .list {
    content: "";
    width: 426px;
    border: 1px solid transparent;
    padding: 5px;
    overflow: hidden;
  }
  .matter-item {
    width: 426px;
    height: 200px;
    padding: 10px;
    margin-bottom: 34px;
    background: #edf6fe;
    border-radius: 16px;
    cursor: pointer;

    .for-short {
      margin-bottom: 10px;
      font-size: 24px;
      font-weight: 500;
      color: #333333;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .name {
      margin-bottom: 10px;
      font-size: 18px;
      font-family: Source Han Sans CN;
      color: #888888;
      line-height: 24px;
      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: 28px;
      .isMore {
        max-width: 320px;
      }
      .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-color1);
  line-height: 28px;
  span {
    font-size: 28px;
  }
}
</style>