questionnaire-answer.component.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import { Component, OnInit } from "@angular/core";
  2. import { ActivatedRoute, Router } from "@angular/router";
  3. import { MainService } from "../../services/main.service";
  4. import { ToolService } from "../../services/tool.service";
  5. import { NzMessageService } from 'ng-zorro-antd';
  6. import { THIS_EXPR } from '@angular/compiler/src/output/output_ast';
  7. import { format, startOfDay, endOfDay } from 'date-fns';
  8. import { DateService } from 'src/app/services/date.service';
  9. @Component({
  10. selector: "app-questionnaire-answer",
  11. templateUrl: "./questionnaire-answer.component.html",
  12. styleUrls: ["./questionnaire-answer.component.less"],
  13. })
  14. export class QuestionnaireAnswerComponent implements OnInit {
  15. constructor(
  16. private mainService: MainService,
  17. private route: ActivatedRoute,
  18. private router: Router,
  19. private tool: ToolService,
  20. private message: NzMessageService,
  21. private dateService: DateService,
  22. ) {}
  23. userInfo: any = JSON.parse(localStorage.getItem("user")) || {}; //登录用户信息
  24. listOfData: any[] = []; //表格数据
  25. listOfDataTh: any[] = []; //表格数据
  26. pageIndex: number = 1; //表格当前页码
  27. pageSize: number = 10; //表格每页展示条数
  28. listLength: number = 10; //表格总数据量
  29. currentHospital; //当前院区
  30. listBaseInfoTh: any[] = []; //陪检患者表格表头
  31. listBaseInfos: any[] = []; //陪检患者表格数据
  32. ngOnInit() {
  33. this.currentHospital = this.tool.getCurrentHospital();
  34. this.getList(1);
  35. }
  36. // 初始化增删改按钮
  37. coopBtns: any = {};
  38. // 导出
  39. loading2 = false;
  40. export() {
  41. let postData = {
  42. idx: 0,
  43. sum: 99999,
  44. qmId: this.route.snapshot.queryParams.id,
  45. startTime: this.startDate || undefined,
  46. endTime: this.endDate || undefined,
  47. };
  48. this.loading2 = true;
  49. this.mainService.exportReport("survey", postData).subscribe(
  50. (data) => {
  51. this.loading2 = false;
  52. this.message.create('success', `导出成功`);
  53. var file = new Blob([data], {
  54. type: "application/vnd.ms-excel",
  55. });
  56. //trick to download store a file having its URL
  57. var fileURL = URL.createObjectURL(file);
  58. var a = document.createElement("a");
  59. a.href = fileURL;
  60. a.target = "_blank";
  61. a.download = `回收数据.xls`;
  62. document.body.appendChild(a);
  63. a.click();
  64. },
  65. (err) => {
  66. this.loading2 = false;
  67. this.message.create('error', `导出失败`);
  68. }
  69. );
  70. }
  71. // 日期选择
  72. startDate: string; //发起时间开始
  73. endDate: string; //发起时间结束
  74. dateRange: any = [];
  75. changeDate(result?): void {
  76. if (result.length==0) {
  77. this.startDate = this.endDate = null;
  78. return;
  79. }
  80. this.startDate = format(result[0], 'yyyy-MM-dd HH:mm:ss');
  81. this.endDate = format(result[1], 'yyyy-MM-dd HH:mm:ss');
  82. this.dateRange = [this.startDate,this.endDate]
  83. }
  84. monthValue:any;
  85. // 快捷选择 1:本月 2:上月
  86. changeMonth(e){
  87. if(e==2){
  88. let lastmonthstartdate = this.dateService.date().lastMonthStartDate;
  89. let lastmonthenddate = this.dateService.date().lastMonthEndDate;
  90. this.startDate = format(lastmonthstartdate, 'yyyy-MM-dd HH:mm:ss');
  91. this.endDate = format(lastmonthenddate, 'yyyy-MM-dd HH:mm:ss');
  92. this.dateRange = [this.startDate,this.endDate]
  93. }else{
  94. let thismonthstartdate = this.dateService.date().thisMonthStartDate;
  95. let thismonthenddate = this.dateService.date().thisMonthEndDate;
  96. this.startDate = format(thismonthstartdate, 'yyyy-MM-dd HH:mm:ss');
  97. this.endDate = format(thismonthenddate, 'yyyy-MM-dd HH:mm:ss');
  98. this.dateRange = [this.startDate,this.endDate]
  99. }
  100. }
  101. // 重置
  102. reset(){
  103. this.pageIndex = 1;
  104. this.startDate = null;
  105. this.endDate = null;
  106. this.dateRange = []
  107. this.getList(1);
  108. }
  109. // 表格数据
  110. loading1 = false;
  111. getList(type) {
  112. if (type == 1) {
  113. this.pageIndex = 1;
  114. }
  115. let postData = {
  116. idx: this.pageIndex - 1,
  117. sum: this.pageSize,
  118. qmId: this.route.snapshot.queryParams.id,
  119. startTime: this.startDate || undefined,
  120. endTime: this.endDate || undefined,
  121. };
  122. this.loading1 = true;
  123. this.mainService
  124. .listQuestionnaire(postData)
  125. .subscribe((data:any) => {
  126. this.loading1 = false;
  127. if (data.status == 200) {
  128. this.listOfData = data.data?data.data.answers:[];
  129. this.listOfDataTh = data.data?data.data.infos:[];
  130. this.listBaseInfos = data.data?data.data.baseInfos:[];
  131. if(this.listBaseInfos&&this.listBaseInfos.length>0){
  132. this.listBaseInfoTh = [
  133. {describe:'患者姓名'},
  134. {describe:'住院号'},
  135. {describe:'工单编号/任务类型'},
  136. ]
  137. for(let i in this.listBaseInfos){
  138. this.listOfData[i].data = this.listBaseInfos[i]
  139. }
  140. }else{
  141. this.listBaseInfoTh = []
  142. }
  143. this.listLength = data.totalNum;
  144. }
  145. });
  146. }
  147. }