import { Component, OnInit, ViewChild, Output, EventEmitter, Input } from "@angular/core";
import { MainService } from "../../services/main.service";
import { NzMessageService } from "ng-zorro-antd";
import { OverlayScrollbarsComponent } from "overlayscrollbars-ngx";

@Component({
  selector: "app-incident-details",
  templateUrl: "./incident-details.component.html",
  styleUrls: ["./incident-details.component.less"],
})
export class IncidentDetailsComponent implements OnInit {
  @Input() incidentId: number;
  @Output() close = new EventEmitter();
  @ViewChild("osComponentRef1", {
    read: OverlayScrollbarsComponent,
    static: false,
  })
  osComponentRef1: OverlayScrollbarsComponent;
  constructor(
    private message: NzMessageService,
    private mainService: MainService
  ) {}

  maskFlag: any = false;

  ngOnInit() {
    this.getDetail();
  }

  // 获取工单详情
  totalMaintenancePrice = null;
  totalPriceConsumable = null;
  totalPriceWorkHourManagement = null;
  summaryObj:any = {};
  getDetail() {
    this.maskFlag = this.message.loading("正在加载中..", {
      nzDuration: 0,
    }).messageId;
    this.mainService.querySummaryDocNew({incidentId: this.incidentId}).subscribe((res:any) => {
      this.message.remove(this.maskFlag);
      this.maskFlag = false;
      if(res.status == 200){
        this.summaryObj = res;
        this.totalMaintenancePrice = this.summaryObj.totalMaintenancePrice;
        this.totalPriceConsumable = this.summaryObj.consumablePrice;
        this.totalPriceWorkHourManagement = this.summaryObj.workHourPrice;
      }
    });
  }

  // 关闭弹框
  closeHandler() {
    this.close.emit();
  }

}
