index.vue 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <div class="body">
  3. <div class="noshadowCard">
  4. <el-card class="box-card">
  5. 问题名称:<el-input
  6. v-model="title"
  7. size="mini"
  8. style="width: 150px; margin-right: 20px"
  9. />
  10. 创建时间:
  11. <el-date-picker
  12. v-model="daterange"
  13. size="mini"
  14. type="daterange"
  15. range-separator="至"
  16. start-placeholder="开始日期"
  17. end-placeholder="结束日期"
  18. value-format="yyyy-MM-dd"
  19. style="width:220px; margin-right: 20px"
  20. @change="dateChange"
  21. />
  22. <el-button type="primary" size="mini" @click="onSearch">查询</el-button>
  23. <el-button size="mini" @click="onReset">重置</el-button>
  24. <el-button type="primary" size="mini" @click="handleAdd">添加问题</el-button>
  25. </el-card>
  26. </div>
  27. <el-table stripe :data="tableData" border style="width: 100%">
  28. <el-table-column prop="title" label="问题名称" />
  29. <el-table-column prop="optType" label="答案类型" />
  30. <el-table-column prop="createDate" label="创建时间">
  31. <template slot-scope="scope">{{
  32. scope.row.createDate.substr(0, 10)
  33. }}</template>
  34. </el-table-column>
  35. <el-table-column fixed="right" label="操作">
  36. <template slot-scope="scope">
  37. <el-button type="text" @click="handleEdit(scope.row)">编辑</el-button>
  38. <el-popconfirm
  39. icon="el-icon-info"
  40. icon-color="red"
  41. title="确定删除这个问题吗?"
  42. @onConfirm="handleDelete(scope.row)"
  43. >
  44. <el-button slot="reference" type="text">删除</el-button>
  45. </el-popconfirm>
  46. </template>
  47. </el-table-column>
  48. </el-table>
  49. <el-pagination
  50. v-show="questionTotal!==0"
  51. style="float:right; margin:20px 0"
  52. :total="questionTotal"
  53. :current-page="currentPage"
  54. :page-size="pageSize"
  55. layout="total, prev, pager, next, sizes"
  56. @size-change="handleSizeChange"
  57. @current-change="handleCurrentChange"
  58. />
  59. </div>
  60. </template>
  61. <script>
  62. import { getQuestionList, deleteQuestion } from '@/api/question'
  63. export default {
  64. props: {
  65. gameId: String
  66. },
  67. data() {
  68. return {
  69. // 问题名称
  70. title: undefined,
  71. daterange: '',
  72. tableData: [],
  73. endDate: undefined,
  74. startDate: undefined,
  75. pageSize: 10,
  76. currentPage: 1,
  77. questionTotal: 0// 条目总数
  78. }
  79. },
  80. watch: {
  81. gameId() {
  82. if (this.gameId) {
  83. this.onSearch()
  84. }
  85. }
  86. },
  87. methods: {
  88. handleSizeChange(val) {
  89. this.pageSize = val
  90. this.changePagination()
  91. },
  92. handleCurrentChange(val) {
  93. this.currentPage = val
  94. this.changePagination()
  95. },
  96. changePagination() {
  97. getQuestionList({ gameId: this.gameId, title: this.title, startDate: this.startDate, endDate: this.endDate, pageSize: this.pageSize, pageNum: this.currentPage }).then(
  98. (res) => {
  99. this.tableData = res.data.records
  100. }
  101. )
  102. },
  103. // 添加问题
  104. handleAdd() {
  105. this.$emit('handleAddQuestion', true)
  106. },
  107. handleEdit(row) {
  108. // 向外传送数据row.questionId
  109. this.$emit('handleEditQuestion', row.questionId)
  110. },
  111. handleDelete(row) {
  112. deleteQuestion(row.questionId).then(() => {
  113. this.$message('删除问题成功')
  114. this.onSearch()
  115. // 关闭编辑问题页面防止编辑页面还没关闭就删除当前问题了
  116. this.$emit('handleCloseQuestion', true)
  117. })
  118. },
  119. onSearch() {
  120. getQuestionList({ gameId: this.gameId, title: this.title, startDate: this.startDate, endDate: this.endDate, pageSize: this.pageSize }).then(
  121. (res) => {
  122. this.tableData = res.data.records
  123. this.questionTotal = res.data.total
  124. this.pageSize = res.data.size
  125. }
  126. )
  127. },
  128. onReset() {
  129. this.title = ''
  130. this.daterange = ''
  131. this.startDate = ''
  132. this.endDate = ''
  133. this.pageSize = 10
  134. this.pageNum = 1
  135. this.onSearch()
  136. },
  137. dateChange(val) {
  138. this.startDate = this.daterange[0]
  139. this.endDate = this.daterange[1]
  140. }
  141. }
  142. }
  143. </script>
  144. <style>
  145. .noshadowCard > .box-card {
  146. box-shadow: none;
  147. }
  148. </style>