<template>
  <div>
    <div class="autoBox container-box">
      <div class="bread-crumb">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: 'home' }">{{$i18n.locale=='en'? 'Home': '首页'}}</el-breadcrumb-item>
          <el-breadcrumb-item>{{$i18n.locale=='en'? 'Conferences': '会议'}}</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <div class="conference-recommend" v-if="bannerData.length">
          <div class="conference-recommend-header">
            <span>{{$t("common.UpcomingEvents")}}</span>
          </div>
          <div class="conference-recommend-body" style="background: #fff; padding: 20px">
            <el-carousel indicator-position="outside" arrow="never" :autoplay="true" :interval="5000" height="388px" style="cursor: pointer; background: #2c558a; padding-top: 70px;">
              <el-carousel-item v-for="(item,index) in bannerData" :key="index" style="background: #fff;">
                <div @click="toView('ConferenceDetail', item.id)">
                  <!-- <img :src="item.flag?item.meetingPicUrl:'./api/fileextend/pub/'+item.meetingPicUrl + '?custom=400_260'" alt style="width: 100%;height: 260px; margin-top: 30px" /> -->
                  <img v-if="item.flag" src="@/assets/img/conference/conference-noon.png" alt style="width: 100%;height: 260px; margin-top: 30px" />
                  <img v-if="!item.flag" :src="'./api/fileextend/pub/'+item.meetingPicUrl + '?custom=400_260'" alt style="width: 100%;height: 260px; margin-top: 30px" />
                  <div style="position: absolute; bottom: -18px; right: 28px; background: #2a548c; color: #fff; padding: 10px 20px; font-size: 18px">{{formatDate(item.meetingStartDate)}} - {{formatDate(item.meetingEndDate)}}</div>
                </div>
                <div style="display: table; height: 100%; padding: 0 30px; box-sizing: border-box; color: #2a548c" @click="toView('ConferenceDetail', item.id)">
                  <div style="width: 100%; display: table-cell; vertical-align: middle;">
                    <div
                      style="font-size: 38px; line-height: 50px; font-weight: 700;"
                    >{{$i18n.locale=='en'?item.meetingNameEn: item.meetingName}} </div>
                    <div style="width: 100%;line-height: 45px;font-size: 14px;">
                      <p style="font-size: 14px; font-weight: bold; margin: 0;">{{$i18n.locale=='en'?item.meetingPlaceEn: item.meetingPlace}}</p>
                      <div
                      class="plate"
                        style="font-size: 16px; height: 150px; line-height: 30px;  -webkit-box-orient: vertical;
                        position:relative;
                        line-height:1.4em;
                        overflow: hidden;
                        height:7em "
                      >{{$i18n.locale=='en'?item.meetingIntroductionEn: item.meetingIntroduction}}</div>
                    </div>
                  </div>
                </div>
              </el-carousel-item>
            </el-carousel>
          </div>
      </div>
      <div class="conference-past">
        <div class="conference-recommend-header">
          <span>{{$t("common.PastEvents")}}</span>
          <div class="conference-search">
            <el-input :placeholder="$i18n.locale=='en'? 'Search events': '搜索会议'" v-model="conferenceKey" class="input-with-select" style="font-size: 18px">
              <el-button slot="append" icon="el-icon-search" style="font-size: 24px; color: #2c558a" @click="conferenceFilter"></el-button>
            </el-input>
          </div>
        </div>
        <div class="conference-recommend-body" v-if="conferenceData.length">
            <ul class="conference-recommend-list">
                <li :key="i" v-for="(item, i) in filteredData" @click="toView('ConferenceResult', item.id)">
                    <!-- <div class="cover" :style="{'backgroundImage': 'url(./api/file/pub/'+item.meetingPicUrl+')'}"></div> -->
                    <div class="cover" :style="{'backgroundImage': 'url(./api/fileextend/pub/'+item.meetingPicUrl+'?custom=400_260)'}"></div>
                    <div class="conference-recommend-list-right">
                      <p class="title">{{$i18n.locale=='en'?item.meetingNameEn: item.meetingName}}</p>
                      <p>
                        <span class="time">{{formatDate(item.meetingStartDate)}} - {{formatDate(item.meetingEndDate)}}</span>
                        <span class="network" v-if="item.meetingMainFormDict == '02'">{{$i18n.locale=="en"? 'Network Meeting': '网络会议'}}</span>
                        <span class="place" v-else>{{$i18n.locale=='en'?item.meetingPlaceEn: item.meetingPlace}}</span>
                      </p>
                      <p class="introduction plate">{{$i18n.locale=='en'?item.meetingIntroductionEn: item.meetingIntroduction}}</p>
                    </div>
                </li>
            </ul>
        </div>
      </div>
    </div>
  </div>
