<template>
  <div class="as-share-wrapper">
    <Card6 type="2" :anualData="anualData"></Card6>
    <Loading v-show="showLoading" />
  </div>
</template>
<script>
import Loading from "@/components/common/common-loading";
import Card6 from "@/components/annual-summary/card-6";
import {
  getWebPageUrl
} from "@/utils"
export default {
  components: {
    Card6,
    Loading
  },
  data() {
    return {
      uuid: '',
      shareUrl: '',
      showLoading: false,
      anualData: {

      }
    }
  },
  created() {
    let href = location.href;
    let uuidIndex = href.indexOf("uuid") || 0;
    if (uuidIndex > 0) {
      this.uuid = href.substr(uuidIndex + 5, 32);
    } else {
      this.uuid = "74ad500d5edf11eba76d000c29f14581"; // 测试用
    }
    this.shareUrl = location.href;
    if (href.indexOf("singlemessage") >= 0 || href.indexOf("wx_code") >= 0) {
      this.shareUrl = getWebPageUrl(`profexam/#/as-share?uuid=${this.uuid}`);
      location.replace(this.shareUrl);
    }
    this.initData();
    // 设置二次分享
    this.secondShare();

    // 全局埋点--对外埋点
    this.$sendBuriedData({
      action: "ACTION_WEB_ENTER",
      component_tag: `561#0#${this.uuid}`
    });

  },

  methods: {
    // 获取数据
    initData() {
      let param = {
        uuid: this.uuid,
      };
      this.showLoading = true;
      this.GET(`stats/year/end/report/share`, param).then(res => {
        if (res.code == "000000") {
          this.showLoading = false;
          this.handlerDate(res.data || {});
        } else {
          this.$toast(res.message);
        }
      });
    },

    // 对数据进行处理
    handlerDate(anualData) {
      let learnTime4Show = 0,
        loginTotalTime = 0,
        loginTotalTimeM = 0,
        loginTotalTimeH = 0,
        orderTotalAmount = 0,
        orderTotalAmountY = 0;
      if (anualData.learnEarliestTimeFlag == 1) {
        learnTime4Show = anualData.learnEarliestTime;
      } else if (anualData.learnLatestTimeFlag == 1) {
        learnTime4Show = anualData.learnLatestTime;
      } else {
        learnTime4Show =
          anualData.learnEarliestTime || anualData.learnLatestTime;
      }
      anualData.learnTime4Show = learnTime4Show;

      loginTotalTime = anualData.loginTotalTime || 0;
      if (loginTotalTime) {
        loginTotalTimeM = Math.floor(loginTotalTime / 1000);
        loginTotalTimeH = Math.floor(loginTotalTime / 1000 / 60);
      }
      anualData.loginTotalTimeM = loginTotalTimeM;
      anualData.loginTotalTimeH = loginTotalTimeH;

      orderTotalAmount = anualData.orderTotalAmount;
      if (orderTotalAmount) {
        orderTotalAmountY = Math.floor(orderTotalAmount / 100);
      }
      anualData.orderTotalAmountY = orderTotalAmountY;
      this.anualData = anualData;
    },

    // 二次分享
    secondShare() {
      this.wechatShare(
        {
          link: this.shareUrl,
          title: "云鹊医2020年度个人学习报告",
          friendtitle: "云鹊医2020年度个人学习报告",
          desc: "点击查看我的专属学习报告",
          imgUrl: "https://file.yunqueyi.com/logo.png"
        },
        () => {
          console.log("share success...");
        }
      );
    }
  }
};
</script>
<style lang="less" scoped>
.as-share-wrapper {
}
</style>