import { Component, OnInit, Input } from '@angular/core';
import { MainService } from '../../../services/main.service';
import { NzMessageService } from 'ng-zorro-antd';
import { ToolService } from 'src/app/services/tool.service';

@Component({
  selector: 'app-incident-handle-handle',
  templateUrl: './incident-handle-handle.component.html',
  styleUrls: ['./incident-handle-handle.component.less']
})
export class IncidentHandleHandleComponent implements OnInit {
  @Input() incidentData: any = {};

  constructor(
    private mainService: MainService,
    private message: NzMessageService,
    private tool: ToolService,
  ) { }

  hosId:any;

  ngOnInit() {
    console.log(this.incidentData);
    this.hosId = this.tool.getCurrentHospital().id;
    this.getRepairImgs();
  }

  // 处理人
  get computedHandlerUser(){
    if(this.incidentData.state.value == 'pending' && this.incidentData.currentLog){
      return this.incidentData.currentLog.workerName;
    }
    if(this.incidentData.state.value != 'pending' && this.incidentData.handlingPersonnelUser){
      return this.incidentData.handlingPersonnelUser.name;
    }
  }

  // 获取处理图片
  handleImgs:any[] = [];//处理图片
  getRepairImgs() {
    this.mainService
      .getPreviewImage('incident', this.incidentData.id)
      .subscribe((res:any) => {
        res.data = res.data || [];
        res.data.forEach(v => {
          v.previewUrl = location.origin + "/file" + v.relativeFilePath;
          v.thumbFilePath = location.origin + "/file" + v.thumbFilePath;
        })
        this.handleImgs = res.data;
      });
  }

  // 预览图片
  imgs = [];
  isPreview = false;
  initialViewIndex:number = 0;
  previewImageHandler(data = [], index = 0) {
    this.initialViewIndex = index;
    console.log(index)
    this.isPreview = false;
    data = data || [];
    this.imgs = data.map((v) => location.origin + '/file' + v.relativeFilePath);
    setTimeout(() => {
      this.isPreview = true;
    }, 0)
  }
}