</template>

  <script>
import { getConfrences, getConfrencesEn, getsOutInfo } from "@/api/meeting/meetingOutInfo";
import { Swiper, SwiperSlide, directive } from 'vue-awesome-swiper'
import 'vue-awesome-swiper/node_modules/swiper/dist/css/swiper.css'
// import 'swiper/css/swiper.css';
import { getToken } from "@/utils/auth";
// import moment from 'moment-timezone';
export default {
  name: "ConferenceServices",
  data() {
    return {
      i: 0,
      conferenceKey: '',
      activeVideo: '',
      showVideo: false,
      overlayIndex: -1,
      locale: "",
      bannerData: [],
      conferenceData: [],
      filteredData: [],
      resultData: [],
      newsData: [],
      materialData: [],
    };
  },
  watch: {
    "$i18n.locale"() {
      this.Myconference()
    },
  },
  mounted() {

    this.Myconference();
    getsOutInfo().then(res=>{
      // console.log('全部', res)
      res.data.meetingOutInfos.forEach(element => {
        if(element.outType == "NEWS"){
          this.newsData.push(element)
        }
        // if(element.outType == "VIDEO" && element.videoCover && element.videoUrl){
        //   this.resultData.push(element)
        // }
        // if(element.outType == "FILE" && element.fileCover){
        //   this.materialData.push(element)
        // }
      });
      this.newsData.splice(3);
      this.materialData.splice(3);
      // console.log('媒体', this.resultData)
      this.$nextTick(()=>{
        // this.activeVideo = this.resultData[0].videoUrl;
        this.swiperInit();
      })
    }).catch((error) => {
      // this.$message.error(error.msg);
    });
  },
  methods: {
    conferenceFilter(){
      if(this.conferenceKey == ''){
        this.filteredData = this.conferenceData;
      }else{
        this.filteredData = this.conferenceData.filter(item=>{
          return item.meetingName.includes(this.conferenceKey)>0 || item.meetingNameEn.includes(this.conferenceKey)>0
        })
      }
      if(!this.filteredData.length){
        this.$message.warning('未找到匹配的内容');
      }
    },
    videoPlay(i){
      this.overlayIndex = i;
      let selectVideo = document.getElementById('lastConferenceVideo');
      selectVideo.play();
      this.showVideo = true;
    },
    swiperInit(){
      let that = this;
      var galleryThumbs = new Swiper('.gallery-thumbs', {
        spaceBetween: 10,
        slidesPerView: 4,
        // loop: true,
        freeMode: true,
        loopedSlides: 5, //looped slides should be the same
        watchSlidesVisibility: true,
        watchSlidesProgress: true,
      });
      var galleryTop = new Swiper('.gallery-top', {
        spaceBetween: 10,
        // loop: true,
        autoplay: false,
        loopedSlides: 5, //looped slides should be the same
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev',
        },
        thumbs: {
          swiper: galleryThumbs,
        },
        on: {
          slideChangeTransitionStart: function(){
            that.showVideo = false;
            that.activeVideo = that.resultData[this.activeIndex].videoUrl;
          },
        },
      });
    },
    // 判断会议是否结束
    isMeetingOver(t){
      var ct = Date.parse(new Date());
      if(ct-t > 0){
        return true;
      }else{
        return false;
      }
    },
    // 时间戳转时间格式
    formatDate(t) {
      if(!t){
          return ''
      }else{
          var original = new Date(t);
          var year=original.getFullYear();
          var month=original.getMonth()+1;
          var date=original.getDate();
          var hour=original.getHours();
          var minute=original.getMinutes();
          var second=original.getSeconds();
          // return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second;
          return year+"/"+month+"/"+date;

          // return moment(t).format('YYYY/MM/DD');
      }
    },
    toView(router, id) {
      localStorage.setItem('conferenceId', id);
      this.$router.push({ path: router , query: { key: id }});
    },
    //获取中文会议或英文会议
    Myconference(){
      if(this.$i18n.locale=='en'){
        getConfrencesEn().then(res=>{
          this.bannerData = [];
          this.conferenceData = [];
          res.data.meetingBasicInfos.forEach(item=>{
            if(!item.meetingPicUrl){
              this.$set(item,'flag','true');
            }
            // 报名未开始会议
            if(!this.isMeetingOver(item.meetingEndDate) && item.meetingIsShow=="01" && item.meetingIsEnroll=="01"){
              this.bannerData.push(item)
            }
            // 已结束会议
            if(this.isMeetingOver(item.meetingEndDate) && item.meetingIsShow=="01"){
              this.conferenceData.push(item)
            }
          })
          this.filteredData = this.conferenceData;
        })
      }else{
        getConfrences().then(res=>{
          // console.log('6666666666666',res)
          // this.conferenceData = res.data.meetingBasicInfos.filter((item)=>{
          //   return item.meetingIsShow == '01';
          // })
          this.bannerData = [];
          this.conferenceData = [];
          res.data.meetingBasicInfos.forEach(item=>{
            if(!item.meetingPicUrl){
              this.$set(item,'flag','true');
            }
            // 报名未开始会议
            if(!this.isMeetingOver(item.meetingEndDate) && item.meetingIsShow=="01" && item.meetingIsEnroll=="01"){
              this.bannerData.push(item)
            }
            // 已结束会议
            if(this.isMeetingOver(item.meetingEndDate) && item.meetingIsShow=="01"){
              this.conferenceData.push(item)
            }
          })
          this.filteredData = this.conferenceData;
          console.log('奇了怪了',this.bannerData)
          // console.log('会议', this.conferenceData)
        })
      };
    }



  },
};
</script>
<style scoped>
#lastConferenceVideo{
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 9;
}
*{
    box-sizing: border-box;
}
.container-box {
  margin: 10px auto;
  /* background: #fff; */
  /* padding: 0 20px; */
  min-height: calc( 100vh - 420px )
}
.bread-crumb {
  background: #fff;
  padding: 20px;
}
body {
  margin: 0;
}
.el-carousel__item > div:nth-child(1) {
  font-size: 18px;
  margin: 0;
  float: left;
  width: 35%;
  position: relative;
}
.el-carousel__item > div:nth-child(2) {
  font-size: 18px;
  margin: 0;
  float: right;
  width: 65%;
}
.conference-recommend{

}
.conference-past .conference-recommend-header{
  margin-top: 20px;
}
.conference-recommend-header{
    position: relative;
    line-height: 40px;
    padding: 20px 0;
}
.conference-recommend-header img{
    vertical-align: middle;
}
.conference-recommend-header span{
    vertical-align: middle;
    font-size: 24px;
    font-weight: bold;
    border-bottom: 4px solid #2c558a;
    display: inline-block;
    padding-bottom: 4px;
    /* margin-left: 16px; */
}
.conference-search{
  background: #2c558a;
  padding: 20px 300px;
  margin-top: 20px;
}
.conference-recommend-header div:hover{
    color: #333;
}
.conference-recommend-body{
    /* display: flex;
    justify-content: space-between; */
    font-size: 16px;
    color: #555;
    /* min-height: 693px; */
}
.conference-recommend-body .cover{
    width: 100%;
    background-size: 100% 100%;
}
.conference-recommend-body .title{
    font-size: 18px;
    font-weight: bold;
    color: #333;
    margin-bottom: 20px;
    margin-top: 10px;
}
.conference-recommend-list{
    /* width: 55%; */
    display: flex;
    flex-wrap: wrap;
}
.conference-recommend-list .introduction{
  height: 106px;
  line-height: 28px;
  -webkit-box-orient: vertical;
  position:relative;
  line-height:1.4em;
  overflow: hidden;
  height:7em
}
.conference-recommend-list .cover{
    height: 220px;
    width: 320px;
}
.conference-recommend-list .title{
    overflow: hidden;
    color: #2c558a;
    font-size: 24px;
    line-height: 24px;
    margin-top: 0;
}
.conference-recommend-list li{
    width: 100%;
    /* padding: 10px; */
    position: relative;
    cursor: pointer;
    display: flex;
    padding: 20px;
    background: #fff;
    margin-bottom: 20px;
}
.conference-recommend-list-right{
  flex: 1;
  margin-left: 20px;
}
.conference-recommend-list-right p span{
  margin-right: 20px;
}
.conference-recommend-list .status{
    width: 80px;
    line-height: 26px;
    position: absolute;
    top: 0px;
    right: 0px;
    background: #e43f3f;
    color: #fff;
    font-size: 14px;
    text-align: center;
    border-radius: 0px 0px 0px 13px;
}
.conference-result-body{
    display: flex;
}
.conference-result-left{
    width: 45%;

}
.conference-result-right{
    width: 54%;
    padding: 10px;
    margin-left: 1%;
}
.conference-result-item {
  padding-bottom: 20px;
}
.conference-result-title {
    height: 20px;
    line-height: 20px;
    font-size: 17px;
    font-weight: bold;
    border-left: 4px solid #2c558a;
    padding-left: 10px;
    margin: 30px 0;
}
.conference-news-list{
    width: 100%;
    font-size: 16px;
    color: #333;
}
.conference-news-list li{
    display: flex;
    cursor: pointer;
    line-height: 48px;
    border-bottom: 1px dashed #999;
}
.conference-news-list li p{
    flex: 1;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin: 0;
}
.conference-news-list li span{
    color: #666;
    margin-left: 20px;
}
.conference-material-list{
    width: 100%;
    display: flex;
    justify-content: space-between;
}
.conference-material-list li{
    width: 30%;
    cursor: pointer;
}
.conference-material-list li img{
    width: 100%;
}
.conference-material-list li p{
    text-align: center;
    margin: 0;
}



