<template>
  <div class="page">
    <div class="title">{{title}}</div>
    <div class="rili">
      <div class="img"></div>
      <div class="day">{{day}}</div>
      <div class="month">二月</div>
      <div class="good">{{todayFortune.suitable}}</div>
      <div class="bad">{{todayFortune.avoid}}</div>
    </div>
    <div class="header">头条新闻</div>
    <div class="home">
      <div class="bar">
        <img class="pic" :src="mainImgUrl">
      </div>
      <div class="tip1">{{headlines.title}}</div>
      <div class="tip2">{{headlines.des}}</div>
    </div>

    <div class="header" v-if="domesticNews.length>0">国内要闻</div>
    <div class="home" v-if="domesticNews.length>0">
      <div class="box" v-for="(item, index) in domesticNews" v-bind:key="index" @click="jump(item)">
        <div class="tip1">{{item.title}}</div>
        <div class="tip2">{{item.des}}</div>
      </div>
    </div>

    <div class="header" v-if="intelNews.length>0">国际新闻</div>
    <div class="home" v-if="intelNews.length>0">
      <div class="box" v-for="(item, index) in intelNews" v-bind:key="index" @click="jump(item)">
        <div class="tip1">{{item.title}}</div>
        <div class="tip2">{{item.des}}</div>
      </div>
    </div>

    <div class="header" v-if="socialNews.length>0">社会新闻</div>
    <div class="home" v-if="socialNews.length>0">
      <div class="box" v-for="(item, index) in socialNews" v-bind:key="index" @click="jump(item)">
        <div class="tip1">{{item.title}}</div>
        <div class="tip2">{{item.des}}</div>
      </div>
    </div>

    <img :src="footerImage" class="pic" alt="">

    <share-footer :scid="1234" v-if="showShare" @doshare="doshare"></share-footer>
  </div>
</template>

<script>
import { get, post } from "@js/request";
import { getUrlParameter, isWeChatApplet } from "@js/tooler";
import { shareConfig, updateLink } from "@js/share";
import ShareFooter from '../../components/shareFooter'

const SCID = getUrlParameter('scid');
const API = {
  h5info: '/kjy/mp/content/h5info'
}

const inMiniprogram = getUrlParameter("mini") == 1;

export default {
  data() {
    return {
      title: '',
      day: 1,
      month: '',
      mainImgUrl: '//yun.dui88.com/h5/miniprogram/kejiji/web/rili.png',
      footerImage: '//yun.dui88.com/h5/miniprogram/kejiji/web/rili.png',
      showShare: false,
      todayFortune: {}, //今日运势
      headlines: {}, //头条新闻
      socialNews: [], //社会新闻
      intelNews: [], //国际新闻
      domesticNews: [] //国内新闻
    };
  },
  components: {ShareFooter},
  methods: {
    showToday() {
      // this.$router.push("/today");
      if(inMiniprogram){
        wx.miniProgram.navigateTo({
          url: '/pages/news/news_today/main?num=3'
        })
      }
      else{

      }
    },
    async initData(){

      if(inMiniprogram){
        this.showShare = true;
        // wx.miniProgram.postMessage({
        //   data: JSON.stringify({
        //     title: "this.title",
        //     src: "this.src"
        //   })
        // })
      }

      // let a = await get('/kjy/mp/seller/getScId', {contentId: 54});
      // console.log(a);
      // this.tip = window.navigator.userAgent.toLowerCase();
      let res = await get(API.h5info, { scid: SCID });
      console.log(res);
      if (res.success) {
        this.title = res.data.title;
        this.mainImgUrl = res.data.mainImgUrl;
        console.log(res.data.mainImgUrl);
        let dailyData = JSON.parse(res.data.text);
        let date = new Date(res.data.releaseTime || Date.now());
        this.day = date.getDate();
        this.month = ("一-二-三-四-五-六-七-八-九-十-十一-十二".split("-"))[date.getMonth()] + "月";
        this.todayFortune = dailyData.todayFortune;
        this.socialNews = dailyData.socialNews;
        this.intelNews = dailyData.intelNews;
        this.headlines = dailyData.headlines;
        this.domesticNews = dailyData.domesticNews;
        this.footerImage = dailyData.footerImage;

        shareConfig({
          link: window.location.href,
          title: this.title,
          desc: '来自客集集的分享',
          img: this.mainImgUrl,
          debug: false
        });
      } else {
        if (res.code == '100010') {
          this.getH5Authorize();
        } else if (res.code == '100020') {
          
        }
      }
      
    },
    getH5Authorize(){
      let url = '/kjy/authorize/wxh5base?uri=/kjy/mp/contentview?scid=' + SCID;
      window.location.href = url;
    },
    jump(item){
      console.log(item);
      let url = item.origin;
      if(!url){
        return;
      }
      if(inMiniprogram){
        wx.miniProgram.navigateTo({
          url: '/pages/news/news_link/main?url=' + encodeURIComponent(url)
        })
      }
      else{
        window.location.href = url;
        // let scid = this.$mp.query.scid;
        // this.pageUrl = 'https://kjj.m.duibatest.com.cn/kjy/mp/contentview?scid=' + scid + '&currentView=minipg';
      }
    },
    doshare(){
      console.log(123);
      updateLink(123);
    }
  },
  created() {
    this.initData();
  }
};
</script>

<style lang="less" scoped src="./today.less">
</style>