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

@Component({
  selector: "app-inspect-active-detail",
  templateUrl: "./inspect-active-detail.component.html",
  styleUrls: ["./inspect-active-detail.component.less"],
})
export class InspectActiveDetailComponent implements OnInit {
  loading1 = false; //获取选中配送人员列表loading
  hosId; //当前院区id
  currentDeptId; //当前配送人员id
  startTime; //当前开始时间
  endTime; //当前结束时间
  listOfData = []; //获取选中配送人员列表
  pageIndex: number = 1; //页码
  listLength: number = 0; //总数据条目数
  pageSize: number = 10; //每页条数
  constructor(
    private mainService: MainService,
    private tool: ToolService,
    private message: NzMessageService,
    private route: ActivatedRoute,
    private router: Router
  ) {}

  ngOnInit() {
    this.hosId = this.tool.getCurrentHospital().id;
    this.currentDeptId = this.route.snapshot.params.deptId;
    this.startTime = this.route.snapshot.params.startTime;
    this.endTime = this.route.snapshot.params.endTime;
    this.getListByDept(this.hosId, this.currentDeptId);
  }
  //获取选中科室的列表
  getListByDept(hosId: number, currentDeptId: number) {
    this.loading1 = true;
    let postData = {
      type: "date",
      idx: this.pageIndex - 1,
      sum: this.pageSize,
      startTime: this.startTime,
      endTime: this.endTime,
      hosId,
      deptId: currentDeptId,
    };
    this.mainService.postReportCount("deptInspect", postData).subscribe(
      (result) => {
        this.loading1 = false;
        if (result.status == 200) {
          this.listOfData = result.list;
          this.listLength = result.totalNum;
        } else {
          this.message.error("获取数据失败");
        }
      },
      (err) => {
        this.loading1 = false;
        this.message.error("获取数据失败");
      }
    );
  }
  //查看工单列表
  integralDetail(obj) {
    this.router.navigateByUrl(
      `/main/inspectActive/inspectActiveDetail/${this.currentDeptId}/${this.startTime}/${this.endTime}/inspectActiveOrderList/${this.currentDeptId}/${this.startTime}/${this.endTime}/${obj.datetime}/${obj.userId}`
    );
  }
  //关闭
  close() {
    this.router.navigateByUrl(`/main/inspectActive`);
  }
}