.swiper-container {
    width: 100%;
    height: 300px;
    margin-left: auto;
    margin-right: auto;
    --swiper-navigation-color: #68b2f8;
    --swiper-navigation-size: 30px;
  }

  .swiper-slide {
    background-size: cover;
    background-position: center;
  }

  .gallery-top {
    height: 80%;
    width: 100%;
  }

  .gallery-thumbs {
    height: 20%;
    box-sizing: border-box;
    padding: 10px 0;
  }

  .gallery-thumbs .swiper-slide {
    height: 100%;
    opacity: 0.4;
  }

  .gallery-thumbs .swiper-slide-thumb-active {
    opacity: 1;
  }

  .overlay-box{
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    background-size: cover;
    text-align: center;
    z-index: 9;
  }
  .overlay-box > img{
    position: absolute;
    top: 50%;
    left: 50%;
    margin-top: -50px;
    margin-left: -50px;
    opacity: 0.7;
    cursor: pointer;
  }
  .overlay-box > img:hover{
    opacity: 1;
  }
  .conference-video-title{
    margin: 0;
    width: 100%;
    height: 40px;
    text-align: center;
    line-height: 40px;
    font-size: 18px;
    font-weight: bold;
    color: #fff;
    background: rgba(0, 0, 0, 0.6);
    overflow: hidden;
    text-overflow:ellipsis;
    white-space: nowrap;
    position: absolute;
    top: -40px;
    left: 0;
    z-index: 999;
    transition: all 0.5s;
  }
  .swiper-slide:hover .conference-video-title{
    top: 0;
  }
  .conference-recommend >>> .el-carousel__indicators--outside {
    text-align: right;
    padding-right: 50px;
  }
  .conference-recommend >>> .el-carousel__button {
      opacity: 1;
      width: 16px;
      height: 16px;
      border-radius: 50%;
      background-color: #FFF;
      -webkit-transition: .3s;
      transition: .3s;
  }
   .conference-recommend >>> .el-carousel__indicator.is-active button {
      background-color: rgb(21, 255, 0);
  }
</style>
