questionnaire-answer.component.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. @Component({
  8. selector: "app-questionnaire-answer",
  9. templateUrl: "./questionnaire-answer.component.html",
  10. styleUrls: ["./questionnaire-answer.component.less"],
  11. })
  12. export class QuestionnaireAnswerComponent implements OnInit {
  13. constructor(
  14. private mainService: MainService,
  15. private route: ActivatedRoute,
  16. private router: Router,
  17. private tool: ToolService,
  18. private message: NzMessageService
  19. ) {}
  20. userInfo: any = JSON.parse(localStorage.getItem("user")) || {}; //登录用户信息
  21. listOfData: any[] = []; //表格数据
  22. listOfDataTh: any[] = []; //表格数据
  23. pageIndex: number = 1; //表格当前页码
  24. pageSize: number = 10; //表格每页展示条数
  25. listLength: number = 10; //表格总数据量
  26. currentHospital; //当前院区
  27. ngOnInit() {
  28. this.currentHospital = this.tool.getCurrentHospital();
  29. this.getList(1);
  30. }
  31. // 初始化增删改按钮
  32. coopBtns: any = {};
  33. // 导出
  34. loading2 = false;
  35. export() {
  36. let postData = {
  37. idx: 0,
  38. sum: 99999,
  39. qmId: this.route.snapshot.queryParams.id,
  40. };
  41. this.loading2 = true;
  42. this.mainService.exportReport("survey", postData).subscribe(
  43. (data) => {
  44. this.loading2 = false;
  45. this.message.create('success', `导出成功`);
  46. var file = new Blob([data], {
  47. type: "application/vnd.ms-excel",
  48. });
  49. //trick to download store a file having its URL
  50. var fileURL = URL.createObjectURL(file);
  51. var a = document.createElement("a");
  52. a.href = fileURL;
  53. a.target = "_blank";
  54. a.download = `回收数据.xls`;
  55. document.body.appendChild(a);
  56. a.click();
  57. },
  58. (err) => {
  59. this.loading2 = false;
  60. this.message.create('error', `导出失败`);
  61. }
  62. );
  63. }
  64. // 表格数据
  65. loading1 = false;
  66. getList(type) {
  67. if (type == 1) {
  68. this.pageIndex = 1;
  69. }
  70. let postData = {
  71. idx: this.pageIndex - 1,
  72. sum: this.pageSize,
  73. qmId: this.route.snapshot.queryParams.id
  74. };
  75. this.loading1 = true;
  76. this.mainService
  77. .listQuestionnaire(postData)
  78. .subscribe((data:any) => {
  79. this.loading1 = false;
  80. if (data.status == 200) {
  81. this.listOfData = data.data?data.data.answers:[];
  82. // if(data.data && data.data.answers){
  83. // data.data.answers
  84. // }
  85. this.listOfDataTh = data.data?data.data.infos:[];
  86. this.listLength = data.totalNum;
  87. }
  88. });
  89. }
  90. }