list.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <div class="app-container">
  3. <div class="filter-container">
  4. <router-link :to="{ path: '/banner/create' }">
  5. <el-button v-waves class="filter-item" type="primary" icon="el-icon-edit">
  6. 新建banner
  7. </el-button>
  8. </router-link>
  9. <!--<el-checkbox v-model="showReviewer" class="filter-item" style="margin-left:15px;" @change="tableKey=tableKey+1">
  10. reviewer
  11. </el-checkbox>-->
  12. </div>
  13. <el-table v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%">
  14. <el-table-column align="center" label="ID" width="80">
  15. <template slot-scope="scope">
  16. <span>{{ scope.row.id }}</span>
  17. </template>
  18. </el-table-column>
  19. <el-table-column width="180px" align="center" label="日期">
  20. <template slot-scope="scope">
  21. <span>{{ scope.row.create_time }}</span>
  22. </template>
  23. </el-table-column>
  24. <el-table-column class-name="status-col" label="状态" width="80px">
  25. <template slot-scope="{row}">
  26. <el-tag :type="row.status | statusFilter">
  27. {{ row.status == '1' ? "正常" : "隐藏" }}
  28. </el-tag>
  29. </template>
  30. </el-table-column>
  31. <el-table-column min-width="300px" label="位置" width="100px">
  32. <template slot-scope="{row}">
  33. <router-link :to="'/banner/edit/'+row.id" class="link-type">
  34. <el-tag :type="row.posiiton | positionFilter">
  35. {{ row.position | positionFilterTxt }}
  36. </el-tag>
  37. </router-link>
  38. </template>
  39. </el-table-column>
  40. <el-table-column min-width="300px" label="排序" width="80px">
  41. <template slot-scope="{row}">
  42. <el-tag :type="info">
  43. {{ row.sort }}
  44. </el-tag>
  45. </template>
  46. </el-table-column>
  47. <el-table-column min-width="300px" label="跳转路径">
  48. <template slot-scope="{row}">
  49. <span>{{ row.redirect }}</span>
  50. </template>
  51. </el-table-column>
  52. <el-table-column align="center" label="Actions" width="190" class-name="small-padding fixed-width">
  53. <template slot-scope="scope">
  54. <router-link :to="'/banner/edit/'+scope.row.id">
  55. <el-button type="primary" size="mini" icon="el-icon-edit">
  56. 修改
  57. </el-button>
  58. </router-link>
  59. <el-button type="danger" size="mini" icon="el-icon-delete" style="margin-left: 10px;" @click="handleDelete(scope)">
  60. 删除
  61. </el-button>
  62. </template>
  63. </el-table-column>
  64. </el-table>
  65. <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.pageSize" @pagination="getList" />
  66. </div>
  67. </template>
  68. <script>
  69. import { fetchList, deleteBanner } from '@/api/banner'
  70. import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
  71. import waves from '@/directive/waves'
  72. export default {
  73. name: 'ArticleList',
  74. components: { Pagination },
  75. directives: { waves },
  76. filters: {
  77. statusFilter(status) {
  78. const statusMap = {
  79. 1: 'success',
  80. draft: 'info',
  81. 2: 'danger'
  82. }
  83. return statusMap[status]
  84. },
  85. positionFilter(status) {
  86. const statusMap = {
  87. 'HOME': 'success',
  88. draft: 'info',
  89. 2: 'danger'
  90. }
  91. return statusMap[status]
  92. },
  93. positionFilterTxt(status) {
  94. const statusMap = {
  95. HOME: '首页',
  96. ACTIVITY: '活动页',
  97. VIDEO: '短视频页',
  98. GUIDE: '开店指导'
  99. }
  100. return statusMap[status]
  101. }
  102. },
  103. data() {
  104. return {
  105. list: null,
  106. total: 0,
  107. listLoading: true,
  108. listQuery: {
  109. page: 1,
  110. pageSize: 10
  111. }
  112. }
  113. },
  114. created() {
  115. this.getList()
  116. },
  117. methods: {
  118. getList() {
  119. this.listLoading = true
  120. fetchList(this.listQuery).then(response => {
  121. this.list = response.data.list
  122. this.total = response.data.count
  123. this.listLoading = false
  124. })
  125. },
  126. handleFilter() {
  127. this.listLoading = true
  128. fetchList(this.listQuery).then(response => {
  129. this.list = response.data.list
  130. this.total = response.data.count
  131. this.listLoading = false
  132. })
  133. },
  134. handleDelete({ $index, row }) {
  135. console.log(row.id)
  136. this.$confirm('您确定要隐藏吗', '警告', {
  137. confirmButtonText: '是的',
  138. cancelButtonText: '取消',
  139. type: 'warning'
  140. })
  141. .then(async() => {
  142. await deleteBanner(row.id)
  143. this.list.splice($index, 1)
  144. this.$message({
  145. type: 'success',
  146. message: '隐藏成功'
  147. })
  148. })
  149. }
  150. }
  151. }
  152. </script>
  153. <style scoped>
  154. .edit-input {
  155. padding-right: 100px;
  156. }
  157. .cancel-btn {
  158. position: absolute;
  159. right: 15px;
  160. top: 10px;
  161. }
  162. .filter-container{
  163. margin-bottom: 20px;
  164. }
  165. .filter-item {
  166. margin-right: 10px;
  167. }
  168. </style>