completion-detail.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <div id="detail">
  3. <detail-frame :title="pageTitle" :returns="toReturns">
  4. <el-card :header="quest.name">
  5. <el-tabs v-model="tabs" :stretch="true" type="card">
  6. <el-tab-pane label="图表分析" name="chart">
  7. <el-row
  8. v-for="(quest, qi) in quest.question"
  9. :key="qi"
  10. type="flex"
  11. align="middle"
  12. justify="center"
  13. style="text-align:center;border-bottom: 1px solid #EBEEF5;"
  14. >
  15. <el-col :span="24">
  16. <charts :data="quest" :nodata="nodata"></charts>
  17. </el-col>
  18. </el-row>
  19. </el-tab-pane>
  20. <el-tab-pane label="具体数据" name="data">
  21. <el-row type="flex" align="middle" justify="end" style="margin-bottom:20px" v-if="cdata.length > 0">
  22. <el-col :span="2">
  23. <el-button size="mini" type="primary" @click="toExcel">导出数据</el-button>
  24. </el-col>
  25. </el-row>
  26. <el-collapse v-model="collapse" accordion>
  27. <el-collapse-item v-for="(data, qi) in cdata" :key="qi" :title="data.studentname" :name="`${qi}`">
  28. <el-row type="flex" align="middle" justify="center" style="border-bottom: 1px solid #EBEEF5;">
  29. <el-col :span="24">
  30. <reports :report="data"></reports>
  31. </el-col>
  32. </el-row>
  33. </el-collapse-item>
  34. </el-collapse>
  35. </el-tab-pane>
  36. </el-tabs>
  37. </el-card>
  38. </detail-frame>
  39. </div>
  40. </template>
  41. <script>
  42. //组件全部转移到frame中,和班主任端共用
  43. import _ from 'lodash';
  44. import charts from '@frame/parts/statistics/quest-chart.vue';
  45. import reports from '@frame/parts/statistics/report.vue';
  46. import detailFrame from '@frame/layout/admin/detail-frame';
  47. import { mapState, createNamespacedHelpers } from 'vuex';
  48. const { mapActions: questionnaire } = createNamespacedHelpers('questionnaire');
  49. const { mapActions: questionanswer } = createNamespacedHelpers('questionanswer');
  50. export default {
  51. name: 'detail',
  52. props: {},
  53. components: { detailFrame, charts, reports },
  54. data: function() {
  55. return {
  56. mylb: null,
  57. tabs: 'chart',
  58. collapse: '',
  59. quest: {},
  60. cdata: [], //具体数据
  61. nodata: false,
  62. };
  63. },
  64. created() {
  65. this.search();
  66. },
  67. methods: {
  68. ...questionnaire(['fetch']),
  69. ...questionanswer(['query']),
  70. async search() {
  71. let res = await this.fetch(this.querys.questionnaireid);
  72. if (!this.$checkRes(res)) return;
  73. let ansres = await this.query(this.querys); //{ questionnaireid: this.id, termid: this.termid, batchid: this.batchid, classid: this.classid }
  74. if (this.$checkRes(ansres)) {
  75. if (_.get(ansres.data, 'length', 0) <= 0) {
  76. this.$set(this, `nodata`, true);
  77. }
  78. let data = _.cloneDeep(_.get(res, 'data'));
  79. let quests = _.cloneDeep(_.get(res.data, `question`, []));
  80. let allAnswer = _.cloneDeep(ansres.data);
  81. let naa = _.flatten(allAnswer.map(i => i.answers)).map(i => {
  82. i.answer = JSON.parse(i.answer);
  83. return i;
  84. });
  85. //统计
  86. let nq = this.getStatistics(naa, quests);
  87. let sta = _.cloneDeep(data);
  88. sta.question = nq;
  89. this.$set(this, `quest`, sta);
  90. //具体数据
  91. let concreteData = this.getConcreteData(quests, allAnswer);
  92. this.$set(this, `cdata`, concreteData);
  93. }
  94. },
  95. //获取图表分析部分
  96. getStatistics(answer, quests) {
  97. let allAnswer = _.cloneDeep(answer);
  98. let questList = _.cloneDeep(quests);
  99. let newquest = questList.map(i => {
  100. //单选题
  101. if (i.type == 0) i = this.dealRadio(i, allAnswer);
  102. //多选题
  103. if (i.type == 1) i = this.dealCheckBox(i, allAnswer);
  104. //简答,应该不需要了
  105. return i;
  106. });
  107. return newquest;
  108. },
  109. dealRadio(quest, answers) {
  110. let rl = answers.filter(f => f.questionid == quest._id);
  111. let ga = _.groupBy(rl, 'answer');
  112. quest.option.map(i => {
  113. let r = _.get(ga[i.opname], 'length', 0);
  114. i.value = r || 0;
  115. return i;
  116. });
  117. return quest;
  118. },
  119. dealCheckBox(quest, answers) {
  120. let rl = answers.filter(f => f.questionid == quest._id);
  121. let mid = _.flatten(rl.map(i => i.answer));
  122. quest.option.map(i => {
  123. let r = mid.filter(f => f == i.opname);
  124. i.value = r.length || 0;
  125. return i;
  126. });
  127. return quest;
  128. },
  129. //具体数据部分
  130. getConcreteData(quests, answers) {
  131. let dquests = _.cloneDeep(quests);
  132. let danswers = _.cloneDeep(answers);
  133. danswers.map(i => {
  134. i.answers = i.answers.map(answer => {
  135. let r = quests.find(f => f._id == answer.questionid);
  136. if (r) {
  137. answer.topic = r.topic;
  138. answer.type = r.type;
  139. }
  140. return answer;
  141. });
  142. return i;
  143. });
  144. return danswers;
  145. },
  146. toReturns() {
  147. window.history.go(-1);
  148. },
  149. //导出excel数据
  150. toExcel() {
  151. const { export_json_to_excel } = require('@frame/excel/Export2Excel');
  152. let duplicate = _.cloneDeep(this.cdata);
  153. let data = [];
  154. for (const dup of duplicate) {
  155. const elm = { studentname: dup.studentname };
  156. for (const answer of dup.answers) {
  157. elm[answer.questionid] = answer.answer;
  158. }
  159. data.push(elm);
  160. }
  161. let dquest = _.cloneDeep(this.quest.question);
  162. let qarr = dquest.map(i => ({ questionid: i._id, topic: i.topic }));
  163. let tHeader = qarr.map(i => i.topic);
  164. tHeader.unshift('学生姓名');
  165. let filterVal = qarr.map(i => i.questionid);
  166. filterVal.unshift('studentname');
  167. data = data.map(v => filterVal.map(j => v[j]));
  168. export_json_to_excel(tHeader, data, this.quest.name);
  169. },
  170. },
  171. computed: {
  172. ...mapState(['user']),
  173. pageTitle() {
  174. return `${this.$route.meta.title}`;
  175. },
  176. id() {
  177. return this.$route.query.id;
  178. },
  179. querys() {
  180. return this.$route.query;
  181. },
  182. },
  183. metaInfo() {
  184. return { title: this.$route.meta.title };
  185. },
  186. };
  187. </script>
  188. <style lang="less" scoped></style>