floor-statistics.component.ts 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. import { TabService } from './../../services/tab.service';
  2. import { debounceTime } from 'rxjs/operators';
  3. import { Subject } from 'rxjs';
  4. import { NzMessageService } from 'ng-zorro-antd/message';
  5. import { Component, OnInit, HostListener, AfterViewInit, ViewChild } from "@angular/core";
  6. import { MainService } from 'src/app/services/main.service';
  7. import { ActivatedRoute } from '@angular/router';
  8. import { CustomChangeDateComponent } from '../../components/custom-change-date/custom-change-date.component';
  9. @Component({
  10. selector: "app-floor-statistics",
  11. templateUrl: "./floor-statistics.component.html",
  12. styleUrls: ["./floor-statistics.component.less"],
  13. })
  14. export class FloorStatisticsComponent implements OnInit, AfterViewInit {
  15. @ViewChild('customChangeDate', { static: false }) customChangeDateComponent!: CustomChangeDateComponent;
  16. constructor(
  17. private mainService: MainService,
  18. private message: NzMessageService,
  19. private route: ActivatedRoute,
  20. private tabService: TabService,
  21. ) {}
  22. listOfData: any[] = []; //表格数据
  23. listOfDataEnd: any[] = []; //表格合计
  24. pageIndex: number = 1; //表格当前页码
  25. pageSize: number = 30; //表格每页展示条数
  26. listLength: number = 0; //表格总数据量
  27. buildingId;//楼栋id
  28. searchTimerSubject = new Subject();
  29. ngOnInit() {
  30. this.searchTimerSubject.pipe(debounceTime(500)).subscribe((v) => {
  31. let fun = v[0];
  32. fun.call(this, v[1]);
  33. });
  34. }
  35. ngAfterViewInit(){
  36. this.initSessionData();
  37. this.getQueryParams();
  38. setTimeout(() => {
  39. this.search();
  40. }, 0)
  41. this.onResize();
  42. }
  43. tableHeight:number = 0;
  44. @HostListener('window:resize')
  45. onResize(): void {
  46. setTimeout(() => {
  47. this.tableHeight = window.innerHeight - (document.querySelector('.searchDataWrap') as HTMLElement).offsetHeight - 64 - 36 - 48 - 8 - (document.querySelector('.ant-table-header') as HTMLElement).offsetHeight - 55 - this.getMoreFilter + 14;
  48. }, 0)
  49. }
  50. getQueryParams(){
  51. let queryParams = this.tabService.getQueryParams();
  52. this.tabService.clearQueryParams();
  53. if(queryParams.dateRange){
  54. this.dateRange = queryParams.dateRange;
  55. this.customChangeDateComponent.initByDate(this.dateRange);
  56. }
  57. }
  58. get getMoreFilter(){
  59. let flag = this.fieldConfig.fields.category1DTO || this.fieldConfig.fields.category2DTO || this.fieldConfig.fields.category3DTO;
  60. return flag ? 37 : 0;
  61. }
  62. // 初始化缓存数据
  63. queryType:any;
  64. hosId:any;
  65. dutyId:any;
  66. parentDutyId:any;
  67. initSessionData(){
  68. let newStatistics = JSON.parse(sessionStorage.getItem('newStatistics'));
  69. let queryType:any = newStatistics.queryType;
  70. let hosId:any = newStatistics.hospitalId;
  71. let dutyId:any = newStatistics.dutyId;
  72. queryType = queryType ? +queryType : undefined;
  73. hosId = hosId ? +hosId : undefined;
  74. dutyId = dutyId ? +dutyId : undefined;
  75. this.queryType = queryType;
  76. if(queryType == 1){
  77. this.hosId = undefined;
  78. this.dutyId = undefined;
  79. this.parentDutyId = undefined;
  80. }else if(queryType == 2){
  81. this.hosId = hosId;
  82. this.dutyId = undefined;
  83. this.parentDutyId = undefined;
  84. }else if(queryType == 3){
  85. this.hosId = undefined;
  86. this.dutyId = dutyId;
  87. this.parentDutyId = undefined;
  88. }else if(queryType == 4){
  89. this.hosId = undefined;
  90. this.dutyId = undefined;
  91. this.parentDutyId = dutyId;
  92. }
  93. }
  94. get getHosId(){
  95. return this.parentDutyId || this.dutyId || this.hosId;
  96. }
  97. // 表格数据
  98. loading1 = false;
  99. getList(num?: number, field?: string, sort?: string) {
  100. if (num !== undefined) {
  101. this.pageIndex = num;
  102. }
  103. let postData:any = {
  104. idx: this.pageIndex - 1,
  105. sum: this.pageSize,
  106. startDate: this.customChangeDateComponent.startDate || undefined,
  107. endDate: this.customChangeDateComponent.endDate || undefined,
  108. hosId: this.hosId || undefined,
  109. dutyId: this.dutyId || undefined,
  110. parentDutyId: this.parentDutyId || undefined,
  111. buildingId: this.buildingId || undefined,
  112. categoryId: this.fieldConfig.fields.categoryId || undefined,
  113. hierarchy: this.fieldConfig.fields.hierarchy || undefined,
  114. };
  115. if (field && sort) {
  116. postData.sort = `${field} ${sort === "ascend" ? `asc` : `desc`}`
  117. }
  118. this.loading1 = true;
  119. this.mainService
  120. .postCustom("itsm/report", "floorIncident", postData)
  121. .subscribe((result) => {
  122. this.loading1 = false;
  123. this.listOfData = result.dataList.filter((v, i) => { return i != result.dataList.length - 1 });
  124. this.listOfDataEnd = result.dataList.filter((v, i) => { return i == result.dataList.length - 1 });
  125. this.listLength = result.totalCount;
  126. });
  127. }
  128. // 列表排序
  129. sortCurrent:any = {};
  130. sortCurrentKey: string = "";
  131. sortCurrentValue: string | null = "";
  132. sort(e) {
  133. const { key, value } = e;
  134. this.sortCurrentKey = key;
  135. this.sortCurrentValue = value;
  136. this.getList(this.pageIndex, this.sortCurrentKey, this.sortCurrentValue);
  137. }
  138. // 搜索
  139. search() {
  140. this.getList(1, this.sortCurrentKey, this.sortCurrentValue);
  141. }
  142. // 日期选择
  143. dateRange: any = [];
  144. // 导出
  145. excelExportLoading:any = false;
  146. excelExport(){
  147. this.excelExportLoading = this.message.loading("导出中..", {
  148. nzDuration: 0,
  149. }).messageId;
  150. let postData:any = {
  151. startDate: this.customChangeDateComponent.startDate || undefined,
  152. endDate: this.customChangeDateComponent.endDate || undefined,
  153. hosId: this.hosId || undefined,
  154. dutyId: this.dutyId || undefined,
  155. parentDutyId: this.parentDutyId || undefined,
  156. buildingId: this.buildingId || undefined,
  157. categoryId: this.fieldConfig.fields.categoryId || undefined,
  158. hierarchy: this.fieldConfig.fields.hierarchy || undefined,
  159. };
  160. if (this.sortCurrentKey && this.sortCurrentValue) {
  161. postData.sort = `${this.sortCurrentKey} ${this.sortCurrentValue === "ascend" ? `asc` : `desc`}`
  162. }
  163. this.mainService
  164. .postExportCustom("itsm/export", "floorIncident", postData)
  165. .subscribe((data) => {
  166. this.message.remove(this.excelExportLoading);
  167. this.excelExportLoading = false;
  168. this.message.success('导出成功');
  169. var file = new Blob([data], {
  170. type: "application/vnd.ms-excel",
  171. });
  172. //trick to download store a file having its URL
  173. var fileURL = URL.createObjectURL(file);
  174. var a = document.createElement("a");
  175. a.href = fileURL;
  176. a.target = "_blank";
  177. a.download = `${this.route.parent.routeConfig.data.title}.xls`;
  178. document.body.appendChild(a);
  179. a.click();
  180. },(err) => {
  181. this.message.remove(this.excelExportLoading);
  182. this.excelExportLoading = false;
  183. this.message.error('导出失败');
  184. });
  185. }
  186. // 重置
  187. reset(){
  188. this.sortCurrentKey = "";
  189. this.sortCurrentValue = "";
  190. this.sortCurrent = {};
  191. this.dateRange = []
  192. this.buildingId = undefined;
  193. this.fieldConfig.fields = {categoryId: undefined};
  194. this.customChangeDateComponent.resetByDate();
  195. this.search();
  196. }
  197. // 楼栋搜索
  198. changeBuildingInp(e) {
  199. this.searchTimer(this.getBuildingList, e);
  200. }
  201. // 防抖
  202. isLoading = false;
  203. searchTimer(fun, e) {
  204. this.isLoading = true;
  205. this.searchTimerSubject.next([fun, e]);
  206. }
  207. openChangeBuilding(flag){
  208. flag && this.getBuildingList();
  209. }
  210. // 获取报修科室列表
  211. buildingList:any[] = [];
  212. getBuildingList(keyword?) {
  213. let data = {
  214. building: {
  215. simpleQuery: true,
  216. buildingName: keyword,
  217. statisticalHosId:this.getHosId,
  218. },
  219. idx: 0,
  220. sum: 20,
  221. };
  222. this.isLoading = true;
  223. this.mainService
  224. .getFetchDataList("data", "building", data)
  225. .subscribe((data) => {
  226. this.isLoading = false;
  227. this.buildingList = data.list;
  228. });
  229. }
  230. // 详细搜索
  231. fieldConfig:any = {
  232. fields: {categoryId: undefined},
  233. config: {category123: true},
  234. }
  235. showSearchMore:boolean = false;
  236. showMore(){
  237. this.showSearchMore = true;
  238. }
  239. cancelEvent(){
  240. this.showSearchMore = false;
  241. }
  242. submitEvent(fields){
  243. this.showSearchMore = false;
  244. this.fieldConfig.fields = fields;
  245. console.log('this.fieldConfig.fields:', this.fieldConfig.fields)
  246. this.search();
  247. this.onResize();
  248. }
  249. }