distribution-department-source-statistics.component.ts 9.0 KB

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