detail.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. <template>
  2. <div class="app-container">
  3. <el-button v-if="!isRead" 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" key="selection" reserve-selection />
  95. <el-table-column label="音频ID" prop="audioId" align="center" key="audioId" show-overflow-tooltip />
  96. <el-table-column label="音频名称" prop="audioName" align="center" key="audioName" show-overflow-tooltip />
  97. <el-table-column label="音频封面" align="center" key="audioPic" width="100px">
  98. <template slot-scope="scope">
  99. <el-image :src="scope.row.audioPic" />
  100. </template>
  101. </el-table-column>
  102. <el-table-column label="音频作者" align="center" show-overflow-tooltip>
  103. <template slot-scope="scope">
  104. <span>
  105. {{ scope.row.singerName ? scope.row.singerName : '-' }}
  106. </span>
  107. </template>
  108. </el-table-column>
  109. <el-table-column label="专辑名称" prop="songName" align="center" show-overflow-tooltip>
  110. <template slot-scope="scope">
  111. <span>
  112. {{ scope.row.songName ? scope.row.songName : '-' }}
  113. </span>
  114. </template>
  115. </el-table-column>
  116. <el-table-column label="音频类型" prop="audioType" align="center" key="audioType" :formatter="audioFormatter" />
  117. <el-table-column label="音频数量" prop="programCount" align="center" key="programCount" />
  118. <el-table-column label="付费类型" align="center" key="isFree" :formatter="freeFormatter" width="100px" />
  119. <el-table-column label="当前状态" align="center" key="status" :formatter="statusFormatter" />
  120. <el-table-column v-if="!isSelection" label="操作" align="center" key="change">
  121. <template slot-scope="scope">
  122. <el-button type="text" @click="getSelect(scope.row)">
  123. 选择
  124. </el-button>
  125. </template>
  126. </el-table-column>
  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.push('contentName', 'module')
  239. } else if (i === '9') {
  240. this.module.push('childList')
  241. } else {
  242. this.module.push(moduleOptions[i])
  243. }
  244. })
  245. if (this.$route.query.threeId) {
  246. this.getDetail()
  247. this.isRead = Boolean(this.$route.query.boolean)
  248. }
  249. }
  250. })
  251. },
  252. // 详情
  253. getDetail() {
  254. detail(this.$route.query.threeId).then(res => {
  255. if (res.code === 0 && res.data.list.length > 0) {
  256. // 将详情数据遍历
  257. res.data.list.map((i, index) => {
  258. let obj = {}
  259. // 是否有简介
  260. if (this.module.find(i => i === 'description')) {
  261. obj.description = i.module.description
  262. }
  263. // 只保留组件模板的参数
  264. for (const key in i) {
  265. if (this.module.find(j => j === key)) {
  266. obj[key] = i[key]
  267. // 跳转方式关联 内容 栏目 地址
  268. if ([0, 1, 2, 3, 4].includes(i.forwardType)) {
  269. obj.contentName = i.contentName
  270. obj.module = i.module
  271. } else if ([5, 6].includes(i.forwardType)) {
  272. obj.forwardUrl = i.forwardUrl
  273. } else if ([7].includes(i.forwardType)) {
  274. obj.contentId = i.module.contentId
  275. obj.module = i.module
  276. }
  277. // 封面模式 关联 图片 缓存内容图片
  278. if (i.isCustom === 1) {
  279. this.picList[index] = i.pic
  280. }
  281. }
  282. obj.status = i.status
  283. }
  284. this.form.push(obj)
  285. })
  286. }
  287. })
  288. },
  289. // 新增模块
  290. getPush() {
  291. let obj = {}
  292. this.module.map(i => {
  293. obj[i] = i === 'childList' ? [] : i === 'module' ? {} : ''
  294. })
  295. this.form.push(obj)
  296. },
  297. // 爱听专区
  298. getSceneList() {
  299. list().then(res => {
  300. if (res.code === 0) {
  301. res.data.map(i => {
  302. this.sceneOptions.push({
  303. value: i.id,
  304. label: i.name
  305. })
  306. })
  307. }
  308. })
  309. },
  310. // 跳转方式
  311. forwardTypeChange(item) {
  312. this.$set(item, 'module', {}),
  313. [0, 1, 2, 3, 4].includes(item.forwardType) ? [
  314. this.$set(item, 'contentName', ''),
  315. delete item.forwardUrl,
  316. delete item.contentId
  317. ] : [5, 6].includes(item.forwardType) ? [
  318. this.$set(item, 'forwardUrl', ''),
  319. delete item.contentName,
  320. delete item.contentId
  321. ] : [
  322. this.$set(item, 'contentId', ''),
  323. delete item.contentName,
  324. delete item.forwardUrl
  325. ]
  326. },
  327. // 封面模式
  328. isCustomChange(item, index) {
  329. item.isCustom === 1 ? item.pic = this.picList[index] : item.pic = ''
  330. },
  331. // 上传图片
  332. upload(e, item) {
  333. item.pic = e.file
  334. },
  335. // 专区页面
  336. contentIdChange(item) {
  337. item.module = {}
  338. item.forwardType === 7 ? [
  339. item.module.contentType = 16,
  340. item.module.contentId = item.contentId
  341. ] : ''
  342. },
  343. // 弹窗
  344. getDialog(item, index, boolean) {
  345. this.dialogVisible = true
  346. this.index = index
  347. this.isSelection = boolean
  348. if ('forwardType' in item) {
  349. this.dialogForm.audioType = this.forwardTypeOptions.find(i => i.value === item.forwardType).type
  350. this.disabled = true
  351. } else {
  352. this.dialogForm.audioType = this.audioOptions[0].value
  353. }
  354. this.getList()
  355. },
  356. // 音频列表
  357. getList() {
  358. this.loading = true
  359. radioList(this.dialogForm).then(res => {
  360. if (res.code === 0) {
  361. this.dialogTableData = res.data.records
  362. this.total = res.data.total
  363. let row = ''
  364. if (this.form[this.index].childList && this.form[this.index].childList.length > 0) {
  365. this.form[this.index].childList.map(i => {
  366. row = res.data.records.find(j => j.audioId === i.module.contentId)
  367. })
  368. }
  369. row ? this.$refs.dialogTableData.toggleRowSelection(row) : this.$refs.dialogTableData.clearSelection();
  370. this.loading = false
  371. }
  372. })
  373. },
  374. // 搜索
  375. getSearch() {
  376. this.dialogForm.pageNum = 1
  377. this.getList()
  378. },
  379. rowKey(row) {
  380. return row.audioId
  381. },
  382. // 选择
  383. getSelect(row) {
  384. let e = this.form[this.index]
  385. e.module = {
  386. contentId: row.audioId,
  387. platformId: row.platformId,
  388. contentType: row.audioType,
  389. description: row.description
  390. }
  391. e.contentName = row.audioName
  392. e.pic = row.audioPic
  393. // 封面模式自定义封面会丢失内容封面图片 所以缓存以便改回来使用
  394. this.picList[this.index] = row.audioPic
  395. // 是否有简介 若有则将音频的简介赋值进去
  396. if (this.module.find(i => i === 'description')) {
  397. e.description = row.description
  398. }
  399. this.$message.success('选择成功!')
  400. this.dialogVisible = false
  401. },
  402. // 批量选择
  403. handleSelectionChange(row) {
  404. this.form[this.index].childList = []
  405. if (row.length > 0) {
  406. row.map(i => {
  407. if (this.form[this.index].childList.findIndex(j => j.module.contentId === i.audioId) === -1) {
  408. this.form[this.index].childList.push({
  409. module: {
  410. contentId: i.audioId,
  411. platformId: i.platformId,
  412. contentType: i.audioType,
  413. description: i.description,
  414. },
  415. contentName: i.audioName,
  416. pic: i.audioPic,
  417. status: i.status
  418. })
  419. }
  420. })
  421. }
  422. },
  423. // 清空
  424. getEmpty(item) {
  425. for (const key in item) {
  426. if (key !== 'id') {
  427. item[key] = key === 'childrenList' ? [] : key === 'module' ? {} : ''
  428. }
  429. // 如果有跳转方式 删除附带组件
  430. if (key === 'forwardType') {
  431. delete item.contentName,
  432. delete item.forwardUrl,
  433. delete item.contentId
  434. }
  435. }
  436. },
  437. // 提交
  438. getSubmit() {
  439. let data = this.secondId ? {
  440. secondId: this.secondId,
  441. list: this.form
  442. } : {
  443. threeId: this.threeId,
  444. list: this.form
  445. }
  446. // 删除仅作展示的缓存数据
  447. for (const index in this.form) {
  448. delete this.form[index].contentId
  449. if ('description' in this.form[index]) {
  450. this.form[index].module.description = this.form[index].description
  451. delete this.form[index].description
  452. }
  453. }
  454. submitThree(data).then(res => {
  455. if (res.code === 0) {
  456. this.$message.success('提交成功!')
  457. this.cancel()
  458. }
  459. })
  460. },
  461. // 返回
  462. cancel() {
  463. this.$tab.closeOpenPage("/operation/operationRecommend");
  464. },
  465. // 删除模块
  466. getDelete(index) {
  467. this.form.splice(index, 1)
  468. },
  469. // 删除关联
  470. getRemove(row, index) {
  471. let e = this.form[index].childList.findIndex(i => i.contentId === row.contentId)
  472. this.form[index].childList.splice(e, 1)
  473. },
  474. // 字典翻译
  475. audioFormatter(row) {
  476. return this.selectDictLabel(this.audioOptions, row.audioType)
  477. },
  478. freeFormatter(row) {
  479. return this.selectDictLabel(this.freeOptions, row.isFree)
  480. },
  481. statusFormatter(row) {
  482. return this.selectDictLabel(this.disabledOptions, row.status)
  483. }
  484. }
  485. }
  486. </script>
  487. <style lang="scss" scoped>
  488. .app-container {
  489. padding-bottom: 100px;
  490. }
  491. .form {
  492. width: 500px;
  493. border: 1px solid #dcdfe6;
  494. box-shadow: 5px 5px 5px 0 #dcdfe6;
  495. padding: 20px;
  496. margin-bottom: 20px;
  497. position: relative;
  498. margin-right: 20px;
  499. .sort {
  500. ::v-deep .el-form-item__label-wrap {
  501. margin: 0 !important;
  502. }
  503. .el-link {
  504. float: right;
  505. }
  506. }
  507. }
  508. .btn {
  509. position: fixed;
  510. bottom: 0;
  511. left: 0;
  512. width: 100%;
  513. height: 100px;
  514. border-top: 1px solid #dcdfe6;
  515. box-shadow: 5px 0 10px 0 #dcdfe6;
  516. line-height: 100px;
  517. text-align: right;
  518. padding: 0 20px;
  519. background: #FFF;
  520. }
  521. </style>