<template>
  <div class="disk"></div>
</template>

<script>
import qs from 'qs';
export default {
  middleware: [
    async ({ base, route, $axios, $auth, redirect, $userAgent }) => {
      const res = await $axios.$get(
        '/resources/v5/client/disk/info/userCard/single',
        {
          params: {
            userCardId: route.params.id,
          },
        },
      );
      const {
        userCardId,
        userName,
        room,
        buyVipType,
        sourceType,
        authPhone,
        validTime,
      } = res.data;
      const token = $auth.strategy.token.get();

      const url = `${location.origin}${base}${
        $userAgent.isIos ? 'screenIos' : 'screenAndroid'
      }/WXtrialInterface.html${qs.stringify(
        {
          userCardId,
          username: userName,
          token,
          rm: room,
          mealType: buyVipType,
          sourceType,
          authPhone,
          validTime,
        },
        {
          addQueryPrefix: true,
        },
      )}`;
      // console.log(url);
      redirect(url);
      // window.open(url, '_self');
    },
  ],
  data() {
    return {
      // diskInfo: null,
    };
  },
  async fetch() {
    // await this.getDiskInfo(this.$route.params.id);
    // this.openDisk();
  },
  methods: {
    // async getDiskInfo(userCardId) {
    //   const res = await this.$axios.$get(
    //     '/resources/v5/client/disk/info/userCard/single',
    //     {
    //       params: {
    //         userCardId,
    //       },
    //     },
    //   );
    //   this.diskInfo = res.data;
    // },
    // openDisk() {
    //   const {
    //     userCardId,
    //     userName,
    //     room,
    //     buyVipType,
    //     sourceType,
    //     authPhone,
    //     validTime,
    //   } = this.diskInfo;
    //   const token = this.$auth.strategy.token.get();
    //   const url = `/screenIos/WXtrialInterface.html${qs.stringify(
    //     {
    //       userCardId,
    //       username: userName,
    //       token,
    //       rm: room,
    //       mealType: buyVipType,
    //       sourceType,
    //       authPhone,
    //       validTime,
    //     },
    //     {
    //       addQueryPrefix: true,
    //     },
    //   )}`;
    //   window.open(url);
    // },
  },
};
</script>
