index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <div class="app-container">
  3. <el-button type="primary" icon="el-icon-plus" size="mini" @click="getDialog('新增')"
  4. v-hasPermi="['music:classify:add']">新增</el-button>
  5. <!-- 列表 -->
  6. <el-table :data="tableData" v-loading="loading">
  7. <el-table-column type="index" label="序号" align="center" />
  8. <el-table-column label="分类名称" prop="title" align="center" />
  9. <el-table-column label="更新时间" align="center">
  10. <template slot-scope="scope">
  11. {{ parseTime(scope.row.updateTime, '{y}-{m}-{d} {h}:{i}:{s}') }}
  12. </template>
  13. </el-table-column>
  14. <el-table-column label="操作" align="center">
  15. <template slot-scope="scope">
  16. <el-button type="text" @click="getDialog('编辑', scope.row.id)"
  17. v-hasPermi="['music:classify:edit']">编辑</el-button>
  18. <el-button type="delete" @click="getDelete(scope.row)" v-hasPermi="['music:classify:delete']">删除</el-button>
  19. </template>
  20. </el-table-column>
  21. </el-table>
  22. <pagination v-show="total > 0" :total="total" :page.sync="form.pageNum" :limit.sync="form.pageSize"
  23. @pagination="getList" />
  24. <!-- 弹窗 -->
  25. <el-dialog :visible.sync="dialogVisible" :title="title" width="500px" :before-close="cancel">
  26. <el-form :model="dialogForm" :rules="rules" ref="dialogForm" label-width="auto">
  27. <el-form-item label="分类名称:" prop="title">
  28. <el-input v-model="dialogForm.title" placeholder="请输入分类名称" />
  29. </el-form-item>
  30. </el-form>
  31. <div slot="footer">
  32. <el-button @click="cancel">取消</el-button>
  33. <el-button type="primary" @click="getSubmit">确定</el-button>
  34. </div>
  35. </el-dialog>
  36. </div>
  37. </template>
  38. <script>
  39. import { list, submit, detail, remove } from '@/api/music/classify'
  40. export default {
  41. data() {
  42. return {
  43. // 遮罩层
  44. loading: false,
  45. // 表单
  46. form: {
  47. pageNum: 1,
  48. pageSize: 10
  49. },
  50. // 列表
  51. tableData: [],
  52. // 总数据
  53. total: 0,
  54. // 弹窗
  55. dialogVisible: false,
  56. // 弹窗名称
  57. title: '新增',
  58. // 弹窗表单
  59. dialogForm: {},
  60. // 校验
  61. rules: {
  62. title: [{
  63. required: true, message: '请输入分类名称', trigger: 'blur'
  64. }]
  65. }
  66. }
  67. },
  68. mounted() {
  69. this.getList()
  70. },
  71. methods: {
  72. // 新增 编辑
  73. getDialog(title, id) {
  74. this.dialogVisible = true
  75. this.title = title
  76. if (id) {
  77. detail(id).then(res => {
  78. if (res.code === 0) {
  79. this.dialogForm = res.data
  80. }
  81. })
  82. }
  83. },
  84. // 提交
  85. getSubmit() {
  86. this.$refs.dialogForm.validate((valid) => {
  87. if (valid) {
  88. submit(this.dialogForm).then(res => {
  89. if (res.code === 0) {
  90. this.$message.success(`${this.title}成功!`)
  91. this.cancel()
  92. this.getList()
  93. }
  94. })
  95. } else {
  96. return false
  97. }
  98. })
  99. },
  100. // 取消
  101. cancel() {
  102. this.$refs.dialogForm.resetFields()
  103. this.dialogForm = {}
  104. this.dialogVisible = false
  105. },
  106. // 列表
  107. getList() {
  108. this.loading = true
  109. list(this.form).then(res => {
  110. if (res.code === 0) {
  111. this.tableData = res.data.records
  112. this.total = res.data.total
  113. this.loading = false
  114. }
  115. })
  116. },
  117. // 删除
  118. getDelete(row) {
  119. this.$confirm(`是否删除${row.title}?`, '提示', {
  120. type: 'warning'
  121. }).then(() => {
  122. remove(row.id).then(res => {
  123. if (res.code === 0) {
  124. this.$message.success('删除成功!')
  125. this.getList()
  126. }
  127. })
  128. }).catch(() => { })
  129. }
  130. }
  131. }
  132. </script>