<template>
  <div class="cultural-relic">
    <ListBanner title="精选文物" />
    <div class="content-wrapper">
      <div class="content">
        <div class="search wow animate__animated animate__fadeIn">
          <!-- <el-row
            style="width: 100%; display: flex; align-items: center"
            :span="2"
          >
            <el-col :span="6"> -->
          <el-input
            class="input item"
            v-model="keyword"
            placeholder="请输入关键词"
            @keyup.enter.native="search"
            clearable
          >
          </el-input>
          <!-- </el-col> -->

          <!-- <el-col :span="6"> -->
          <el-select
            class="type item"
            v-model="type"
            placeholder="请选择所属类别"
            filterable
            @change="handleTypeChange"
            clearable
          >
            <el-option
              v-for="(value, key) in dicts.culturalRelicType"
              :key="key"
              :label="value"
              :value="key"
            >
            </el-option>
          </el-select>
          <!-- </el-col> -->
          <!-- <el-col :span="6"> -->
          <el-cascader
            class="years item"
            v-model="years"
            :options="culturalRelicYears"
            :props="culturalRelicYearsProps"
            placeholder="请选择文物年代"
            filterable
            @change="handleYearsChange"
            clearable
            ref="years"
          >
          </el-cascader>
          <!-- </el-col> -->
          <el-col :span="3">
            <div class="search-button" @click="search" style="width: 100%">
              <svg-icon icon-class="search"></svg-icon>
              检索
            </div>
          </el-col>

          <el-col :span="3" class="threeD" @click.native="handleClickThreeD">
            <!-- <div class="threeD" @click="handleClickThreeD">
                <div class="box">
                  <i class="el-icon-check" v-show="onlyShow3d"></i>
                </div>
              </div> -->
            <svg-icon
              :icon-class="onlyShow3d ? 'filter-s' : 'filter'"
            ></svg-icon>
            <div class="text">3D文物</div>
          </el-col>
          <!-- </el-row> -->
        </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="showIcon" v-if="item && item.url3d">
                <svg-icon icon-class="3d" class="icon"></svg-icon>
              </div>
              <div class="desc">
                <div class="name">{{ item.name }}</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 { getCulturalRelicList } from "@/api/culturalRelic";
