<!--  -->
<template>
  <div class="exhibition-type">
    <div class="wrapper">
      <div class="top">
        <img
          class="bg"
          :src="require('@/assets/images/exhibition-type-top-bg.png')"
          alt=""
        />
        <div class="btn" @click="jumpTo(onlineLink)">线上展览<img :src="require('@/assets/images/exhibition-right-arrow.png')" alt=""/></div>
      </div>
      <div class="bottom">
        <img
          class="bg"
          :src="require('@/assets/images/survey-type-bottom-bg.png')"
          alt=""
        />

        <div class="content">
          <div class="nav">
            <img
              class="bg"
              :src="require('@/assets/images/survey-type-nav-bg.png')"
              alt=""
            />
            <div class="nav-con">
              <div class="nav-con-title">展览</div>
              <div class="nav-con-type">
                <ul>
                  <li
                    :class="{ cur: exhibitionType === 'hot' }"
                    @click="switchType('hot')"
                  >
                    <a>正在热展</a>
                    <div class="arrow" v-if="exhibitionType === 'hot'">
                      <img :src="require('@/assets/images/arrow.png')" alt="" />
                    </div>
                  </li>
                  <li
                    :class="{ cur: exhibitionType === 'preview' }"
                    @click="switchType('preview')"
                  >
                    <a>固定展览</a>
                    <div class="arrow" v-if="exhibitionType === 'preview'">
                      <img :src="require('@/assets/images/arrow.png')" alt="" />
                    </div>
                  </li>
                  <li
                    :class="{ cur: exhibitionType === 'review' }"
                    @click="switchType('review')"
                  >
                    <a>展览回顾</a>
                    <div class="arrow" v-if="exhibitionType === 'review'">
                      <img :src="require('@/assets/images/arrow.png')" alt="" />
                    </div>
                  </li>
                </ul>
              </div>
            </div>
          </div>
          <div class="con">
            <img
              class="bg"
              :src="require('@/assets/images/survey-type-con-bg.png')"
              alt=""
            />
            <ul class="list">
              <li v-for="(item, index) in dataList" :key="index" @click="toDetail(item)">
                <div class="pic">
                  <img :src="$cdnUrl + item.thumb" alt="" />
                </div>
                <div class="cover">
                  <div class="txt">
                    <div class="txt-name">{{ item.name }}</div>
                    <div class="txt-time" v-if="exhibitionType!=='preview'">{{ item.startTime | dateFormat2('yyyy-MM-yy') }}-{{item.endTime | dateFormat2('yyyy-MM-yy') }}</div>
                  </div>
                </div>
              </li>
            </ul>
            <el-empty :image-size="200" v-if="dataList.length === 0"></el-empty>
            <div class="my-paging" v-if="dataList.length">
              <Paging
                v-if="paging.total"
                :paging="paging"
                @changeCurrent="pageChange"
              />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import Paging from '@/components/pagination'
