import { Component, OnInit, ViewChild } from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router";
import {
  FormBuilder,
  Validators,
  FormGroup,
  FormControl,
} from "@angular/forms";

import { MainService } from "../../services/main.service";
import { OverlayScrollbarsComponent } from "overlayscrollbars-ngx";
import { ToolService } from "../../services/tool.service";
import { format } from "date-fns";
import { NzMessageService } from "ng-zorro-antd";
import { Subject } from "rxjs";
import { debounceTime, filter } from "rxjs/operators";
import host from "../../../assets/js/http";
import { HttpRequest, HttpResponse, HttpClient } from '@angular/common/http';

@Component({
  selector: "app-office-management",
  templateUrl: "./office-management.component.html",
  styleUrls: ["./office-management.component.less"],
})
export class OfficeManagementComponent implements OnInit {
  @ViewChild("osComponentRef1", {
    read: OverlayScrollbarsComponent,
    static: false,
  })
  osComponentRef1: OverlayScrollbarsComponent;
  constructor(
    private message: NzMessageService,
    private fb: FormBuilder,
    private route: ActivatedRoute,
    private router: Router,
    private mainService: MainService,
    private tool: ToolService,
    private http: HttpClient,
  ) {}

  ngOnInit() {
    this.searchParentDeptSubject.pipe(debounceTime(500)).subscribe((v: any) => {
      this.getAllParentdepart(v,'qd').subscribe((result) => {
        this.isLoading = false;
        if (result.status == 200) {
          this.allParentdepart = result.list;
        }
      });
    });
		this.searchBusinessDeptSubject.pipe(debounceTime(500)).subscribe((v: any) => {
      this.getAllParentdepart(v,'yw').subscribe((result) => {
        this.isLoading = false;
        if (result.status == 200) {
          this.businessDept = result.list;
        }
      });
    });
    this.coopBtns = this.tool.initCoopBtns(this.route);
    this.initForm();
    this.getAllHospital();
    this.getType();
    this.getDeptHandoverType();
		this.getPrioritys();
  }
  listOfData: any[] = []; //表格数据
  promptContent: string; //操作提示框提示信息
  ifSuccess: boolean; //操作成功/失败
  promptInfo: string; //操作结果提示信息
  promptModalShow: boolean; //操作提示框是否展示
  modal: boolean = false; //新增/编辑模态框
  add: boolean; //true:新增；false:编辑
  validateForm: FormGroup; //新增/编辑表单
  coopId: number; //表格中执行操作的id
  hospital: number; //所属院区
  name; //名称
  num; //编码
  deptalias; //别名
  type; //类型
  deptHandoverType; //类型
  pageIndex: number = 1; //页码
  listLength: number = 10; //总条数
  pageSize: number = 10; //每页条数

  btnLoading: boolean = false; //确认按钮loading状态
  printLoading: boolean = false; //批量打印按钮loading状态
  deptPhones: any = []; //新添加的科室电话列表
  isAddDeptsPhone = true; //添加新的科室电话是否禁用
  deptsPhoneId = 1; //科室电话自增id
  allParentdepart: any = []; //所有的父级科室列表
  hospitals1: any = []; //院区列表(搜索)
  searchParentDeptSubject = new Subject();
	searchBusinessDeptSubject = new Subject();
  // 初始化增删改按钮
  coopBtns: any = {};
  // 模板导出
  excelExport(){
    this.maskFlag = this.message.loading("下载模板中..", {
      nzDuration: 0,
    }).messageId;
    this.mainService.exportExcel("department", {}).subscribe(
      (data) => {
        this.message.remove(this.maskFlag);
        this.maskFlag = false;
        this.message.success('下载模板成功');
        var file = new Blob([data], {
          type: "application/vnd.ms-excel",
        });
        //trick to download store a file having its URL
        var fileURL = URL.createObjectURL(file);
        var a = document.createElement("a");
        a.href = fileURL;
        a.target = "_blank";
        a.download = "科室导入模板.xls";
        document.body.appendChild(a);
        a.click();
      },
      (err) => {
        this.message.remove(this.maskFlag);
        this.maskFlag = false;
        this.message.error('下载模板失败');
      }
    );
  }

