group-statistics.component.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. import { TabService } from './../../services/tab.service';
  2. import { NzMessageService } from 'ng-zorro-antd/message';
  3. import { Component, OnInit, HostListener, AfterViewInit, ViewChild } from "@angular/core";
  4. import { MainService } from 'src/app/services/main.service';
  5. import { ActivatedRoute, Router } from '@angular/router';
  6. import { CustomChangeDateComponent } from '../../components/custom-change-date/custom-change-date.component';
  7. @Component({
  8. selector: "app-group-statistics",
  9. templateUrl: "./group-statistics.component.html",
  10. styleUrls: ["./group-statistics.component.less"],
  11. })
  12. export class GroupStatisticsComponent implements OnInit, AfterViewInit {
  13. @ViewChild('customChangeDate', { static: false }) customChangeDateComponent!: CustomChangeDateComponent;
  14. constructor(
  15. private mainService: MainService,
  16. private message: NzMessageService,
  17. private route: ActivatedRoute,
  18. private router: Router,
  19. private tabService: TabService,
  20. ) {}
  21. listOfData: any[] = []; //表格数据
  22. listOfDataEnd: any[] = []; //表格合计
  23. pageIndex: number = 1; //表格当前页码
  24. pageSize: number = 30; //表格每页展示条数
  25. listLength: number = 0; //表格总数据量
  26. ngOnInit() {}
  27. ngAfterViewInit(){
  28. this.initSessionData();
  29. this.getQueryParams();
  30. setTimeout(() => {
  31. this.search();
  32. }, 0)
  33. this.onResize();
  34. }
  35. tableHeight:number = 0;
  36. @HostListener('window:resize')
  37. onResize(): void {
  38. setTimeout(() => {
  39. 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;
  40. }, 0)
  41. }
  42. // 数据下钻
  43. viewDetail1(data, type){
  44. let query = null
  45. if(type=='all'){
  46. query = {
  47. startDate: this.customChangeDateComponent.startDate || undefined,
  48. endDate: this.customChangeDateComponent.endDate || undefined,
  49. searchQuery:{
  50. statusValue: 'close',
  51. }
  52. }
  53. }else{
  54. query = {
  55. startDate: this.customChangeDateComponent.startDate || undefined,
  56. endDate: this.customChangeDateComponent.endDate || undefined,
  57. searchQuery:{
  58. statusValue: 'close',
  59. groupId: data.groupId ? data.groupId : -1,
  60. categoryId: this.fieldConfig.fields.categoryId || undefined,
  61. hierarchy: this.fieldConfig.fields.hierarchy || undefined,
  62. buildingId: this.fieldConfig.fields.buildingId || undefined,
  63. floorId: this.fieldConfig.fields.floorId || undefined,
  64. }
  65. }
  66. }
  67. sessionStorage.setItem('maintenanceData',JSON.stringify(query))
  68. this.router.navigateByUrl('/newStatistics/maintenanceStatistics/incidentList')
  69. }
  70. // 数据下钻
  71. viewDetail2(data, type){
  72. let query = null
  73. if(type=='all'){
  74. query = {
  75. startDate: this.customChangeDateComponent.startDate || undefined,
  76. endDate: this.customChangeDateComponent.endDate || undefined,
  77. searchQuery:{
  78. statusValue: 'close',
  79. overtimeId: 1,
  80. }
  81. }
  82. }else{
  83. query = {
  84. startDate: this.customChangeDateComponent.startDate || undefined,
  85. endDate: this.customChangeDateComponent.endDate || undefined,
  86. searchQuery:{
  87. statusValue: 'close',
  88. groupId: data.groupId ? data.groupId : -1,
  89. overtimeId: 1,
  90. categoryId: this.fieldConfig.fields.categoryId || undefined,
  91. hierarchy: this.fieldConfig.fields.hierarchy || undefined,
  92. buildingId: this.fieldConfig.fields.buildingId || undefined,
  93. floorId: this.fieldConfig.fields.floorId || undefined,
  94. }
  95. }
  96. }
  97. sessionStorage.setItem('maintenanceData',JSON.stringify(query))
  98. this.router.navigateByUrl('/newStatistics/maintenanceStatistics/incidentList')
  99. }
  100. // 数据下钻
  101. viewDetail3(data, type){
  102. let query = null
  103. if(type=='all'){
  104. query = {
  105. startDate: this.customChangeDateComponent.startDate || undefined,
  106. endDate: this.customChangeDateComponent.endDate || undefined,
  107. searchQuery:{
  108. statusValue: 'close',
  109. isHangId: 1,
  110. }
  111. }
  112. }else{
  113. query = {
  114. startDate: this.customChangeDateComponent.startDate || undefined,
  115. endDate: this.customChangeDateComponent.endDate || undefined,
  116. searchQuery:{
  117. statusValue: 'close',
  118. groupId: data.groupId ? data.groupId : -1,
  119. isHangId: 1,
  120. categoryId: this.fieldConfig.fields.categoryId || undefined,
  121. hierarchy: this.fieldConfig.fields.hierarchy || undefined,
  122. buildingId: this.fieldConfig.fields.buildingId || undefined,
  123. floorId: this.fieldConfig.fields.floorId || undefined,
  124. }
  125. }
  126. }
  127. sessionStorage.setItem('maintenanceData',JSON.stringify(query))
  128. this.router.navigateByUrl('/newStatistics/maintenanceStatistics/incidentList')
  129. }
  130. // 数据下钻
  131. viewDetail4(data, type){
  132. let query = null
  133. if(type=='all'){
  134. query = {
  135. startDate: this.customChangeDateComponent.startDate || undefined,
  136. endDate: this.customChangeDateComponent.endDate || undefined,
  137. searchQuery:{
  138. statusValue: 'close',
  139. evaluateId: 20424,
  140. }
  141. }
  142. }else{
  143. query = {
  144. startDate: this.customChangeDateComponent.startDate || undefined,
  145. endDate: this.customChangeDateComponent.endDate || undefined,
  146. searchQuery:{
  147. statusValue: 'close',
  148. groupId: data.groupId ? data.groupId : -1,
  149. evaluateId: 20424,
  150. categoryId: this.fieldConfig.fields.categoryId || undefined,
  151. hierarchy: this.fieldConfig.fields.hierarchy || undefined,
  152. buildingId: this.fieldConfig.fields.buildingId || undefined,
  153. floorId: this.fieldConfig.fields.floorId || undefined,
  154. }
  155. }
  156. }
  157. sessionStorage.setItem('maintenanceData',JSON.stringify(query))
  158. this.router.navigateByUrl('/newStatistics/maintenanceStatistics/incidentList')
  159. }
  160. getQueryParams(){
  161. let queryParams = this.tabService.getQueryParams();
  162. this.tabService.clearQueryParams();
  163. if(queryParams.dateRange){
  164. this.dateRange = queryParams.dateRange;
  165. this.customChangeDateComponent.initByDate(this.dateRange);
  166. }
  167. }
  168. get getMoreFilter(){
  169. let flag = this.fieldConfig.fields.category1DTO || this.fieldConfig.fields.category2DTO || this.fieldConfig.fields.category3DTO || this.fieldConfig.fields.buildingDTO || this.fieldConfig.fields.floorDTO;
  170. return flag ? 37 : 0;
  171. }
  172. // 初始化缓存数据
  173. queryType:any;
  174. hosId:any;
  175. dutyId:any;
  176. parentDutyId:any;
  177. initSessionData(){
  178. let newStatistics = JSON.parse(sessionStorage.getItem('newStatistics'));
  179. let queryType:any = newStatistics.queryType;
  180. let hosId:any = newStatistics.hospitalId;
  181. let dutyId:any = newStatistics.dutyId;
  182. queryType = queryType ? +queryType : undefined;
  183. hosId = hosId ? +hosId : undefined;
  184. dutyId = dutyId ? +dutyId : undefined;
  185. this.queryType = queryType;
  186. if(queryType == 1){
  187. this.hosId = undefined;
  188. this.dutyId = undefined;
  189. this.parentDutyId = undefined;
  190. }else if(queryType == 2){
  191. this.hosId = hosId;
  192. this.dutyId = undefined;
  193. this.parentDutyId = undefined;
  194. }else if(queryType == 3){
  195. this.hosId = undefined;
  196. this.dutyId = dutyId;
  197. this.parentDutyId = undefined;
  198. }else if(queryType == 4){
  199. this.hosId = undefined;
  200. this.dutyId = undefined;
  201. this.parentDutyId = dutyId;
  202. }
  203. }
  204. get getHosId(){
  205. return this.parentDutyId || this.dutyId || this.hosId;
  206. }
  207. // 表格数据
  208. loading1 = false;
  209. getList(num?: number, field?: string, sort?: string) {
  210. if (num !== undefined) {
  211. this.pageIndex = num;
  212. }
  213. let postData:any = {
  214. idx: this.pageIndex - 1,
  215. sum: this.pageSize,
  216. startDate: this.customChangeDateComponent.startDate || undefined,
  217. endDate: this.customChangeDateComponent.endDate || undefined,
  218. hosId: this.hosId || undefined,
  219. dutyId: this.dutyId || undefined,
  220. parentDutyId: this.parentDutyId || undefined,
  221. categoryId: this.fieldConfig.fields.categoryId || undefined,
  222. hierarchy: this.fieldConfig.fields.hierarchy || undefined,
  223. buildingId: this.fieldConfig.fields.buildingId || undefined,
  224. placeId: this.fieldConfig.fields.floorId || undefined,
  225. };
  226. if (field && sort) {
  227. postData.sort = `${field} ${sort === "ascend" ? `asc` : `desc`}`
  228. }
  229. this.loading1 = true;
  230. this.mainService
  231. .postCustom("itsm/report", "repairGroup", postData)
  232. .subscribe((result) => {
  233. this.loading1 = false;
  234. this.listOfData = result.dataList.filter((v, i) => { return i != result.dataList.length - 1 });
  235. this.listOfDataEnd = result.dataList.filter((v, i) => { return i == result.dataList.length - 1 });
  236. this.listLength = result.totalCount;
  237. });
  238. }
  239. // 列表排序
  240. sortCurrent:any = {};
  241. sortCurrentKey: string = "";
  242. sortCurrentValue: string | null = "";
  243. sort(e) {
  244. const { key, value } = e;
  245. this.sortCurrentKey = key;
  246. this.sortCurrentValue = value;
  247. this.getList(this.pageIndex, this.sortCurrentKey, this.sortCurrentValue);
  248. }
  249. // 搜索
  250. search() {
  251. this.getList(1, this.sortCurrentKey, this.sortCurrentValue);
  252. }
  253. // 日期选择
  254. dateRange: any = [];
  255. // 导出
  256. excelExportLoading:any = false;
  257. excelExport(){
  258. this.excelExportLoading = this.message.loading("导出中..", {
  259. nzDuration: 0,
  260. }).messageId;
  261. let postData:any = {
  262. startDate: this.customChangeDateComponent.startDate || undefined,
  263. endDate: this.customChangeDateComponent.endDate || undefined,
  264. hosId: this.hosId || undefined,
  265. dutyId: this.dutyId || undefined,
  266. parentDutyId: this.parentDutyId || undefined,
  267. categoryId: this.fieldConfig.fields.categoryId || undefined,
  268. hierarchy: this.fieldConfig.fields.hierarchy || undefined,
  269. buildingId: this.fieldConfig.fields.buildingId || undefined,
  270. placeId: this.fieldConfig.fields.floorId || undefined,
  271. };
  272. if (this.sortCurrentKey && this.sortCurrentValue) {
  273. postData.sort = `${this.sortCurrentKey} ${this.sortCurrentValue === "ascend" ? `asc` : `desc`}`
  274. }
  275. this.mainService
  276. .postExportCustom("itsm/export", "repairGroup", postData)
  277. .subscribe((data) => {
  278. this.message.remove(this.excelExportLoading);
  279. this.excelExportLoading = false;
  280. this.message.success('导出成功');
  281. var file = new Blob([data], {
  282. type: "application/vnd.ms-excel",
  283. });
  284. //trick to download store a file having its URL
  285. var fileURL = URL.createObjectURL(file);
  286. var a = document.createElement("a");
  287. a.href = fileURL;
  288. a.target = "_blank";
  289. a.download = `${this.route.parent.routeConfig.data.title}.xls`;
  290. document.body.appendChild(a);
  291. a.click();
  292. },(err) => {
  293. this.message.remove(this.excelExportLoading);
  294. this.excelExportLoading = false;
  295. this.message.error('导出失败');
  296. });
  297. }
  298. // 重置
  299. reset(){
  300. this.sortCurrentKey = "";
  301. this.sortCurrentValue = "";
  302. this.sortCurrent = {};
  303. this.dateRange = []
  304. this.fieldConfig.fields = {categoryId: undefined, buildingId: undefined, floorId: undefined};
  305. this.customChangeDateComponent.resetByDate();
  306. this.search();
  307. }
  308. // 防抖
  309. isLoading = false;
  310. // 详细搜索
  311. fieldConfig:any = {
  312. fields: {categoryId: undefined, buildingId: undefined, floorId: undefined},
  313. config: {category123: true, buildingAndFloor: true},
  314. }
  315. showSearchMore:boolean = false;
  316. showMore(){
  317. this.showSearchMore = true;
  318. }
  319. cancelEvent(){
  320. this.showSearchMore = false;
  321. }
  322. submitEvent(fields){
  323. this.showSearchMore = false;
  324. this.fieldConfig.fields = fields;
  325. console.log('this.fieldConfig.fields:', this.fieldConfig.fields)
  326. this.search();
  327. this.onResize();
  328. }
  329. }