inspection-distance.component.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import { Component, OnInit } from "@angular/core";
  2. import { ActivatedRoute } from "@angular/router";
  3. import { NzMessageService } from "ng-zorro-antd";
  4. import { MainService } from "src/app/services/main.service";
  5. import { ToolService } from "src/app/services/tool.service";
  6. @Component({
  7. selector: "app-inspection-distance",
  8. templateUrl: "./inspection-distance.component.html",
  9. styleUrls: ["./inspection-distance.component.less"],
  10. })
  11. export class InspectionDistanceComponent implements OnInit {
  12. coopBtns: any = {};
  13. id: number = 0; //id
  14. hosId; //当前院区id
  15. buildings = []; //所有楼栋距离组合
  16. loading2: boolean = false; //获取所有楼栋配置的loading
  17. loading3: boolean = false; //保存所有楼栋配置的loading
  18. loading4: boolean = false; //删除楼栋配置的loading
  19. delModal: boolean = false; //删除的模态框
  20. delObj; //要删除的元素
  21. constructor(
  22. private route: ActivatedRoute,
  23. private mainService: MainService,
  24. private tool: ToolService,
  25. private message: NzMessageService
  26. ) {}
  27. ngOnInit() {
  28. this.hosId = this.tool.getCurrentHospital().id;
  29. this.coopBtns = this.tool.initCoopBtns(this.route);
  30. this.getBuildingConfig(this.hosId);
  31. }
  32. //获取楼栋距离配置
  33. getBuildingConfig(hosId) {
  34. let postData = { idx: 0, sum: 9999, workOrderInspectScore: { hosId } };
  35. this.loading2 = true;
  36. this.mainService
  37. .getFetchDataList("simple/data", "workOrderInspectScore", postData)
  38. .subscribe((result) => {
  39. this.loading2 = false;
  40. if (result.status == 200) {
  41. this.buildings = result.list.map((item) => {
  42. return {
  43. id: item.id,
  44. inspectMode: item.inspectMode,
  45. increaseScore: item.increaseScore,
  46. border: "none",
  47. };
  48. });
  49. } else {
  50. this.message.error("请求数据失败");
  51. }
  52. });
  53. }
  54. //新增
  55. addBuilding() {
  56. this.buildings.push({
  57. id: --this.id,
  58. inspectMode: '',
  59. buildingStart: null,
  60. buildingEnd: null,
  61. increaseScore: 0,
  62. border: "none",
  63. });
  64. }
  65. // 删除
  66. delete(obj) {
  67. this.delModal = true;
  68. this.delObj = obj;
  69. }
  70. //隐藏删除模态框
  71. hideDelModal() {
  72. this.delModal = false;
  73. }
  74. // 确定删除
  75. confirmDel() {
  76. this.loading4 = true;
  77. this.mainService.delBuildings([this.delObj.id]).subscribe((result) => {
  78. this.loading4 = false;
  79. if (result["status"] == 200) {
  80. this.message.success("删除成功");
  81. this.buildings = this.buildings.filter(
  82. (item) => item.id !== this.delObj.id
  83. );
  84. } else {
  85. this.message.error("删除失败");
  86. }
  87. this.hideDelModal();
  88. });
  89. }
  90. //保存
  91. save() {
  92. this.buildings = this.buildings.filter(
  93. (item) => item.inspectMode && (item.increaseScore || item.increaseScore === 0)
  94. );
  95. let postData = this.buildings.map((item) => {
  96. return {
  97. id: item.id,
  98. inspectMode: item.inspectMode,
  99. increaseScore: item.increaseScore,
  100. hosId: this.hosId,
  101. };
  102. });
  103. postData.forEach((item) => {
  104. if (item.id < 0) {
  105. delete item.id;
  106. }
  107. });
  108. this.loading3 = true;
  109. this.mainService.saveInspections(postData).subscribe((result) => {
  110. this.loading3 = false;
  111. if (result["status"] == 200) {
  112. this.message.success("保存成功");
  113. this.getBuildingConfig(this.hosId);
  114. } else {
  115. this.message.error("保存失败");
  116. result["data"].forEach((item) => {
  117. let i = this.buildings.findIndex((v) => v.id === item.id);
  118. this.buildings[i].border = "red";
  119. });
  120. }
  121. });
  122. }
  123. //trackBy
  124. trackById(index, item) {
  125. return item.id;
  126. }
  127. }