questionnaireResult.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div>
  3. <main-top :crumb="crumbData" :questionBack="true">
  4. <div slot="con"></div>
  5. </main-top>
  6. <div class="table-interface">
  7. <div class="top-body">
  8. <div class="desc">
  9. <div class="desc-title">
  10. <div class="txt">问卷名称:&nbsp;&nbsp;{{ detail.name }}</div>
  11. <div class="time">发布时间:&nbsp;&nbsp;{{ detail.createTime }}</div>
  12. </div>
  13. <div class="desc-data">
  14. 显示数据:&nbsp;&nbsp;
  15. <el-radio v-model="showDataType" label="0">百分比</el-radio>
  16. <el-radio v-model="showDataType" label="1">计数</el-radio>
  17. </div>
  18. </div>
  19. <el-table
  20. :data="tableData"
  21. height="61vh"
  22. class="collection-con"
  23. :tree-props="{ children: 'children' }"
  24. row-key="id"
  25. style="width: 100%"
  26. >
  27. <el-table-column prop="num" label="题号"></el-table-column>
  28. <el-table-column
  29. :prop="key"
  30. :label="key"
  31. v-for="(value, key) in maxObject"
  32. :key="key"
  33. >
  34. <template slot-scope="scope">
  35. {{ handleData(scope.row[key])}}
  36. </template>
  37. </el-table-column>
  38. </el-table>
  39. </div>
  40. </div>
  41. </div>
  42. </template>
  43. <script>
  44. import MainTop from "@/components/main-top";
  45. const crumbData = [
  46. {
  47. name: "问卷调查结果",
  48. id: 5 - 2,
  49. },
  50. ];
  51. export default {
  52. components: {
  53. MainTop,
  54. },
  55. data() {
  56. return {
  57. crumbData,
  58. detail: {},
  59. tableData: [],
  60. showDataType: "0",
  61. questionGroupId: "",
  62. maxObject: [],
  63. };
  64. },
  65. computed: {},
  66. watch: {
  67. showDataType: {
  68. handler() {
  69. this.getInformation();
  70. },
  71. },
  72. },
  73. created() {
  74. this.questionGroupId =
  75. (this.$route.params && this.$route.params.questionGroupId) || "";
  76. this.getInformation();
  77. },
  78. mounted() {},
  79. methods: {
  80. handleData(data) {
  81. return (data !== 0 && (!data || data === 'null' )) ? '-': this.showDataType==='0'? String(data*100).slice(0,4)+'%' :data
  82. },
  83. async getInformation() {
  84. let result = await this.$http({
  85. method: "get",
  86. url: `/manage/countAnswer/detail/${this.questionGroupId}/${this.showDataType}`,
  87. });
  88. if (result.code !== 0) {
  89. return;
  90. }
  91. this.detail = result.data;
  92. this.tableData = this.detail.answer;
  93. let maxLen = 0;
  94. let maxNum = 0;
  95. let maxArr = [];
  96. this.tableData.map((item) => {
  97. if (Object.entries(item).length > maxLen) {
  98. maxLen = Object.entries(item).length;
  99. maxNum = item.num;
  100. }
  101. });
  102. maxArr = this.tableData.filter((item) => item.num === maxNum);
  103. this.maxObject = { ...maxArr[0] };
  104. delete this.maxObject.num;
  105. },
  106. },
  107. };
  108. </script>
  109. <style lang="less" scoped>
  110. .top-body {
  111. border-top: 0.0625rem solid #e6e6e6;
  112. line-height: 1.5;
  113. padding: 0 1.25rem 1.25rem;
  114. align-items: center;
  115. box-sizing: border-box;
  116. background: #fff;
  117. margin: 1rem 0;
  118. }
  119. .table-interface {
  120. height: calc(100% - 3rem);
  121. overflow: auto;
  122. }
  123. .info-top {
  124. padding: 1.25rem 0;
  125. display: flex;
  126. justify-content: space-between;
  127. border-bottom: 0.0625rem #a5a5a5 solid;
  128. }
  129. .desc {
  130. padding: 20px;
  131. .desc-title {
  132. margin-bottom: 20px;
  133. display: flex;
  134. .txt {
  135. margin-right: 50px;
  136. }
  137. .time {
  138. }
  139. }
  140. }
  141. </style>