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

<script>
import ServiceBasekq from './ServiceBaseKQ.vue'
export default {
  name: 'ServiceKQ',
  data () {
    return {
      centerNo: '',
    }
  },

  mounted () {
    console.log('xst mounted')
    aplus_queue.push({
      'action': 'aplus.sendPV',
      'arguments': [{
        is_auto: false
      }]
    })
    this.checkAuth()

  },
  activated () {
    console.log('KQ activated')
    this.checkAuth()
  },
  methods: {
    checkAuth () {
      let centerNo = this.common.getUrlParam('center_no') || sessionStorage.getItem('centerNo');
      if (centerNo) {
        this.centerNo = centerNo
        sessionStorage.setItem('centerNo', centerNo);
        console.log(111)
        this.getUserInfo()
      } else {
        console.log(222)
        const sUserAgent = window.navigator.userAgent.toLowerCase()
        const dtdreamweb = sUserAgent.indexOf("dtdreamweb") > -1
        const miniprogram = sUserAgent.indexOf("miniprogram") > -1 && sUserAgent.indexOf("alipay") > -1
        if (dtdreamweb) {
          console.log(333)
          alert('浙里办')
          // window.location.href = `https://puser.zjzwfw.gov.cn/sso/mobile.do?action=oauth&scope=1&servicecode=hswsy`;
          this.centerNo = '20210930160466993660'
          sessionStorage.setItem('centerNo', '20210930160466993660');
          this.getUserInfo()
        }
        // else if (miniprogram) {
        //   alert('支付宝')
        //   window.location.href = `https://puser.zjzwfw.gov.cn/sso/alipay.do?action=ssoLogin&servicecode=passp&goto=`;
        // }
        else {
          console.log('非浙里办渠道访问，显示测试用户数据')
          this.centerNo = '20210930160466993660'
          sessionStorage.setItem('centerNo', '20210930160466993660');
          this.getUserInfo()
        }
      }
    },
    // 获取用户信息
    getUserInfo: function () {
      this.mgop({
        api: 'mgop.sz.hswsy.getPortalUserByNum', // 必须
        // host: 'https://mapi.zjzwfw.gov.cn/',
        // dataType: 'JSON',
        // type: 'GET',
        appKey: 'fuxgnukl+2001895516+edccpx', // 必须
        headers: {
          //   'isTestUrl': '1'
        },
        data: {
          "userNum": this.centerNo
        },
        onSuccess: res => {
          console.log('getUserInfo', res)
          if (res.data.code == 200) {
            sessionStorage.setItem('userInfo', JSON.stringify(res.data.data.userInfo))
          }
        },
        onFail: err => {
          console.log('err', err)
        }
      });
    },
  },
  components: {
    ServiceBasekq
  }
}
</script>
