<template>
  <mobile v-if="!isPC" :com="com" :dev="dev" :pre="pre" :vipDetail="vipDetail" :isCom="isCom"></mobile>
</template>

<script>
import { mapState } from "vuex";
import pc from "@/components/type/vip/pc";
import mobile from "@/components/type/vip/mobile";
import getDeviceType from "@/mixins/getDeviceType";
import qs from "qs";

export default {
  head: {
    title: "会员中心页 - 程序员客栈"
  },
  components: {
    pc,
    mobile
  },
  mixins: [getDeviceType],
  data() {
    return {
      vipList: [],
      vipDetail: {}
    };
  },
  computed: {
    ...mapState(["isPC"]),
    com() {
      return this.vipList[0];
    },
    dev() {
      return this.vipList[1];
    },
    pre() {
      return this.vipList[2];
    },
    isCom() {
      if (this.$route.query.isCom) return true;
      return this.vipDetail.vip_type_id !== "2";
    }
  },
  async mounted() {
    await this.getList();
    this.getVipDetail();
    if (this.isPC){
      location.href="/#vip";
    }
  },
  methods: {
    async getList() {
      let extraHeaders = {};
      if (this.deviceType === "ios") {
        extraHeaders = this.getSign();
      }
      let res = await this.$axios.$post(`/api/vip/getList`, extraHeaders);
      if (Number(res.status) === 1) {
        this.vipList = res.data;
      }
    },
    async getVipDetail() {
      let res = await this.$axios.$post("/api/vip/getVipUserDetail");
      // if (!res || !res.data) return
      this.vipDetail = res && res.data ? res.data : {};
      if (this.isCom) this.currentCom = true;
    }
  }
};
</script>

<style>
</style>
