detail.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <div class="app-container">
  3. <!-- 表单 -->
  4. <el-form label-width="100px" :disabled="disabled">
  5. <el-form-item label="场景标题:">
  6. <el-input v-model="form.name" placeholder="请输入场景标题" />
  7. </el-form-item>
  8. <el-form-item label="场景副标题:">
  9. <el-input v-model="form.subName" placeholder="请输入场景副标题" />
  10. </el-form-item>
  11. <el-form-item label="场景封面:">
  12. <Upload listType="picture-card" :url="form.pic" @upload="upload($event, 'pic')" :disabled="disabled" />
  13. </el-form-item>
  14. <el-form-item label="专区背景图:">
  15. <Upload listType="picture-card" :url="form.backgroundPic" @upload="upload($event, 'backgroundPic')"
  16. :disabled="disabled" />
  17. </el-form-item>
  18. </el-form>
  19. <div class="form-btn" style="margin-bottom: 40px">
  20. <el-button @click="cancel">取消</el-button>
  21. <el-button v-if="!disabled" type="primary" @click="getSubmit">提交</el-button>
  22. </div>
  23. <el-form label-width="100px" :disabled="disabled">
  24. <el-form-item label="专区列表:" style="width: 1200px">
  25. <el-table :data="tableData" v-loading="loading" :default-sort="{prop: 'sort'}">
  26. <el-table-column label="排序" prop="sort" align="center" />
  27. <el-table-column label="标签名称" prop="name" align="center" />
  28. <el-table-column label="标签封面" align="center" width="100px">
  29. <template slot-scope="scope">
  30. <el-image v-if="scope.row.pic" :src="scope.row.pic" />
  31. </template>
  32. </el-table-column>
  33. <el-table-column label="歌单数量" prop="songCount" align="center" />
  34. <el-table-column label="当前状态" prop="status" align="center" :formatter="statusFormatter" />
  35. <el-table-column label="操作" align="center">
  36. <template slot-scope="scope">
  37. <el-button type="text" @click="getDialog(scope.row.id, '查看')">查看</el-button>
  38. <el-button v-if="scope.row.status === 0" type="text" @click="getChange(scope.row, 1, '禁用')">禁用</el-button>
  39. <span v-else style="margin-left: 10px">
  40. <el-button type="text" @click="getDialog(scope.row.id, '编辑')">编辑</el-button>
  41. <el-button type="text" @click="getChange(scope.row, 0, '启用')">启用</el-button>
  42. <el-button type="delete" @click="getChange(scope.row, 2, '删除')">删除</el-button>
  43. </span>
  44. </template>
  45. </el-table-column>
  46. </el-table>
  47. <pagination v-show="total > 0" :total="total" :page.sync="form.pageNum" :limit.sync="form.pageSize"
  48. @pagination="getList" />
  49. </el-form-item>
  50. </el-form>
  51. <!-- 弹窗 -->
  52. <el-dialog :visible.sync="dialogVisible" :title="title" width="600px" :before-close="getClose">
  53. <el-form :model="dialogForm" ref="dialogForm" label-width="100px" :disabled="title === '查看' ? true : false">
  54. <el-form-item label="标签名称:" prop="name">
  55. <el-input v-model="dialogForm.name" placeholder="请输入标签名称" />
  56. </el-form-item>
  57. <el-form-item label="标签封面:" prop="pic">
  58. <Upload listType="picture-card" :url="dialogForm.pic" @upload="upload($event, 'pic')"
  59. :disabled="title === '查看' ? true : false" />
  60. </el-form-item>
  61. <el-form-item label="排序:" prop="sort">
  62. <el-input-number v-model="dialogForm.sort" step-strictly />
  63. </el-form-item>
  64. </el-form>
  65. <div slot="footer">
  66. <el-button @click="getClose">取消</el-button>
  67. <el-button v-if="title === '查看' ? false : true" type="primary" @click="getDetailSubmit">确定</el-button>
  68. </div>
  69. </el-dialog>
  70. </div>
  71. </template>
  72. <script>
  73. import { detail, edit, detailList, change, menuDetail, editMenu } from '@/api/operation/scene'
  74. import { disabledMixin } from '@/mixin/index'
  75. export default {
  76. mixins: [disabledMixin],
  77. data() {
  78. return {
  79. // 遮罩层
  80. loading: false,
  81. // 表单
  82. form: {},
  83. // 列表
  84. tableData: [],
  85. // 专区表单
  86. listForm: {
  87. pageNum: 1,
  88. pageSize: 10
  89. },
  90. total: 0,
  91. // 弹窗
  92. dialogVisible: false,
  93. title: '编辑',
  94. // 弹窗表单
  95. dialogForm: {},
  96. // 只读
  97. disabled: false
  98. }
  99. },
  100. mounted() {
  101. if (this.$route.query.id) {
  102. this.form.id = this.listForm.groupId = this.$route.query.id
  103. this.disabled = Boolean(this.$route.query.boolean)
  104. this.getDetail()
  105. this.getList()
  106. }
  107. },
  108. methods: {
  109. // 详情
  110. getDetail() {
  111. detail(this.form.id).then(res => {
  112. if (res.code === 0) {
  113. this.form = res.data
  114. }
  115. })
  116. },
  117. // 上传图片
  118. upload(e, key) {
  119. this.dialogVisible ? this.dialogForm[key] = e.file : this.form[key] = e.file
  120. },
  121. // 提交
  122. getSubmit() {
  123. edit(this.form).then(res => {
  124. if (res.code === 0) {
  125. this.$message.success('编辑成功!')
  126. this.cancel()
  127. }
  128. })
  129. },
  130. // 取消
  131. cancel() {
  132. this.$tab.closeOpenPage('/operation/scene')
  133. },
  134. // 专区列表
  135. getList() {
  136. this.loading = true
  137. detailList(this.listForm).then(res => {
  138. if (res.code === 0) {
  139. this.tableData = res.data.records
  140. this.total = res.data.total
  141. this.loading = false
  142. }
  143. })
  144. },
  145. // 上下架
  146. getChange(row, status, title) {
  147. this.$confirm(`是否${title}${row.name}?`, '提示', {
  148. type: 'warning'
  149. }).then(() => {
  150. change(row.id, 2, status).then(res => {
  151. if (res.code === 0) {
  152. this.$message.success(`${title}成功!`)
  153. this.getList()
  154. }
  155. })
  156. }).catch(() => { })
  157. },
  158. // 弹窗
  159. getDialog(id, title) {
  160. this.dialogVisible = true
  161. this.title = title
  162. menuDetail(id).then(res => {
  163. if(res.code === 0){
  164. this.dialogForm = res.data
  165. }
  166. })
  167. },
  168. // 关闭
  169. getClose(){
  170. this.dialogVisible = false
  171. this.$refs.dialogForm.resetFields()
  172. },
  173. // 确定
  174. getDetailSubmit() {
  175. editMenu(this.dialogForm).then(res => {
  176. if (res.code === 0) {
  177. this.$message.success('编辑成功!')
  178. this.dialogVisible = false
  179. this.getList()
  180. }
  181. })
  182. },
  183. // 字典翻译
  184. statusFormatter(row) {
  185. return this.selectDictLabel(this.disabledOptions, row.status)
  186. }
  187. }
  188. }
  189. </script>
  190. <style lang="scss" scoped>
  191. .el-form {
  192. width: 500px;
  193. }
  194. </style>