import { Component } from '@angular/core';

// 引用服务
import { Router } from '@angular/router';

// 引入Parse第三方库
import * as Parse from "parse"
(Parse as any).serverURL = "http://metapunk.cn:9999/parse"
Parse.initialize("dev")

@Component({
  selector: 'app-community',
  templateUrl: './community.component.html',
  styleUrls: ['./community.component.scss']
})
export class CommunityComponent {

  scienceList: Array<Parse.Object> = []
  recommendList: Array<Parse.Object> = []
  attentionList: Array<Parse.Object> = []


  // 依赖注入
  constructor(private router: Router) {
    this.initPage();
  }
  // 首次进入页面，默认加载首批数据
  async initPage() {
    this.scienceList = await this.getScienceData()
    this.recommendList = await this.gteRecommendData()
    this.attentionList = await this.gteAttentionData()
  }

  // 数据加载相关函数
  async getScienceData() {
    let query = new Parse.Query("PetScience");
    let list = await query.find();
    return list
  }
  async gteRecommendData() {
    let query = new Parse.Query("PetRecommend");
    let list = await query.find();
    return list
  }
  async gteAttentionData() {
    let query = new Parse.Query("PetAttention");
    let list = await query.find();
    return list
  }

  cate: string = "推荐"


  // 跳转函数
  goScienceDetail(science: Parse.Object) {
    this.router.navigate(["/lesson/community/scienceDetail"], {
      queryParams: science
    })
  }

  goRecommendDetail(recommend: Parse.Object) {
    this.router.navigate(["/lesson/community/recommendDetail"], {
      queryParams: recommend
    })
  }

  goAttentionDetail(attention: Parse.Object) {
    this.router.navigate(["/lesson/community/attentionDetail"], {
      queryParams: attention
    })
  }


}
