detail.vue 20 KB

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