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

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