<template>
  <service-basekq :centerNo="centerNo" v-if="showData" @setWxShare="setWxShare"></service-basekq>
</template>

<script>
// import ServiceBaseKQ from './ServiceBaseKQ.vue'
import ServiceBasekq from './ServiceBaseKQ.vue'
// import vConsole from 'vconsole'
export default {
  name: 'ServiceKQ',
  data () {
    return {
      centerNo: '',
      showData: false,
      publicName: 'KQ',
      appId: 'wx1305e88d2bc74073',
    }
  },

  mounted () {
    console.log('xst mounted')
    sessionStorage.setItem('publicName', this.publicName);
    sessionStorage.setItem('prePageQuery', JSON.stringify({ showTab: this.$route.query.showTab }));
    sessionStorage.setItem('prePage', 'Service' + this.publicName);
    if (process.env.NODE_ENV === "production") {
      let openId = sessionStorage.getItem('openId' + this.publicName);
      if (!openId) {
        this.$router.push({ name: 'Authorize' + this.publicName })
      } else {
        this.getUserInfo()
      }
    } else {
      sessionStorage.setItem('unionId', 'oJPmPuLaAx2x2DaRGfCFeYuLWzLU');
      this.$nextTick(()=>{
        this.getUserInfo()
      })
    }
  },
  activated () {
    console.log('KQ activated')
    sessionStorage.setItem('publicName', this.publicName);
    sessionStorage.setItem('prePageQuery', JSON.stringify({ showTab: this.$route.query.showTab }));
    sessionStorage.setItem('prePage', 'Service' + this.publicName);
    if (process.env.NODE_ENV === "production"&&this.common.isWeiXin()) {
      let openId = sessionStorage.getItem('openId' + this.publicName);
      if (!openId) {
        this.$router.push({ name: 'Authorize' + this.publicName })
      } else {
        this.getUserInfo()
      }
    } else {
      sessionStorage.setItem('unionId', 'oJPmPuLaAx2x2DaRGfCFeYuLWzLU');
      this.$nextTick(()=>{
        this.getUserInfo()
      })
    }
  },
  methods: {
    setWxShare (tabName) {
      // 设置分享
      this.$emit('getWxConfig', {
        title: '趣研学啦', // 分享标题
        desc: '现在世界是孩子的书本，一起学才更好玩！', // 分享描述
        link: 'https://payment.myjxt.com/center/#/service_kq?showTab=' + tabName, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
        imgUrl: 'https://payment.myjxt.com/share_qxy.png', // 分享图标
      })
    },
    // 获取用户信息
    getUserInfo () {
      let userInfo = sessionStorage.getItem('userInfo');
      let unionId = sessionStorage.getItem('unionId');
      if (userInfo) {
        userInfo = JSON.parse(userInfo)
        this.centerNo = userInfo.centerNo
        this.showData = true;
      } else {
        this.$toast.loading({
          message: '加载中...',
          duration: 0,
          forbidClick: true
        })
        this.yxAxios.get(`${this.proxyUrl}/prod/api/wx/${this.appId}/getUserInfo?unionId=${unionId}`).then((res) => {
          this.$toast.clear()
          if (res.data.code == 200) {
            this.centerNo = res.data.data.centerNo
            this.showData = true
            sessionStorage.setItem('userInfo', JSON.stringify(res.data.data))
          } else {
            console.log('getUserInfo失败')
            this.showData = true;
            // this.$router.push({ name: 'LoginPublic', query: { publicName: this.publicName } })
          }
        })
      }
    },
  },
  components: {
    ServiceBasekq,
    // ServiceBaseKQ
  }
}
</script>
