PageStructDialog.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <el-dialog
  3. class="page-struct-dialog"
  4. :visible.sync="modalIsShow"
  5. title="题卡结构"
  6. top="10vh"
  7. width="600px"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. append-to-body
  11. @open="visibleChange"
  12. >
  13. <el-table :data="structData">
  14. <el-table-column
  15. prop="topicNo"
  16. label="大题号"
  17. width="80"
  18. ></el-table-column>
  19. <el-table-column prop="topicName" label="大题名称"></el-table-column>
  20. <el-table-column prop="questionsCount" label="小题数" width="80">
  21. <span slot-scope="scope">{{ scope.row.questionsCount || "--" }}</span>
  22. </el-table-column>
  23. </el-table>
  24. <div slot="footer"></div>
  25. </el-dialog>
  26. </template>
  27. <script>
  28. import { mapState } from "vuex";
  29. export default {
  30. name: "PageStructDialog",
  31. data() {
  32. return {
  33. modalIsShow: false,
  34. structData: []
  35. };
  36. },
  37. computed: {
  38. ...mapState("card", ["topics"])
  39. },
  40. methods: {
  41. visibleChange() {
  42. let structData = {};
  43. let curTopicNo = "";
  44. this.topics.forEach(topic => {
  45. if (!topic.parent) return;
  46. curTopicNo = topic.parent.topicNo;
  47. let questionsCount = 0;
  48. if (topic.type === "EXPLAIN") {
  49. questionsCount = topic.parent.questionsCount;
  50. } else if (topic.type === "COMPOSITION") {
  51. questionsCount = 1;
  52. } else {
  53. questionsCount = topic.questionsCount;
  54. }
  55. if (structData[curTopicNo]) {
  56. if (topic.type !== "EXPLAIN") {
  57. structData[curTopicNo].questionsCount += questionsCount;
  58. }
  59. } else {
  60. let sd = {
  61. topicNo: curTopicNo,
  62. topicName: topic.parent.topicName,
  63. questionsCount
  64. };
  65. structData[curTopicNo] = sd;
  66. }
  67. });
  68. structData = Object.values(structData);
  69. structData.sort((a, b) => a.topicNo - b.topicNo);
  70. this.structData = structData;
  71. },
  72. cancel() {
  73. this.modalIsShow = false;
  74. },
  75. open() {
  76. this.modalIsShow = true;
  77. }
  78. }
  79. };
  80. </script>