dispensing-batch.component.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. import { Component, OnInit, ViewChild, OnDestroy } from "@angular/core";
  2. import { ActivatedRoute, Router } from "@angular/router";
  3. import {
  4. FormBuilder,
  5. Validators,
  6. FormGroup,
  7. FormControl,
  8. } from "@angular/forms";
  9. import { MainService } from "../../services/main.service";
  10. import { OverlayScrollbarsComponent } from "overlayscrollbars-ngx";
  11. import { ToolService } from "../../services/tool.service";
  12. import { format, startOfDay, endOfDay, subDays} from "date-fns";
  13. import { NzMessageService } from "ng-zorro-antd";
  14. import { Subject } from "rxjs";
  15. import { debounceTime, filter } from "rxjs/operators";
  16. import host from "../../../assets/js/http";
  17. import { HttpRequest, HttpResponse, HttpClient } from '@angular/common/http';
  18. @Component({
  19. selector: "app-dispensing-batch",
  20. templateUrl: "./dispensing-batch.component.html",
  21. styleUrls: ["./dispensing-batch.component.less"],
  22. })
  23. export class DispensingBatchComponent implements OnInit, OnDestroy {
  24. @ViewChild("osComponentRef1", {
  25. read: OverlayScrollbarsComponent,
  26. static: false,
  27. })
  28. osComponentRef1: OverlayScrollbarsComponent;
  29. constructor(
  30. private message: NzMessageService,
  31. private fb: FormBuilder,
  32. private route: ActivatedRoute,
  33. private router: Router,
  34. private mainService: MainService,
  35. private tool: ToolService,
  36. private http: HttpClient,
  37. ) {}
  38. ngOnDestroy() {
  39. clearInterval(this.logTimer)
  40. }
  41. ngOnInit() {
  42. this.searchParentDeptSubject.pipe(debounceTime(500)).subscribe((e) => {
  43. this.getAddDeparts(e);
  44. });
  45. this.hosId = this.tool.getCurrentHospital().id;
  46. this.coopBtns = this.tool.initCoopBtns(this.route);
  47. this.initForm();
  48. this.getTaskTypesId();
  49. this.getAllHospital();
  50. this.getDeptHandoverType();
  51. this.autoUpdate(true)
  52. }
  53. listOfData: any[] = []; //表格数据
  54. promptContent: string; //操作提示框提示信息
  55. ifSuccess: boolean; //操作成功/失败
  56. promptInfo: string; //操作结果提示信息
  57. promptModalShow: boolean; //操作提示框是否展示
  58. modal: boolean = false; //新增/编辑模态框
  59. add: boolean; //true:新增;false:编辑
  60. validateForm: FormGroup; //新增/编辑表单
  61. coopId: number; //表格中执行操作的id
  62. department: number; //所属科室
  63. infoDepartment: number; //所属科室
  64. hosId: number;
  65. dateRange;//时间
  66. loadAllConsumeDept: boolean = true;//是否加载所有消耗科室
  67. batchNumber; //批次号
  68. num; //编码
  69. deptalias; //别名
  70. type; //类型
  71. deptHandoverType; //类型
  72. pageIndex: number = 1; //页码
  73. listLength: number = 10; //总条数
  74. pageSize: number = 10; //每页条数
  75. btnLoading: boolean = false; //确认按钮loading状态
  76. printLoading: boolean = false; //批量打印按钮loading状态
  77. deptPhones: any = []; //新添加的科室电话列表
  78. isAddDeptsPhone = true; //添加新的科室电话是否禁用
  79. deptsPhoneId = 1; //科室电话自增id
  80. allParentdepart: any = []; //所有的父级科室列表
  81. hospitals1: any = []; //科室列表(搜索)
  82. addHospitals: any = [];
  83. rowData: any = null; //打印选择列表
  84. editModal:boolean = false; //编辑时弹框
  85. searchParentDeptSubject = new Subject();
  86. // 初始化增删改按钮
  87. coopBtns: any = {};
  88. saveLoading:boolean = false;
  89. taskTypeData:{id:''};
  90. // 导入---end
  91. //搜索父级科室
  92. isDeptLoading = false;
  93. changeInp(e) {
  94. this.isDeptLoading = true;
  95. this.searchParentDeptSubject.next(e);
  96. }
  97. // 配送建单
  98. coopData:any = {};
  99. addDateModal(data) {
  100. this.coopData = data;
  101. this.showDelModal1();
  102. }
  103. showDelModal1() {
  104. this.editModal = true;
  105. }
  106. hideDelModal1() {
  107. this.editModal = false;
  108. }
  109. // 30s倒计时
  110. logTimer = null; //定时器
  111. logTime = 0; //自动刷新秒数
  112. logTimeConst = 30; //自动刷新秒数
  113. autoUpdate(flag = true) {
  114. if (flag) {
  115. this.logTime = this.logTimeConst;
  116. }
  117. clearInterval(this.logTimer);
  118. this.logTimer = setInterval(() => {
  119. this.logTime--;
  120. if (this.logTime === 0) {
  121. this.logTime = this.logTimeConst;
  122. this.getList()
  123. }
  124. }, 1000);
  125. }
  126. // 编辑保存
  127. confirmDel1() {
  128. var that = this;
  129. for (const i in that.validateForm.controls) {
  130. that.validateForm.controls[i].markAsDirty();
  131. that.validateForm.controls[i].updateValueAndValidity();
  132. }
  133. if (that.validateForm.invalid) return;
  134. let data: any = {
  135. startTime:this.formStartDate?this.formStartDate:this.loadStartTime,//发起时间开始
  136. endTime:this.formEndDate?this.formEndDate:this.loadEndTime,//发起时间结束
  137. hosId:this.hosId,
  138. pharmacy:this.validateForm.value.addDepartment,
  139. id:that.coopId,
  140. loadAllConsumeDept:this.validateForm.value.loadAllConsumeDept?1:0
  141. };
  142. that.saveLoading = true;
  143. that.mainService
  144. .simplePost("addData", "drugsBatch", data)
  145. .subscribe((data) => {
  146. that.saveLoading = false;
  147. that.hideModal();
  148. that.initForm();
  149. if (data.status == 200) {
  150. this.editModal = false;
  151. that.showPromptModal("编辑", true, "");
  152. } else {
  153. that.showPromptModal("编辑", false, data.msg);
  154. }
  155. });
  156. }
  157. // 搜索
  158. search() {
  159. this.pageIndex = 1;
  160. this.getList();
  161. }
  162. // 重置
  163. reset() {
  164. this.pageIndex = 1;
  165. this.batchNumber = null;
  166. this.startDate = null;
  167. this.endDate = null;
  168. this.dateRange = [];
  169. this.getList();
  170. }
  171. // 表格数据
  172. loading1 = false;
  173. getList() {
  174. var that = this;
  175. let data = {
  176. idx: that.pageIndex - 1,
  177. sum: that.pageSize,
  178. drugsBatch: {
  179. batchNo:that.batchNumber,
  180. startTime: this.startDate,
  181. endTime: this.endDate,
  182. hosId: this.hosId
  183. },
  184. };
  185. if(that.batchNumber){
  186. data.drugsBatch.batchNo = that.batchNumber
  187. }else{
  188. delete data.drugsBatch.batchNo
  189. }
  190. this.loading1 = true;
  191. that.mainService
  192. .getFetchDataList("data", "drugsBatch", data)
  193. .subscribe((data) => {
  194. this.loading1 = false;
  195. that.listOfData = data.list;
  196. that.listLength = data.totalNum;
  197. });
  198. }
  199. // 日期选择
  200. startDate: string; //发起时间开始
  201. endDate: string; //发起时间结束
  202. changeDate(result?): void {
  203. if (!result) {
  204. this.startDate = this.endDate = "";
  205. return;
  206. }
  207. this.startDate = format(startOfDay(result[0]), 'yyyy-MM-dd HH:mm:ss');
  208. this.endDate = format(endOfDay(result[1]), 'yyyy-MM-dd HH:mm:ss');
  209. }
  210. // 新增、编辑日期选择
  211. formStartDate: string; //发起时间开始
  212. formEndDate: string; //发起时间结束
  213. formChangeDate(result?): void {
  214. if (!result) {
  215. this.formStartDate = this.formEndDate = "";
  216. return;
  217. }
  218. this.formStartDate = format(result[0], 'yyyy-MM-dd HH:mm:ss');
  219. this.formEndDate = format(result[1], 'yyyy-MM-dd HH:mm:ss');
  220. }
  221. // 获取所有科室
  222. getDeparts() {
  223. let data = {
  224. batchId:this.rowData.id
  225. };
  226. this.mainService
  227. .getConsumeDept(data)
  228. .subscribe((res) => {
  229. this.isDeptLoading = false;
  230. this.hospitals1 = res.data
  231. });
  232. }
  233. // 获取药房科室
  234. getAddDeparts(dept) {
  235. var that = this;
  236. let data:any = {
  237. department: {
  238. dept,
  239. hosIds: this.hosId,
  240. type:{
  241. id:''
  242. }
  243. },
  244. idx: 0,
  245. sum: 20,
  246. };
  247. if(this.isParentData==1){
  248. if(this.tool.getCurrentUserInfo().currentHospital &&
  249. this.tool.getCurrentUserInfo().currentHospital.parent){
  250. data.department.hosIds = this.hosId +','+this.tool.getCurrentUserInfo().currentHospital.parent.id
  251. }else{
  252. data.department.hosIds = this.hosId
  253. }
  254. }
  255. that.mainService.getDictionary("list", "dept_type").subscribe((res) => {
  256. let typeData = res.find(i=>i.value=='pharmacyRoom');
  257. if(typeData){
  258. data.department.type.id = typeData.id
  259. }
  260. that.mainService
  261. .getFetchDataList("data", "department", data)
  262. .subscribe((data) => {
  263. this.addHospitals = data.list
  264. that.isDeptLoading = false;
  265. });
  266. });
  267. }
  268. // 获取所有院区
  269. getAllHospital() {
  270. this.getList();
  271. }
  272. // 获取科室汇总交接类型
  273. deptHandoverTypes: Array<any> = [];
  274. getDeptHandoverType() {
  275. var that = this;
  276. that.mainService.getDictionary("list", "dept_handover_type").subscribe((data) => {
  277. console.log(data);
  278. that.deptHandoverTypes = data;
  279. });
  280. }
  281. // 获取任务id
  282. getTaskTypesId() {
  283. this.mainService.getDictionary("list", "ordinary_field").subscribe((data) => {
  284. this.taskTypeData = data.find(i=>i.value=='infusionSolutions')
  285. });
  286. }
  287. // 获取配置
  288. isParentData:any;
  289. getConfig(type) {
  290. let postData = {
  291. idx: 0,
  292. sum: 10,
  293. taskTypeConfig: {
  294. hosId:this.hosId,
  295. taskType:this.taskTypeData.id
  296. }
  297. };
  298. this.mainService
  299. .getFetchDataList("simple/data", "taskTypeConfig", postData)
  300. .subscribe((result) => {
  301. if (result.status == 200) {
  302. let data = result.list[0] || {};
  303. this.isParentData = data.quoteParentData;
  304. if(type=='add'){
  305. this.add = true;
  306. this.isAddDeptsPhone = true;
  307. this.validateForm.controls.addDepartment.setValue(data.pharmacyDept || '');
  308. }
  309. this.getAddDeparts('')
  310. this.modal = true;
  311. }
  312. });
  313. }
  314. // 新增弹框
  315. showModal() {
  316. this.initForm();
  317. this.getConfig('add');
  318. }
  319. hideModal() {
  320. this.coopItem = null;
  321. this.modal = false;
  322. this.initForm();
  323. }
  324. // 初始化新增form表单
  325. loadStartTime = '';
  326. loadEndTime = '';
  327. initForm() {
  328. this.validateForm = this.fb.group({
  329. dispensingTime: [null, [Validators.required]],
  330. addDepartment: [null, [Validators.required]],
  331. loadAllConsumeDept: [true,[]]
  332. });
  333. let date = new Date();
  334. this.loadStartTime = format(subDays(date, 1), "yyyy-MM-dd") +' '+'08:00:00'
  335. this.loadEndTime = format(date, "yyyy-MM-dd") +' '+'08:00:00'
  336. this.validateForm.controls.dispensingTime.setValue([this.loadStartTime, this.loadEndTime]);
  337. }
  338. // 表单提交
  339. submitForm(): void {
  340. var that = this;
  341. for (const i in that.validateForm.controls) {
  342. that.validateForm.controls[i].markAsDirty();
  343. that.validateForm.controls[i].updateValueAndValidity();
  344. }
  345. if (that.validateForm.invalid) return;
  346. let data: any = {
  347. startTime:this.formStartDate?this.formStartDate:this.loadStartTime,//发起时间开始
  348. endTime:this.formEndDate?this.formEndDate:this.loadEndTime,//发起时间结束
  349. hosId:this.hosId,
  350. pharmacy:this.validateForm.value.addDepartment,
  351. loadAllConsumeDept:this.validateForm.value.loadAllConsumeDept?1:0
  352. };
  353. if (!that.add) {
  354. this.editModal = true
  355. }else{
  356. that.btnLoading = true;
  357. that.mainService
  358. .simplePost("addData", "drugsBatch", data)
  359. .subscribe((data) => {
  360. that.btnLoading = false;
  361. that.hideModal();
  362. that.initForm();
  363. if (data.status == 200) {
  364. that.showPromptModal(that.add ? "新增" : "编辑", true, "");
  365. } else {
  366. that.showPromptModal(that.add ? "新增" : "编辑", false, data.msg);
  367. }
  368. });
  369. }
  370. }
  371. // 编辑
  372. coopItem: any = null;
  373. edit(e, data) {
  374. e.stopPropagation();
  375. this.getConfig('edit');
  376. this.add = false;
  377. this.coopId = data.id;
  378. this.coopItem = data;
  379. this.validateForm.controls.addDepartment.setValue(data.pharmacy);
  380. this.validateForm.controls.dispensingTime.setValue([data.startTime,data.endTime]);
  381. if(data.loadAllConsumeDept==1){
  382. this.validateForm.controls.loadAllConsumeDept.setValue(true);
  383. }else{
  384. this.validateForm.controls.loadAllConsumeDept.setValue(false);
  385. }
  386. this.loadStartTime = data.startTime
  387. this.loadEndTime = data.endTime
  388. this.modal = true
  389. }
  390. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  391. showPromptModal(con, success, promptInfo?) {
  392. this.promptModalShow = false;
  393. this.promptContent = con;
  394. this.ifSuccess = success;
  395. this.promptInfo = promptInfo;
  396. setTimeout(() => {
  397. this.promptModalShow = true;
  398. }, 100);
  399. this.getList();
  400. }
  401. delModal: boolean = false; //删除模态框
  402. coopIds: any;
  403. coopFlag: any = false;
  404. /**
  405. *
  406. * @param e 事件对象
  407. * @param id
  408. */
  409. showDelModal(e, id) {
  410. e.stopPropagation();
  411. this.delModal = true;
  412. this.coopId = id;
  413. }
  414. hideDelModal() {
  415. this.delModal = false;
  416. }
  417. // 确认删除
  418. confirmDel() {
  419. var that = this;
  420. that.btnLoading = true;
  421. that.mainService
  422. .coopTypeConfig(
  423. "rmvData",
  424. "drugsBatch",
  425. [that.coopId]
  426. )
  427. .subscribe((data) => {
  428. that.btnLoading = false;
  429. that.delModal = false;
  430. if (data.status==200) {
  431. that.showPromptModal("删除", true, "");
  432. } else {
  433. that.showPromptModal("删除", false, data.data[0].msg);
  434. }
  435. });
  436. }
  437. // 发药总量
  438. grossModal:boolean = false;
  439. grossLoading:boolean = false;
  440. viewData:any = [];
  441. dispensingGross(e,data){
  442. this.grossModal = true
  443. this.grossLoading = true
  444. this.mainService
  445. .drugsGross(data.id)
  446. .subscribe((res:any) => {
  447. this.grossLoading = false;
  448. this.viewData = res.data
  449. });
  450. }
  451. // 关闭发药总量
  452. hideGrossModal(){
  453. this.grossModal = false
  454. }
  455. // 发药信息
  456. infoModal:boolean = false;
  457. infoLoading:boolean = false;
  458. infoData:any = [];
  459. dispensingInfo(e,data){
  460. this.rowData = data
  461. this.getDeparts()
  462. this.infoModal = true
  463. this.infoLoading = true
  464. this.mainService
  465. .drugsInfo({
  466. batchId:data.id,
  467. dataType:'batchDispensingMedicine'
  468. }).subscribe((res:any) => {
  469. this.infoLoading = false;
  470. this.infoData = res.list
  471. });
  472. }
  473. // 关闭发药信息
  474. hideInfoModal(){
  475. this.infoModal = false
  476. }
  477. // 发药信息搜索
  478. searchInfo(){
  479. this.getInfo()
  480. }
  481. getInfo(){
  482. this.infoLoading = true
  483. this.mainService
  484. .drugsInfo({
  485. deptId:this.infoDepartment,
  486. batchId:this.rowData.id,
  487. dataType:'batchDispensingMedicine'
  488. }).subscribe((res:any) => {
  489. this.infoLoading = false;
  490. this.infoData = res.list
  491. });
  492. }
  493. // 发药信息重置
  494. resetInfo(){
  495. this.infoDepartment = null
  496. this.getInfo()
  497. }
  498. // 导出
  499. maskFlag:any = null;
  500. exportPc(e,data){
  501. this.maskFlag = this.message.loading("正在导出..", {
  502. nzDuration: 0,
  503. }).messageId;
  504. this.mainService.exportReport("drugsBatch", {
  505. batchId:data.id
  506. }).subscribe(
  507. (res:any) => {
  508. this.message.remove(this.maskFlag);
  509. this.maskFlag = false;
  510. this.message.success('导出成功');
  511. var file = new Blob([res], {
  512. type: "application/vnd.ms-excel",
  513. });
  514. var fileURL = URL.createObjectURL(file);
  515. var a = document.createElement("a");
  516. a.href = fileURL;
  517. a.target = "_blank";
  518. a.download = `发药批次数据-${data.batchNo}.xls`;
  519. document.body.appendChild(a);
  520. a.click();
  521. },
  522. (err) => {
  523. this.message.remove(this.maskFlag);
  524. this.maskFlag = false;
  525. this.message.error('导出失败');
  526. }
  527. );
  528. }
  529. // 查看
  530. detail(e, data) {
  531. e.stopPropagation();
  532. this.router.navigateByUrl(`/dispensingDetail/${data.id}`);
  533. }
  534. // 发药并打印
  535. printData = [];
  536. summaryDataList = [];
  537. batchNo:any = null;
  538. print(e, data, id){
  539. this.rowData = data
  540. e.stopPropagation();
  541. let that = this;
  542. that.printLoading = true;
  543. that.mainService
  544. .transfusionPrint("drugsBatch", id)
  545. .subscribe((res) => {
  546. this.batchNo = res.data.batchNo
  547. let arr = res.data.drugsListDTOS;
  548. this.summaryDataList = res.data.summaryDataList;
  549. for(let i of arr){
  550. for(let t of i.drugsConfigureDTOS){
  551. t.deptName = i.pharmacyDTO?i.pharmacyDTO.dept:'-'
  552. }
  553. i.drugsConfigureDTOS.push({
  554. drugsInfoDTO:{
  555. drugName:'合计',
  556. specs:'',
  557. },
  558. expendCount:i.totalExpendCount,
  559. addSub:i.totalAddSub,
  560. deptName:'',
  561. cartonActual:i.cartonActual
  562. })
  563. }
  564. that.printData = arr;
  565. that.printLoading = false;
  566. that.btnLoading = false;
  567. that.printModal = false;
  568. setTimeout(() => {
  569. const printContent = document.getElementById("report");
  570. const WindowPrt = window.open("", "", "width=1000,height=1200");
  571. WindowPrt.document.write(printContent.innerHTML);
  572. WindowPrt.document.close();
  573. WindowPrt.focus();
  574. WindowPrt.print();
  575. WindowPrt.close();
  576. setTimeout(()=>{
  577. this.getList();
  578. },200)
  579. }, 500);
  580. });
  581. }
  582. printModal = false;
  583. printE = '';
  584. printItemData = '';
  585. printItemId = '';
  586. dispensingPrint(e, data, id){
  587. this.printModal = true
  588. this.printE = e
  589. this.printItemData = data
  590. this.printItemId = id
  591. }
  592. confirmPrintDel(){
  593. this.btnLoading = true;
  594. this.print(this.printE, this.printItemData, this.printItemId)
  595. }
  596. hidePrintModal(){
  597. this.printModal = false
  598. }
  599. }