<template>
  <div class="autoBox container-box">
    <div class="bread-crumb">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: 'home' }">{{lang=='en'? 'Home': '首页'}}</el-breadcrumb-item>
        <el-breadcrumb-item :to="{ path: 'ConferenceServices'}">{{lang=='en'? 'Conferences': '会议'}}</el-breadcrumb-item>
        <el-breadcrumb-item>{{lang=='en'? baseInfo.meetingNameEn: baseInfo.meetingName}}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="content-box">
      <div class="feed-back" @click="toFeedback(baseInfo.id)"><i class="el-icon-edit"></i> {{$t("common.FeedbackAndSuggestions")}}</div>
      <div style="display: flex; border-bottom: 4px solid #f2f2f2; padding-bottom: 30px">
        <div class="section-left">
          <div class="confrence-item confrence-introduce" v-if="baseInfo">
            <!-- <div class="confrence-item-header" id="introduction">{{$t("common.Introduction")}}</div> -->
            <div class="confrence-item-body">
              <p class="title">{{lang=='en'?baseInfo.meetingNameEn: baseInfo.meetingName}}</p>
              <!-- <p>
                <span>{{lang=='en'? 'Sponsor': '主办方'}}：</span><span class="sponsor">{{lang=='en'? baseInfo.meetingSponsorEn: baseInfo.meetingSponsor}}</span>
              </p> -->
              <div style="display: flex; justify-content: space-between;margin-top: 50px">
                <div>
                  <span
                  class="time"
                  v-if="baseInfo.meetingStartDate"
                >{{formatDate(baseInfo.meetingStartDate)}}-{{formatDate(baseInfo.meetingEndDate)}}</span>
                <span class="place">{{lang=='en'?baseInfo.meetingPlaceEn: baseInfo.meetingPlace}}</span>
                </div>
                <div class="share">
                    <!-- <span @click=""><i class="el-icon-star-off"></i> {{lang=='en'? 'Attention': '关注'}}</span> -->
                    <!-- <span><i class="el-icon-share"></i> {{lang=='en'? 'Share': '分享'}}</span> -->
                    <!-- <span class="share cursor" :style="ifcommon?'color: #66b1ff;':''"
                      style="margin-right: 20px;" @click="shareChange()">
                      <i class="el-icon-star-off" :style="ifcommon?'color: #66b1ff;':''"> </i>
                      {{ifcommon?$t('common.Concerned'):$t('common.follow')}}
                    </span> -->
                </div>
              </div>
              <div class="confrence-introduce-content">
                <p>{{lang=='en'? baseInfo.meetingIntroductionEn: baseInfo.meetingIntroduction}}</p>
              </div>
            </div>
          </div>
          <div class="confrence-item" v-if="baseInfo.meetingYichengEn && baseInfo.meetingYicheng">
              <div class="confrence-item-body">
                  <div v-html="lang=='en'? baseInfo.meetingYichengEn: baseInfo.meetingYicheng"></div>
              </div>
          </div>
          <div class="confrence-item">
              <div class="confrence-item-body" style="margin-top: 30px">
                  <div>
                    <a :href="'./api/file/pub/'+agendaData" target="_blank" class="agenda-title" v-if="agendaData">{{lang=='en'? 'View the Meeting agenda': '查看会议议程'}}</a>
                  </div>
              </div>
          </div>
        </div>
        <div class="section-right">
          <div class="conference-recommend" v-if="recommendData.length">
            <p class="title">{{lang=='en'? 'Upcoming Events': '近期会议'}}</p>
            <ul class="conference-recommend-list">
                <li v-for="(item, i) in recommendData" :key="i" @click="toViewById('ConferenceDetail', item.id)">
                    <div class="conference-recommend-top">
                      <span class="time">{{formatDate(item.meetingStartDate)}}</span>
                      <span class="step"></span>
                      <span class="title">{{lang=='en'?item.meetingNameEn: item.meetingName}}</span>
                    </div>
                    <div class="conference-recommend-body">
                      <span class="place">{{lang=='en'? item.meetingPlaceEn: item.meetingPlace}}</span>
                      <p class="introduction plate">{{lang=='en'? item.meetingIntroductionEn: item.meetingIntroduction}}</p>
                      <!-- <p class="sponsor">{{lang=='en'? item.meetingSponsorEn: item.meetingSponsor}}</p> -->
                    </div>
                </li>
            </ul>
            <div class="no-data" v-if="recommendData.length < 4">{{lang=='en'? 'Coming Soon': '敬请期待'}}</div>
            <!-- <span class="more">{{lang=='en'? 'MORE': '更多'}}</span> -->
          </div>
          <div v-else style="text-align: center">
            <img v-if="lang=='en'" width="150" height="150" src="@/assets/img/conference/no-data-en.png" alt="">
            <img v-else width="150" height="150" src="@/assets/img/conference/no-data-zh.png" alt="">
          </div>
        </div>
      </div>
      <ul class="result-model-btn">
        <li v-show="item.isShow" :class="{active: modelView==item.view}" @click="modelChange(item.view)" v-for="(item, i) in modelBtns" :key="i">{{lang=='en'? item.textEN: item.text}}</li>
      </ul>
      <div class="result-model-view">
        <keep-alive>
          <component :is="modelView"></component>
        </keep-alive>
      </div>
    </div>
    <LoginReminder ref="loginReminder"></LoginReminder>
    <el-dialog
      :title="$i18n.locale=='zh'?'提示':'Reminder'"
      :visible.sync="toViewLogin"
      :width="$i18n.locale=='zh'?'500px':'750px'"
      :height="$i18n.locale=='zh'?'300px':'386px'"
      :before-close="toViewLoginChange"
    >
    <div style="width: 100%;height: 100%;">
    <img src="@/assets/img/loginTips.png" alt="" style="width: 180px;height: 180px;margin-left: 20px;">
    <div style="float: right;margin-right: 20px;" :style="$i18n.locale=='zh'?'width: 49%;margin-top: 10px;':'width: 453px;margin-top: -25px;'">
      <div style="font-size: 20px;font-weight: normal;color: #333333;
            font-family: HiraginoSansGB-W3, HiraginoSansGB;
            line-height: 40px;">
        {{$t('common.ReminderFirst')}}
      </div>
      <div style="font-size: 16px;font-family: HiraginoSansGB-W3, HiraginoSansGB;
          font-weight: normal;color: #666666;line-height: 30px;">
        {{$t('common.ReminderSecond')}} <span style="color: #0091FF;font-size: 18px;">{{num}}</span> {{$t('common.ReminderThird')}}
      </div>
      <div style="font-size: 14px;font-family: HiraginoSansGB-W3, HiraginoSansGB;
          font-weight: normal;color: #666666;line-height: 30px;">
        {{$t('common.ReminderForth')}}
      </div>
      <div style="font-size: 14px;font-family: HiraginoSansGB-W3, HiraginoSansGB;
          height:33px;line-height:60px;font-weight: normal;color: #0091FF;">
            <span style="margin-left: 40px;" class="cursor" @click="toView('login')">
              {{$t('common.ReminderFifth')}}
            </span>
        <span style="margin-left: 10px;" class="cursor" @click="toView('Register')">
              {{$t('common.ReminderSixth')}}
            </span>
      </div>
    </div>
    </div>
    </el-dialog>
  </div>
