tab13.page.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { Component, OnInit } from '@angular/core';
  2. import { DataService } from '../data.service';
  3. import { Title } from '@angular/platform-browser';
  4. @Component({
  5. selector: 'app-tab13',
  6. templateUrl: './tab13.page.html',
  7. styleUrls: ['./tab13.page.scss'],
  8. })
  9. export class Tab13Page implements OnInit {
  10. replyContent: string = " ";
  11. lostFoundItems: any[] = [];
  12. constructor(private dataService: DataService,private titleService: Title) {}
  13. ngOnInit() {
  14. this.lostFoundItems = this.dataService.getLostFoundItems();
  15. // 假设helpItems是从DataService中获取的求助信息数组,确保数据已经被加载
  16. if (this.lostFoundItems.length > 0) {
  17. this.titleService.setTitle(this.lostFoundItems[0].title);
  18. }
  19. }
  20. submitReply(item: any) {
  21. if (this.replyContent.trim() !== '') {
  22. const reply = { content: this.replyContent, sender:"小序", floor: "" }; // 可以根据实际情况设置回复人,初始化楼层号
  23. this.dataService.addReplyToLostFoundItems(item.id, reply);
  24. this.replyContent = ''; // 清空回复框
  25. }
  26. }
  27. onFileChange(event: any, item: any) {
  28. const file = event.target.files[0];
  29. const reader = new FileReader();
  30. reader.onload = (e: any) => {
  31. item.image = e.target.result;
  32. };
  33. reader.readAsDataURL(file);
  34. }
  35. }