import { Component, OnInit } from "@angular/core";
import { MainService } from "src/app/services/main.service";
import { ToolService } from "src/app/services/tool.service";
import { ActivatedRoute } from '@angular/router';

@Component({
  selector: "app-inventory-information",
  templateUrl: "./inventory-information.component.html",
  styleUrls: ["./inventory-information.component.less"],
})
export class InventoryInformationComponent implements OnInit {
  constructor(
    private mainService: MainService,
    private tool: ToolService,
    private route: ActivatedRoute,
  ) {}

  hosId;
  listOfData: any[] = []; //表格数据
  pageIndex: number = 1; //表格当前页码
  pageSize: number = 10; //表格每页展示条数
  listLength: number = 10; //表格总数据量

  otherData:any =  {
    intoWeight: 0,
    outWeight: 0,
  }

  // 初始化增删改按钮
  coopBtns: any = {};
  ngOnInit() {
    this.coopBtns = this.tool.initCoopBtns(this.route);
    this.getHospital();
  }

  // 获取所有院区
  getHospital() {
    this.hosId = this.tool.getCurrentHospital().id;
    this.getList(1);
  }

  // 查看标本历史记录
  historyPromptModalShow = false; //标本历史记录弹窗开关
  id = ""; //查看历史记录携带
  viewHistory(data) {
    this.id = data.clinicalWasteType.id;
    this.historyPromptModalShow = true;
  }
  // 关闭标本历史记录弹窗
  closeModelHistory(e) {
    this.historyPromptModalShow = JSON.parse(e).show;
  }

  // 表格数据
  loading1 = false;
  getList(type) {
    if (type == 1) {
      this.pageIndex = 1;
    }
    let postData: any = {
      idx: this.pageIndex - 1,
      sum: this.pageSize,
      clinicalWasteInventory: {
        hosId: this.hosId,
      },
    };
    this.loading1 = true;
    this.mainService
      .getFetchDataList("simple/data", "clinicalWasteInventory", postData)
      .subscribe((data) => {
        this.loading1 = false;
        if (data["status"] == 200) {
          this.listOfData = data["list"];
          this.listLength = data["totalNum"];
          this.otherData = data.otherData || {};
        }
      });
  }
}