  // 导入---start
  // model-取消
  isShow = false;
  hideExcelImport() {
    this.isShow = false;
  }
  // 触发
  excelImport() {
    this.isShow = true;
  }
  submitExcelImport({fileList}){
    this.isShow = false;
    const formData = new FormData();
    fileList.forEach((file: any) => {
      formData.append('file', file);
    });
    this.maskFlag = this.message.loading("正在导入中..", {
      nzDuration: 0,
    }).messageId;
    const req = new HttpRequest('Post', this.mainService.returnImportExcelUrl('department'), formData, {
      reportProgress: true
    });
    this.http
      .request(req)
      .pipe(filter(e => e instanceof HttpResponse))
      .subscribe(
        (res:any) => {
          if(res.body.status == 200){
            this.message.remove(this.maskFlag);
            this.maskFlag = false;
            this.message.success('导入成功');
            this.getList();
          }else{
            this.message.remove(this.maskFlag);
            this.maskFlag = false;
            this.showPromptModal("导入", false, res.body.msg);
          }
        },
        () => {
          this.message.remove(this.maskFlag);
          this.maskFlag = false;
          this.message.error('导入失败');
        },
      );
  }
  // 导入---end
  //搜索父级科室
  changeInp(e) {
    this.isLoading = true;
    this.searchParentDeptSubject.next(e);
  }
	
	changeInp2(e) {
    this.isLoading = true;
    this.searchBusinessDeptSubject.next(e);
  }
  // 打开父级科室下拉框baba
  isLoading = false;
  openDeptSelect(flag) {
    if (flag) {
      this.isLoading = true;
      this.getAllParentdepart('','qd').subscribe((result) => {
        this.isLoading = false;
        if (result.status == 200) {
          this.allParentdepart = result.list;
        }
      });
    }
  }
	
	openDeptSelect2(flag) {
    if (flag) {
      this.isLoading = true;
      this.getAllParentdepart('','yw').subscribe((result) => {
        this.isLoading = false;
        if (result.status == 200) {
          this.businessDept = result.list;
        }
      });
    }
  }
  // 启用/停用弹框
  coopData:any = {};
  addDateModal(data) {
    this.coopData = data;
    this.showDelModal1();
  }
  delModal1: boolean = false; //删除模态框

  showDelModal1() {
    this.delModal1 = true;
  }
  hideDelModal1() {
    this.delModal1 = false;
  }
  // 确认
  confirmDel1() {
    this.btnLoading = true;
    this.mainService
      .coopData("updData", "department", {department:{...this.coopData, ...{flag: this.coopData.flag == 1 ? 0 : 1}}})
      .subscribe((data) => {
        this.btnLoading = false;
        this.delModal1 = false;
        if (data.status == 200) {
          this.showPromptModal(this.coopData.flag == 1 ? "停用" : "启用", true, "");
        } else {
          this.showPromptModal(this.coopData.flag == 1 ? "停用" : "启用", false, data.msg);
        }
      });
  }
  //获取所有的父级科室列表
  getAllParentdepart(keyWord = "", type) {
    let postData: any = {
      idx: 0,
      sum: 10,
      department: {
        hospital: { id: this.add ? this.tool.getCurrentHospital().id : this.hospital },
        keyWord: keyWord,
      },
    };
		if(type=='qd'){
			if (this.coopItem) {
			  // 过滤这个科室及其子科室
			  postData.department.filterByDeptId = this.coopItem.id;
			}
		}else{
			if (this.coopItem) {
			  // 过滤这个科室及其子科室
			  postData.department.filterBusiByDeptId = this.coopItem.id;
			}
		}

    return this.mainService.getFetchDataList("data", "department", postData);
  }
  // 新添加科室号码
  addDeptPhone(e: MouseEvent) {
    e.preventDefault();
    this.deptPhones.push({ id: ++this.deptsPhoneId, phone: "" });
    this.deptsPhoneChange();
  }
  // 删除新添加科室号码
  removeDeptPhone(index: number, e: MouseEvent) {
    e.preventDefault();
    this.deptPhones.splice(index, 1);
    this.deptsPhoneChange();
  }
  //监听科室电话输入事件
  deptsPhoneChange(e?, phone?) {
    if (e !== undefined && phone !== undefined) {
      phone.phone = e;
    }
    // -------------判断添加按钮是否禁用 start
    this.isAddDeptsPhone = !this.validateForm.value.officeNum;
    if (!this.isAddDeptsPhone) {
      //如果没禁用
      this.isAddDeptsPhone = this.deptPhones.some((item) => item.phone === "");
    }
    // -------------判断添加按钮是否禁用 end
  }

