page-psysurvey.component_20241224103358.ts 2.1 KB

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