index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <!-- 弹窗 -->
  3. <el-dialog :visible.sync="dialogVisible" title="关联内容" width="1400px">
  4. <el-form inline size="mini" style="width:100%">
  5. <el-form-item label="音频类型:">
  6. <el-select v-model="dialogForm.audioType">
  7. <el-option v-for="item in channelOptions[channelType]" :key="item.value" :value="item.value"
  8. :label="item.label" />
  9. </el-select>
  10. </el-form-item>
  11. <el-form-item label="资源平台:">
  12. <el-select v-model="dialogForm.platformId" :disabled="[16, 17].includes(channelType)" clearable>
  13. <el-option v-for="item in platformOptions" :key="item.value" :value="item.value" :label="item.label" />
  14. </el-select>
  15. </el-form-item>
  16. <el-form-item label="付费类型:" v-if="![2, 10, 11].includes(dialogForm.audioType)">
  17. <el-select v-model="dialogForm.isFree" placeholder="请选择付费类型" clearable>
  18. <el-option v-for="item in freeOptions" :key="item.value" :label="item.label" :value="item.value" />
  19. </el-select>
  20. </el-form-item>
  21. <el-form-item label="内容名称:">
  22. <el-input v-model="dialogForm.keyword" placeholder="请输入内容名称" clearable />
  23. </el-form-item>
  24. <el-form-item>
  25. <el-button type="primary" icon="el-icon-search" @click="getSearch">搜索</el-button>
  26. <el-button icon="el-icon-refresh" @click="getRefresh">重置</el-button>
  27. </el-form-item>
  28. </el-form>
  29. <el-table :data="tableData" ref="tableData" :row-key="getRowKey" @selection-change="getChange" v-loading="loading">
  30. <el-table-column v-if="!isOnly" type="selection" align="center" key="selection" :reserve-selection="true" />
  31. <el-table-column label="音频ID" prop="audioId" align="center" key="audioId" show-overflow-tooltip />
  32. <el-table-column label="音频名称" prop="audioName" align="center" key="audioName" show-overflow-tooltip />
  33. <el-table-column label="音频封面" align="center" key="audioPic" width="100px">
  34. <template slot-scope="scope">
  35. <el-image v-if="scope.row.audioPic" :src="scope.row.audioPic" />
  36. </template>
  37. </el-table-column>
  38. <el-table-column label="音频作者" align="center" key="singerName" show-overflow-tooltip>
  39. <template slot-scope="scope">
  40. <span>
  41. {{ scope.row.singerName ? scope.row.singerName : '-' }}
  42. </span>
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="专辑名称" prop="songName" align="center" key="songName" show-overflow-tooltip>
  46. <template slot-scope="scope">
  47. <span>
  48. {{ scope.row.songName ? scope.row.songName : '-' }}
  49. </span>
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="付费类型" prop="isFree" align="center" key="isFree" :formatter="freeFormatter" />
  53. <el-table-column label="资源平台" align="center" key="platformId" :formatter="platfromFormatter" />
  54. <el-table-column v-if="isOnly" label="操作" width="50px">
  55. <template slot-scope="scope">
  56. <el-button type="text" @click="handleChoice(scope.row)">选择</el-button>
  57. </template>
  58. </el-table-column>
  59. </el-table>
  60. <div slot="footer">
  61. <pagination v-show="total > 0" :total="total" :page.sync="dialogForm.pageNum" :limit.sync="dialogForm.pageSize"
  62. @pagination="getList" />
  63. </div>
  64. </el-dialog>
  65. </template>
  66. <script>
  67. import { list } from '@/api/operation/channel'
  68. import { platformMixin, isFreeMixin, channelMixin } from '@/mixin/index'
  69. export default {
  70. mixins: [platformMixin, isFreeMixin, channelMixin],
  71. props: {
  72. visible: {
  73. type: Boolean,
  74. default: false
  75. },
  76. channelType: {
  77. type: String | Number,
  78. default: ''
  79. },
  80. data: {
  81. type: Array,
  82. default: () => []
  83. },
  84. // 是否单选
  85. isOnly: {
  86. type: Boolean,
  87. default: false
  88. }
  89. },
  90. data() {
  91. return {
  92. // 遮罩层
  93. loading: false,
  94. // 总数
  95. total: 0,
  96. dialogForm: {
  97. pageNum: 1,
  98. pageSize: 10,
  99. status: 1,
  100. platformId: null,
  101. audioType: null
  102. },
  103. // 弹窗列表
  104. tableData: [],
  105. }
  106. },
  107. watch: {
  108. dialogVisible(val) {
  109. if (val) {
  110. this.dialogForm.platformId = this.channelType === 16 ? 3 : this.channelType === 17 ? 2 : null
  111. this.getPlatform({
  112. audioType: this.dialogForm.audioType
  113. })
  114. this.getList()
  115. }
  116. },
  117. channelType(val) {
  118. this.dialogForm.audioType = this.channelOptions[val][0].value
  119. },
  120. 'dialogForm.audioType'(val) {
  121. if (this.dialogVisible) {
  122. this.getPlatform({
  123. audioType: val
  124. })
  125. this.getList()
  126. }
  127. }
  128. },
  129. computed: {
  130. // 弹窗
  131. dialogVisible: {
  132. get() {
  133. return this.visible
  134. },
  135. set(val) {
  136. this.$emit('close', val)
  137. }
  138. }
  139. },
  140. methods: {
  141. // 搜索
  142. getSearch() {
  143. this.dialogForm.pageNum = 1
  144. this.getList()
  145. },
  146. // 重置
  147. getRefresh() {
  148. this.dialogForm = {
  149. pageNum: 1,
  150. pageSize: 10,
  151. status: 1,
  152. audioType: this.dialogForm.audioType,
  153. platformId: null,
  154. }
  155. this.getList()
  156. },
  157. // 列表
  158. getList() {
  159. this.loading = true
  160. list(this.dialogForm).then(res => {
  161. if (res.code === 0) {
  162. this.tableData = res.data.records
  163. this.total = res.data.total
  164. this.loading = false
  165. this.$refs.tableData.clearSelection()
  166. if (this.data.length > 0) {
  167. this.data.map(i => {
  168. let row = this.tableData.find(j => j.audioId === i.audioId)
  169. if (row) {
  170. this.$refs.tableData.toggleRowSelection(row, true)
  171. }
  172. })
  173. }
  174. }
  175. })
  176. },
  177. getRowKey(row) {
  178. return row.audioId
  179. },
  180. // 选择
  181. getChange(row) {
  182. if (row.length > 0) {
  183. row.map(i => {
  184. if (this.data.findIndex(j => j.audioId === i.audioId) === -1) {
  185. this.data.push(i)
  186. }
  187. })
  188. }
  189. },
  190. // 单选
  191. handleChoice(row) {
  192. this.$emit('handleChoice', row)
  193. },
  194. // 字典翻译
  195. freeFormatter(row) {
  196. return this.selectDictLabel(this.freeOptions, row.isFree)
  197. },
  198. platfromFormatter(row) {
  199. return this.selectDictLabel(this.platformOptions, row.platformId)
  200. },
  201. }
  202. }
  203. </script>