shortcut-build-orders.component.ts 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. import { Component, OnInit } from "@angular/core";
  2. import { ActivatedRoute, Router } from "@angular/router";
  3. import { FormBuilder, Validators, FormGroup } from "@angular/forms";
  4. import { MainService } from "../../services/main.service";
  5. import { ToolService } from "../../services/tool.service";
  6. import { forkJoin, Subject } from "rxjs";
  7. import { debounceTime } from "rxjs/operators";
  8. import { NzMessageService } from "ng-zorro-antd";
  9. @Component({
  10. selector: "app-shortcut-build-orders",
  11. templateUrl: "./shortcut-build-orders.component.html",
  12. styleUrls: ["./shortcut-build-orders.component.less"],
  13. })
  14. export class ShortcutBuildOrdersComponent implements OnInit {
  15. constructor(
  16. private message: NzMessageService,
  17. private fb: FormBuilder,
  18. private mainService: MainService,
  19. private route: ActivatedRoute,
  20. private router: Router,
  21. private tool: ToolService
  22. ) {}
  23. userInfo: any = JSON.parse(localStorage.getItem("user")) || {}; //登录用户信息
  24. searchCriteria = {
  25. //搜索条件
  26. name: "",
  27. hospital: null,
  28. startDepartment: null,
  29. };
  30. // roundRobinTypes = [
  31. // { id: '163', hosName: '标本轮巡' }
  32. // ];//快捷建单类型
  33. roundRobinTypes = []; //快捷建单类型
  34. createUser = "";
  35. department = []; // 院区下的科室列表(分类型)
  36. department1 = []; // 院区下的科室列表
  37. departmentSearch = []; // 院区下的科室列表(搜索框)
  38. allHospital: any = []; //院区下拉框
  39. hosId: any; //当前选中院区
  40. listOfData: any[] = []; //表格数据
  41. pageIndex: number = 1; //表格当前页码
  42. pageSize: number = 10; //表格每页展示条数
  43. listLength: number = 10; //表格总数据量
  44. tableHeight: number; //表格动态高
  45. modal: boolean = false; //新增/编辑模态框
  46. add: boolean; //true:新增;false:编辑
  47. validateForm: FormGroup; //新增/编辑表单
  48. coopId: number; //当前操作列id
  49. hospitalList: Array<object> = []; //院区列表
  50. btnLoading: boolean = false; //提交按钮loading状态
  51. printLoading: boolean = false; //批量打印按钮loading状态
  52. promptContent: string; //操作提示框提示信息
  53. ifSuccess: boolean; //操作成功/失败
  54. promptInfo: string; //操作结果提示信息
  55. promptModalShow: boolean; //操作提示框是否展示
  56. demoValue: number = 0;
  57. changeInpSubject = new Subject();
  58. ngOnInit() {
  59. this.changeInpSubject.pipe(debounceTime(500)).subscribe((v) => {
  60. this.searchDepartment(v[0], v[1]);
  61. });
  62. this.coopBtns = this.tool.initCoopBtns(this.route);
  63. this.getAllHospital();
  64. this.initForm();
  65. this.getHospitalList();
  66. }
  67. // 重置
  68. reset() {
  69. this.searchCriteria = {
  70. //搜索条件
  71. name: "",
  72. hospital: this.allHospital[0] ? this.allHospital[0]["id"] + "" : null,
  73. startDepartment: null,
  74. };
  75. this.getList(1);
  76. }
  77. // 获取轮巡类型
  78. getRoundRobinTypes(id) {
  79. this.mainService
  80. .getFetchDataList("configuration", "taskType", {
  81. taskType: { hosId: { id }, associationType: { id: 380 } },
  82. idx: 0,
  83. sum: 100,
  84. })
  85. .subscribe((data) => {
  86. if (data.status == 200) {
  87. this.roundRobinTypes = data.list.map((item) => {
  88. return { id: item.id + "", hosName: item.taskName };
  89. });
  90. this.validateForm.controls.roundRobinType.setValue(
  91. this.roundRobinTypes[0] && this.roundRobinTypes[0].id
  92. );
  93. }
  94. });
  95. }
  96. // 打印
  97. codes = []; //二维码
  98. print(e, batch, id?) {
  99. e.stopPropagation();
  100. this.printLoading = true;
  101. this.mainService
  102. .printShortcutBuildOrders(batch ? this.checkedDepIds : [id])
  103. .subscribe((data) => {
  104. if (data.status == 200) {
  105. this.codes = data.data;
  106. this.printLoading = false;
  107. setTimeout(() => {
  108. const printContent = document.getElementById("report");
  109. const WindowPrt = window.open("", "", "width=700,height=900");
  110. WindowPrt.document.write(printContent.innerHTML);
  111. WindowPrt.document.close();
  112. WindowPrt.focus();
  113. WindowPrt.print();
  114. WindowPrt.close();
  115. }, 100);
  116. }
  117. });
  118. }
  119. // 选中表格中快捷建单
  120. mapOfCheckedId = {};
  121. checkedDepIds = []; //已选中快捷建单id
  122. refreshStatus(): void {
  123. this.isAllDisplayDataChecked = this.listOfData.every(
  124. (item) => this.mapOfCheckedId[item.id]
  125. );
  126. let arr = [];
  127. for (var k in this.mapOfCheckedId) {
  128. if (this.mapOfCheckedId[k]) {
  129. arr.push(Number(k));
  130. }
  131. }
  132. this.checkedDepIds = arr;
  133. console.log(this.checkedDepIds);
  134. }
  135. // 整行操作
  136. selectedListData(id) {
  137. this.mapOfCheckedId[id] = !this.mapOfCheckedId[id];
  138. this.refreshStatus();
  139. }
  140. // 全选
  141. isAllDisplayDataChecked = false; //当前页是否全选
  142. checkAll(value: boolean): void {
  143. this.listOfData.forEach((item) => (this.mapOfCheckedId[item.id] = value));
  144. this.refreshStatus();
  145. }
  146. // 选择院区
  147. changeHospital(id, type) {
  148. if (type === "search") {
  149. this.searchCriteria.startDepartment = null;
  150. } else {
  151. if (
  152. this.validateForm &&
  153. this.validateForm.value &&
  154. this.validateForm.value.endDepartment
  155. ) {
  156. this.validateForm.controls.startDepartment.setValue(null);
  157. this.validateForm.controls.endDepartment.setValue(null);
  158. this.validateForm.controls.roundRobinType.setValue(null);
  159. }
  160. }
  161. // 1,请求指定科室类型的科室列表
  162. let data = {
  163. department: {
  164. hospital: { id },
  165. type: { id: 383 },
  166. },
  167. idx: 0,
  168. sum: 20,
  169. };
  170. this.mainService
  171. .getFetchDataList("data", "department", data)
  172. .subscribe((data) => {
  173. if (data.status == 200) {
  174. if (type === "search") {
  175. this.departmentSearch = data.list;
  176. } else {
  177. this.department = data.list;
  178. }
  179. }
  180. });
  181. if (type === "search") {
  182. return;
  183. }
  184. // 2,请求科室类型为检验科的科室列表
  185. let data2 = {
  186. department: {
  187. hospital: { id },
  188. type: { id: 282 },
  189. },
  190. idx: 0,
  191. sum: 20,
  192. };
  193. this.mainService
  194. .getFetchDataList("data", "department", data2)
  195. .subscribe((data) => {
  196. if (data.status == 200) {
  197. this.department1 = data.list;
  198. }
  199. });
  200. }
  201. // 打开搜索框
  202. changeSearch(flag) {
  203. if (flag) {
  204. this.changeInp("no", "search");
  205. }
  206. }
  207. changeForm(flag) {
  208. if (flag) {
  209. this.changeInp("no", "form");
  210. }
  211. }
  212. changeFormEnd(flag) {
  213. if (flag) {
  214. this.changeInp("no", "formEnd");
  215. }
  216. }
  217. // 边输边搜节流阀
  218. isLoading = false;
  219. changeInp(dept, type) {
  220. if (dept === "no") {
  221. dept = "";
  222. }
  223. if (type === "form" || type === "formEnd") {
  224. if (!this.hosId) {
  225. this.department = [];
  226. return;
  227. }
  228. }
  229. this.isLoading = true;
  230. this.changeInpSubject.next([dept, type]);
  231. }
  232. // 修改起点科室院区
  233. changeStartHospital(e){
  234. console.log(e);
  235. this.validateForm.controls.startDepartment.setValue(null);
  236. }
  237. // 修改终点科室院区
  238. changeEndHospital(e){
  239. console.log(e);
  240. this.validateForm.controls.endDepartment.setValue(null);
  241. }
  242. // 搜索科室
  243. snum = 0;
  244. searchDepartment(dept, type) {
  245. let data = {
  246. department: {
  247. dept,
  248. type: { id: 383 },
  249. hospital: {
  250. id: this.hosId,
  251. },
  252. },
  253. idx: 0,
  254. sum: 20,
  255. };
  256. if (type === "form") {
  257. if(this.validateForm.value.startDepartmentHospital){
  258. data.department.hospital.id = this.validateForm.value.startDepartmentHospital;
  259. }else{
  260. this.department = [];
  261. this.isLoading = false;
  262. return;
  263. }
  264. }
  265. // 终点科室的科室类型为检验科
  266. if (type === "formEnd") {
  267. data.department.type.id = 282;
  268. if(this.validateForm.value.endDepartmentHospital){
  269. data.department.hospital.id = this.validateForm.value.endDepartmentHospital;
  270. }else{
  271. this.department1 = [];
  272. this.isLoading = false;
  273. return;
  274. }
  275. }
  276. this.snum++;
  277. this.mainService
  278. .getFetchDataList("data", "department", data)
  279. .subscribe((data) => {
  280. this.snum--;
  281. if (data.status == 200) {
  282. if (type === "search") {
  283. if (this.snum === 0) {
  284. this.isLoading = false;
  285. }
  286. this.departmentSearch = data.list;
  287. } else if (type === "form") {
  288. if (this.snum === 0) {
  289. this.isLoading = false;
  290. }
  291. this.department = data.list;
  292. } else if (type === "formEnd") {
  293. if (this.snum === 0) {
  294. this.isLoading = false;
  295. }
  296. this.department1 = data.list;
  297. }
  298. }
  299. });
  300. }
  301. // 初始化增删改按钮
  302. coopBtns: any = {};
  303. // 获取所有院区
  304. /**
  305. *
  306. *
  307. * @memberof RoundRobinComponent
  308. */
  309. getAllHospital() {
  310. this.allHospital = [this.tool.getCurrentHospital()];
  311. this.hosId = this.tool.getCurrentHospital().id;
  312. this.searchCriteria.hospital = this.tool.getCurrentHospital().id + "";
  313. this.getList(1);
  314. this.changeHospital(this.searchCriteria.hospital, "search");
  315. this.getRoundRobinTypes(this.hosId);
  316. }
  317. // 表格数据
  318. loading1 = false;
  319. getList(type) {
  320. if (type == 1) {
  321. this.pageIndex = 1;
  322. }
  323. let data = {
  324. idx: this.pageIndex - 1,
  325. sum: this.pageSize,
  326. quickOrder: {
  327. hospital: this.searchCriteria.hospital,
  328. startDept:
  329. this.searchCriteria.startDepartment === null
  330. ? ""
  331. : this.searchCriteria.startDepartment,
  332. title:
  333. this.searchCriteria.name === null ? "" : this.searchCriteria.name,
  334. },
  335. };
  336. this.mapOfCheckedId = {};
  337. this.checkedDepIds = [];
  338. this.isAllDisplayDataChecked = false;
  339. this.loading1 = true;
  340. this.mainService
  341. .getFetchDataList("api", "quickOrder", data)
  342. .subscribe((data) => {
  343. this.loading1 = false;
  344. if (data.status == 200) {
  345. this.listOfData = data.list;
  346. this.listLength = data.totalNum;
  347. }
  348. });
  349. }
  350. // 新增/编辑弹框
  351. addModal() {
  352. this.add = true; //新增
  353. this.modal = true;
  354. this.initForm();
  355. }
  356. //关闭新增/编辑弹框
  357. hideAddModal() {
  358. this.modal = false;
  359. this.initForm();
  360. }
  361. // 初始化新增form表单
  362. initForm() {
  363. this.createUser = this.userInfo.user.name ? this.userInfo.user.name : "";
  364. this.validateForm = this.fb.group({
  365. roundRobinName: [null, [Validators.required]],
  366. roundRobinType: [null, [Validators.required]],
  367. startDepartmentHospital: [null, [Validators.required]],
  368. startDepartment: [null, [Validators.required]],
  369. endDepartmentHospital: [null, [Validators.required]],
  370. endDepartment: [null, [Validators.required]],
  371. });
  372. this.validateForm.controls.roundRobinType.setValue(
  373. this.roundRobinTypes[0] && this.roundRobinTypes[0].id
  374. );
  375. this.timeSelectedValue = [];
  376. }
  377. // 新增/编辑表单提交
  378. submitForm(): void {
  379. this.btnLoading = true;
  380. for (const i in this.validateForm.controls) {
  381. this.validateForm.controls[i].markAsDirty();
  382. this.validateForm.controls[i].updateValueAndValidity();
  383. }
  384. if (this.validateForm.invalid) {
  385. this.btnLoading = false;
  386. return;
  387. }
  388. let data = {};
  389. if (this.add) {
  390. //新增
  391. data = {
  392. quickOrder: {
  393. title: this.validateForm.value.roundRobinName,
  394. hospital: this.hosId,
  395. startDept: this.validateForm.value.startDepartment,
  396. taskType: this.roundRobinTypes[0].id,
  397. targetDept: this.validateForm.value.endDepartment.join(),
  398. },
  399. };
  400. } else {
  401. //编辑
  402. data = {
  403. quickOrder: {
  404. id: this.coopId,
  405. title: this.validateForm.value.roundRobinName,
  406. hospital: this.hosId,
  407. startDept: this.validateForm.value.startDepartment,
  408. taskType: this.roundRobinTypes[0].id,
  409. targetDept: this.validateForm.value.endDepartment.join(),
  410. },
  411. };
  412. }
  413. this.mainService
  414. .addShortcutBuildOrders(this.add ? "addData" : "updData", data)
  415. .subscribe((data) => {
  416. this.btnLoading = false;
  417. this.hideAddModal();
  418. this.initForm();
  419. if (data.status == 200) {
  420. this.listLength++;
  421. this.showPromptModal(this.add ? "新增" : "修改", true, "");
  422. } else {
  423. this.showPromptModal(this.add ? "新增" : "修改", false, data.msg);
  424. }
  425. });
  426. }
  427. // 编辑
  428. maskFlag: any = false;
  429. edit(e, data) {
  430. e.stopPropagation();
  431. this.add = false;
  432. this.coopId = data.id;
  433. this.createUser = data.createUserName; //创建人
  434. this.validateForm.controls.roundRobinName.setValue(data.title); //名称
  435. this.validateForm.controls.startDepartmentHospital.setValue(data.startDeptHosId.toString());//起点科室院区
  436. this.validateForm.controls.endDepartmentHospital.setValue(data.targetDeptHosId.toString());//终点科室院区
  437. let taskType$ = this.mainService.getFetchDataList(
  438. "configuration",
  439. "taskType",
  440. {
  441. taskType: {
  442. hosId: { id: data.hospital },
  443. associationType: { id: 380 },
  444. },
  445. idx: 0,
  446. sum: 100,
  447. }
  448. );
  449. // --------起点科室---
  450. let startDeptArr = []; //临时起点科室数组
  451. let startDept = data.startDept; //科室id
  452. let startDeptShow = data.startDeptShow; //科室名称
  453. startDeptArr.push({ id: startDept, dept: startDeptShow });
  454. let startDept$ = this.mainService.getFetchDataList("data", "department", {
  455. department: {
  456. hospital: { id: data.startDeptHosId },
  457. type: { id: 383 }, //科室类型为中转科室
  458. },
  459. idx: 0,
  460. sum: 20,
  461. });
  462. // --------/起点科室---
  463. // --------终点科室---
  464. let targetDeptArr = []; //临时终点科室数组
  465. let targetDept = data.targetDept.split(","); //科室id
  466. let targetDeptShow = data.targetDeptShow.split(","); //科室名称
  467. targetDept.forEach((item, index) => {
  468. targetDeptArr.push({ id: item, dept: targetDeptShow[index] });
  469. });
  470. let targetDept$ = this.mainService.getFetchDataList("data", "department", {
  471. department: {
  472. hospital: { id: data.targetDeptHosId },
  473. type: { id: 282 },
  474. },
  475. idx: 0,
  476. sum: 20,
  477. });
  478. // --------/终点科室---
  479. this.maskFlag = this.message.loading("正在加载中..", {
  480. nzDuration: 0,
  481. }).messageId;
  482. forkJoin(taskType$, startDept$, targetDept$).subscribe((res) => {
  483. this.message.remove(this.maskFlag);
  484. this.maskFlag = false;
  485. this.modal = true;
  486. // 任务类型
  487. if (res[0]["status"] == 200) {
  488. this.roundRobinTypes = res[0]["list"].map((item) => {
  489. return { id: item.id + "", hosName: item.taskName };
  490. });
  491. this.validateForm.controls.roundRobinType.setValue(
  492. this.roundRobinTypes[0].id
  493. ); //快捷建单类型
  494. }
  495. //起点科室
  496. if (res[1]["status"] == 200) {
  497. let add = startDeptArr.filter(
  498. (item) => !res[1]["list"].some((ele) => ele.id == item.id)
  499. ); //过滤掉已有的选项
  500. this.department = add.concat(res[1]["list"]); //拼接数组
  501. this.validateForm.controls.startDepartment.setValue(
  502. data.startDept + ""
  503. ); //起点科室
  504. }
  505. //终点科室
  506. if (res[2]["status"] == 200) {
  507. let add = targetDeptArr.filter(
  508. (item) => !res[2]["list"].some((ele) => ele.id == item.id)
  509. ); //过滤掉已有的选项
  510. this.department1 = add.concat(res[2]["list"]); //拼接数组
  511. this.validateForm.controls.endDepartment.setValue(targetDept); //终点科室
  512. }
  513. });
  514. }
  515. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  516. showPromptModal(con, success, promptInfo?) {
  517. this.promptModalShow = false;
  518. this.promptContent = con;
  519. this.ifSuccess = success;
  520. this.promptInfo = promptInfo;
  521. setTimeout(() => {
  522. this.promptModalShow = true;
  523. }, 100);
  524. this.getList(0);
  525. }
  526. // 删除快捷建单
  527. delModal: boolean = false; //删除模态框
  528. tipsMsg1: string; //提示框信息
  529. tipsMsg2: string; //操作后信息
  530. confirmDelType: string; //确认的类型(启用/停用,删除)
  531. confirmDelIsSwitch: boolean; //启用/停用
  532. showDelModal(
  533. e,
  534. id: number,
  535. tipsMsg1: string,
  536. tipsMsg2: string,
  537. type: string,
  538. isSwitch?: boolean
  539. ) {
  540. e.stopPropagation();
  541. this.confirmDelIsSwitch = isSwitch;
  542. this.confirmDelType = type;
  543. this.delModal = true;
  544. this.coopId = id;
  545. this.tipsMsg1 = tipsMsg1;
  546. this.tipsMsg2 = tipsMsg2;
  547. }
  548. // 隐藏删除框
  549. hideDelModal() {
  550. this.delModal = false;
  551. }
  552. // 确认删除
  553. confirmDel() {
  554. this.btnLoading = true;
  555. if (this.confirmDelType === "del") {
  556. //删除
  557. this.mainService.delShortcutBuildOrders(this.coopId).subscribe((data) => {
  558. this.btnLoading = false;
  559. this.delModal = false;
  560. if (data.status == 200) {
  561. if (
  562. this.listOfData.length == 1 &&
  563. this.pageIndex == Math.ceil(this.listLength / this.pageSize)
  564. ) {
  565. this.listLength--;
  566. if (this.listLength === 0) {
  567. this.pageIndex = 1;
  568. } else {
  569. this.pageIndex = Math.ceil(this.listLength / this.pageSize);
  570. }
  571. }
  572. this.showPromptModal(this.tipsMsg2, true, "");
  573. } else {
  574. this.showPromptModal(this.tipsMsg2, false, data.msg);
  575. }
  576. });
  577. } else if (this.confirmDelType === "switch") {
  578. //启用/停用
  579. this.mainService
  580. .switchRoundRobin(
  581. this.confirmDelIsSwitch ? "stop" : "active",
  582. this.coopId
  583. )
  584. .subscribe((data) => {
  585. this.btnLoading = false;
  586. this.delModal = false;
  587. if (data.status == 200) {
  588. this.showPromptModal(this.tipsMsg2, true, "");
  589. } else {
  590. this.showPromptModal(this.tipsMsg2, false, data.msg);
  591. }
  592. });
  593. }
  594. }
  595. // 院区列表
  596. getHospitalList() {
  597. this.hospitalList = [this.tool.getCurrentHospital()];
  598. }
  599. // 查看
  600. detail(e, id) {
  601. e.stopPropagation();
  602. this.router.navigateByUrl(
  603. "/main/shortcutBuildOrders/shortcutBuildOrdersDetail/" + id
  604. );
  605. }
  606. //时间选择框相关
  607. timeSelectedValue = [];
  608. defaultSelectTimesOption = [];
  609. time: Date | null = null;
  610. defaultTimePickerOpenValue = new Date();
  611. timePickerOpen = false;
  612. timeSelectFocus() {
  613. this.timePickerOpen = true;
  614. }
  615. timePickerClick() {
  616. this.timePickerOpen = false;
  617. this.time = this.time || new Date();
  618. let hour = (this.time.getHours() + "").padStart(2, "0");
  619. let minute = (this.time.getMinutes() + "").padStart(2, "0");
  620. let str = `${hour}:${minute}`;
  621. if (!this.timeSelectedValue.includes(str)) {
  622. this.defaultSelectTimesOption.push(str);
  623. this.timeSelectedValue.push(str);
  624. }
  625. }
  626. timePickerChange() {
  627. if (this.timePickerOpen) {
  628. this.timePickerOpen = false;
  629. }
  630. }
  631. }