  // 搜索
  search() {
    this.pageIndex = 1;
    this.getList();
  }
  // 重置
  reset() {
    this.pageIndex = 1;
    this.hospital = this.tool.getCurrentHospital().id;
    this.type = null;
    this.deptHandoverType = null;
    this.name = "";
    this.num = "";
    this.deptalias = "";
    this.getList();
  }
  // 表格数据
  loading1 = false;
  getList() {
    var that = this;
    let data = {
      idx: that.pageIndex - 1,
      sum: that.pageSize,
      department: {
        hospital: { id: that.hospital || "" },
        dept: that.name || "",
        pcode: that.num || "",
        type: { id: that.type || "" },
        deptHandoverType: { id: that.deptHandoverType || "" },
        deptalias: that.deptalias || "",
      },
    };

    that.mapOfCheckedId = {};
    that.checkedDepIds = [];
    that.isAllDisplayDataChecked = false;
    this.loading1 = true;
    that.mainService
      .getFetchDataList("data", "department", data)
      .subscribe((data) => {
        this.loading1 = false;
        that.listOfData = data.list;
        that.listLength = data.totalNum;
      });
  }

  // 获取所有院区
  getAllHospital() {
    this.hospitals1 = this.tool.getHospitalList();
    this.hospital = this.tool.getCurrentHospital().id;
    this.getList();
  }

  // 切换院区选项
  buildings: any = []; //楼栋
  maskFlag: any = false;
  changeHosp(obj?) {
    let hospitalId;
    if (obj) {
      hospitalId = obj.hospital.id;
    }
    let hid;
    if (hospitalId || hospitalId == 0) {
      hid = hospitalId - 0;
    } else {
      hid = this.hospital - 0;
    }
    let data = {
      cascadeHosId: this.add ? this.tool.getCurrentHospital().id : hid,
    };
    this.maskFlag = this.message.loading("正在加载中..", {
      nzDuration: 0,
    }).messageId;
    this.mainService
      .coopData("getBuildingOrFloor", "building", data)
      .subscribe((data) => {
        this.buildings = data.data;
        this.floors = [];
        // ---------
        if (obj) {
          //编辑
          let arr = this.buildings.map((item) => item.id);
          if (obj.building.id && arr.includes(obj.building.id)) {
            //有楼栋
            this.changeBuilding(obj.building.id, obj);
            this.validateForm.controls.building.setValue(obj.building.id + "");
          } else {
            //无楼栋
            this.floors = [];
            this.message.remove(this.maskFlag);
            this.maskFlag = false;
            this.modal = true;
            this.validateForm.controls.building.setValue(null);
            this.validateForm.controls.officeAddress.setValue(null);
          }
        } else {
          //新增
          this.message.remove(this.maskFlag);
          this.maskFlag = false;
          this.modal = true;
        }
        // ---------
      });
  }

  // 切换楼栋信息
  floors: Array<any> = []; //楼层
  floorLoading: boolean = false;
  changeBuilding(buildingId?, obj?) {
    var that = this;
    that.floors = [];
    var bid;
    if (buildingId || buildingId == 0) {
      bid = buildingId - 0;
    } else if (!that.add && that.validateForm.value.building) {
      bid = that.validateForm.value.building - 0;
    } else {
      return;
    }
    let data = {
      buildingId: bid,
    };
    this.floorLoading = true;
    that.mainService
      .coopData("getBuildingOrFloor", "floor", data)
      .subscribe((data) => {
        this.floorLoading = false;
        this.message.remove(this.maskFlag);
        this.maskFlag = false;
        this.modal = true;
        that.floors = data.data;
        if (obj) {
          let floorId = obj.floor.id;
          let arr = that.floors.map((item) => item["id"]);
          if (floorId && arr.includes(floorId)) {
            this.validateForm.controls.floor.setValue(floorId + "");
          } else {
            this.validateForm.controls.floor.setValue(null);
            this.validateForm.controls.officeAddress.setValue(null);
          }
        }
      });
  }

  // 获取科室类型
  types: Array<any> = [];
  getType() {
    var that = this;
    that.mainService.getDictionary("list", "dept_type").subscribe((data) => {
      console.log(data);
      that.types = data;
    });
  }
	
	// 获取优先级
	priority_c_List: any = [];
	getPrioritys() {
	  let postData = {
	    priority: {},
	    idx: 0,
	    sum: 9999,
	  };
	  this.mainService
	    .getFetchDataList("simple/data", "priority", postData)
	    .subscribe((data) => {
	      this.isLoading = false;
	      this.priority_c_List = data.list || [];
	    });
	}
	
