QuestionStatisticsDialog.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <el-dialog
  3. class="question-statistics-dialog"
  4. :visible.sync="modalIsShow"
  5. title="试题统计"
  6. :modal="false"
  7. :close-on-click-modal="false"
  8. :close-on-press-escape="false"
  9. append-to-body
  10. fullscreen
  11. @open="visibleChange"
  12. >
  13. <div class="margin-bottom-15">
  14. <el-button
  15. v-for="item in types"
  16. :key="item.code"
  17. :type="item.code === curType ? 'primary' : 'default'"
  18. @click="toSwitch(item)"
  19. >{{ item.name }}</el-button
  20. >
  21. </div>
  22. <div class="part-box">
  23. <el-table
  24. v-if="curType === 'base'"
  25. key="base"
  26. :data="baseDataList"
  27. :span-method="spanMethod"
  28. >
  29. <el-table-column label="题型">
  30. <el-table-column
  31. label="题型大类"
  32. prop="questionMainTypeName"
  33. ></el-table-column>
  34. <el-table-column
  35. label="题型小类"
  36. prop="questionTypeName"
  37. ></el-table-column>
  38. </el-table-column>
  39. <el-table-column
  40. label="试题数量"
  41. prop="questionDifficultInfoCont"
  42. ></el-table-column>
  43. </el-table>
  44. <el-form v-if="curType === 'blue'">
  45. <el-form-item label="可选属性">
  46. <el-select v-model="curProperty" @change="propertyChange">
  47. <el-option
  48. v-for="item in blueDataList"
  49. :key="item.name"
  50. :value="item.name"
  51. :label="item.name"
  52. ></el-option>
  53. </el-select>
  54. </el-form-item>
  55. </el-form>
  56. <el-table
  57. v-if="curType === 'blue'"
  58. key="blue"
  59. :data="curBlueDataList"
  60. :span-method="spanMethod"
  61. >
  62. <el-table-column label="蓝图属性" width="520" fixed="left">
  63. <el-table-column
  64. label="一级属性"
  65. width="260"
  66. prop="firstPropertyName"
  67. ></el-table-column>
  68. <el-table-column
  69. label="二级属性"
  70. width="260"
  71. prop="secondPropertyName"
  72. ></el-table-column>
  73. </el-table-column>
  74. <el-table-column label="题型">
  75. <el-table-column
  76. v-for="item in blueQtypes"
  77. :key="item"
  78. :label="item"
  79. :prop="item"
  80. min-width="220"
  81. ></el-table-column>
  82. </el-table-column>
  83. </el-table>
  84. </div>
  85. </el-dialog>
  86. </template>
  87. <script>
  88. import {
  89. questionDistributionStatisticsApi,
  90. questionPropertyDistributionStatisticsApi,
  91. } from "../api";
  92. export default {
  93. name: "QuestionStatisticsDialog",
  94. props: {
  95. courseId: {
  96. type: [String, Number],
  97. default: null,
  98. },
  99. },
  100. data() {
  101. return {
  102. modalIsShow: false,
  103. filter: {
  104. courseId: "",
  105. coursePropertyId: "",
  106. },
  107. types: [
  108. {
  109. name: "基础构成",
  110. code: "base",
  111. },
  112. {
  113. name: "蓝图分布",
  114. code: "blue",
  115. },
  116. ],
  117. curType: "base",
  118. baseDataList: [],
  119. blueDataList: [],
  120. blueQtypes: [],
  121. curProperty: "",
  122. curBlueDataList: [],
  123. };
  124. },
  125. methods: {
  126. visibleChange() {
  127. this.filter.courseId = this.courseId;
  128. this.toSwitch({ code: "base" });
  129. },
  130. cancel() {
  131. this.modalIsShow = false;
  132. },
  133. open() {
  134. this.modalIsShow = true;
  135. },
  136. toSwitch(item) {
  137. this.curType = item.code;
  138. this.getData();
  139. },
  140. spanMethod({ row, columnIndex }) {
  141. if (columnIndex === 0) {
  142. return {
  143. rowspan: row.rowspan || 0,
  144. colspan: 1,
  145. };
  146. }
  147. },
  148. getData() {
  149. if (this.curType === "base") {
  150. this.getBaseData();
  151. } else {
  152. this.getBlueData();
  153. }
  154. },
  155. getQuesDiffContent({ questionCount, questionDifficultInfo }) {
  156. if (!questionCount) return "--";
  157. const qinfo = questionDifficultInfo
  158. .map((item) => `${item.difficultLevel}${item.questionCount}`)
  159. .join(",");
  160. return `${questionCount}${qinfo})`;
  161. },
  162. async getBaseData() {
  163. const res = await questionDistributionStatisticsApi(this.courseId);
  164. // console.log(res.data);
  165. // parse data
  166. let baseDataList = [];
  167. res.data.forEach((mainGroup) => {
  168. const rowspan = mainGroup.questionTypeStatisticList.length;
  169. mainGroup.questionTypeStatisticList.forEach((quesItem, index) => {
  170. let nitem = {
  171. questionMainTypeName: mainGroup.questionMainTypeName,
  172. questionTypeName: quesItem.questionTypeName,
  173. questionDifficultInfoCont: this.getQuesDiffContent(quesItem),
  174. };
  175. if (index === 0) nitem.rowspan = rowspan;
  176. baseDataList.push(nitem);
  177. });
  178. });
  179. this.baseDataList = baseDataList;
  180. },
  181. async getBlueData() {
  182. const res = await questionPropertyDistributionStatisticsApi(this.filter);
  183. this.blueDataList = res.data.map((mainGroup) => {
  184. let dataList = [];
  185. mainGroup.distributeInfo.forEach((item) => {
  186. if (!item.children || !item.children.length) return;
  187. const rowspan = item.children.length;
  188. item.children.forEach((elem, index) => {
  189. let nelem = {
  190. firstPropertyName: item.propertyName,
  191. secondPropertyName: elem.propertyName,
  192. };
  193. if (index === 0) nelem.rowspan = rowspan;
  194. elem.distributeByQuestionTypeList.forEach((qt) => {
  195. nelem[qt.questionStructTypeName] = this.getQuesDiffContent(qt);
  196. });
  197. if (!this.blueQtypes.length) {
  198. this.blueQtypes = elem.distributeByQuestionTypeList.map(
  199. (qt) => qt.questionStructTypeName
  200. );
  201. }
  202. dataList.push(nelem);
  203. });
  204. });
  205. return {
  206. name: mainGroup.coursePropertyName,
  207. dataList,
  208. };
  209. });
  210. if (!this.blueDataList.length) return;
  211. this.curProperty = this.blueDataList[0].name;
  212. this.curBlueDataList = this.blueDataList[0].dataList;
  213. },
  214. propertyChange() {
  215. const data = this.blueDataList.find(
  216. (item) => item.name === this.curProperty
  217. );
  218. if (!data) return;
  219. this.curBlueDataList = data.dataList;
  220. },
  221. },
  222. };
  223. </script>