date-business-statistics.component.ts 14 KB

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