  // 获取科室汇总交接类型
  deptHandoverTypes: Array<any> = [];
  getDeptHandoverType() {
    var that = this;
    that.mainService.getDictionary("list", "dept_handover_type").subscribe((data) => {
      console.log(data);
      that.deptHandoverTypes = data;
    });
  }

  // 新增弹框
  showModal() {
    this.initForm();
    this.changeHosp();
    this.add = true;
    this.isAddDeptsPhone = true;
    this.deptPhones = [];
  }
  hideModal() {
    this.coopItem = null;
    this.modal = false;
    this.initForm();
  }
  // 初始化新增form表单
  initForm() {
    this.endTime1Hourdis = () => [];
    this.endTime1Mindis = () => [];
    this.endTime2Hourdis = () => [];
    this.endTime2Mindis = () => [];
    this.startTime1Hourdis = () => [];
    this.startTime1Mindis = () => [];
    this.startTime2Hourdis = () => [];
    this.startTime2Mindis = () => [];
    this.validateForm = this.fb.group({
      orders: [null],
      parentOfficeName: [null],
			busiParent: [null],
      officeName: [null, [Validators.required]],
      deptalias: [null],
      officeNo: [null, [Validators.required]],
      officeNum: [null, [Validators.required]],
      building: [null, [Validators.required]],
      floor: [null, [Validators.required]],
      officeAddress: [null, [Validators.required]],
      officeType: [null, [Validators.required]],
			priority: [null], //优先级
      deptHandoverType: [null],
      startTime1: [null],
      endTime1: [null],
      dynamicCode1: [null],
      startTime2: [null],
      endTime2: [null],
      dynamicCode2: [null],
    });
  }
  // 科室位置必填
  buildValidator = (control: FormControl): { [s: string]: boolean } => {
    if (
      this.validateForm &&
      this.validateForm.value &&
      (!this.validateForm.value.building ||
        !this.validateForm.value.floor ||
        !this.validateForm.value.officeAddress)
    ) {
      return { required: true };
    }
  };
  /**
   * 生成一个从 start 到 end 的连续数组
   * @param start
   * @param end
   */
  generateArray(start, end) {
    return Array.from(new Array(end).keys()).slice(start);
  }

