<template>
  <div class="disk-page">
    <disk :user-card-id="userCardId"></disk>
  </div>
</template>

<script>
import qs from 'qs';
const isNew = false;
export default {
  name: 'DiskPage',
  middleware: [
    async ({ base, route, $axios, $auth, redirect, $userAgent }) => {
      if (isNew) {
        return;
      }
      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,
        id,
      } = res.data;
      const token = $auth.strategy.token.get();
      const url = `${location.origin}${base}${
        $userAgent.isIos ? 'screenIos' : 'screenAndroid'
      }/WXtrialInterface.html${qs.stringify(
        {
          userCardId,
          username: $auth.user.username,
          token,
          rm: room,
          mealType: buyVipType,
          sourceType,
          authPhone: authPhone ? 'huo' : 'none',
          validTime,
          record: id,
        },
        {
          addQueryPrefix: true,
        },
      )}`;
      redirect(url);
    },
  ],
  data() {
    return {
      userCardId: null,
    };
  },
  fetch() {
    this.userCardId = +this.$route.params.id;
  },
  methods: {},
};
</script>

<style lang="scss" scoped>
.disk-page {
  height: 100vh;
  position: relative;
}
</style>
