<template>
  <common ref="login" @jihuo="jihuo" temp="tencent"> </common>
</template>

<script>
import common from "../treatyNew/index.vue";
import { changeUserid } from "../../api";
export default {
  data() {
    return {};
  },
  methods: {
    async jihuo(data) {
      if (this.$store.state.user.userid) {
        let res = await this.useridCode();
        let url =
          "https://mcgi.v.qq.com/unicom/check_user_order?usermob=" +
          res.data +
          "&otype=json&platform=5&_t=" +
          Math.random() +
          "&callback=test";
        this.myJsonp(
          url,
          (data) => {
            let params = data;
            QQVideoBridge.saveResult("saveSubscriptionStatus", params).done(
              (result) => {
                let res = JSON.parse(result);
                if (res.errcode === 0) {
                  this.$toast.success("激活成功");
                } else {
                  this.$toast.fail("激活失败");
                }
              }
            );
          },
          "test"
        );
      } else {
        this.$refs.login.showLogin = true
        this.$refs.login.text = "腾讯激活"
      }
    },
    useridCode() {
      let cpid = "tencent";
      let userid = this.$store.state.user.userid;
      return changeUserid({ cpid, userid });
    },
    myJsonp(url, callback, callbackname) {
      window[callbackname] = callback;
      let script = document.createElement("script");
      script.src = url;
      script.type = "text/javascript";
      document.head.appendChild(script);
      // document.head.removeChild(script);
    },
  },
  components: { common },
};
</script>

<style lang="scss">
</style>
