/**
 * @author yeyuchao
 * @description news center.
 */
import NetWork from '../../base/NetWork.js';
import {addEvent} from '../../base/Utils';
import {scrollElementControl} from '../../base/Utils.js';
import {Device} from '../../base/Device';
import { WOW } from 'wowjs';
import {UAnimateContainer, UAnimate} from 'vue-wow';
// import 'animate.css';
const screenWidth = window.screen.width;
const screenHeight = window.screen.height;
export default {
  data() {
    return {
      listView:false,//列表模式
      rectangleView:true,
      pageListData:null,
      screenWidth:screenWidth,
      screenHeight:screenHeight,
      iframeUrl:"",
      iframeShow:false,
      deviceMobile:false,
      device:null,

    };
  },

  components: {
    UAnimateContainer,
    UAnimate
  },

  mounted() {
    /*this.$nextTick(() => { // 在dom渲染完后,再执行动画
      let options={
        live:true,
        mobile:true,
        boxClass: 'wow',
        animateClass: 'animated',
        offset: 100
      };
      let wow=new WOW(options);
      wow.init();
    })*/
  },
  watch: {
    cases() {
      /*this.$nextTick(() => { // 在dom渲染完后,再执行动画
        let options={
          live:true,
          mobile:true,
          boxClass: 'wow',
          animateClass: 'animated',
          offset: 100
        };
        let wow=new WOW(options);
        wow.init();
      })*/
    }
  },

  created() {
    window.itemType = 3;
    this.device = new Device();
    if(this.device.phone){
      this.deviceMobile = true;
    }
    // broadcast.$emit('menuBlock',"true");
    this.getPageList();
    const newsBody = document.getElementById("item-fill");

    addEvent(newsBody, 'touchmove', () => {
      // that._onLoaded();
      console.log("touchmove");
      if(this.iframeShow){
        e.preventDefault();
        e.stopPropagation();
      }
    });
    addEvent(newsBody, 'onscroll', () => {
      // that._onLoaded();
      console.log("onscroll");
      if(this.iframeShow){
        e.preventDefault();
        e.stopPropagation();
      }
    });
    addEvent(newsBody, 'DOMMouseScroll', () => {
      // that._onLoaded();
      console.log("DOMMouseScroll");
      if(this.iframeShow){
        e.preventDefault();
        e.stopPropagation();
      }
    });
  },
  methods:{
    getTarget() {
      return this.$el;
    },
    getPageList(){
      const that = this;
      NetWork.fetchGet('listNews').then((date)=>{
        that.pageListData = date.data.result;
        console.log("getPageList："+JSON.stringify(date));
      }).catch((err)=>{
      })
    },
    navigateToWebiew(idx){
      let url = this.pageListData[idx].linkPcUrl;
      if(this.deviceMobile){
        url = this.pageListData[idx].linkUrl;
      }
      this.createIframe(url);
      this.iframeShow = true;
    },
    closeNews(){
      this.iframeShow = false;
      setTimeout(()=>{
        const iframe = document.getElementById("iframe-news");
        iframe.parentNode.removeChild(iframe);
        const param = {open:false};
        broadcast.$emit('NewsIframeOpen',param);
      },1000)
    },
    createIframe(lineUrl){
      const iframeParent = document.getElementById("iframe-page");
      let iframeHtml = document.createElement("iframe");
      iframeHtml.setAttribute('frameborder','0');
      iframeHtml.setAttribute('height','100%');
      iframeHtml.setAttribute('width','100%');
      iframeHtml.setAttribute('scrolling','auto');
      iframeHtml.setAttribute('class',"iframe-news");
      iframeHtml.setAttribute('id',"iframe-news");

      iframeHtml.onload = function(){
        // reinitIframe();
      };
      iframeParent.appendChild(iframeHtml);
      iframeHtml.setAttribute('src',lineUrl);
      const param = {open:true};
      broadcast.$emit('NewsIframeOpen',param);

    },
    /*elementScrollControl(){
      const element = document.getElementsByClassName("news");
      scrollElementControl(element);
    }*/
  }
};
