<template>
  <div class="display">
    <!-- <NavBar /> -->
    <ListBanner title="精选展览" />
    <div class="content-wrapper">
      <div class="content">
        <div class="search wow animate__animated animate__fadeIn">
          <el-input
            class="input item"
            v-model="keyword"
            placeholder="请输入关键词"
            @keyup.enter.native="search"
            clearable
          >
            <!-- <span class="input-icon" slot="prefix">
              <svg-icon icon-class="keyword"></svg-icon>
            </span> -->
          </el-input>
          <el-select
            class="type item"
            v-model="type"
            placeholder="请选择所属类别"
            filterable
            @change="handleTypeChange"
            clearable
          >
            <el-option
              v-for="(value, key) in dicts.displayType"
              :key="key"
              :label="value"
              :value="key"
            >
            </el-option>
          </el-select>
          <el-cascader
            class="years item"
            v-model="regionCode"
            :options="regionTree"
            :props="culturalRegionProps"
            placeholder="请选择所属地区"
            filterable
            @change="handleRegionChange"
            clearable
            ref="region"
          >
          </el-cascader>

          <div class="search-button" @click="search">
            <svg-icon icon-class="search"></svg-icon>
            检索
          </div>
        </div>
        <el-row :gutter="40" class="cr-list">
          <el-col
            :span="item.status == 1 ? 8 : 0"
            class="cr-item"
            @click.native="handleClick(item)"
            @mouseenter.native="handleEnterImg(item)"
            @mouseleave.native="handleLeaveImg(item)"
            v-for="(item, index) in list.records"
            :key="index"
          >
            <div
              class="container wow animate__animated animate__fadeInUp"
              v-if="item.status == 1"
            >
              <div class="img-container">
                <img
                  :src="
                    $getFullUrl(item.faceImagePressUrl || item.faceImageUrl)
                  "
                  width="100%"
                  class="face-image"
                  lazy
                />
                <div class="deco-left-top">
                  <img
                    :src="
                      require(`@/assets/imgs/list/img-deco${
                        item == currentImg ? '' : '-g'
                      }.png`)
                    "
                    alt=""
                  />
                </div>
                <div class="deco-left-bottom">
                  <img
                    :src="
                      require(`@/assets/imgs/list/img-deco${
                        item == currentImg ? '' : '-g'
                      }.png`)
                    "
                    alt=""
                  />
                </div>
                <div class="deco-right-top">
                  <img
                    :src="
                      require(`@/assets/imgs/list/img-deco${
                        item == currentImg ? '' : '-g'
                      }.png`)
                    "
                    alt=""
                  />
                </div>
                <div class="deco-right-bottom">
                  <img
                    :src="
                      require(`@/assets/imgs/list/img-deco${
                        item == currentImg ? '' : '-g'
                      }.png`)
                    "
                    alt=""
                  />
                </div>
              </div>
              <div class="desc">
                <div class="name">{{ item.title }}</div>
                <div class="desc-container">
                  <div class="left">
                    <div class="deptName">
                      <span>关键词：</span>
                      <span>{{ item.keyword ||'暂无' }}</span>
                    </div>
                    <div class="deptName">
                      <span>展览单位：</span>
                      <span>{{ item.deptName }}</span>
                    </div>
                  </div>
                  <!-- <div class="right">
                    <span class="collect">
                      <svg-icon icon-class="collect"></svg-icon>
                      <span>{{
                        item.collectCount ? item.collectCount : "收藏"
                      }}</span>
                    </span>
                    <span class="view">
                      <svg-icon icon-class="view"></svg-icon>
                      <span>{{ item.browseCount }}</span>
                    </span>
                  </div> -->
                </div>
              </div>
            </div>
          </el-col>
        </el-row>
        <el-empty
          description="暂无数据"
          v-if="list.records.length == 0"
        ></el-empty>
        <div class="pagination-container">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="Number(list.current)"
            :page-sizes="[20, 40, 100]"
            :page-size="Number(list.size)"
            layout="total, prev, pager, next"
            :total="Number(list.total)"
            class="pagination"
          >
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import ListBanner from "@/components/ListBanner";
import { getList } from "@/api/display";
import { mapGetters } from "vuex";
import { debounce } from "@/utils/index";
export default {
  name: "Display",
  components: { ListBanner },
  data() {
    return {
      list: {
        records: [],
        size: 15,
        current: 1,
        total: 0,
      },
      culturalRegionProps: {
        value: "code",
        label: "name",
        children: "children",
        checkStrictly: true, //单选选择任意一级选项
      },
      onlyShow3d: false,
      keyword: "",
      type: "",
      regionCode: [],
      regionTree: [],
      currentImg: null,
    };
  },
  computed: {
    ...mapGetters(["dicts"]),
  },
  async created() {
    await this.$store.dispatch("dict/getDictList", ["displayType"]);
  },
  mounted() {
    this.loadData();
    this.loadRegionTree();
  },
  // watch: {
  //   keyword(value) {
  //     debounce(this.handleKeyWordChange(value), 1000); //500ms
  //   },
  // },
  methods: {
    search() {
      this.loadData();
    },

    async loadData() {
      const params = {
        page: this.list.current,
        limit: this.list.size,
        title: this.keyword,
        type: this.type,
        regionCode: this.regionCode[this.regionCode.length - 1],
      };
      let res = await getList(params);
      if (res.code == 0) {
        this.list = res.data;
      }
    },
    // 改变页容量
    handleSizeChange(value) {
      this.list.size = value;
      this.loadData();
    },

    // 改变当前显示页
    handleCurrentChange(value) {
      this.list.current = value;
      this.loadData();
    },

    handleClick(item) {
      const { themeType, exhibitionId } = item;
      // const newPage = this.$router.resolve({
      //   path: `display/${themeType}/${exhibitionId}`,
      // });
      // window.open(newPage.href, "_blank");
      this.$router.push(`display/${themeType}/${exhibitionId}`);
    },
    defImg(e) {
      e.target.src = require("@/assets/404_images/no-pic.png");
    },

    handleTypeChange(value) {
      this.type = value;
      this.list.current = 1;
      this.loadData();
    },
    // handleKeyWordChange(value) {
    //   this.keyword = value;
    //   this.loadData();
    // },

    handleRegionChange(value) {
      this.regionCode = value;
      this.$refs.region.dropDownVisible = false;
      this.list.current = 1;
      this.loadData();
    },

    loadRegionTree() {
      let parentId = "";
      this.$store.dispatch("org/getSysRegionTreeData", parentId).then((res) => {
        this.regionTree = res;
        loopTree(this.regionTree);
        function loopTree(arr) {
          if (arr && arr.length > 0) {
            arr.forEach((item) => {
              if (item.children && item.children.length == 0) {
                delete item.children;
              } else {
                loopTree(item.children);
              }
            });
          }
        }
      });
    },
    handleEnterImg(item) {
      this.currentImg = item;
    },
    handleLeaveImg() {
      this.currentImg = null;
    },
    // loadRegionData() {
    //   this.$store.dispatch("org/getMuseumTreeData", false).then((res) => {
    //     this.museumTree = res[0].children;
    //   });
    // },
  },
};
</script>

