page-psysurvey.component_20241227173254.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. constructor(private router: Router) { }
  25. goTab1(){
  26. this.router.navigate(['tabs/tab1']);
  27. }
  28. goPublishSurvey(){
  29. this.router.navigate(['tabs/page-publishsurvey'])
  30. }
  31. ngOnInit() {
  32. this.getSurveys(); // 在获取到用户信息后获取问卷
  33. }
  34. async getSurveys() {
  35. let query = new CloudQuery("Survey");
  36. this.surveys = await query.find(); // 假设响应是问卷数组
  37. this.filterSurveys(); // 过滤问卷
  38. }
  39. filterSurveys() {
  40. let user = new CloudUser();
  41. console.log(user)
  42. this.filteredSurveys = this.surveys.filter(survey => {
  43. console.log(survey.get("audience"), user.get("department"))
  44. return (survey.get("audience") === user.get("department") || survey.get("audience") === 'all');
  45. });
  46. }
  47. }