BannerManager.vue 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <div>
  3. <div class="operation">
  4. <el-button type="primary" @click="goEdit({id:0})" size="mini">添加</el-button>
  5. </div>
  6. <el-table :data="items">
  7. <el-table-column label="标题" prop="title"></el-table-column>
  8. <el-table-column label="宣传图" prop="icon"></el-table-column>
  9. <el-table-column label="跳转地址" prop="url"></el-table-column>
  10. <el-table-column label="状态">
  11. <template slot-scope="scope">
  12. <template v-if="scope.row.status === 1">
  13. <p class="online">启用</p>
  14. </template>
  15. <template v-else>
  16. <p class="offline">禁用</p>
  17. </template>
  18. </template>
  19. </el-table-column>
  20. <el-table-column label="操作">
  21. <template slot-scope="scope">
  22. <template v-if="scope.row.status == 0">
  23. <el-button type="success" @click="setStatus(scope.row)" size="mini">启用</el-button>
  24. </template>
  25. <template v-else>
  26. <el-button type="danger" @click="setStatus(scope.row)" size="mini">禁用</el-button>
  27. </template>
  28. <el-button type="text" size="small" @click="goEdit(scope.row)">编辑</el-button>
  29. </template>
  30. </el-table-column>
  31. </el-table>
  32. </div>
  33. </template>
  34. <script>
  35. export default {
  36. data() {
  37. return {
  38. items: []
  39. };
  40. },
  41. methods: {
  42. getItems: function() {
  43. this.$http.bannerList({}, this).then(res => {
  44. if (res.code === 0) {
  45. this.items = res.obj;
  46. }
  47. });
  48. },
  49. setStatus: function(row) {
  50. var status = row.status === 1 ? 0 : 1;
  51. var msg = status === 1 ? "启用" : "禁用";
  52. this.$confirm(
  53. '您确定要将此Banner设置为 "' + msg + '" , 是否继续?',
  54. "提示",
  55. {
  56. confirmButtonText: "确定",
  57. cancelButtonText: "取消",
  58. type: "warning"
  59. }
  60. ).then(() => {
  61. this.$http
  62. .bannerSetStatus({ id: row.id, status: status }, this)
  63. .then(res => {
  64. if (res.code === 0) {
  65. this.$message({
  66. message: "操作成功",
  67. type: "success"
  68. });
  69. row.status = status;
  70. }
  71. });
  72. });
  73. },
  74. goEdit: function(row) {
  75. this.$router.push({ path: "/editBanner", query: { id: row.id } });
  76. }
  77. },
  78. mounted: function() {
  79. this.getItems();
  80. }
  81. };
  82. </script>
  83. <style scoped>
  84. .online {
  85. color: #67c23a;
  86. }
  87. .offline {
  88. color: #f56c6c;
  89. }
  90. .operation {
  91. height: 50px;
  92. border-bottom: 1px solid #e6e6e6;
  93. margin-bottom: 10px;
  94. }
  95. </style>