<template>
  <div class="cultural-relic">
    <!-- <NavBar /> -->
    <div style="height: 100px; background-color: #2069c4; width: 100%"></div>
    <div class="content-wrapper">
      <div class="content">
        <el-row :gutter="40">
          <el-col :span="24">
            <div class="title wow animate__animated animate__fadeInLeft">
              精选藏品
            </div>
            <div
              class="bottom-line wow animate__animated animate__fadeInLeft"
            ></div>
            <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-select
                class="type item"
                v-model="type"
                placeholder="所属类别"
                style="width: 100%"
                filterable
                @change="handleTypeChange"
                clearable
              >
                <el-option
                  v-for="(value, key) in dicts.culturalRelicType"
                  :key="key"
                  :label="value"
                  :value="key"
                >
                </el-option>
              </el-select>
              <el-cascader
                class="years item"
                style="width: 100%"
                v-model="years"
                :options="culturalRelicYears"
                :props="culturalRelicYearsProps"
                placeholder="请选择文物年代"
                filterable
                @change="handleYearsChange"
                clearable
              >
              </el-cascader>
              <div class="threeD item" @click="handleClickThreeD">
                <div class="box">
                  <i class="el-icon-check" v-show="onlyShow3d"></i>
                </div>
                <div class="text">只看3D</div>
              </div>
              <div class="search-button" @click="search">搜 索</div>
            </div>
            <el-row :gutter="40" class="cr-list">
              <el-col
                :span="6"
                class="cr-item"
                @click.native="handleClick(item)"
                v-for="(item, index) in list.records"
                :key="index"
              >
                <div
                  class="container wow animate__animated animate__fadeInUp"
                  v-if="$getFullUrl(item.faceImagePressUrl) ||$getFullUrl(item.faceImageUrl)"
                >
                  <div class="img">
                    <img
                      :src="$getFullUrl(item.faceImagePressUrl)"
                      v-if="$getFullUrl(item.faceImagePressUrl)"
                      width="100%"
                      class="img"
                      lazy
                    />
                    <img
                      v-else-if="$getFullUrl(item.faceImageUrl)"
                      :src="$getFullUrl(item.faceImageUrl)"
                      width="100%"
                      height="100%"
                      class="img"
                    />
                    <img
                      v-else
                      src="@/assets/404_images/no-pic.png"
                      alt=""
                      width="100%"
                      height="100%"
                      class="img"
                    />
                  </div>
                  <div class="showIcon" v-if="item && item.url3d">
                    <img src="@/assets/imgs/cr/3D.png" class="icon" />
                    <div class="text" @click.stop="handleTo3D(item.url3d)">
                      点击查看3D链接
                    </div>
                  </div>
                  <div class="desc">
                    <span class="name">{{ item.name }}</span>
                  </div>
                </div>
              </el-col>
            </el-row>
            <el-empty description="暂无数据" v-if="list.records.length==0"></el-empty>
            <div class="pagination">
              <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, jumper"
                :total="Number(list.total)"
                class="pagination"
              >
              </el-pagination>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>

<script>
import SearchBar from "@/components/SearchBar";
// import NavBar from "@/components/NavBar";
// import Footer from "@/components/Footer";
import { getCulturalRelicList } from "@/api/culturalRelic";
import { mapGetters } from "vuex";
import { debounce } from "@/utils/index";
export default {
  name: "CulturalRelic",
  // components: { SearchBar, NavBar, Footer },
  components: { SearchBar },
  data() {
    return {
      list: {
        records: [],
        size: 20,
        current: 1,
        total: 0,
      },
      culturalRelicYearsProps: {
        value: "value",
        label: "label",
        children: "children",
        checkStrictly: true, //单选选择任意一级选项
      },
      culturalRelicYears: [],
      onlyShow3d: false,
      keyword: "",
      type: "",
      years: "",
    };
  },
  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;
  },
  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,
      };
      if (params.years.length == 0) {
        delete params.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) {
      console.log(item);
      const { crId } = item;
      this.$router.push({
        path: "culturalRelic/" + crId,
      });
    },
    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) {
      this.years = value;
      this.loadData();
    },
    handleKeyWordChange(value) {
      this.keyword = value;
      this.loadData();
    },
    handleTo3D(url3d) {
      window.open(url3d, "_blank");
    },
  },
};
</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;
    .title {
      font-family: KaiTi;
      font-size: 44px;
      margin-bottom: 16px;
    }
    .bottom-line {
      width: 50px;
      background-color: #b8b8b8;
      height: 2px;
      margin-bottom: 40px;
    }
    .search {
      display: flex;
      justify-content: center;
      align-items: center;
      background-color: rgba($blue, 0.2);
      padding: 20px 40px;
      margin-bottom: 40px;

      .item {
        margin-right: 20px;
      }
      .threeD {
        display: flex;
        width: 420px;
        cursor: pointer;
        .box {
          width: 36px;
          height: 36px;
          display: flex;
          justify-content: center;
          align-items: center;
          border: 2px solid #563f17;
          margin-right: 6px;
          i {
            font-size: 28px;
          }
        }
        .text {
          display: flex;
          justify-content: center;
          align-items: center;
        }
      }
      .search-button {
        cursor: pointer;
        width: 420px;
        height: 48px;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: $blue;
        color: #fff;
      }
    }
    .content {
      width: 100%;
      .cr-list {
        .cr-item {
          margin-bottom: 40px;
          .container {
            border: 1px solid #f1f1f1;
            height: 300px;
            position: relative;
            display: flex;
            flex-direction: column;
            cursor: pointer;
            &:hover {
              img {
                transform: scale(1.2);
              }
              .desc {
                background-color: $blue;
                color: #fff;
              }
            }
            .img {
              background-color: #f8f8f8;
              height: 240px;
              cursor: pointer;
              transition: all 0.5s ease;
              overflow: hidden;
              &:hover {
                img {
                  transform: scale(1.2);
                }
              }
              img {
                height: 100%;
                object-fit: contain;
                // width: auto;
              }
            }
            .desc {
              padding: 16px 0;
              display: flex;
              justify-content: center;
              transition: all 0.5s ease;
              flex: 1;
            }
            .showIcon {
              position: absolute;
              top: 10px;
              right: 10px;
              z-index: 99;
              // 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;
              &:hover {
                .icon {
                  display: none;
                }
                .text {
                  display: block;

                }
                width: 130px;
                padding: 4px 8px;
                background-color: $blue;
              }
              .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;
  }
}

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

::v-deep .el-input {
  .el-input__inner {
    border: none;
    border-radius: 0;
  }
}
</style>