import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { MainService } from '../../services/main.service';
import { Router } from '@angular/router';

@Component({
  selector: 'app-order-prompt-modal',
  templateUrl: './order-prompt-modal.component.html',
  styleUrls: ['./order-prompt-modal.component.less']
})
export class OrderPromptModalComponent implements OnInit {
  // 切换科室，切换弹窗
  hsLoading = false;
  historySpecimenList: any = [];
  historySpecimenPageIndex: number = 1;//表格当前页码
  historySpecimenPageSize: number = 5;//表格每页展示条数
  historySpecimenListLength: number = 10;//表格总数据量
  @Input() show: Boolean;
  @Input() workId: any;

  @Output() closeModelHs = new EventEmitter<any>();//1.组件暴露一个 EventEmitter 属性，当事件发生时，子组件利用该属性 emits(向上弹射)事件

  constructor(private mainService: MainService,private router: Router) { }

  ngOnInit() {
    this.getOrders();
  }
  // 关闭弹窗
  hideModal() {
    this.closeModelHs.emit(JSON.stringify({ show: false }));//emits(向上弹射)事件
  }
  // 查看工单详情
  goToOrderDetail(id){
    this.router.navigateByUrl(`specimenView2/detailSample/${id}`);
  }
  // 获取列表数据
  getOrders(idx?) {
    if (idx) {
      this.historySpecimenPageIndex = 1;
    }
    let postData = {
      idx: this.historySpecimenPageIndex - 1,
      sum: this.historySpecimenPageSize,
      workOrder: {
        hosId: JSON.parse(localStorage.getItem("user")).user.currentHospital.id,
        worker: {id: this.workId},
        gdState: {id: "72"},
        taskType: {associationType: {id: 256}},
      }
    }
    this.hsLoading = true;
    this.mainService.getFetchDataList('data','workOrder',postData).subscribe(data => {
      this.hsLoading = false;
      this.historySpecimenList = data.list || [];
      this.historySpecimenListLength = data.totalNum || 0;
    })
  }
}