</template>

<script>
import { getConfrenceDetail, getConfrences } 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 Base from "@/views/base/Base";
import speaker from './modelView/speaker'
import pic from './modelView/picture'
import news from './modelView/news'
import doc from './modelView/documents'
import vid from './modelView/video'
import {getToken} from "@/utils/auth";
import LoginReminder from './LoginReminder'
import { saveFollowModel } from "@/api/operation/basePortalModelFollowInfo";
import {getFollowModeNumlByModelIdAndUserId} from "@/api/operation/basePortalModelFollowInfo";
export default {
  extends: Base,
  components: {
    speaker,
    pic,
    news,
    doc,
    vid,
    LoginReminder
  },
  data() {
    return {
      recommendData: [],
      agendaData: '',
      viewpointData: [],
      imgData: [],
      newsData: [],
      materialData: [],
      modelView: '',
      modelShowBtns: [],
      num:5,
      toViewLogin:false,
      ifcommon:false,
      modelBtns: [
        {
          text: '嘉宾观点',
          textEN: 'Speakers',
          view: 'speaker',
          isShow: false

        },{
          text: '图片资料',
          textEN: 'Picture',
          view: 'pic',
          isShow: false
        },{
          text: '媒体报道',
          textEN: 'News',
          view: 'news',
          isShow: false
        },{
          text: '文件资料',
          textEN: 'Document',
          view: 'doc',
          isShow: false
        },{
          text: '视频资料',
          textEN: 'Video',
          view: 'vid',
          isShow: false
        },
      ],
      baseInfo: {},
      navIndex: -1,
      resultData: [],
      evaluateText: "",
      lang: '',
      showPointNum: 3,
      dialogShow: false,
    };
  },
  created(){
      this.lang = this.$i18n.locale;
  },
  watch: {
      '$i18n.locale'(val){
          this.lang = val;
      },
      "toViewLogin"(){
        if(this.toViewLogin==true){
          this.loginTipsChange();
        }
      }
  },
  mounted() {
    getConfrences().then(res=>{
        console.log('近期会议', res)
        res.data.meetingBasicInfos.forEach(item=>{
            if(!this.isMeetingOver(item.meetingEndDate) && item.meetingIsShow=="01" && item.meetingIsEnroll=="01"){
                this.recommendData.push(item)
            }
        })
        // console.log('会议', this.recommendData)
    })
    
    getConfrenceDetail(this.$route.query.key).then((res) => {
      this.baseInfo = res.data.basicInfo;
      let user = window.localStorage.getItem("user");
      if(user){
          var users = JSON.parse(user);
          var token = "" + getToken();
          var projectId = this.baseInfo.id;
          let userId = users.userId;
          getFollowModeNumlByModelIdAndUserId(
            projectId,
            "meeting",
            this.userId
          ).then((res) => {
              this.ifcommon = res.data;
              console.log(
                  res.data,
                  "---------------------------------------------------------------------------"
              );
          });
      }
     
      this.resultData = res.data.meetingOutInfo.video.filter(item =>{
          return (item.outType == "VIDEO" && item.videoUrl);
      });
      this.modelBtns[4].isShow = this.resultData.length;
      
      if(res.data.meetingOutInfo.image.length){
          let filterdFile = [];
          res.data.meetingOutInfo.image.forEach((item) => {
              if(item.photoType == "meeting_yicheng"){
                  filterdFile.push(item);
              }else if(item.photoType == "meeting_pro_img"){
                item.list.forEach((_item) => {
                  this.imgData.push(_item.attachmentSavePath);
                });
              }
          });
          if(filterdFile[0].list.length){
            this.agendaData = filterdFile[0].list[0].attachmentSavePath;
          }else{
            this.agendaData = '';
          }
      }else{
          this.agendaData = '';
          this.imgData = [];
      }
      this.modelBtns[1].isShow = this.imgData.length;

      this.viewpointData = res.data.meetingOutInfo.guandian.concat(res.data.meetingOutInfo.guandian_file, res.data.meetingOutInfo.guandian_video);
      this.modelBtns[0].isShow = this.viewpointData.length;
      // console.log('观点',this.viewpointData)
      this.newsData = res.data.meetingOutInfo.news.slice(0, 5);
      this.modelBtns[2].isShow = this.newsData.length;

      this.materialData = res.data.meetingOutInfo.file;
      this.modelBtns[3].isShow = this.materialData.length;
      // console.log('全部',res)
      // console.log('资料',this.materialData)
      // console.log('新闻',this.newsData)

      this.modelShowBtns = this.modelBtns.filter(item=>{
        return item.isShow > 0;
      })
      this.modelView = this.modelShowBtns[0].view;
    });
  },
  methods: {
     // 未登录跳转
     loginTipsChange(){
        const that=this;
        this.num =5;
        // clearInterval(timer_interval);

        this.timer = setInterval(function() {
          if (that.num > 0) {
            that.num--;
          } else {
            if(that.toViewLogin==true){
              clearInterval(that.timer);
              that.toView('login');
            }else {
              clearInterval(that.timer);
            }
          }
        }, 1000)
      },
      // 判断未登录跳转是否关闭
    toViewLoginChange(done){
      this.toViewLogin=false;
      this.num=5;
      clearInterval(this.timer);
    },
    shareChange() {
        if (this.ifcommon) {
            this.saveFollowModelDo("unfollow");
        } else {
            this.saveFollowModelDo("follow");
        }
    },
    saveFollowModelDo: function(followType){
        let user = window.localStorage.getItem('user');
        if (!this.$Cookies.get('token')) {
              this.toViewLogin=true;
        } else {
            var users = JSON.parse(user);
            var token = "" + getToken();
            var projectId = this.baseInfo.id;
            var userId = users.userId
            // 接口逻辑
            this.submitHandler(token => {
                saveFollowModel(projectId,"meeting", userId,followType,token).then(result => {
                    // console.log(result);
                    this.$message({
                        message: result.data,
                        type: 'success'
                    });
                    this.ifcommon=!this.ifcommon
                    this.resetToken();
                }).catch(error => {
                    // 此处你的业务代码

                });
            });
        }
    },
    toAgenda(){
      // const {href} = this.$router.resolve({
      //   path: '/ConferenceAgenda',
      //   query: {
      //     pdf: JSON.stringify(this.agendaData)
      //   }
      // })
      // window.open(href, '_blank')
    },
    toFeedback(id){
      this.$refs.loginReminder.activeChange('ConferenceFeedback', id);
    },
    modelChange(view){
      this.modelView = view
    },
    toView(router, json) {
      this.$router.push({ path: router, query: { key: json } });
    },
    toViewById(path, id){
      // localStorage.setItem('conferenceId', id);
      this.$router.push({ path: path, query:{ key: id} });
    },
    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;
      }
    },
    isMeetingOver(t){
        var ct = Date.parse(new Date());
        if(ct-t > 0){
            return true;
        }else{
            return false;
        }
    },
  },
};
</script>
<style scoped>
#ConferenceResultVideo{
  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 0;
}
.content-box {
  position: relative;
  padding-bottom: 40px;
}
.section-left{
  width: 70%; 
  padding-right: 40px;
  border-right: 4px solid #f2f2f2;
}
.section-right{
  width: 30%;
}
.conference-recommend{
  position: relative;
  padding-bottom: 40px;
  padding-left: 20px;
}
.conference-recommend .no-data{
  color: #555;
  line-height: 26px;
  background: #f2f2f2;
  padding: 0 6px;
  font-size: 14px;
  text-align: center;
}
.conference-recommend .more{
  font-size: 20px;
  position: absolute;
  line-height: 27px;
  bottom: 10px;
  right: 10px;
}
.conference-recommend > .title{
    font-size: 18px;
    line-height: 18px;
    font-weight: bold;
    margin-top: 20px;
    margin-bottom: 20px;
    border-left: 8px solid #02a7f0;
    padding-left: 10px;
}
.conference-recommend-list{
    background: #fff;
}
.conference-recommend-top{
  background: #f2f2f2;
  line-height: 20px;
  font-size: 14px;
  display: flex;
  padding: 3px 6px;
}
.conference-recommend-top .step{
  display: block;
  width: 10px;
  position: relative;
  margin: 0 12px;
}
.conference-recommend-top .step::after{
  content: '';
  display: block;
  width: 9px;
  height: 9px;
  border: 1px solid #02a7f0;
  border-radius: 50%;
  position: absolute;
  top: 5px;
  left: 0px;
}
.conference-recommend-top .title{
  flex: 1;
  color: #02a7f0;
}
.section-left .time{
  color: #555;
  position: relative;
  padding-right: 15px;
  margin-right: 15px;
}
.section-left .time::after{
  width: 1px;
  height: 12px;
  background: #555;
  content: '';
  display: block;
  position: absolute;
  top: 5px;
  right: 0;
}
.section-right .time{
  width: 76px;
}
.conference-recommend-body{
  display: flex;
  color: #aaa;
  padding: 12px 0;  
}
.conference-recommend-body .place{
  font-size: 12px;
  width: 100px;
  border-right: 1px dotted #f2f2f2;
  text-align: right;
  line-height: 24px;
  padding: 0 12px;
}
.conference-recommend-body .introduction{
  font-size: 12px;
  flex: 1;
  margin: 0 10px;
  line-height: 20px;
  -webkit-box-orient: vertical;
  position:relative;
  overflow: hidden;
  height:84px;
}
.conference-recommend-list li{
    margin-bottom: 30px;
    cursor: pointer;
}
.conference-recommend-list li img{
    width: 100%;
}
.conference-recommend-list li p{
    margin: 20px 0;
}
.conference-recommend-list li:hover p{
    color: #2c558a;
}
.conference-title {
  font-size: 20px;
  font-weight: bold;
  color: #333;
  margin-bottom: 20px;
  margin-top: 10px;
}
.confrence-item-header {
  line-height: 28px;
  font-size: 28px;
  font-weight: bold;
  margin: 30px 0;
}
.confrence-introduce p {
  margin: 0;
  font-size: 16px;
}
.confrence-introduce p span{
  line-height: 48px;
  color: #797979
}
.confrence-introduce .title{
  font-size: 36px;
  margin: 20px 0;
}
.confrence-introduce-content{
  line-height: 40px;
  margin-top: 20px;
  color: #555;
}