// import { format } from 'date-fns'
export default {
  name: 'exhibition-type',
  // import引入的组件需要注入到对象中才能使用
  components: {
    Paging
  },
  data () {
    // 这里存放数据
    return {
      exhibitionType: 'hot',
      dataList: [],
      paging: {
        pageSize: 9,
        pageNum: 1,
        total: 0,
        showSize: 9,
        current: 1
      },
      params: {
        pageNum: 1,
        pageSize: 9,
        type: ''
      },
      typeChange: {
        hot: 'start',
        preview: 'unstart',
        review: 'end'
      }
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {
    paging: {
      deep: true,
      handler: function () {}
    }
  },
  // 方法集合
  methods: {
    async getList () {
      if (this.exhibitionType === 'hot') this.params.type = 'start'
      if (this.exhibitionType === 'preview') this.params.type = 'fixed'
      if (this.exhibitionType === 'review') this.params.type = 'end'
      let result = await this.$http({
        method: 'post',
        url: '/api/web/exhibition/list',
        data: this.params
      })
      this.dataList = result.data.list
      this.paging.total = result.data.total
      console.log('this.dataList-----------------------', this.dataList)
      //   // 暂时没有图片
      this.dataList = this.dataList.map((item) => {
        return {
          ...item,
          imgUrl:
            'test-exhibition.png'
        }
      })
    },
    switchType (type) {
      this.exhibitionType = type
      this.params['type'] = this.typeChange[this.exhibitionType]
      this.params['pageNum'] = 1
      this.paging.current = 1
      this.getList()
    },
    back () {
      this.$router.push({ path: '/exhibition' })
    },
    pageChange (val) {
      console.log(val)
      this.paging.current = val
      this.params.pageNum = val
      this.getList()
    },
    toDetail (item) {
      this.$router.push({
        path: '/exhibition-detail',
        query: { ...item, navType: this.exhibitionType }
      })
    },
    jumpTo (onlineLink) {
      window.open(onlineLink)
    },
    async getOnlineLink () {
      let result = await this.$http({
        method: 'get',
        url: '/api/web/exhibition/online',
        data: this.params
      })
      this.onlineLink = result && result.data && result.data.url
    }
  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created () {
    this.exhibitionType =
      (this.$route.query && this.$route.query['type']) || 'preview'
    this.params['type'] = this.typeChange[this.exhibitionType]
    this.getList()
    this.getOnlineLink()
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted () {},
  beforeCreate () {}, // 生命周期 - 创建之前
  beforeMount () {}, // 生命周期 - 挂载之前
  beforeUpdate () {}, // 生命周期 - 更新之前
  updated () {}, // 生命周期 - 更新之后
  beforeDestroy () {}, // 生命周期 - 销毁之前
  destroyed () {}, // 生命周期 - 销毁完成
  activated () {} // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style lang='less' scoped>
.bg {
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
  z-index: -1;
}
.exhibition-type {
  width: 100%;
  margin-bottom: 98px;
  .wrapper {
    width: 100%;
    .top {
      width: 100%;
      height: 278px;
      position: relative;
      .btn {
        position: absolute;
        background: #945335;
        box-shadow: 0 0 6px rgba(255, 255, 255, 1);
        text-align: center;
        line-height: 55px;
        width: 200px;
        height: 55px;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        font-size: 20px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #ffffff;
        cursor: pointer;
        >img {
          position: absolute;
          right: 20px;
          top:14px;
          width: 29px;
          height: 29px;
        }
      }
    }
    .bottom {
      width: 100%;
      position: relative;
      .content {
        min-width: 1090px;
        margin: 0 auto;
        width: 57%;
        display: flex;
        justify-content: center;
        .nav {
          flex: 1;
          margin-right: 1%;
          margin-top: -68px;
          position: relative;
          .nav-con {
            width: 85%;
            margin: 94px auto 0;
            .nav-con-title {
              background: #945335;
              padding: 14.5px 0 14.5px 46px;
              font-size: 20px;
              font-family: Microsoft YaHei;
              font-weight: bold;
              color: #ffffff;
              opacity: 1;
            }
            .nav-con-type {
              margin-top: 3px;
              background: rgba(148, 83, 53, .6);
              overflow: hidden;
              > ul {
                width: 100%;
                margin-top: 21px;
                margin-bottom: 105px;
                > li {
                  width: 100%;
                  padding: 8px 0 8px 51px;
                  font-size: 16px;
                  font-family: Microsoft YaHei;
                  font-weight: 400;
                  color: #000000;
                  position: relative;
                  cursor: pointer;
                  .arrow {
                    position: absolute;
                    top: 10px;
                    right: 11.5px;
                    width: 10.5px;
                    height: 18px;
                    > img {
                      width: 100%;
                      height: 100%;
                    }
                  }
                }
                .cur {
                  background: linear-gradient(180deg, #585a5a 0%, #949198 100%);
                  color: #ffffff;
                }
              }
            }
          }
        }
        .con {
          flex: 3;
          margin-top: -68px;
          position: relative;
          .back {
            width: 19px;
            position: absolute;
            left: 26px;
            top: 97px;
            cursor: pointer;
            > img {
              width: 100%;
            }
          }
          > ul {
            margin: 94px 19px 62px;
            display: flex;
            align-items: center;
            justify-content: flex-start;
            flex-wrap: wrap;
            > li {
              display: flex;
              align-items: center;
              justify-content: flex-start;
              margin-bottom: 2%;
              margin-right: 2%;
              width: 32%;
              cursor: pointer;
              position: relative;
              &:nth-of-type(3n){
                  margin-right:0;
              }
              .pic {
                width: 100%;
                font-size: 0; // 消除img自带间距
                > img {
                  width: 100%;
                }
              }
              .cover {
                width: 100%;
                height: 100%;
                background: rgba(148, 83, 53, 0.8);
                box-shadow: 0 0 15px rgba(0, 0, 0, 1);
                position: absolute;
                top: 0;
                left: 0;
                display: none;
                .txt {
                  width: 100%;
                  position: absolute;
                  top: 50%;
                  left: 50%;
                  transform: translate(-50%, -50%);
                  text-align: center;
                  font-size: 24px;
                  font-family: Microsoft YaHei;
                  font-weight: 300;
                  color: #ffffff;
                  opacity: 1;
                  .txt-name {
                    width: 80%;
                    margin: 0 auto;
                    margin-bottom: 13px;
                  }
                  .txt-time {
                    width: 80%;
                    margin: 0 auto;
                  }
                }
              }
              &:hover {
                  .cover {
                      display: block;
                  }
              }
            }
          }
          .my-paging {
            margin: 25px auto;
            text-align: right;
          }
        }
      }
    }
  }
}
</style>