<style lang="scss" scoped>
$blue: #2069c4;
$text-indent: 16px;
.display {
  width: 100%;
  // background-color: #2069c4;
  // color: #fff;
  .content-wrapper {
    padding-top: 60px;
    padding-bottom: 126px;
    background-color: #fff;

    .search {
      display: flex;
      justify-content: center;
      align-items: center;
      background-image: url("@/assets/imgs/list/search-bg.png");
      background-size: 22%;
      margin-bottom: 40px;
      // height: 214px;
      padding: 90px 70px 80px;
      .item {
        margin-right: 20px;
        &:hover {
          -webkit-box-reflect: below 2px
            linear-gradient(transparent, rgba(0, 0, 0, 0.3));
        }
      }
      .input-icon {
        height: 100%;
        display: flex;
        align-items: center;
        font-size: 20px;
        margin-left: 12px;
        color: #444;
      }

      .search-button {
        cursor: pointer;
        display: flex;
        justify-content: center;
        align-items: center;
        background: url("@/assets/imgs/list/search-button-bg.png");
        background-size: 100% 100%;
        color: #444;
        font-size: 14px;
        width: 156px;
        height: 40px;
        &:hover {
          -webkit-box-reflect: below 2px
            linear-gradient(transparent, rgba(0, 0, 0, 0.3));
        }
        // height: 100%;
        .svg-icon {
          margin-right: 4px;
        }
      }
    }
    .content {
      width: 100%;
      box-shadow: 0px 1px 56px 4px rgba(0, 0, 0, 0.16);
      .cr-list {
        padding: 0 74px;
        .cr-item {
          margin-bottom: 40px;
          .container {
            border: 2px solid #f1f1f1;
            position: relative;
            display: flex;
            flex-direction: column;
            cursor: pointer;
            transition: all 0.5s ease;
            &:hover {
              border: 2px solid #2069c4;
              .face-image {
                transform: scale(1.2);
              }
              .desc {
                background: url("@/assets/imgs/list/card-title-bg.png");
              }
              .img-container {
                .deco-left-top,
                .deco-left-bottom,
                .deco-right-top,
                .deco-right-bottom {
                  display: block;
                }
              }
            }
            .img-container {
              background-color: #f8f8f8;
              height: 268px;
              cursor: pointer;
              transition: all 0.5s ease;
              overflow: hidden;
              position: relative;
              .face-image {
                height: 100%;
                object-fit: cover;
                transition: all 0.5s ease;
              }
              .deco-left-top,
              .deco-left-bottom,
              .deco-right-top,
              .deco-right-bottom {
                position: absolute;
                width: 36px;
                height: 36px;
                // display: none;
                transition: all 0.5s ease;
                img {
                  width: 100%;
                  height: 100%;
                }
              }

              .deco-left-top {
                left: 0;
                top: 0;
                transform: rotate(180deg);
              }
              .deco-left-bottom {
                left: 0;
                bottom: 0;
                transform: rotate(90deg);
              }
              .deco-right-top {
                right: 0;
                top: 0;
                transform: rotate(270deg);
              }
              .deco-right-bottom {
                right: 0;
                bottom: 0;
              }
            }
            .desc {
              height: 150px;
              padding: 36px 30px;
              transition: all 0.5s ease;
              background: #fff;
              .name {
                font-size: 18px;
                font-weight: bold;
                color: #2069c4;
                margin-bottom: 18px;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
              }
              .desc-container {
                display: flex;
                align-items: flex-end;
                justify-content: space-between;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
                .left {
                  // flex: 1;

                  .deptName {
                    font-size: 14px;
                    font-weight: 300;
                    color: #444444;
                    white-space: nowrap;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    width: 100%;
                    margin-bottom: 4px;
                  }
                }
                .right {
                  color: #858484;
                  width: 120px;
                  .collect {
                    margin-right: 10px;
                  }
                  .svg-icon {
                    margin-right: 4px;
                  }
                }
              }
            }
          }
        }
      }
    }
  }

  .pagination {
    margin: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-image: url("@/assets/imgs/list/search-bg.png");
    background-size: 22%;
    height: 116px;
  }
}

::v-deep .el-cascader .el-input .el-icon-arrow-down,
::v-deep .el-select .el-input .el-select__caret {
  font-weight: bold;
}

::v-deep .el-input,
.el-cascader {
  .el-input__inner {
    width: 100%;
    border: none;
    border-radius: 0;
    background: url("@/assets/imgs/list/input-border.png");
    background-size: 100% 100%;
    height: 40px;
    &::placeholder {
      text-indent: 10px;
      color: #999;
      font-size: 14px;
    }
  }
}
::v-deep .el-pagination {
  .btn-prev,
  .btn-next {
    background: transparent;
  }
}

::v-deep .el-input {
  width: auto !important;
}
::v-deep .el-pager {
  li {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #2069c4;
    min-width: 0;
    margin: 0 10px;
    color: #b7b7b7;
  }
  .active {
    color: #fff;
  }
}
</style>