index.vue 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <div class="body">
  3. <el-card class="box-card" shadow="never" body-style="padding:0">
  4. <div slot="header" class="clearfix">
  5. <h3 style="float:left">题库列表</h3>
  6. <h4 v-if="resultMode==='examination'" style="float:left;margin-left: 10px;">总分{{ totalScore }}</h4>
  7. <el-button
  8. type="primary"
  9. style="float: right"
  10. icon="el-icon-plus"
  11. @click="handleAdd"
  12. >添加题目</el-button>
  13. </div>
  14. <ul style="list-style-type: none;margin:24px 0 0 -40px">
  15. <li v-for="item,index in tableData" :key="index" class="questionli" @click="handleEdit(item)">
  16. <span style="width:45px">第{{ index+1 }}题</span>
  17. <span style="width:45px">{{ item.optType === 'single'?'单选题':item.optType==='many'?'多选题':'判断题' }}</span>
  18. <span style="flex:1">{{ item.title }}</span>
  19. <el-popconfirm
  20. style="width:30px"
  21. icon="el-icon-info"
  22. icon-color="red"
  23. title="确定删除这个问题吗?"
  24. @onConfirm="handleDelete(item)"
  25. >
  26. <el-button slot="reference" type="text" style="color:red">删除</el-button>
  27. </el-popconfirm>
  28. </li>
  29. </ul>
  30. <el-pagination
  31. v-show="questionTotal!==0"
  32. style="float:right; margin:24px 0"
  33. :total="questionTotal"
  34. :current-page="currentPage"
  35. :page-size="pageSize"
  36. layout="total, prev, pager, next, sizes"
  37. @size-change="handleSizeChange"
  38. @current-change="handleCurrentChange"
  39. />
  40. </el-card>
  41. </div>
  42. </template>
  43. <script>
  44. import { getQuestionList } from '@/api/question'
  45. import { deleteGameLeverQuestion } from '@/api/gamelevelquestion'
  46. export default {
  47. props: {
  48. gameId: {
  49. type: String,
  50. required: true
  51. },
  52. resultMode: String
  53. },
  54. data() {
  55. return {
  56. tableData: [],
  57. pageSize: 20,
  58. currentPage: 1,
  59. questionTotal: 0, // 条目总数
  60. totalScore: 0
  61. }
  62. },
  63. watch: {
  64. gameId: {
  65. handler(val) {
  66. if (val) {
  67. this.onSearch()
  68. }
  69. },
  70. immediate: true // 页面加载时就启动
  71. }
  72. },
  73. methods: {
  74. handleSizeChange(val) {
  75. this.pageSize = val
  76. this.changePagination()
  77. },
  78. handleCurrentChange(val) {
  79. this.currentPage = val
  80. this.changePagination()
  81. },
  82. changePagination() {
  83. getQuestionList({ gameId: this.gameId, pageSize: this.pageSize, pageNum: this.currentPage }).then(
  84. (res) => {
  85. this.tableData = res.data.records
  86. }
  87. )
  88. },
  89. // 添加问题
  90. handleAdd() {
  91. this.$emit('handleAddQuestion', true)
  92. },
  93. handleEdit(row) {
  94. // 向外传送数据row.gameQuestionMapId
  95. this.$emit('handleEditQuestion', row.gameQuestionMapId)
  96. },
  97. handleDelete(row) {
  98. deleteGameLeverQuestion(row.gameQuestionMapId).then(() => {
  99. this.$message('删除问题成功')
  100. this.onSearch()
  101. // 关闭编辑问题页面防止编辑页面还没关闭就删除当前问题了
  102. this.$emit('handleCloseQuestion', true)
  103. })
  104. },
  105. onSearch() {
  106. getQuestionList({ gameId: this.gameId, pageSize: this.pageSize }).then(
  107. (res) => {
  108. this.tableData = res.data.records
  109. this.questionTotal = res.data.total
  110. this.pageSize = res.data.size
  111. this.totalScore = 0
  112. res.data.records.map(item => {
  113. this.totalScore += item.score
  114. })
  115. }
  116. )
  117. }
  118. }
  119. }
  120. </script>
  121. <style scoped lang="scss">
  122. .questionli {
  123. width: 100%;
  124. overflow: hidden;
  125. display: flex;
  126. line-height:40px;
  127. background-color: white;
  128. padding:0 8px;
  129. border: 1px solid #f0f2f5;
  130. }
  131. .questionli:nth-of-type(even) {
  132. background: #f0f2f5;
  133. }
  134. .questionli:hover {
  135. background-color: rgb(230, 247, 255);
  136. }
  137. </style>