  //服务时间选择
  // 禁用的小时
  startTime1Hourdis() {
    return [];
  }
  endTime1Hourdis() {
    return [];
  }
  startTime2Hourdis() {
    return [];
  }
  endTime2Hourdis() {
    return [];
  }
  // 禁用的分钟
  startTime1Mindis() {
    return [];
  }
  endTime1Mindis() {
    return [];
  }
  startTime2Mindis() {
    return [];
  }
  endTime2Mindis() {
    return [];
  }
  timeChange(e: boolean, type: string, num: number) {
    if (!e && this.validateForm.value[type + num]) {
      let hour = new Date(this.validateForm.value[type + num]).getHours();
      let minute = new Date(this.validateForm.value[type + num]).getMinutes();
      if (type == "startTime" && num === 1) {
        this.endTime1Hourdis = () => this.generateArray(0, hour);
        this.endTime1Mindis = () => this.generateArray(0, minute + 1);
      } else if (type == "startTime" && num === 2) {
        this.endTime2Hourdis = () => this.generateArray(0, hour);
        this.endTime2Mindis = () => this.generateArray(0, minute + 1);
      } else if (type == "endTime" && num === 1) {
        this.startTime1Hourdis = () => this.generateArray(hour + 1, 24);
        this.startTime1Mindis = () => this.generateArray(minute, 60);
      } else if (type == "endTime" && num === 2) {
        this.startTime2Hourdis = () => this.generateArray(hour + 1, 24);
        this.startTime2Mindis = () => this.generateArray(minute, 60);
      }
    }
  }
  // 表单提交
  submitForm(): void {
    var that = this;
    for (const i in that.validateForm.controls) {
      that.validateForm.controls[i].markAsDirty();
      that.validateForm.controls[i].updateValueAndValidity();
    }
    console.log(that.validateForm);
    if (that.validateForm.invalid) return;
    let deptsPhone = this.deptPhones.map((item) => item.phone).join();
    let data: any = {
      department: {
        orders: that.validateForm.value.orders || undefined,
        dept: that.validateForm.value.officeName,
        deptalias: that.validateForm.value.deptalias,
        hospital: { id: that.add ? that.tool.getCurrentHospital().id : that.hospital },
        pcode: that.validateForm.value.officeNo,
				priority: this.validateForm.value.priority,
        manyPhone: deptsPhone
          ? that.validateForm.value.officeNum + "," + deptsPhone
          : that.validateForm.value.officeNum,
        building: { id: that.validateForm.value.building - 0 },
        floor: { id: that.validateForm.value.floor - 0 },
        address: that.validateForm.value.officeAddress,
        type: { id: that.validateForm.value.officeType },
        deptHandoverType: { id: that.validateForm.value.deptHandoverType },
      },
    };
    if (this.validateForm.value.parentOfficeName) {
      data.department.parent = { id: this.validateForm.value.parentOfficeName };
    }
		if (this.validateForm.value.busiParent) {
		  data.department.busiParent = this.validateForm.value.busiParent;
		}
    if (
      this.validateForm.value.startTime1 ||
      this.validateForm.value.endTime1
    ) {
      if (
        this.validateForm.value.startTime1 &&
        this.validateForm.value.endTime1
      ) {
        data.department["startTime1"] = format(
          this.validateForm.value.startTime1,
          "yyyy-MM-dd HH:mm:ss"
        );
        data.department["endTime1"] = format(
          this.validateForm.value.endTime1,
          "yyyy-MM-dd HH:mm:ss"
        );
        data.department["dynamicCode1"] = this.validateForm.value.dynamicCode1 ? 1 : 0;
      } else {
        return;
      }
    }
    if (
      this.validateForm.value.startTime2 ||
      this.validateForm.value.endTime2
    ) {
      if (
        this.validateForm.value.startTime2 &&
        this.validateForm.value.endTime2
      ) {
        data.department["startTime2"] = format(
          this.validateForm.value.startTime2,
          "yyyy-MM-dd HH:mm:ss"
        );
        data.department["endTime2"] = format(
          this.validateForm.value.endTime2,
          "yyyy-MM-dd HH:mm:ss"
        );
        data.department["dynamicCode2"] = this.validateForm.value.dynamicCode2 ? 1 : 0;
      } else {
        return;
      }
    }
    if (!that.add) {
      data.department["id"] = that.coopId;
    }
    that.btnLoading = true;
    that.mainService
      .coopData(that.add ? "addData" : "updData", "department", data)
      .subscribe((data) => {
        that.btnLoading = false;
        that.hideModal();
        that.initForm();
        if (data.status == 200) {
          that.showPromptModal(that.add ? "新增" : "编辑", true, "");
        } else {
          that.showPromptModal(that.add ? "新增" : "编辑", false, data.msg);
        }
      });
  }

  // 编辑
  coopItem: any = null;
	businessDept:any;
  edit(e, data) {
    e.stopPropagation();
    this.add = false;
    this.coopId = data.id;
    this.coopItem = data;
    this.isAddDeptsPhone = false;
    this.deptPhones = [];
    let phones = data.manyPhone ? data.manyPhone.split(",") : [];
    if (phones.length === 0) {
      this.validateForm.controls.officeNum.setValue("");
      this.deptPhones = [];
    } else if (phones.length === 1) {
      this.validateForm.controls.officeNum.setValue(phones[0]);
      this.deptPhones = [];
    } else {
      this.validateForm.controls.officeNum.setValue(phones[0]);
      this.deptPhones = phones.slice(1).map((item) => {
        return {
          id: ++this.deptsPhoneId,
          phone: item,
        };
      });
    }
    if (data.startTime1 && data.endTime1) {
      this.validateForm.controls.startTime1.setValue(new Date(data.startTime1));
      this.validateForm.controls.endTime1.setValue(new Date(data.endTime1));
      this.validateForm.controls.dynamicCode1.setValue(data.dynamicCode1 == 1);
    }
    if (data.startTime2 && data.endTime2) {
      this.validateForm.controls.startTime2.setValue(new Date(data.startTime2));
      this.validateForm.controls.endTime2.setValue(new Date(data.endTime2));
      this.validateForm.controls.dynamicCode2.setValue(data.dynamicCode2 == 1);
    }
    this.validateForm.controls.officeAddress.setValue(data.address);
		if(data.busiParentDTO){
			this.getAllParentdepart(data.busiParentDTO.dept,'yw').subscribe((res) => {
			  if (res.status == 200) {
			    this.businessDept = res.list;
					this.validateForm.controls.busiParent.setValue(data.busiParentDTO.id);
				}
			});
		}
    if (data.parent) {
      this.getAllParentdepart(data.parent.dept,'qd').subscribe((res) => {
        if (res.status == 200) {
          this.allParentdepart = res.list;
          this.validateForm.controls.parentOfficeName.setValue(data.parent.id);
				}
      });
    }
    this.validateForm.controls.orders.setValue(data.orders);
    this.validateForm.controls.officeName.setValue(data.dept);
    this.validateForm.controls.deptalias.setValue(data.deptalias);
    this.validateForm.controls.officeNo.setValue(data.pcode);
    this.validateForm.controls.officeType.setValue(data.type.id + "");
    this.validateForm.controls.deptHandoverType.setValue(data.deptHandoverType ? data.deptHandoverType.id + "" : null);
    this.changeHosp(data);
		if(data.priorityDTO){
			this.validateForm.controls.priority.setValue(data.priorityDTO.id);
		}
    this.validateForm.controls.officeAddress.setValue(data.address);
  }

