123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <div class="body" style="font-size:14px">
  3. <el-button type="primary" size="mini" style="float: right; margin-bottom: 20px;" @click="handleAdd">添加特征</el-button>
  4. <el-table stripe :data="tableData" border style="width: 100%">
  5. <el-table-column prop="name" label="实例名称" />
  6. <el-table-column prop="thumb" label="实例图片">
  7. <template slot-scope="scope">
  8. <el-image :src="scope.row.thumb" style="width: 100px; height: 100px" />
  9. </template>
  10. </el-table-column>
  11. <el-table-column prop="createDate" label="创建时间">
  12. <template slot-scope="scope">{{
  13. scope.row.createDate.substr(0, 10)
  14. }}</template>
  15. </el-table-column>
  16. <el-table-column fixed="right" label="操作">
  17. <template slot-scope="scope">
  18. <el-button type="text" @click="handleEdit(scope.row)">编辑</el-button>
  19. <el-popconfirm
  20. icon="el-icon-info"
  21. icon-color="red"
  22. title="确定删除这个特征吗?"
  23. @onConfirm="handleDelete(scope.row)"
  24. >
  25. <el-button slot="reference" type="text">删除</el-button>
  26. </el-popconfirm>
  27. </template>
  28. </el-table-column>
  29. </el-table>
  30. <el-pagination
  31. v-show="characterTotal!==0"
  32. style="float:right; margin:20px 0"
  33. :total="characterTotal"
  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. </div>
  41. </template>
  42. <script>
  43. import { getGameCharacterList, deleteGameCharacter } from '@/api/gameCharacter'
  44. export default {
  45. props: {
  46. gameId: String
  47. },
  48. data() {
  49. return {
  50. name: undefined,
  51. daterange: '',
  52. tableData: [],
  53. endDate: undefined,
  54. startDate: undefined,
  55. pageSize: 10,
  56. currentPage: 1,
  57. characterTotal: 0
  58. }
  59. },
  60. watch: {
  61. gameId: {
  62. handler(val) {
  63. if (this.gameId) {
  64. this.onSearch()
  65. }
  66. },
  67. immediate: true // 页面加载时就启动
  68. }
  69. },
  70. methods: {
  71. // 改变每页显示条数
  72. handleSizeChange(val) {
  73. this.pageSize = val
  74. this.changePagination()
  75. },
  76. // 改变页码
  77. handleCurrentChange(val) {
  78. this.currentPage = val
  79. this.changePagination()
  80. },
  81. // 改变分页组件重新查询数据
  82. changePagination() {
  83. getGameCharacterList({
  84. gameId: this.gameId,
  85. pageNum: this.currentPage,
  86. pageSize: this.pageSize
  87. }).then((res) => {
  88. this.tableData = res.data.records
  89. // 讲特征列表写入store 供问题答案特征下拉使用
  90. const list = []
  91. this.tableData.map(item => {
  92. list.push({ characterId: item.characterId, name: item.name })
  93. })
  94. this.$store.dispatch('game/setWordListValue', list).then(() => {})
  95. })
  96. },
  97. handleAdd() {
  98. this.$emit('handleAddGameCharacter', true)
  99. },
  100. handleEdit(row) {
  101. this.$emit('handleEditGameCharacter', row.characterId)
  102. },
  103. handleDelete(row) {
  104. deleteGameCharacter(row.characterId).then(() => {
  105. // 让父组件给右边编辑特征页面一个空的characterId
  106. // 防止当前特征正在编辑时删除了右边再次进行保存会报错
  107. this.$message('删除特征成功')
  108. this.$emit('handleCloseGameCharacter', true)
  109. this.onSearch()
  110. })
  111. },
  112. onSearch() {
  113. getGameCharacterList({
  114. gameId: this.gameId
  115. }).then((res) => {
  116. this.tableData = res.data.records
  117. this.characterTotal = res.data.total
  118. this.pageSize = res.data.size
  119. // 讲特征列表写入store 供问题答案特征下拉使用
  120. const list = []
  121. this.tableData.map(item => {
  122. list.push({ characterId: item.characterId, name: item.name })
  123. })
  124. this.$store.dispatch('game/setWordListValue', list).then(() => {})
  125. })
  126. },
  127. dateChange(val) {
  128. this.startDate = this.daterange[0]
  129. this.endDate = this.daterange[1]
  130. }
  131. }
  132. }
  133. </script>
  134. <style>
  135. </style>