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, startOfDay, endOfDay, subDays} 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-dispensing-batch", templateUrl: "./dispensing-batch.component.html", styleUrls: ["./dispensing-batch.component.less"], }) export class DispensingBatchComponent 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((e) => { this.isDeptLoading = true; this.getDeparts(e); }); this.hosId = this.tool.getCurrentHospital().id; this.coopBtns = this.tool.initCoopBtns(this.route); this.initForm(); this.getAllHospital(); this.getType(); this.getDeptHandoverType(); } listOfData: any[] = []; //表格数据 promptContent: string; //操作提示框提示信息 ifSuccess: boolean; //操作成功/失败 promptInfo: string; //操作结果提示信息 promptModalShow: boolean; //操作提示框是否展示 modal: boolean = false; //新增/编辑模态框 add: boolean; //true:新增;false:编辑 validateForm: FormGroup; //新增/编辑表单 coopId: number; //表格中执行操作的id department: number; //所属科室 hosId: number; dateRange;//时间 batchNumber; //批次号 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 = []; //科室列表(搜索) rowData: object = {}; //打印选择列表 editModal:boolean = false; //编辑时弹框 searchParentDeptSubject = new Subject(); // 初始化增删改按钮 coopBtns: any = {}; saveLoading:boolean = false; // 模板导出 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', host.host + '/user/data/importExcel/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 //搜索父级科室 isDeptLoading = false; changeInp(e) { this.searchParentDeptSubject.next(e); } // 打开父级科室下拉框baba isLoading = false; openDeptSelect(flag) { if (flag) { this.isLoading = true; this.getAllParentdepart().subscribe((result) => { this.isLoading = false; if (result.status == 200) { this.allParentdepart = result.list; } }); } } // 配送建单 coopData:any = {}; addDateModal(data) { this.coopData = data; this.showDelModal1(); } showDelModal1() { this.editModal = true; } hideDelModal1() { this.editModal = false; } // 编辑保存 confirmDel1() { var that = this; for (const i in that.validateForm.controls) { that.validateForm.controls[i].markAsDirty(); that.validateForm.controls[i].updateValueAndValidity(); } if (that.validateForm.invalid) return; let data: any = { startTime:this.formStartDate?this.formStartDate:this.loadStartTime,//发起时间开始 endTime:this.formEndDate?this.formEndDate:this.loadEndTime,//发起时间结束 hosId:this.hosId, pharmacy:this.validateForm.value.department, id:that.coopId }; that.saveLoading = true; that.mainService .simplePost("addData", "drugsBatch", data) .subscribe((data) => { that.saveLoading = false; that.hideModal(); that.initForm(); if (data.status == 200) { this.editModal = false; that.showPromptModal("编辑", true, ""); } else { that.showPromptModal("编辑", false, data.msg); } }); } //获取所有的父级科室列表 getAllParentdepart(keyWord = "") { let postData: any = { idx: 0, sum: 10, department: { // hospital: { id: this.add ? this.tool.getCurrentHospital().id : this.hospital }, keyWord: keyWord, }, }; if (this.coopItem) { // 过滤这个科室及其子科室 postData.department.filterByDeptId = 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.batchNumber = null; this.startDate = null; this.endDate = null; this.dateRange = []; this.getList(); } // 表格数据 loading1 = false; getList() { var that = this; let data = { idx: that.pageIndex - 1, sum: that.pageSize, drugsBatch: { batchNo:that.batchNumber, startTime: this.startDate, endTime: this.endDate, hosId: this.hosId }, }; if(that.batchNumber){ data.drugsBatch.batchNo = that.batchNumber }else{ delete data.drugsBatch.batchNo } this.loading1 = true; that.mainService .getFetchDataList("data", "drugsBatch", data) .subscribe((data) => { this.loading1 = false; that.listOfData = data.list; that.listLength = data.totalNum; }); } // 日期选择 startDate: string; //发起时间开始 endDate: string; //发起时间结束 changeDate(result?): void { if (!result) { this.startDate = this.endDate = ""; return; } this.startDate = format(startOfDay(result[0]), 'yyyy-MM-dd HH:mm:ss'); this.endDate = format(endOfDay(result[1]), 'yyyy-MM-dd HH:mm:ss'); } // 新增、编辑日期选择 formStartDate: string; //发起时间开始 formEndDate: string; //发起时间结束 formChangeDate(result?): void { if (!result) { this.formStartDate = this.formEndDate = ""; return; } this.formStartDate = format(result[0], 'yyyy-MM-dd HH:mm:ss'); this.formEndDate = format(result[1], 'yyyy-MM-dd HH:mm:ss'); } // 获取所有科室 getDeparts(dept) { var that = this; let data = { department: { dept, hospital: { id: this.hosId }, type:{ id:'' } }, idx: 0, sum: 20, }; that.mainService.getDictionary("list", "dept_type").subscribe((res) => { let typeData = res.find(i=>i.value=='pharmacyRoom'); if(typeData){ data.department.type.id = typeData.id } that.mainService .getFetchDataList("data", "department", data) .subscribe((data) => { setTimeout(_=>{ this.hospitals1 = data.list that.isDeptLoading = false; },500) }); }); } // 获取所有院区 getAllHospital() { this.getDeparts('') 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 = { hosId: 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 = []; //楼层 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 = []; getType() { var that = this; that.mainService.getDictionary("list", "dept_type").subscribe((data) => { console.log(data); that.types = data; }); } // 获取科室汇总交接类型 deptHandoverTypes: Array = []; getDeptHandoverType() { var that = this; that.mainService.getDictionary("list", "dept_handover_type").subscribe((data) => { console.log(data); that.deptHandoverTypes = data; }); } // 新增弹框 showModal() { this.initForm(); this.add = true; this.modal = true; this.isAddDeptsPhone = true; } hideModal() { this.coopItem = null; this.modal = false; this.initForm(); } // 初始化新增form表单 loadStartTime = ''; loadEndTime = ''; initForm() { this.validateForm = this.fb.group({ dispensingTime: [null, [Validators.required]], department: [null, [Validators.required]] }); let date = new Date(); this.loadStartTime = format(subDays(date, 1), "yyyy-MM-dd") +' '+'08:00:00' this.loadEndTime = format(date, "yyyy-MM-dd") +' '+'08:00:00' this.validateForm.controls.dispensingTime.setValue([this.loadStartTime, this.loadEndTime]); } // 科室位置必填 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(); } if (that.validateForm.invalid) return; let data: any = { startTime:this.formStartDate?this.formStartDate:this.loadStartTime,//发起时间开始 endTime:this.formEndDate?this.formEndDate:this.loadEndTime,//发起时间结束 hosId:this.hosId, pharmacy:this.validateForm.value.department }; if (!that.add) { this.editModal = true }else{ that.btnLoading = true; that.mainService .simplePost("addData", "drugsBatch", 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; edit(e, data) { e.stopPropagation(); this.add = false; this.coopId = data.id; this.coopItem = data; this.validateForm.controls.department.setValue(data.pharmacy); this.validateForm.controls.dispensingTime.setValue([data.startTime,data.endTime]); this.loadStartTime = data.startTime this.loadEndTime = data.endTime this.modal = true } // 展示信息提示框(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 id */ showDelModal(e, id) { e.stopPropagation(); this.delModal = true; this.coopId = id; } hideDelModal() { this.delModal = false; } // 确认删除 confirmDel() { var that = this; that.btnLoading = true; that.mainService .coopTypeConfig( "rmvData", "drugsBatch", [that.coopId] ) .subscribe((data) => { that.btnLoading = false; that.delModal = false; if (data.status==200) { that.showPromptModal("删除", true, ""); } else { that.showPromptModal("删除", false, data.data[0].msg); } }); } // 查看 detail(e, data) { e.stopPropagation(); this.router.navigateByUrl(`/dispensingDetail/${data.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(); } // 发药并打印 printData = []; print(e, data, id){ this.rowData = data e.stopPropagation(); let that = this; that.printLoading = true; that.mainService .transfusionPrint("drugsBatch", id) .subscribe((res) => { let arr = res.data.drugsListDTOS; for(let i of arr){ for(let t of i.drugsConfigureDTOS){ t.deptName = i.pharmacyDTO?i.pharmacyDTO.dept:'-' } i.drugsConfigureDTOS.push({ drugsInfoDTO:{ drugName:'合计', specs:'', }, actualCount:i.totalActual, cartonNum:i.totalCarton, deptName:'' }) } that.printData = arr; that.printLoading = false; that.btnLoading = false; that.printModal = false; setTimeout(() => { const printContent = document.getElementById("report"); const WindowPrt = window.open("", "", "width=1000,height=900"); WindowPrt.document.write(printContent.innerHTML); WindowPrt.document.close(); WindowPrt.focus(); WindowPrt.print(); WindowPrt.close(); setTimeout(()=>{ this.getList(); },200) }, 500); }); } printModal = false; printE = ''; printItemData = ''; printItemId = ''; dispensingPrint(e, data, id){ this.printModal = true this.printE = e this.printItemData = data this.printItemId = id } confirmPrintDel(){ this.btnLoading = true; this.print(this.printE, this.printItemData, this.printItemId) } hidePrintModal(){ this.printModal = false } }