<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
          >件事项
          <!-- ，<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 v-if="matter.isRecommend" class="hot-icon flex jcc aic">
              <i class="iconfont icon-hot"></i>
              <span>热门</span>
            </div>
            <div
              class="for-short"
              :class="{ isRecommend: matter.isRecommend }"
              v-html="matter.matterName"
            ></div>
            <div class="name">
              <span class="matter-fullName">事项全称</span
              ><span v-html="matter.matterFullName"></span>
            </div>
            <!-- 材料展示 -->
            <!-- <div
              class="materials flex aic"
              v-for="(item, index) in matter.matterDatumList.slice(0, 3)"
              :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">
                  {{
                    `${
                      matter.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>
        <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 { getSampleformMatterList, getMatterForFlownum } from "@/api";
import { mapMutations } from "vuex";
export default {
  components: {
    Header,
    PageTop,
    SearchBox,
    MateralsList,
    YEmpty,
  },
  data() {
    return {
      row: 4,
      searchVal: this.$route.query.val,
      total: 0,
      current: 1,
      size: 16,
      matterInfo: {},
      visible: false,
      matterTotal: 0,
      matterDatumTotal: 0,
      matterList: [], // 事项列表
      matterDatumList: [], // 所有材料列表
    };
  },
  created() {
    this.typeSearch();
    // this.getAllmaterials();
  },
  watch: {
    searchVal(newVal) {
      if (newVal === "") {
        this.current = 1;
        this.typeSearch();
      }
    },
  },
  methods: {
    ...mapMutations(["SET_operTime"]),
    // 区分搜索
    async typeSearch() {
      let reg = /^[\u4e00-\u9fa5]+$/;
      if (reg.test(this.searchVal) || this.searchVal == "") {
        this.getSampleformMatterList(this.searchVal);
      } else {
        await this.getMatterForFlownum(this.searchVal);
      }
    },
    // 获取事项列表
    async getSampleformMatterList(matterFullName) {
      let res = await getSampleformMatterList({
        page: this.current,
        size: this.size,
        isTerminal: 1,
        matterFullName,
      });
      let { total, matterDatumTotal, data } = res.data.data;
      this.matterList = data;
      this.total = total;
      this.matterDatumTotal = matterDatumTotal;
    },
    // 排队编号获取事项
    async getMatterForFlownum(flownum) {
      let matterFullName = "";
      let res = await getMatterForFlownum({ flownum });
      if (res.data.code == 1) {
        let { data } = res.data.data;
        if (data.length) {
          matterFullName = data[0].matterName;
          this.getSampleformMatterList(matterFullName);
        }
      }
    },
    // 搜索
    handleSearch() {
      this.current = 1;
      this.typeSearch();
    },
    // 分页
    changePage(cur) {
      this.current = cur;
      this.typeSearch();
    },
    // 查看
    handleCheck(row) {
      let time = this.$moment().format("YYYY-MM-DD HH:mm:ss");
      this.SET_operTime(time);
      this.matterInfo = row;
      this.visible = true;
    },
    // 重置搜索
    // handleClear() {
    //   this.searchVal = "";
    // },
  },
};
</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;
  }
}
.matter-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;
  }
  .matter-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
  }
  .list {
    content: "";
    width: 422px;
    border: 1px solid transparent;
    padding: 5px;
    overflow: hidden;
  }
  .matter-item {
    width: 422px;
    // height: 210px;
    height: 150px;
    // padding: 10px 20px;
    padding: 20px;
    margin-bottom: 30px;
    background: #edf6fe;
    border-radius: 16px;
    position: relative;
    cursor: pointer;
    .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;
      margin-bottom: 18px;
      font-size: 28px;
      font-weight: 500;
      color: #333333;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .isRecommend {
      max-width: 320px;
    }
    .name {
      margin-bottom: 10px;
      font-size: 22px;
      font-family: Source Han Sans CN;
      color: #888888;
      line-height: 24px;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      overflow: hidden;
    }
    .material-name {
      display: inline-block;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .materials {
      font-size: 22px;
      font-family: Source Han Sans CN;
      color: #333333;
      line-height: 28px;
      .isMore {
        max-width: 270px;
      }
      .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>