user-business-statistics.component.ts 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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-user-business-statistics",
  11. templateUrl: "./user-business-statistics.component.html",
  12. styleUrls: ["./user-business-statistics.component.less"],
  13. })
  14. export class UserBusinessStatisticsComponent 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. widthConfig: any[] = [];
  27. groupId;//分组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. this.initSessionData();
  35. this.getQueryParams();
  36. this.search();
  37. }
  38. ngAfterViewInit(){
  39. this.onResize();
  40. }
  41. tableHeight:number = 0;
  42. @HostListener('window:resize')
  43. onResize(): void {
  44. setTimeout(() => {
  45. 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;
  46. }, 0)
  47. }
  48. getQueryParams(){
  49. let queryParams = this.tabService.getQueryParams();
  50. this.tabService.clearQueryParams();
  51. if(queryParams.dateRange){
  52. this.dateRange = queryParams.dateRange;
  53. }
  54. }
  55. get getMoreFilter(){
  56. let flag = this.fieldConfig.fields.buildingDTO || this.fieldConfig.fields.deptDTO;
  57. return flag ? 37 : 0;
  58. }
  59. // 初始化缓存数据
  60. queryType:any;
  61. hosId:any;
  62. dutyId:any;
  63. parentDutyId:any;
  64. initSessionData(){
  65. let newStatistics = JSON.parse(sessionStorage.getItem('newStatistics'));
  66. let queryType:any = newStatistics.queryType;
  67. let hosId:any = newStatistics.hospitalId;
  68. let dutyId:any = newStatistics.dutyId;
  69. queryType = queryType ? +queryType : undefined;
  70. hosId = hosId ? +hosId : undefined;
  71. dutyId = dutyId ? +dutyId : undefined;
  72. this.queryType = queryType;
  73. if(queryType == 1){
  74. this.hosId = undefined;
  75. this.dutyId = undefined;
  76. this.parentDutyId = undefined;
  77. }else if(queryType == 2){
  78. this.hosId = hosId;
  79. this.dutyId = undefined;
  80. this.parentDutyId = undefined;
  81. }else if(queryType == 3){
  82. this.hosId = undefined;
  83. this.dutyId = dutyId;
  84. this.parentDutyId = undefined;
  85. }else if(queryType == 4){
  86. this.hosId = undefined;
  87. this.dutyId = undefined;
  88. this.parentDutyId = dutyId;
  89. }
  90. }
  91. get getHosId(){
  92. return this.parentDutyId || this.dutyId || this.hosId;
  93. }
  94. // 表格数据
  95. loading1 = false;
  96. dictionaryList: any[] = [];
  97. getList(num?: number, field?: string, sort?: string) {
  98. this.mainService.getDictionary('list', 'statistics_date_type').subscribe((data) => {
  99. let dictionaryList = data || [];
  100. dictionaryList.push({id: 0, name: '其他', value: 'dateOther'});
  101. this.dictionaryList = dictionaryList;
  102. this.widthConfig = new Array(this.dictionaryList.length * 2 + 3).fill('100px').map((v, i) => { return i == 0 ? '150px' : '100px' });
  103. if (num !== undefined) {
  104. this.pageIndex = num;
  105. }
  106. let postData:any = {
  107. idx: this.pageIndex - 1,
  108. sum: this.pageSize,
  109. startDate: this.dateRange[0] || undefined,
  110. endDate: this.dateRange[1] || undefined,
  111. hosId: this.getHosId,
  112. buildingId: this.fieldConfig.fields.buildingId || undefined,
  113. deptId: this.fieldConfig.fields.deptId || undefined,
  114. groupId: this.groupId || undefined,
  115. };
  116. if (field && sort) {
  117. postData.sort = `${field} ${sort === "ascend" ? `asc` : `desc`}`
  118. }
  119. this.loading1 = true;
  120. this.mainService
  121. .postCustom("itsm/report", "userTransOrder", postData)
  122. .subscribe((result) => {
  123. this.loading1 = false;
  124. this.listOfData = result.dataList.filter((v, i) => { return i != result.dataList.length - 1 });
  125. this.listOfDataEnd = result.dataList.filter((v, i) => { return i == result.dataList.length - 1 });
  126. this.listLength = result.totalCount;
  127. });
  128. });
  129. }
  130. // 列表排序
  131. sortCurrent:any = {};
  132. sortCurrentKey: string = "";
  133. sortCurrentValue: string | null = "";
  134. sort(e) {
  135. const { key, value } = e;
  136. this.sortCurrentKey = key;
  137. this.sortCurrentValue = value;
  138. this.getList(this.pageIndex, this.sortCurrentKey, this.sortCurrentValue);
  139. }
  140. // 搜索
  141. search() {
  142. this.getList(1, this.sortCurrentKey, this.sortCurrentValue);
  143. }
  144. // 日期选择
  145. 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')];
  146. changeDate(result?): void {
  147. result[0] = format(startOfDay(result[0]), 'yyyy-MM-dd HH:mm:ss');
  148. result[1] = format(endOfDay(result[1]), 'yyyy-MM-dd HH:mm:ss');
  149. this.dateRange = result;
  150. }
  151. onCalendarChangeDate(dateArr){
  152. console.log(dateArr)
  153. if(dateArr.length == 2){
  154. this.dateRange = [format(startOfDay(dateArr[0]), 'yyyy-MM-dd HH:mm:ss'), format(endOfDay(dateArr[1]), 'yyyy-MM-dd HH:mm:ss')];
  155. }
  156. }
  157. // 导出
  158. excelExportLoading:any = false;
  159. excelExport(){
  160. this.excelExportLoading = this.message.loading("导出中..", {
  161. nzDuration: 0,
  162. }).messageId;
  163. let postData:any = {
  164. startDate: this.dateRange[0] || undefined,
  165. endDate: this.dateRange[1] || undefined,
  166. hosId: this.getHosId,
  167. buildingId: this.fieldConfig.fields.buildingId || undefined,
  168. deptId: this.fieldConfig.fields.deptId || undefined,
  169. groupId: this.groupId || undefined,
  170. };
  171. if (this.sortCurrentKey && this.sortCurrentValue) {
  172. postData.sort = `${this.sortCurrentKey} ${this.sortCurrentValue === "ascend" ? `asc` : `desc`}`
  173. }
  174. this.mainService
  175. .postExportCustom("itsm/export", "userTransOrder", postData)
  176. .subscribe((data) => {
  177. this.message.remove(this.excelExportLoading);
  178. this.excelExportLoading = false;
  179. this.message.success('导出成功');
  180. var file = new Blob([data], {
  181. type: "application/vnd.ms-excel",
  182. });
  183. //trick to download store a file having its URL
  184. var fileURL = URL.createObjectURL(file);
  185. var a = document.createElement("a");
  186. a.href = fileURL;
  187. a.target = "_blank";
  188. a.download = `${this.route.parent.routeConfig.data.title}.xls`;
  189. document.body.appendChild(a);
  190. a.click();
  191. },(err) => {
  192. this.message.remove(this.excelExportLoading);
  193. this.excelExportLoading = false;
  194. this.message.error('导出失败');
  195. });
  196. }
  197. // 重置
  198. reset(){
  199. this.sortCurrentKey = "";
  200. this.sortCurrentValue = "";
  201. this.sortCurrent = {};
  202. 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')]
  203. this.groupId = undefined;
  204. this.fieldConfig.fields = {buildingId: undefined, deptId: undefined};
  205. this.search();
  206. }
  207. // 分组搜索
  208. changeGroupInp(e) {
  209. this.searchTimer(this.getGroupList, e);
  210. }
  211. // 防抖
  212. isLoading = false;
  213. searchTimer(fun, e) {
  214. this.isLoading = true;
  215. this.searchTimerSubject.next([fun, e]);
  216. }
  217. openChangeGroup(flag){
  218. flag && this.getGroupList();
  219. }
  220. // 获取分组列表
  221. groupList:any[] = [];
  222. getGroupList(keyword?) {
  223. let data = {
  224. group2: {
  225. statisticalHosId: this.getHosId,
  226. groupName: keyword,
  227. },
  228. idx: 0,
  229. sum: 20,
  230. };
  231. this.isLoading = true;
  232. this.mainService
  233. .getFetchDataList("data", "group2", data)
  234. .subscribe((data) => {
  235. this.isLoading = false;
  236. this.groupList = data.list;
  237. });
  238. }
  239. // 详细搜索
  240. fieldConfig:any = {
  241. fields: {buildingId: undefined, deptId: undefined},
  242. config: {building: true, dept: true},
  243. }
  244. showSearchMore:boolean = false;
  245. showMore(){
  246. this.showSearchMore = true;
  247. }
  248. cancelEvent(){
  249. this.showSearchMore = false;
  250. }
  251. submitEvent(fields){
  252. this.showSearchMore = false;
  253. this.fieldConfig.fields = fields;
  254. console.log('this.fieldConfig.fields:', this.fieldConfig.fields)
  255. this.search();
  256. this.onResize();
  257. }
  258. }