<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"
            suffix-icon="el-icon-search"
            v-model="keyword"
            placeholder="请输入关键词"
            @keyup.enter.native="search"
            clearable
          >
          </el-input>
          <el-cascader
            class="years item"
            v-model="regionCode"
            :options="regionTree"
            :props="culturalRegionProps"
            placeholder="请选择所属地区"
            filterable
            @change="handleRegionChange"
            clearable
          >
          </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"
          >
          <!-- id为1 的是文旅厅 -->
            <div
              class="container wow animate__animated animate__fadeInUp"
              v-if="item.status == 1 && item.id != '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.name }}</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 { getMuseumListPage } from "@/api/org";
import { mapGetters } from "vuex";
import { debounce } from "@/utils/index";
export default {
  name: "Museum",
  // components: { SearchBar, NavBar, Footer },
  components: { ListBanner },
  data() {
    return {
      list: {
        records: [],
        size: 20,
        current: 1,
        total: 0,
      },
      culturalRegionProps: {
        value: "code",
        label: "name",
        children: "children",
        checkStrictly: true, //单选选择任意一级选项
      },
      culturalRelicYears: [],
      onlyShow3d: false,
      keyword: "",
      type: "",
      regionCode: [],
      regionTree: [],
      currentImg: null,
    };
  },
  computed: {
    ...mapGetters(["dicts"]),
  },
  async created() {
    await this.$store.dispatch("dict/getDictList", ["displayType"]);
    let res = await this.$store.dispatch("dict/getDictTree", [
      "culturalRelicYears",
    ]);
    this.culturalRelicYears = res.culturalRelicYears;
  },
  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,
        name: this.keyword,
        regionCode: this.regionCode[this.regionCode.length - 1],
      };
      let res = await getMuseumListPage(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();
    },

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

    handleTypeChange(value) {
      this.type = value;
      this.loadData();
    },
    handleKeyWordChange(value) {
      this.keyword = value;
      this.loadData();
    },

    handleRegionChange(value) {
      console.log(value);
      console.log(value[value.length - 1]);
      this.regionCode = value;
      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;
    },
  },
};
</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;
      padding: 90px 70px 80px;
      height: 214px;
      .item {
        margin-right: 20px;
      }
      .search-button {
        cursor: pointer;
        width: 156px;
        height: 54px;
        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;
        .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: 110px;
              padding: 36px 30px;
              transition: all 0.5s ease;
              background: #fff;
              .name {
                font-size: 22px;
                font-weight: bold;
                color: #2069c4;
                margin-bottom: 18px;
              }
              .deptName {
                font-size: 14px;
                font-weight: 300;
                color: #444444;
              }
            }
          }
        }
      }
    }
  }

  .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 {
  width: 368px !important;
  .el-input__inner {
    width: 100%;
    border: none;
    border-radius: 0;
    background: url("@/assets/imgs/list/input-border.png");
    background-size: 100% 100%;
    height: 54px;
    &::placeholder {
      text-indent: 10px;
      color: #999;
    }
  }
}
::v-deep .el-pagination {
  .btn-prev,
  .btn-next {
    background: transparent;
  }
}
::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>