detail.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. <template>
  2. <div class="app-container">
  3. <el-button type="primary" icon="el-icon-plus" size="mini" @click="getPush">新增</el-button>
  4. <!-- 模块 -->
  5. <div style="display: flex; flex-wrap: wrap;">
  6. <el-form class="form" v-for="(item, index) in form" :key="item.id" label-width="auto" :disabled="isRead">
  7. <el-form-item class="sort" :label="(index + 1).toString()">
  8. <el-link icon="el-icon-close" :underline="false" @click="getDelete(index)" />
  9. </el-form-item>
  10. <el-form-item v-if="'title' in item" label="标题:">
  11. <el-input v-model="item.title" placeholder="请输入内容标题" />
  12. </el-form-item>
  13. <el-form-item v-if="'description' in item" label="简介:">
  14. <el-input v-model="item.description" type="textarea" :autosize="{ minRows: 5, maxRows: 10 }"
  15. placeholder="请输入简介" />
  16. </el-form-item>
  17. <el-form-item v-if="'contentName' in item" label="内容:">
  18. <el-input v-model="item.contentName" prefix-icon="el-icon-search" placeholder="选择内容"
  19. @focus="getDialog(item, index, false)" />
  20. </el-form-item>
  21. <el-form-item v-if="'forwardType' in item" label="跳转方式:">
  22. <el-select v-model="item.forwardType" placeholder="请选择跳转方式" @change="forwardTypeChange(item)">
  23. <el-option v-for="item in forwardTypeOptions" :key="item.value" :label="item.label" :value="item.value" />
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item v-if="'forwardUrl' in item" label="跳转地址:">
  27. <el-input v-model="item.forwardUrl" placeholder="请输入跳转地址" />
  28. </el-form-item>
  29. <el-form-item v-if="'contentId' in item" label="专区页面:">
  30. <el-select v-model="item.contentId" placeholder="请选择跳转专区" @change="contentIdChange(item)">
  31. <el-option v-for="item in sceneOptions" :key="item.value" :value="item.value" :label="item.label" />
  32. </el-select>
  33. </el-form-item>
  34. <el-form-item v-if="'isCustom' in item" label="封面模式:">
  35. <el-select v-model="item.isCustom" placeholder="选择封面模式" @change="isCustomChange(item, index)">
  36. <el-option v-for="item in coverOptions" :key="item.value" :label="item.label" :value="Number(item.value)" />
  37. </el-select>
  38. </el-form-item>
  39. <el-form-item v-if="'pic' in item" label="图片:">
  40. <Upload listType="picture-card" :url="item.pic" @upload="upload($event, item)" :disabled="isRead" />
  41. </el-form-item>
  42. <el-form-item v-if="'sort' in item" label="排序:">
  43. <el-input-number v-model="item.sort" />
  44. </el-form-item>
  45. <el-form-item v-if="'childList' in item" label="列表:">
  46. <el-button type="primary" @click="getDialog(item, index, true)">添加内容</el-button>
  47. <el-table :data="item.childList">
  48. <el-table-column label="电台名称" prop="contentName" align="center" show-overflow-tooltip />
  49. <el-table-column label="当前状态" prop="status" align="center" :formatter="statusFormatter" />
  50. <el-table-column label="操作" align="center">
  51. <template slot-scope="scope">
  52. <el-button type="delete" @click="getRemove(scope.row, index)">删除</el-button>
  53. </template>
  54. </el-table-column>
  55. </el-table>
  56. </el-form-item>
  57. <el-form-item label="当前状态:">
  58. <el-select v-model="item.status" placeholder="请选择当前状态">
  59. <el-option v-for="item in disabledOptions" :key="item.value" :value="item.value" :label="item.label" />
  60. </el-select>
  61. </el-form-item>
  62. <el-form-item style="float: right">
  63. <el-button type="info" @click="getEmpty(item, index)">清空</el-button>
  64. </el-form-item>
  65. </el-form>
  66. </div>
  67. <!-- 提交 返回按钮 -->
  68. <div class="btn">
  69. <el-button @click="cancel">取消</el-button>
  70. <el-button v-if="!isRead" type="primary" @click="getSubmit">确定</el-button>
  71. </div>
  72. <!-- 弹窗 -->
  73. <el-dialog :visible.sync="dialogVisible" title="添加内容" width="1000px">
  74. <el-form inline size="mini">
  75. <el-form-item label="音频类型:">
  76. <el-select v-model="dialogForm.audioType" placeholder="请选择类型" :disabled="disabled">
  77. <el-option v-for="item in audioOptions" :key="item.value" :label="item.label" :value="Number(item.value)" />
  78. </el-select>
  79. </el-form-item>
  80. <el-form-item label="资源平台:">
  81. <el-select v-model="dialogForm.platformId" placeholder="请选择平台">
  82. <el-option v-for="item in platformOptions" :key="item.value" :label="item.label" :value="item.value" />
  83. </el-select>
  84. </el-form-item>
  85. <el-form-item label="内容:">
  86. <el-input v-model="dialogForm.keyword" placeholder="请输入内容关键词" clearable />
  87. </el-form-item>
  88. <el-form-item>
  89. <el-button type="primary" icon="el-icon-search" @click="getSearch">搜索</el-button>
  90. </el-form-item>
  91. </el-form>
  92. <el-table :data="dialogTableData" ref="dialogTableData" :row-key="rowKey" @selection-change="handleSelectionChange"
  93. v-loading="loading">
  94. <el-table-column v-if="isSelection" type="selection" align="center" reserve-selection key="selection" />
  95. <el-table-column v-else label="操作" align="center" key="change">
  96. <template slot-scope="scope">
  97. <el-button type="text" @click="getSelect(scope.row)">
  98. 选择
  99. </el-button>
  100. </template>
  101. </el-table-column>
  102. <el-table-column label="音频ID" prop="audioId" align="center" key="audioId" show-overflow-tooltip />
  103. <el-table-column label="音频名称" prop="audioName" align="center" key="audioName" show-overflow-tooltip />
  104. <el-table-column label="音频封面" align="center" key="audioPic" width="100px">
  105. <template slot-scope="scope">
  106. <el-image :src="scope.row.audioPic" />
  107. </template>
  108. </el-table-column>
  109. <el-table-column label="音频作者" align="center" show-overflow-tooltip>
  110. <template slot-scope="scope">
  111. <span>
  112. {{ scope.row.singerName ? scope.row.singerName : '-' }}
  113. </span>
  114. </template>
  115. </el-table-column>
  116. <el-table-column label="专辑名称" prop="songName" align="center" show-overflow-tooltip>
  117. <template slot-scope="scope">
  118. <span>
  119. {{ scope.row.songName ? scope.row.songName : '-' }}
  120. </span>
  121. </template>
  122. </el-table-column>
  123. <el-table-column label="音频类型" prop="audioType" align="center" key="audioType" :formatter="audioFormatter" />
  124. <el-table-column label="音频数量" prop="programCount" align="center" key="programCount" />
  125. <el-table-column label="付费类型" align="center" key="isFree" :formatter="freeFormatter" width="100px" />
  126. <el-table-column label="当前状态" align="center" key="status" :formatter="statusFormatter" />
  127. </el-table>
  128. <pagination v-show="total > 0" :total="total" :page.sync="dialogForm.pageNum" :limit.sync="dialogForm.pageSize"
  129. @pagination="getList" />
  130. </el-dialog>
  131. </div>
  132. </template>
  133. <script>
  134. import { list } from '@/api/operation/scene'
  135. import { detail, moduleList, radioList, submitThree } from '@/api/operation/recommend'
  136. import { coverMixin, audioMixin, platformMixin, isFreeMixin, disabledMixin } from '@/mixin/index'
  137. export default {
  138. mixins: [coverMixin, audioMixin, platformMixin, isFreeMixin, disabledMixin],
  139. data() {
  140. return {
  141. // 遮罩层
  142. loading: false,
  143. // 二级id
  144. secondId: this.$route.query.secondId,
  145. // 三级id
  146. threeId: this.$route.query.threeId,
  147. // 表单
  148. form: [],
  149. // 模板
  150. module: {},
  151. // 弹窗
  152. dialogVisible: false,
  153. // 弹窗表单
  154. dialogForm: {
  155. pageNum: 1,
  156. pageSize: 10,
  157. audioType: '',
  158. platformId: ''
  159. },
  160. // 弹窗列表
  161. dialogTableData: [],
  162. // 总数据
  163. total: 0,
  164. // 禁止操作
  165. disabled: false,
  166. // 是否启用多选
  167. isSelection: true,
  168. // 弹窗索引
  169. index: 0,
  170. // 专区模块
  171. sceneOptions: [],
  172. // 跳转方式
  173. forwardTypeOptions: [{
  174. value: 0,
  175. label: 'APP内容跳转广播',
  176. type: 2
  177. }, {
  178. value: 1,
  179. label: 'APP内容跳转歌曲',
  180. type: 11
  181. }, {
  182. value: 2,
  183. label: 'APP内容跳转歌单',
  184. type: 10
  185. }, {
  186. value: 3,
  187. label: 'APP内容跳转专辑',
  188. type: 8
  189. }, {
  190. value: 4,
  191. label: 'APP内容跳转节目',
  192. type: 6
  193. }, {
  194. value: 7,
  195. label: 'APP内容跳转专区',
  196. type: 16
  197. }, {
  198. value: 5,
  199. label: 'H5内链'
  200. }, {
  201. value: 6,
  202. label: 'H5外链'
  203. }],
  204. // 只读
  205. isRead: false,
  206. // 缓存内容图片
  207. picList: {}
  208. }
  209. },
  210. watch: {
  211. 'dialogForm.audioType'(val) {
  212. this.getPlatform({
  213. audioType: val
  214. })
  215. }
  216. },
  217. mounted() {
  218. this.getSceneList()
  219. this.getModule()
  220. },
  221. methods: {
  222. // 模块 详情
  223. getModule() {
  224. let moduleOptions = {
  225. 1: 'title',
  226. 3: 'description',
  227. 4: 'contentName',
  228. 5: 'forwardType',
  229. 6: 'isCustom',
  230. 7: 'pic',
  231. 8: 'sort',
  232. 9: 'childList'
  233. }
  234. moduleList(this.$route.query.moduleTypeId).then(res => {
  235. if (res.code === 0) {
  236. res.data.elementIds.map(i => {
  237. if (i === '4') { // 内容 关联 音频数据 存在底层module
  238. this.module.contentName = ''
  239. this.module.module = {}
  240. } else if (i === '9') {
  241. this.module.childList = []
  242. } else {
  243. this.module[moduleOptions[i]] = ''
  244. }
  245. })
  246. if (this.$route.query.threeId) {
  247. this.getDetail()
  248. this.isRead = Boolean(this.$route.query.boolean)
  249. }
  250. }
  251. })
  252. },
  253. // 详情
  254. getDetail() {
  255. detail(this.$route.query.threeId).then(res => {
  256. if (res.code === 0 && res.data.list.length > 0) {
  257. // 将详情数据遍历
  258. res.data.list.map((i, index) => {
  259. let obj = {}
  260. // 是否有简介
  261. if ('description' in this.module) {
  262. obj.description = i.module.description
  263. }
  264. // 只保留组件模板的参数
  265. for (const key in i) {
  266. if (this.module.hasOwnProperty(key)) {
  267. obj[key] = i[key]
  268. // 跳转方式关联 内容 栏目 地址
  269. if ([0, 1, 2, 3, 4].includes(i.forwardType)) {
  270. obj.contentName = i.contentName
  271. obj.module = i.module
  272. } else if ([5, 6].includes(i.forwardType)) {
  273. obj.forwardUrl = i.forwardUrl
  274. } else if ([7].includes(i.forwardType)) {
  275. obj.contentId = i.module.contentId
  276. obj.module = i.module
  277. }
  278. // 封面模式 关联 图片 缓存内容图片
  279. if (i.isCustom === 1) {
  280. this.picList[index] = i.pic
  281. }
  282. }
  283. obj.status = i.status
  284. }
  285. this.form.push(obj)
  286. })
  287. }
  288. })
  289. },
  290. // 新增模块
  291. getPush() {
  292. this.form.push(this.module)
  293. },
  294. // 爱听专区
  295. getSceneList() {
  296. list().then(res => {
  297. if (res.code === 0) {
  298. res.data.map(i => {
  299. this.sceneOptions.push({
  300. value: i.id,
  301. label: i.name
  302. })
  303. })
  304. }
  305. })
  306. },
  307. // 跳转方式
  308. forwardTypeChange(item) {
  309. this.$set(item, 'module', {}),
  310. [0, 1, 2, 3, 4].includes(item.forwardType) ? [
  311. this.$set(item, 'contentName', ''),
  312. delete item.forwardUrl,
  313. delete item.contentId
  314. ] : [5, 6].includes(item.forwardType) ? [
  315. this.$set(item, 'forwardUrl', ''),
  316. delete item.contentName,
  317. delete item.contentId
  318. ] : [
  319. this.$set(item, 'contentId', ''),
  320. delete item.contentName,
  321. delete item.forwardUrl
  322. ]
  323. },
  324. // 封面模式
  325. isCustomChange(item, index) {
  326. item.isCustom === 1 ? item.pic = this.picList[index] : item.pic = ''
  327. },
  328. // 上传图片
  329. upload(e, item) {
  330. item.pic = e.file
  331. },
  332. // 专区页面
  333. contentIdChange(item) {
  334. item.module = {}
  335. item.forwardType === 7 ? [
  336. item.module.contentType = 16,
  337. item.module.contentId = item.contentId
  338. ] : ''
  339. },
  340. // 弹窗
  341. getDialog(item, index, boolean) {
  342. this.dialogVisible = true
  343. this.index = index
  344. this.isSelection = boolean
  345. if ('forwardType' in item) {
  346. this.dialogForm.audioType = this.forwardTypeOptions.find(i => i.value === item.forwardType).type
  347. this.disabled = true
  348. } else {
  349. this.dialogForm.audioType = this.audioOptions[0].value
  350. }
  351. this.getList()
  352. },
  353. // 音频列表
  354. getList() {
  355. this.loading = true
  356. radioList(this.dialogForm).then(res => {
  357. if (res.code === 0) {
  358. this.dialogTableData = res.data.records
  359. this.total = res.data.total
  360. let row = ''
  361. if (this.form[this.index].childList && this.form[this.index].childList.length > 0) {
  362. this.form[this.index].childList.map(i => {
  363. row = res.data.records.find(j => j.audioId === i.module.contentId)
  364. })
  365. }
  366. row ? this.$refs.dialogTableData.toggleRowSelection(row) : this.$refs.dialogTableData.clearSelection();
  367. this.loading = false
  368. }
  369. })
  370. },
  371. // 搜索
  372. getSearch() {
  373. this.dialogForm.pageNum = 1
  374. this.getList()
  375. },
  376. rowKey(row) {
  377. return row.audioId
  378. },
  379. // 选择
  380. getSelect(row) {
  381. let e = this.form[this.index]
  382. e.module = {
  383. contentId: row.audioId,
  384. platformId: row.platformId,
  385. contentType: row.audioType,
  386. description: row.description
  387. }
  388. e.contentName = row.audioName
  389. e.pic = row.audioPic
  390. // 封面模式自定义封面会丢失内容封面图片 所以缓存以便改回来使用
  391. this.picList[this.index] = row.audioPic
  392. // 是否有简介 若有则将音频的简介赋值进去
  393. if ('description' in this.module) {
  394. e.description = row.description
  395. }
  396. this.$message.success('选择成功!')
  397. this.dialogVisible = false
  398. },
  399. // 批量选择
  400. handleSelectionChange(row) {
  401. this.form[this.index].childList = []
  402. if (row.length > 0) {
  403. row.map(i => {
  404. if (this.form[this.index].childList.findIndex(j => j.module.contentId === i.audioId) === -1) {
  405. this.form[this.index].childList.push({
  406. module: {
  407. contentId: i.audioId,
  408. platformId: i.platformId,
  409. contentType: i.audioType,
  410. description: i.description,
  411. },
  412. contentName: i.audioName,
  413. pic: i.audioPic,
  414. status: i.status
  415. })
  416. }
  417. })
  418. }
  419. },
  420. // 清空
  421. getEmpty(item) {
  422. for (const key in item) {
  423. if (key !== 'id') {
  424. item[key] = key === 'childrenList' ? [] : key === 'module' ? {} : ''
  425. }
  426. }
  427. },
  428. // 提交
  429. getSubmit() {
  430. let data = this.secondId ? {
  431. secondId: this.secondId,
  432. list: this.form
  433. } : {
  434. threeId: this.threeId,
  435. list: this.form
  436. }
  437. // 删除仅作展示的缓存数据
  438. for (const index in this.form) {
  439. delete this.form[index].contentId
  440. this.form[index].module.description = this.form[index].description
  441. delete this.form[index].description
  442. }
  443. submitThree(data).then(res => {
  444. if (res.code === 0) {
  445. this.$message.success('提交成功!')
  446. this.cancel()
  447. }
  448. })
  449. },
  450. // 返回
  451. cancel() {
  452. this.$tab.closeOpenPage("/operation/operationRecommend");
  453. },
  454. // 删除模块
  455. getDelete(index) {
  456. this.form.splice(index, 1)
  457. },
  458. // 删除关联
  459. getRemove(row, index) {
  460. let e = this.form[index].childList.findIndex(i => i.contentId === row.contentId)
  461. this.form[index].childList.splice(e, 1)
  462. },
  463. // 字典翻译
  464. audioFormatter(row) {
  465. return this.selectDictLabel(this.audioOptions, row.audioType)
  466. },
  467. freeFormatter(row) {
  468. return this.selectDictLabel(this.freeOptions, row.isFree)
  469. },
  470. statusFormatter(row) {
  471. return this.selectDictLabel(this.disabledOptions, row.status)
  472. }
  473. }
  474. }
  475. </script>
  476. <style lang="scss" scoped>
  477. .app-container {
  478. padding-bottom: 100px;
  479. }
  480. .form {
  481. width: 500px;
  482. border: 1px solid #dcdfe6;
  483. box-shadow: 5px 5px 5px 0 #dcdfe6;
  484. padding: 20px;
  485. margin-bottom: 20px;
  486. position: relative;
  487. margin-right: 20px;
  488. .sort {
  489. ::v-deep .el-form-item__label-wrap {
  490. margin: 0 !important;
  491. }
  492. .el-link {
  493. float: right;
  494. }
  495. }
  496. }
  497. .btn {
  498. position: fixed;
  499. bottom: 0;
  500. left: 0;
  501. width: 100%;
  502. height: 100px;
  503. border-top: 1px solid #dcdfe6;
  504. box-shadow: 5px 0 10px 0 #dcdfe6;
  505. line-height: 100px;
  506. text-align: right;
  507. padding: 0 20px;
  508. background: #FFF;
  509. }
  510. </style>