import { Component } from '@angular/core';
// 引用Parse JS SDK
import Parse from "parse";
Parse.initialize("dev"); // 设置applicationId
Parse.serverURL = "http://web2023.fmode.cn:9999/parse"; // 设置serverURL
@Component({
  selector: 'app-tab3',
  templateUrl: 'tab3.page.html',
  styleUrls: ['tab3.page.scss']
})
export class Tab3Page {
  orderInfo:any;
  messages: BookMessage[] = [];
  constructor() {
  }

  ngOnInit() {
    this.loadAllOrder();
  }

  confirmDelivery(message: BookMessage): void {
    message.status = '已签收';
  }
  
  async loadAllOrder(){  
        
      let query = new Parse.Query("AWOrder");
      query.find().then((results) => {
        results.forEach((result) => {
          let messagesInfo:BookMessage = {
            title: 'Book A', 
            author: 'Author A', 
            id:"202407091001", 
            status: '派送中', 
            deliveryTime: new Date('2024-07-09T07:20:00')
          };
          messagesInfo.title = result.get("title");
          messagesInfo.author = result.get("authors");
          messagesInfo.id = result.get("orderNumber");      
          messagesInfo.status = result.get("status");
          messagesInfo.deliveryTime = result.get("deliveryTime");
          this.messages.push(messagesInfo);
      });
      });
    
  }

}

interface BookMessage {
  title: string;
  author: string;
  id:string;
  status: '派送中' | '订单处理中' | '已签收' | '已送至指定地点';
  deliveryTime: Date;
}
