import { Component, OnInit } from '@angular/core';
import { ParseService } from '../../server/parse.service';  // 确保路径正确
Parse.initialize("dev");
(Parse as any).serverURL = 'http://web2023.fmode.cn:9999/parse'
import * as Parse from 'parse';
import { NavController } from '@ionic/angular';
// constructor(private Router: Router) {}
@Component({
  selector: 'app-dynamic',
  templateUrl: './dynamic.page.html',
  styleUrls: ['./dynamic.page.scss'],
})
export class DynamicPage implements OnInit {
  dongtais: Parse.Object[] = [];
  searchKeyword: string = '';
  newBiaoti: string = '';  // 新增的属性
  newNeirong: string = ''; // 新增的属性
  newTime: string = '';    // 新增的属性
  // navCtrl: any;
  // navController: any;
  
  constructor(private navCtrl: NavController,private parseService: ParseService) { }
  // constructor(private parseService: ParseService) { }

  ngOnInit() {
    this.loadDongTai();
  }

  async loadDongTai() {
    this.dongtais = await this.parseService.getDongTai();
  }

  async searchDongTai() {
    this.dongtais = await this.parseService.searchDongTai(this.searchKeyword);
  }

  async deleteDongTai(id: string) {
    await this.parseService.deleteDongTai(id);
    this.loadDongTai();
  }

  async createDongTai(biaoti: string, neirong: string, time: string, imageFile: File) {
    await this.parseService.createDongTai(biaoti, neirong, time, imageFile);
    this.loadDongTai();
  }

  onFileSelected(event: any) {
    const file: File = event.target.files[0];
    if (file) {
      this.createDongTai(this.newBiaoti, this.newNeirong, this.newTime, file);
    }
  }
  async submitDongTai() {
    console.log(111);
    // this.navCtrl.navigateForward('../../app/tab3');
    this.navCtrl.back();

  }
}
  