import { mapGetters } from "vuex";
export default {
  name: "CulturalRelic",
  components: { ListBanner },
  data() {
    return {
      list: {
        records: [],
        size: 15,
        current: 1,
        total: 0,
      },
      culturalRelicYearsProps: {
        value: "value",
        label: "label",
        children: "children",
        checkStrictly: true, //单选选择任意一级选项
      },
      culturalRelicYears: [],
      onlyShow3d: false,
      keyword: "",
      type: "",
      years: "",
      currentImg: null,
    };
  },
  computed: {
    ...mapGetters(["dicts"]),
  },
  async created() {
    await this.$store.dispatch("dict/getDictList", ["culturalRelicType"]);
    let res = await this.$store.dispatch("dict/getDictTree", [
      "culturalRelicYears",
    ]);
    this.culturalRelicYears = res.culturalRelicYears;
    traveseYears(this.culturalRelicYears);
    function traveseYears(arr) {
      if (arr &&arr.length > 0) {
        arr.map((item) => {
          if (item.children && item.children.length == 0) {
            delete item.children;
          } else {
            traveseYears(item.children);
          }
        });
      }
    }
  },
  mounted() {
    this.loadData();
  },
  watch: {
    onlyShow3d(value) {
      this.onlyShow3d = value;
      this.search();
    },
    // keyword(value) {
    //   debounce(this.handleKeyWordChange(value), 1000); //500ms
    // },
  },
  methods: {
    search() {
      this.loadData();
    },

    async loadData() {
      const params = {
        flag3d: this.onlyShow3d ? "1" : "0",
        page: this.list.current,
        limit: this.list.size,
        name: this.keyword,
        type: this.type,
        years: this.years,
      };
      let res = await getCulturalRelicList(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 { crId } = item;
      const newPage = this.$router.resolve({
        path: "culturalRelic/" + crId,
      });
      window.open(newPage.href, "_blank");
    },
    handleClickThreeD() {
      this.onlyShow3d = !this.onlyShow3d;
    },
    defImg(e) {
      e.target.src = require("@/assets/404_images/no-pic.png");
    },

    handleTypeChange(value) {
      this.type = value;
      this.loadData();
    },
    handleYearsChange(value) {
      if (value && value instanceof Array) {
        this.years = value[value.length - 1];
      } else {
        this.years = value;
      }
      this.loadData();
      this.$refs.years.dropDownVisible = false;
    },
    handleKeyWordChange(value) {
      this.keyword = value;
      this.loadData();
    },
    handleTo3D(url3d) {
      window.open(url3d, "_blank");
    },

    handleEnterImg(item) {
      this.currentImg = item;
    },
    handleLeaveImg() {
      this.currentImg = null;
    },
  },
};
</script>

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

    .search {
      display: flex;
      justify-content: center;
      align-items: center;
      padding: 90px 70px 80px;
      margin-bottom: 40px;
      background-image: url("@/assets/imgs/list/search-bg.png");
      background-size: 22%;
      height: 214px;
      .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;
      }
      .threeD {
        display: flex;
        cursor: pointer;
        font-size: 20px;
        color: #666;
        margin-left: 20px;
        transition: all ease 0.3s;
        // -webkit-box-reflect: below 10px linear-gradient(transparent, rgba(0, 0, 0, 0.4));
        .svg-icon {
          margin-right: 4px;
          font-size: 24px;
        }
        &:hover {
          -webkit-box-reflect: below 2px
            linear-gradient(transparent, rgba(0, 0, 0, 0.5));
        }
        // .box {
        //   width: 28px;
        //   height: 28px;
        //   display: flex;
        //   justify-content: center;
        //   align-items: center;
        //   border: 2px solid #444;
        //   margin-right: 6px;
        //   i {
        //     font-size: 28px;
        //   }
        // }
        // .text {
        //   display: flex;
        //   justify-content: center;
        //   align-items: center;
        //   color: #444;
        // }
      }
      .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") transparent;
        background-size: 100% 100%;
        color: #444;
        font-size: 14px;
        transition: all 0.2s ease;

        &:hover {
          -webkit-box-reflect: below 2px
            linear-gradient(transparent, rgba(0, 0, 0, 0.3));
        }
        .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);
              }
              .img-container {
                .deco-left-top,
                .deco-left-bottom,
                .deco-right-top,
                .deco-right-bottom {
                  display: block;
                }
              }
              .desc {
                background: url("@/assets/imgs/list/card-title-bg.png");
              }
            }
            .img-container {
              background-color: #fff;
              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: 22px;
                font-weight: bold;
                color: #2069c4;
                margin-bottom: 18px;
              }
              .desc-container {
                display: flex;
                align-items: flex-end;
                justify-content: space-between;
                .left {
                  .deptName {
                    font-size: 14px;
                    font-weight: 300;
                    color: #444444;
                  }
                }
                .right {
                  color: #858484;
                  .collect {
                    margin-right: 10px;
                  }
                  .svg-icon {
                    margin-right: 4px;
                  }
                }
              }
            }
            .showIcon {
              position: absolute;
              top: 10px;
              right: 10px;
              z-index: 9;
              // background-color: rgba(0, 0, 0, 0.1);
              height: 28px;
              padding: 4px;
              display: flex;
              justify-content: center;
              align-items: center;
              transition: all 0.3s ease;
              width: 28px;
              white-space: nowrap;
              overflow: hidden;

              background: rgba(0, 0, 0, 0.3);
              color: #fff;
              border-radius: 8px;
              font-size: 16px;

              .icon {
                width: 20px;
                display: inline-block;
              }
              .text {
                font-size: 14px;
                color: #fff;
                padding: 4px 8px;
                cursor: pointer;
                display: none;
              }
              img {
                width: 100%;
                height: 100%;
              }
            }
          }
        }
      }
    }
  }

  .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-input {
  width: auto !important;
}

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