  // 展示信息提示框（con:提示信息，success:操作是否成功，promptInfo:操作结果提示信息）
  showPromptModal(con, success, promptInfo?) {
    this.promptModalShow = false;
    this.promptContent = con;
    this.ifSuccess = success;
    this.promptInfo = promptInfo;
    setTimeout(() => {
      this.promptModalShow = true;
    }, 100);
    this.getList();
  }

  delModal: boolean = false; //删除模态框
  coopIds: any;
  coopFlag: any = false;
  /**
   *
   * @param e 事件对象
   * @param flag true是批量删除，false是单个删除
   * @param id
   */
  showDelModal(e, flag, id) {
    e.stopPropagation();
    this.delModal = true;
    this.coopFlag = flag;
    if (flag) {
      this.coopIds = id;
    } else {
      this.coopId = id;
    }
  }
  hideDelModal() {
    this.delModal = false;
  }
  // 确认删除
  confirmDel() {
    var that = this;
    that.btnLoading = true;
    that.mainService
      .coopData(
        "rmvData",
        "department",
        this.coopFlag ? this.coopIds : [that.coopId]
      )
      .subscribe((data) => {
        that.btnLoading = false;
        that.delModal = false;
        if (data.data && data.data[0]) {
          if (!data.data[0].msg) {
            if (
              that.listOfData.length == 1 &&
              that.pageIndex == Math.ceil(that.listLength / that.pageSize)
            ) {
              that.listLength--;
              that.pageIndex = Math.ceil(that.listLength / that.pageSize) || 1;
            }
            that.showPromptModal("删除", true, "");
          } else {
            that.showPromptModal("删除", false, data.data[0].msg);
          }
        } else {
          that.showPromptModal("删除", false, "");
        }
      });
  }

  // 查看
  detail(e, id) {
    e.stopPropagation();
    this.router.navigateByUrl("/main/officeManagement/officeDetail/" + id);
  }

  // 选中表格中科室
  mapOfCheckedId: { [key: string]: boolean } = {};
  checkedDepIds = []; //已选中科室id
  refreshStatus(): void {
    this.isAllDisplayDataChecked = this.listOfData.every(
      (item) => this.mapOfCheckedId[item.id]
    );
    let arr = [];
    for (var k in this.mapOfCheckedId) {
      if (this.mapOfCheckedId[k]) {
        arr.push(Number(k));
      }
    }
    this.checkedDepIds = arr;
    console.log(this.checkedDepIds);
  }
  //表格整行选中
  selectedListData(id) {
    this.mapOfCheckedId[id] = !this.mapOfCheckedId[id];
    this.refreshStatus();
  }
  // 全选
  isAllDisplayDataChecked = false; //当前页是否全选
  checkAll(value: boolean): void {
    this.listOfData.forEach((item) => (this.mapOfCheckedId[item.id] = value));
    this.refreshStatus();
  }

  // 打印
  codes = []; //二维码
  print(e, batch, id?) {
    e.stopPropagation();
    let that = this;
    that.printLoading = true;
    that.mainService
      .postCustomCode("dept", "deptCodes", batch ? that.checkedDepIds : [id])
      .subscribe((data) => {
        that.codes = data.data;
        that.printLoading = false;
        setTimeout(() => {
          const printContent = document.getElementById("report");
          const WindowPrt = window.open("", "", "width=700,height=900");
          WindowPrt.document.write(printContent.innerHTML);
          WindowPrt.document.close();
          WindowPrt.focus();
          WindowPrt.print();
          WindowPrt.close();
        }, 100);
      });
  }
}
