list.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <div class="app-container">
  3. <el-table v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%">
  4. <el-table-column align="center" label="ID" width="80">
  5. <template slot-scope="scope">
  6. <span>{{ scope.row.id }}</span>
  7. </template>
  8. </el-table-column>
  9. <el-table-column width="180px" align="center" label="日期">
  10. <template slot-scope="scope">
  11. <span>{{ scope.row.create_time }}</span>
  12. </template>
  13. </el-table-column>
  14. <el-table-column class-name="status-col" label="状态" width="80ß">
  15. <template slot-scope="{row}">
  16. <el-tag :type="row.status | statusFilter">
  17. {{ row.status == '1' ? "正常" : "删除" }}
  18. </el-tag>
  19. </template>
  20. </el-table-column>
  21. <el-table-column min-width="300px" label="问题">
  22. <template slot-scope="{row}">
  23. <router-link :to="'/advice/edit/'+row.id" class="link-type">
  24. <span>{{ row.advice }}</span>
  25. </router-link>
  26. </template>
  27. </el-table-column>
  28. <el-table-column align="center" label="Actions" width="190" class-name="small-padding fixed-width">
  29. <template slot-scope="scope">
  30. <router-link :to="'/advice/edit/'+scope.row.id">
  31. <el-button type="primary" size="mini" icon="el-icon-edit">
  32. 修改
  33. </el-button>
  34. </router-link>
  35. <el-button type="danger" size="mini" icon="el-icon-delete" style="margin-left: 10px;" @click="handleDelete(scope)">
  36. 删除
  37. </el-button>
  38. </template>
  39. </el-table-column>
  40. </el-table>
  41. <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.pageSize" @pagination="getList" />
  42. </div>
  43. </template>
  44. <script>
  45. import { fetchList, deleteAdvice } from '@/api/advice'
  46. import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
  47. import waves from '@/directive/waves'
  48. export default {
  49. name: 'ArticleList',
  50. components: { Pagination },
  51. directives: { waves },
  52. filters: {
  53. statusFilter(status) {
  54. const statusMap = {
  55. normal: 'success',
  56. draft: 'info',
  57. deleted: 'danger'
  58. }
  59. return statusMap[status]
  60. }
  61. },
  62. data() {
  63. return {
  64. list: null,
  65. total: 0,
  66. listLoading: true,
  67. listQuery: {
  68. page: 1,
  69. pageSize: 10
  70. }
  71. }
  72. },
  73. created() {
  74. this.getList()
  75. },
  76. methods: {
  77. getList() {
  78. this.listLoading = true
  79. fetchList(this.listQuery).then(response => {
  80. this.list = response.data.list
  81. this.total = response.data.count
  82. this.listLoading = false
  83. })
  84. },
  85. handleFilter() {
  86. this.listLoading = true
  87. fetchList(this.listQuery).then(response => {
  88. this.list = response.data.list
  89. this.total = response.data.count
  90. this.listLoading = false
  91. })
  92. },
  93. handleDelete({ $index, row }) {
  94. console.log(row.id)
  95. this.$confirm('您确定要删除吗', '警告', {
  96. confirmButtonText: '是的',
  97. cancelButtonText: '取消',
  98. type: 'warning'
  99. })
  100. .then(async() => {
  101. await deleteAdvice(row.id)
  102. this.list.splice($index, 1)
  103. this.$message({
  104. type: 'success',
  105. message: '删除成功'
  106. })
  107. })
  108. }
  109. }
  110. }
  111. </script>
  112. <style scoped>
  113. .edit-input {
  114. padding-right: 100px;
  115. }
  116. .cancel-btn {
  117. position: absolute;
  118. right: 15px;
  119. top: 10px;
  120. }
  121. .filter-container{
  122. margin-bottom: 20px;
  123. }
  124. .filter-item {
  125. margin-right: 10px;
  126. }
  127. </style>