.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: 99;
  transition: all 0.5s;
}
.swiper-slide:hover .conference-video-title {
  top: 0;
}
/deep/ .el-carousel {
  height: 800px;
  width: 600px;
  margin: 0 auto;
}
/deep/ .el-carousel__container {
  height: 800px;
}
/deep/ .el-carousel__item {
  height: 800px;
}
/deep/ .el-carousel__item img {
  max-width: 100%;
  max-height: 100%;
}
/deep/ .el-carousel__indicator--horizontal {
    padding: 0 3px;
}
/deep/ .el-carousel__button {
    width: 8px;
    height: 8px;
    background-color: #999;
    border-radius: 100%;
}
/deep/ .is-active .el-carousel__button{
    background: #3a8ee6;
}
.browse-all{
  text-align: center;
}
.image-box{
  line-height: 800px;
  text-align: center;
}
.image-box img{
  max-height: 100%;
  max-width: 100%;
  vertical-align: middle;
}
.agenda-title{
  font-size: 20px;
  line-height: 42px;
  height: 42px;
  cursor: pointer;
  color: #02a7f0;
  font-weight: bold;
  text-decoration: none;
  border-bottom: 2px solid #02a7f0;
  font-style: italic;
  
}
.agenda-title:hover{
  color: #d55421;
  border-bottom-color: #d55421;
}
.agenda-dialog{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50% ,-50%);
}
.agenda-mask{
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, .8);
    position: fixed;
    top: 0;
    right: 0;
    z-index: 99;
}
.share span{
    cursor: pointer;
    margin-left: 30px;
}
.share span:hover{
    color: #168dbf;
}
.result-model-btn{
  margin: 30px 0;
}
.result-model-btn li{
  display: inline-block;
  padding: 6px 10px;
  margin-right: 40px;
  font-size: 18px;
  cursor: pointer;
}
.result-model-btn li:hover,
.result-model-btn li.active{
  color: #fff;
  font-weight: bold;
  background: #02a7f0;
}
.result-model-view{
  min-height: 350px;
}
.feed-back{
  position: fixed;
  background: #2c558a;
  color: #fff;
  bottom: 240px;
  right: -110px;
  height: 40px;
  width: 150px;
  line-height: 40px;
  font-size: 18px;
  padding: 0 16px;
  border-radius: 25px 0 0 25px;
  z-index: 0;
  transition: all .5s;
  cursor: pointer;
}
.feed-back i{
  margin-right: 10px;
}
.feed-back:hover{
  right: 0px;
}
</style>