page-psysurvey.component_20241228182203.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { CommonModule } from '@angular/common';
  2. import { Component, OnInit } from '@angular/core';
  3. import { Router } from '@angular/router';
  4. import { IonHeader,IonButton, IonContent, IonIcon,
  5. IonCardHeader,IonCardTitle,IonCardContent, IonTitle,IonCard, IonToolbar } from '@ionic/angular/standalone';
  6. import { FormsModule } from '@angular/forms'; // 导入 FormsModule
  7. import { CloudQuery, CloudUser } from 'src/lib/ncloud';
  8. @Component({
  9. selector: 'app-page-psysurvey',
  10. templateUrl: './page-psysurvey.component.html',
  11. styleUrls: ['./page-psysurvey.component.scss'],
  12. standalone: true,
  13. imports: [IonHeader,IonToolbar,IonTitle,IonContent,
  14. IonCardTitle,FormsModule,
  15. IonIcon,IonButton,IonCardContent,
  16. IonCard,IonCardHeader,
  17. CommonModule
  18. ]
  19. })
  20. export class PagePsysurveyComponent implements OnInit {
  21. surveys: any[] = []; // 存储问卷通知
  22. filteredSurveys: any[] = []; // 存储过滤后的问卷
  23. userDepartment: string = '' ; // 当前用户的学院
  24. async getSurveys() {
  25. let query = new CloudQuery("Survey");
  26. this.surveys = await query.find(); // 假设响应是问卷数组
  27. this.filterSurveys(); // 过滤问卷
  28. }
  29. filterSurveys() {
  30. let user = new CloudUser();
  31. console.log(user)
  32. this.filteredSurveys = this.surveys.filter(survey => {
  33. console.log(survey.get("audience"), user.get("department"))
  34. return (survey.get("audience") === user.get("department") || survey.get("audience") === 'all');
  35. });
  36. }
  37. constructor(private router: Router) { }
  38. goTab1(){
  39. this.router.navigate(['tabs/tab1']);
  40. }
  41. goPublishSurvey(){
  42. this.router.navigate(['tabs/page-publishsurvey'])
  43. }
  44. ngOnInit() {
  45. this.getSurveys(); // 在获取到用户信息后获取问卷
  46. }
  47. }