detail.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <div class="app-container">
  3. <!-- 表单 -->
  4. <el-form class="form" label-width="100px">
  5. <el-row>
  6. <el-col :span="12">
  7. <el-form-item label="频道名称:">
  8. <el-input v-model="form.aliasName" placeholder="请输入频道名称" />
  9. </el-form-item>
  10. <el-form-item label="频道属性:">
  11. <el-select v-model="form.channelType" placeholder="请选择频道属性" :disabled="disabled">
  12. <el-option v-for="item in dict.type.channels_type" :key="item.value" :value="Number(item.value)"
  13. :label="item.label" />
  14. </el-select>
  15. </el-form-item>
  16. <el-form-item label="频道封面:">
  17. <Upload listType="picture-card" :url="form.pic" @upload="getUpload" />
  18. </el-form-item>
  19. </el-col>
  20. <el-col :span="12">
  21. <el-form-item label="频道简介:">
  22. <el-input v-model="form.description" type="textarea" rows="12" placeholder="请输入频道简介" />
  23. </el-form-item>
  24. </el-col>
  25. </el-row>
  26. <el-form-item label="频道内容:">
  27. <el-button type="primary" icon="el-icon-plus" @click="getDialog">
  28. 新增内容
  29. </el-button>
  30. <el-table :data="tableData" v-loading="loading">
  31. <el-table-column label="内容ID" prop="audioId" align="center" />
  32. <el-table-column label="音频名称" prop="audioName" align="center" />
  33. <el-table-column label="音频封面" align="center">
  34. <template slot-scope="scope">
  35. <el-image :src="scope.row.audioPic" :previewSrcList="[scope.row.audioPic]" fit="scale-down" />
  36. </template>
  37. </el-table-column>
  38. <el-table-column label="付费" prop="isFree" align="center" width="100px" :formatter="freeFormatter" />
  39. <el-table-column label="来源" prop="source" align="center" width="100px" />
  40. <el-table-column label="操作" align="center" width="100px">
  41. <template slot-scope="scope">
  42. <el-button type="delete" @click="getDelete(scope.row)">删除</el-button>
  43. </template>
  44. </el-table-column>
  45. </el-table>
  46. </el-form-item>
  47. </el-form>
  48. <!-- 按钮 -->
  49. <div class="form-btn">
  50. <el-button @click="cancel">取消</el-button>
  51. <el-button type="primary" @click="submit">提交</el-button>
  52. </div>
  53. <!-- 弹窗 -->
  54. <el-dialog :visible.sync="dialogVisible" title="新增内容" width="1000px">
  55. <!-- 搜索 -->
  56. <el-form inline size="mini" @submit.native.prevent>
  57. <el-form-item label="内容名称:">
  58. <el-input v-model="dialogForm.keyword" placeholder="请输入内容名称" clearable />
  59. </el-form-item>
  60. <el-form-item label="分类:">
  61. <el-select v-model="dialogForm.classifyId" placeholder="请选择分类" clearable>
  62. <el-option v-for="item in classifyOptions" :key="item.id" :label="item.name" :value="item.id" />
  63. </el-select>
  64. </el-form-item>
  65. <el-form-item>
  66. <el-button icon="el-icon-search" type="primary" @click="getSearch">搜索</el-button>
  67. <el-button icon="el-icon-refresh" @click="getRefresh">重置</el-button>
  68. </el-form-item>
  69. </el-form>
  70. <!-- 列表 -->
  71. <el-table :data="dialogData" height="476" ref="table" :row-key="getRowKey"
  72. @selection-change="getChange">
  73. <el-table-column type="selection" align="center" :reserve-selection="true" />
  74. <el-table-column label="内容ID" prop="id" align="center" />
  75. <el-table-column label="音频名称" prop="audioName" align="center" />
  76. <el-table-column label="音频封面" align="center">
  77. <template slot-scope="scope">
  78. <el-image :src="scope.row.audioPic" :previewSrcList="[scope.row.audioPic]" fit="scale-down" />
  79. </template>
  80. </el-table-column>
  81. <el-table-column label="付费" prop="isFree" align="center" width="100px" :formatter="freeFormatter" />
  82. <el-table-column label="来源" prop="source" align="center" width="100px" />
  83. </el-table>
  84. <pagination v-show="total>0" :total="total" :page.sync="dialogForm.pageNum"
  85. :limit.sync="dialogForm.pageSize" @pagination="getPage" />
  86. <div slot="footer">
  87. <el-button @click="getAdd" type="primary">确定</el-button>
  88. </div>
  89. </el-dialog>
  90. </div>
  91. </template>
  92. <script>
  93. import Upload from '@/components/Upload/index'
  94. import { channelList, channelTemplate, channelDetail, edit, list, remove, queryList } from '@/api/operation/channel'
  95. import { isFreeMixin } from '@/mixin/index'
  96. export default {
  97. dicts: ['channels_type'],
  98. mixins: [isFreeMixin],
  99. components: {
  100. Upload
  101. },
  102. data() {
  103. return {
  104. // 遮罩层
  105. loading: false,
  106. // 弹窗
  107. dialogVisible: false,
  108. // 频道内容
  109. tableData: [],
  110. dialogData: [],
  111. // 编辑表单
  112. form: {},
  113. // 频道属性
  114. channelId: this.$route.query.channelId,
  115. disabled: this.$route.query.index == '0' || this.$route.query.index == '1' ? true : false,
  116. // 列表表单
  117. dialogForm: {
  118. pageNum: 1,
  119. pageSize: 10
  120. },
  121. total: 0,
  122. classifyOptions: [],
  123. // 添加频道内容
  124. ids: [],
  125. }
  126. },
  127. mounted() {
  128. this.getDetail()
  129. this.getList()
  130. },
  131. methods: {
  132. // 频道详情
  133. getDetail() {
  134. channelDetail({
  135. channelId: this.channelId
  136. }).then(res => {
  137. if (res.code === 0) {
  138. this.form = res.data
  139. }
  140. })
  141. },
  142. // 频道内容列表
  143. getList() {
  144. queryList(this.channelId).then(res => {
  145. if (res.code === 0) {
  146. this.tableData = res.data
  147. }
  148. })
  149. },
  150. // 可选全部频道内容列表
  151. getPage() {
  152. channelTemplate({
  153. audioType: this.form.channelType
  154. }).then(res => {
  155. if (res.code === 0) {
  156. this.classifyOptions = res.data
  157. }
  158. })
  159. channelList({
  160. channelId: this.channelId,
  161. audioType: this.form.channelType,
  162. ...this.dialogForm
  163. }).then(res => {
  164. if (res.code == 0) {
  165. this.dialogData = res.data[0].pageData.records
  166. this.total = res.data[0].pageData.total
  167. if (this.tableData.length > 0) {
  168. this.tableData.map(i => {
  169. let row = res.data[0].pageData.records.find(j => j.id === i.audioId)
  170. if (row) {
  171. this.$refs.table.toggleRowSelection(row, true)
  172. }
  173. })
  174. }
  175. }
  176. })
  177. },
  178. // 上传频道封面
  179. getUpload(e) {
  180. this.form.pic = e.file
  181. },
  182. // 打开弹窗
  183. getDialog() {
  184. this.dialogVisible = true
  185. this.ids = []
  186. this.getPage()
  187. },
  188. // 搜索
  189. getSearch() {
  190. this.dialogForm.pageNum = 1
  191. this.getPage()
  192. },
  193. // 重置
  194. getRefresh() {
  195. this.dialogForm = {
  196. pageNum: 1,
  197. pageSize: 10,
  198. ...this.data
  199. }
  200. this.getPage()
  201. },
  202. // 提交
  203. submit() {
  204. edit(this.form).then(res => {
  205. if (res.code === 0) {
  206. this.$message.success('修改成功!')
  207. this.getDetail()
  208. }
  209. })
  210. },
  211. // 取消
  212. cancel() {
  213. this.$tab.closeOpenPage('/operation/channel')
  214. },
  215. // 删除
  216. getDelete(row) {
  217. remove(row.id).then(res => {
  218. if (res.code === 0) {
  219. this.$message.success('删除成功!')
  220. this.getList()
  221. }
  222. })
  223. },
  224. getRowKey(row) {
  225. return row.id
  226. },
  227. // 表格多选
  228. getChange(row) {
  229. this.ids = []
  230. if (row.length > 0) {
  231. row.map(i => {
  232. if (this.ids.findIndex(j => j === i.id) === -1) {
  233. this.ids.push(i.id)
  234. }
  235. })
  236. }
  237. },
  238. // 添加频道内容
  239. getAdd() {
  240. list({
  241. audioType: this.form.channelType,
  242. channelDefaultId: this.channelId,
  243. ids: this.ids
  244. }).then(res => {
  245. if (res.code === 0) {
  246. this.$message.success('添加成功!')
  247. this.dialogVisible = false
  248. this.getList()
  249. }
  250. })
  251. },
  252. // 字典翻译
  253. freeFormatter(row) {
  254. return this.selectDictLabel(this.freeOptions, row.isFree)
  255. }
  256. }
  257. }
  258. </script>
  259. <style lang="scss" scoped>
  260. .form {
  261. width: 1000px;
  262. }
  263. .el-image {
  264. width: 80px;
  265. height: 80px;
  266. }
  267. </style>