<template>
  <div v-loading.body.fullscreen="fullscreenLoading" element-loading-background="rgba(255, 255, 255, 0)">
    <favoriteList v-if="myFavoriteList.length && loading" />
    <favoriteNo v-if="myFavoriteList.length == 0 && loading" />
  </div>
</template>
<script>
import favoriteList from "./components/list.vue";
import favoriteNo from "./components/favoriteNo.vue";
import { mapGetters } from "vuex";
import bus from '@/utils/bus'
export default {
  components: {
    favoriteList,
    favoriteNo
  },
  data () {
    return {
      loading: false
    }
  },
  computed: {
    ...mapGetters(["myFavoriteList"]),
  },
  activated() {
    if (this.loading) {
      this.updateSubscribe()
    }
  },
  created() {
    if (this.myFavoriteList.length) {
      this.loading = true
    }
    this.getProductUserList()
  },
  methods: {
    getProductUserList() {
      this.fullscreenLoading = true
      this.$store.dispatch('getProductUserList').then(() => {
        this.updateSubscribe()
      }).catch(() => {}).finally(() => {
        this.fullscreenLoading = false
      })
    },
    updateSubscribe() {
      this.loading = true;
      var symbolList = []
      this.myFavoriteList.forEach((item, index) => {
        symbolList.push(item.symbol);
      })
      bus.$emit("alterProductData", {
        getData: symbolList,
        subscribeList: symbolList,
      });
    }
  }
}
</script>
<style lang="less" scoped>
</style>