batch-specimen.component.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. import { Component, OnInit, AfterViewInit, ElementRef, ViewChild } from '@angular/core';
  2. import { ToolService } from 'src/app/services/tool.service';
  3. import { MainService } from 'src/app/services/main.service';
  4. import { NzMessageService } from 'ng-zorro-antd';
  5. import { Location } from '@angular/common';
  6. import { Subject } from 'rxjs';
  7. import { debounceTime } from 'rxjs/operators';
  8. import { Router, ActivatedRoute } from '@angular/router';
  9. @Component({
  10. selector: 'app-batch-specimen',
  11. templateUrl: './batch-specimen.component.html',
  12. styleUrls: ['./batch-specimen.component.less']
  13. })
  14. export class BatchSpecimenComponent implements OnInit, AfterViewInit {
  15. @ViewChild('printBtn', { static: false }) printBtn: ElementRef<HTMLElement>;
  16. @ViewChild('specimenCodeElement', { static: false}) specimenCodeElementRef: ElementRef;
  17. constructor(
  18. private mainService: MainService,
  19. private tool: ToolService,
  20. private message: NzMessageService,
  21. private _location: Location,
  22. public router: Router,
  23. private route: ActivatedRoute,
  24. ) { }
  25. hosId:any = this.tool.getCurrentHospital().id; //当前院区
  26. deptDTO:any = this.tool.getCurrentUserDept(); //当前科室
  27. deptDisplay; //护士端是否显示可以别名,1是显示科室名称,2是显示科室别名
  28. listOfData: any[] = []; //表格数据
  29. searchTimerSubject = new Subject(); //防抖
  30. ngOnInit() {
  31. //防抖
  32. this.searchTimerSubject.pipe(debounceTime(500)).subscribe((v) => {
  33. let fun = v[0];
  34. fun.call(this, v[1]);
  35. });
  36. this.tool.getDeptDisplay().subscribe((result) => {
  37. if (result.status == 200) {
  38. this.deptDisplay = result.list[0].valueconfig;
  39. }
  40. });
  41. this.init();
  42. }
  43. ngAfterViewInit() {
  44. this.specimenCodeElementRef.nativeElement.focus();
  45. }
  46. init(){
  47. this.getConfig();
  48. }
  49. // 获取配置
  50. configs:any = {};
  51. getConfig() {
  52. let postData = {
  53. idx: 0,
  54. sum: 10,
  55. taskTypeConfig: {
  56. taskTypeDTO: {
  57. hosId: {
  58. id: this.hosId
  59. },
  60. ordinaryField: {
  61. key:"ordinary_field",
  62. value: 'specimenPackage'
  63. }
  64. }
  65. }
  66. };
  67. this.mainService
  68. .getFetchDataList("simple/data", "taskTypeConfig", postData)
  69. .subscribe((result) => {
  70. if (result.status == 200) {
  71. this.configs = result.list[0] || {};
  72. this.querySaveSpePackage(true);
  73. }
  74. });
  75. }
  76. // 获取患者、试管类型列表、标本总数
  77. total:any;
  78. typeSpecimentList:any[] = [];
  79. patientSpecimentList:any[] = [];
  80. package:any = {};
  81. querySaveSpePackage(isInit = false){
  82. this.maskFlag = this.message.loading("正在加载中..", {
  83. nzDuration: 0,
  84. }).messageId;
  85. let postData:any = {
  86. deptId: this.deptDTO.id,
  87. };
  88. if(this.route.snapshot.queryParams.id){
  89. postData.packageId = +this.route.snapshot.queryParams.id;
  90. }
  91. this.mainService
  92. .querySaveSpePackage(postData)
  93. .subscribe((result:any) => {
  94. this.message.remove(this.maskFlag);
  95. this.maskFlag = false;
  96. if (result.state == 200) {
  97. this.total = result.totalCount;
  98. this.typeSpecimentList = result.tube || [];
  99. this.patientSpecimentList = result.patient || [];
  100. this.package = result.package || {};
  101. if(isInit){
  102. this.showDelModal({}, '您确认要重置标本吗,重置会先清空标本在根据规则自动清点?','重置标本','reset');
  103. }else{
  104. this.getList();
  105. }
  106. }
  107. })
  108. }
  109. // 批量移除
  110. infoContent:any;
  111. batchDel(){
  112. if(this.checkedDepIds.length==0){
  113. this.message.error('请勾选标本列表')
  114. return
  115. }
  116. this.confirmDelType = 'batchDel';
  117. this.tipsMsg1 = `您确认要移除${this.checkedDepIds.length}项标本吗?`
  118. this.delModal = true;
  119. }
  120. // 选中表格中科室
  121. mapOfCheckedId: { [key: string]: boolean } = {};
  122. checkedDepIds = []; //已选中科室id
  123. refreshStatus(): void {
  124. this.isAllDisplayDataChecked = this.listOfData.every(
  125. (item) => this.mapOfCheckedId[item.id]
  126. );
  127. let arr = [];
  128. for (var k in this.mapOfCheckedId) {
  129. if (this.mapOfCheckedId[k]) {
  130. arr.push(Number(k));
  131. }
  132. }
  133. this.checkedDepIds = arr;
  134. console.log(this.checkedDepIds);
  135. }
  136. //表格整行选中
  137. selectedListData(id) {
  138. this.mapOfCheckedId[id] = !this.mapOfCheckedId[id];
  139. this.refreshStatus();
  140. }
  141. // 全选
  142. isAllDisplayDataChecked = false; //当前页是否全选
  143. checkAll(value: boolean): void {
  144. this.listOfData.forEach((item) => (this.mapOfCheckedId[item.id] = value));
  145. this.refreshStatus();
  146. }
  147. inspectActiveList: any = [];//选中检查列表
  148. patientActiveList: any = [];//选中患者列表
  149. coopData: any = {}; //当前操作列
  150. btnLoading: boolean = false; //提交按钮loading状态
  151. delModal: boolean = false; //删除模态框
  152. tipsMsg1: string; //提示框信息
  153. tipsMsg2: string; //操作后信息
  154. confirmDelType: string; //确认的类型(启用/停用,删除)
  155. showDelModal(
  156. data,
  157. tipsMsg1: string,
  158. tipsMsg2: string,
  159. type: string,
  160. ) {
  161. this.confirmDelType = type;
  162. this.delModal = true;
  163. this.coopData = data;
  164. this.tipsMsg1 = tipsMsg1;
  165. this.tipsMsg2 = tipsMsg2;
  166. }
  167. // 隐藏删除框
  168. hideDelModal() {
  169. this.delModal = false;
  170. this.isShowEndDeptId = false;
  171. }
  172. // 确认删除
  173. confirmDel(e) {
  174. console.log(e)
  175. this.btnLoading = true;
  176. if (this.confirmDelType === "del" || this.confirmDelType ==='batchDel') {
  177. //删除-移除标本
  178. let postData = {
  179. speIds: this.confirmDelType === "del" ? this.coopData.id.toString() : this.checkedDepIds.toString(),
  180. packageId: this.package.id,
  181. }
  182. this.mainService
  183. .removePackageSpe(postData)
  184. .subscribe((data:any) => {
  185. this.btnLoading = false;
  186. this.delModal = false;
  187. if (data.state == 200) {
  188. this.showPromptModal('移除', true, "");
  189. } else {
  190. this.showPromptModal('移除', false, data.msg);
  191. }
  192. });
  193. }else if (this.confirmDelType === "reset") {
  194. //先重置再自动清点
  195. let postData = {
  196. packageId: this.package.id,
  197. }
  198. this.mainService
  199. .resetPackageSpe(postData)
  200. .subscribe((data:any) => {
  201. this.btnLoading = false;
  202. this.delModal = false;
  203. if (data.state == 200) {
  204. this.showPromptModal(this.tipsMsg2, true, "");
  205. } else {
  206. this.showPromptModal(this.tipsMsg2, false, data.msg);
  207. }
  208. });
  209. }else if (this.confirmDelType === "package") {
  210. //打包
  211. let postData = {
  212. type: 'specimenPackage',
  213. id: this.package.id,
  214. endDeptId: e.endDeptId,
  215. }
  216. this.mainService
  217. .createOrTakeOrderSpecimen(postData)
  218. .subscribe((data:any) => {
  219. this.btnLoading = false;
  220. this.delModal = false;
  221. this.isShowEndDeptId = false;
  222. if (data.state == 200) {
  223. this.printPackage();
  224. } else {
  225. this.message.error(data.msg || "操作失败");
  226. }
  227. });
  228. }
  229. if(this.listOfData.length){
  230. this.listOfData.forEach(item => (this.mapOfCheckedId[item.id] = false));
  231. this.refreshStatus();
  232. }
  233. }
  234. // 打印
  235. base64:string = '';
  236. printPackage(){
  237. this.mainService
  238. .makeQrCode({}, this.package.packCode)
  239. .subscribe((data:any) => {
  240. if (data.state == 200) {
  241. this.total = data.totalCount;
  242. this.typeSpecimentList = data.tube || [];
  243. this.patientSpecimentList = data.patient || [];
  244. this.package = data.package || {};
  245. this.base64 = data.base64 || '';
  246. this.message.success("操作成功");
  247. setTimeout(()=>{
  248. this.printBtn.nativeElement.click();
  249. this.goBack();
  250. },0)
  251. } else {
  252. this.message.error(data.msg || "操作失败");
  253. }
  254. });
  255. }
  256. // 打包
  257. isShowEndDeptId:boolean = false;
  258. packageHandler(){
  259. this.isShowEndDeptId = true;
  260. this.getSpePackageEndDeptList();
  261. }
  262. // 查询标本包里的所有终点科室
  263. isShowEndDeptIdArr:any[] = [];
  264. getSpePackageEndDeptList(){
  265. this.mainService
  266. .getSpePackageEndDeptList({packageId: this.package.id})
  267. .subscribe((data:any) => {
  268. if (data.state == 200) {
  269. this.isShowEndDeptIdArr = data.data;
  270. this.showDelModal({}, `你确认要打包${this.total}只标本吗?`,'打包','package')
  271. } else {
  272. this.message.error(data.msg || "操作失败");
  273. }
  274. });
  275. }
  276. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  277. promptContent: string; //操作提示框提示信息
  278. ifSuccess: boolean; //操作成功/失败
  279. promptInfo: string; //操作结果提示信息
  280. promptModalShow: boolean; //操作提示框是否展示
  281. showPromptModal(con, success, promptInfo?) {
  282. this.promptModalShow = false;
  283. this.promptContent = con;
  284. this.ifSuccess = success;
  285. this.promptInfo = promptInfo;
  286. setTimeout(() => {
  287. this.promptModalShow = true;
  288. }, 100);
  289. this.querySaveSpePackage();
  290. }
  291. loading1:boolean = false;
  292. getList(){
  293. let data = {
  294. idx: 0,
  295. sum: 99999,
  296. specimen: {
  297. packageId: this.package ? this.package.id : undefined,
  298. patientNo: this.activePatientNo || undefined,
  299. tubeType: this.activeTypeId ? { id: this.activeTypeId } : undefined,
  300. },
  301. };
  302. this.loading1 = true;
  303. this.mainService
  304. .getFetchDataList("simple/data", "specimen", data)
  305. .subscribe((data) => {
  306. this.loading1 = false;
  307. if (data.status == 200) {
  308. this.listOfData = data.list;
  309. // if(this.confirmDelType ==='batchDel'){
  310. // this.listOfData.forEach(item => (this.mapOfCheckedId[item.id] = false));
  311. // setTimeout(_=>{
  312. // this.refreshStatus();
  313. // })
  314. // }
  315. }else{
  316. this.message.error(data.msg || "请求数据失败");
  317. }
  318. });
  319. }
  320. // 返回
  321. goBack(){
  322. this._location.back();
  323. }
  324. // 选择试管类型
  325. activeTypeId:any;
  326. clickType(item){
  327. if(this.activeTypeId == item.id){
  328. this.activeTypeId = undefined;
  329. }else{
  330. this.activeTypeId = item.id;
  331. }
  332. this.querySaveSpePackage();
  333. }
  334. // 选择患者
  335. activePatientNo:any;
  336. clickPatient(item){
  337. if(this.activePatientNo == item.no){
  338. this.activePatientNo = undefined;
  339. }else{
  340. this.activePatientNo = item.no;
  341. }
  342. this.querySaveSpePackage();
  343. }
  344. /**
  345. * @description: PDA扫码复制到文本输入框
  346. * @return {*}
  347. * @author: seimin
  348. */
  349. specimenCode:string = '';
  350. inputChange(e){
  351. if(this.specimenCode.length >= 8){
  352. this.searchTimer(this.addSpeciment, this.specimenCode);
  353. }
  354. }
  355. // 添加标本
  356. maskFlag: any = false;
  357. addSpeciment(speCode){
  358. this.maskFlag = this.message.loading("正在加载中..", {
  359. nzDuration: 0,
  360. }).messageId;
  361. let postData = {
  362. speCode,
  363. packageId: this.package.id,
  364. };
  365. this.mainService
  366. .addPackageSpe(postData)
  367. .subscribe((result:any) => {
  368. this.message.remove(this.maskFlag);
  369. this.maskFlag = false;
  370. if(result.state == 200){
  371. this.message.success('操作成功!');
  372. this.specimenCode = '';//清空
  373. this.querySaveSpePackage();
  374. }else{
  375. this.message.error(result.msg || '操作失败!');
  376. }
  377. });
  378. }
  379. // 防抖
  380. searchTimer(fun, e) {
  381. this.searchTimerSubject.next([fun, e]);
  382. }
  383. // 自动清点规则
  384. isShowPackageSpecimenRule:boolean = false;
  385. showPackageSpecimenRule(){
  386. this.isShowPackageSpecimenRule = true;
  387. }
  388. // 关闭自动清点规则
  389. closePackageSpecimenRule(e){
  390. this.isShowPackageSpecimenRule = e;
  391. }
  392. }