detail.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. <!-- 音频管理 播客专辑详情 -->
  2. <template>
  3. <div class="app-container">
  4. <el-form
  5. class="form"
  6. :model="form"
  7. ref="form"
  8. :rules="rules"
  9. label-width="100px"
  10. :disabled="disabled"
  11. >
  12. <el-form-item label="播客名称:" prop="name">
  13. <el-input v-model="form.name" placeholder="请输入播客名称" />
  14. </el-form-item>
  15. <el-form-item label="主播名称:" prop="podcasterIds">
  16. <el-select
  17. v-model="form.podcasterIds"
  18. multiple
  19. filterable
  20. remote
  21. reserve-keyword
  22. placeholder="请输入主播名称"
  23. :remote-method="getSelect"
  24. no-data-text="请新增主播"
  25. >
  26. <el-option
  27. v-for="item in anchorOptions"
  28. :key="item.value"
  29. :value="item.value"
  30. :label="item.label"
  31. />
  32. </el-select>
  33. </el-form-item>
  34. <el-form-item label="播客分类:" prop="categoryIds">
  35. <el-select
  36. v-model="form.categoryIds"
  37. multiple
  38. placeholder="请选择播客分类"
  39. >
  40. <el-option
  41. v-for="item in blogClassOptions"
  42. :key="item.value"
  43. :value="item.value"
  44. :label="item.label"
  45. />
  46. </el-select>
  47. </el-form-item>
  48. <el-form-item label="播客介绍:" prop="description">
  49. <el-input
  50. v-model="form.description"
  51. type="textarea"
  52. :autosize="{ minRows: 5, maxRows: 10 }"
  53. maxlength="300"
  54. show-word-limit
  55. placeholder=" 请输入播客介绍"
  56. />
  57. </el-form-item>
  58. <el-form-item label="资源平台:" prop="platformId">
  59. <el-select
  60. v-model="form.platformId"
  61. placeholder="请选择资源平台"
  62. :disabled="disabledPlatformId(form.platformId)"
  63. >
  64. <el-option
  65. v-for="item in platformOptions"
  66. :key="item.value"
  67. :value="item.value"
  68. :label="item.label"
  69. :disabled="disabledJoinType(item.joinType)"
  70. />
  71. </el-select>
  72. </el-form-item>
  73. <el-form-item label="付费类型:" prop="charging">
  74. <el-select v-model="form.charging" placeholder="请选择付费类型">
  75. <el-option
  76. v-for="item in payTypeOptions"
  77. :key="item.value"
  78. :value="item.value"
  79. :label="item.label"
  80. />
  81. </el-select>
  82. </el-form-item>
  83. <el-form-item v-if="form.charging !== 1" label="原价:" prop="price">
  84. <el-input-number
  85. v-model="form.price"
  86. placeholder="请输入原价"
  87. :min="1"
  88. :precision="2"
  89. :controls="false"
  90. />
  91. </el-form-item>
  92. <el-form-item
  93. v-if="form.charging !== 1"
  94. label="折扣价:"
  95. prop="discountedPrice"
  96. >
  97. <el-input-number
  98. v-model="form.discountedPrice"
  99. placeholder="请输入折扣价"
  100. :min="1"
  101. :precision="2"
  102. :controls="false"
  103. />
  104. </el-form-item>
  105. <el-form-item label="播客封面" prop="thumb">
  106. <Upload
  107. listType="picture-card"
  108. :url="form.thumb"
  109. @upload="upload"
  110. :disabled="disabled"
  111. />
  112. </el-form-item>
  113. <el-form-item label="关联节目:" prop="adminPodCastProgramDetailResp">
  114. <el-button type="primary" @click="getDialog">关联节目</el-button>
  115. <el-button @click="getDelete" :disabled="ids.length > 0 ? false : true"
  116. >解除关联</el-button
  117. >
  118. </el-form-item>
  119. <el-form-item style="width: 100%">
  120. <el-table
  121. :data="form.adminPodCastProgramDetailResp"
  122. @selection-change="handleSelect"
  123. >
  124. <el-table-column type="selection" align="center" />
  125. <el-table-column
  126. label="ID"
  127. prop="id"
  128. align="center"
  129. show-overflow-tooltip
  130. />
  131. <el-table-column
  132. label="节目名称"
  133. prop="name"
  134. align="center"
  135. show-overflow-tooltip
  136. />
  137. <el-table-column
  138. label="资源平台"
  139. prop="platformId"
  140. align="center"
  141. :formatter="platformFormatter"
  142. />
  143. <el-table-column
  144. label="当前状态"
  145. prop="status"
  146. align="center"
  147. :formatter="statusFormatter"
  148. />
  149. <el-table-column label="操作" align="center">
  150. <template slot-scope="scope">
  151. <!-- 向上移动 -->
  152. <el-button
  153. type="text"
  154. icon="el-icon-caret-top"
  155. @click="getChange(true, scope.$index, scope.$index - 1)"
  156. :disabled="(scope.$index < 1 && !disabled) || !canOrder"
  157. />
  158. <!-- 向下移动 -->
  159. <el-button
  160. type="text"
  161. icon="el-icon-caret-bottom"
  162. @click="getChange(false, scope.$index, scope.$index + 1)"
  163. :disabled="
  164. (scope.$index >
  165. form.adminPodCastProgramDetailResp.length - 2 &&
  166. !disabled) ||
  167. !canOrder
  168. "
  169. />
  170. </template>
  171. </el-table-column>
  172. </el-table>
  173. </el-form-item>
  174. </el-form>
  175. <div class="form-btn">
  176. <el-button @click="cancel">取消</el-button>
  177. <el-button v-if="!disabled" type="primary" @click="getSubmit"
  178. >确定</el-button
  179. >
  180. </div>
  181. <!-- 弹窗 -->
  182. <el-dialog :visible.sync="dialogVisible" title="关联节目" width="1200px">
  183. <el-form inline size="mini" style="width: 100%">
  184. <el-form-item label="节目ID:">
  185. <el-input
  186. v-model="dialogForm.id"
  187. placeholder="请输入节目ID"
  188. clearable
  189. />
  190. </el-form-item>
  191. <el-form-item label="节目名称:">
  192. <el-input
  193. v-model="dialogForm.name"
  194. placeholder="请输入节目名称"
  195. clearable
  196. />
  197. </el-form-item>
  198. <el-form-item label="付费类型:">
  199. <el-select
  200. v-model="dialogForm.isFree"
  201. placeholder="请选择付费类型"
  202. clearable
  203. >
  204. <el-option
  205. v-for="item in freeOptions"
  206. :key="item.value"
  207. :value="item.value"
  208. :label="item.label"
  209. />
  210. </el-select>
  211. </el-form-item>
  212. <el-form-item label="资源平台:">
  213. <el-select
  214. v-model="dialogForm.platformId"
  215. placeholder="请选择资源平台"
  216. >
  217. <el-option
  218. v-for="item in platformOptions.filter(
  219. (i) => !i.joinType.includes('1')
  220. )"
  221. :key="item.value"
  222. :value="item.value"
  223. :label="item.label"
  224. />
  225. </el-select>
  226. </el-form-item>
  227. <el-form-item>
  228. <el-button type="primary" icon="el-icon-search" @click="getSearch"
  229. >搜索</el-button
  230. >
  231. <el-button icon="el-icon-refresh" @click="getRefresh">重置</el-button>
  232. </el-form-item>
  233. </el-form>
  234. <el-table
  235. :data="dialogTableData"
  236. ref="multipleTable"
  237. :row-key="tableKey"
  238. v-loading="loading"
  239. @selection-change="handleSelectionChange"
  240. >
  241. <el-table-column
  242. type="selection"
  243. align="center"
  244. key="selection"
  245. reserve-selection
  246. />
  247. <el-table-column label="ID" prop="id" align="center" />
  248. <el-table-column
  249. label="节目名称"
  250. prop="name"
  251. align="center"
  252. show-overflow-tooltip
  253. />
  254. <el-table-column
  255. label="资源平台"
  256. prop="platformId"
  257. align="center"
  258. :formatter="platformFormatter"
  259. />
  260. <el-table-column
  261. label="付费类型"
  262. prop="isFree"
  263. align="center"
  264. :formatter="freeFormatter"
  265. />
  266. <el-table-column
  267. label="当前状态"
  268. prop="status"
  269. align="center"
  270. :formatter="statusFormatter"
  271. />
  272. <!-- <el-table-column label="操作" align="center">
  273. <template slot-scope="scope">
  274. <el-button
  275. type="text"
  276. @click="getChecked(scope.row)"
  277. :disabled="
  278. form.adminPodCastProgramDetailResp.findIndex(
  279. (i) => i.id === scope.row.id
  280. ) === -1
  281. ? false
  282. : true
  283. "
  284. >
  285. 选择
  286. </el-button>
  287. </template>
  288. </el-table-column> -->
  289. </el-table>
  290. <pagination
  291. v-show="total > 0"
  292. :total="total"
  293. :page.sync="dialogForm.pageNum"
  294. :limit.sync="dialogForm.pageSize"
  295. @pagination="getList"
  296. />
  297. </el-dialog>
  298. </div>
  299. </template>
  300. <script>
  301. import { selectAnchor } from "@/api/music/anchor";
  302. import { checkList, detail, relieve, submit } from "@/api/music/blog";
  303. import {
  304. blogClassMixin,
  305. isFreeMixin,
  306. onOrOffMixin,
  307. payTypeMixin,
  308. platformMixin,
  309. } from "@/mixin/index";
  310. export default {
  311. mixins: [
  312. blogClassMixin,
  313. platformMixin,
  314. payTypeMixin,
  315. onOrOffMixin,
  316. isFreeMixin,
  317. ],
  318. data() {
  319. // 判断原价是否大于折扣价
  320. var checkPrice = (rule, value, callback) => {
  321. if (!value) {
  322. callback(new Error("请输入原价"));
  323. } else {
  324. if (this.form.discountedPrice && value <= this.form.discountedPrice) {
  325. callback(new Error("原价必须大于折扣价"));
  326. }
  327. callback();
  328. }
  329. };
  330. // 判断折扣价是否小于原价
  331. var checkDiscount = (rule, value, callback) => {
  332. if (this.form.price && value >= this.form.price) {
  333. callback(new Error("折扣价必须小于原价"));
  334. } else {
  335. callback();
  336. }
  337. };
  338. return {
  339. // 遮罩层
  340. loading: false,
  341. // 表单
  342. form: {
  343. adminPodCastProgramDetailResp: [],
  344. podcastProgramIds: [],
  345. categoryIds: [],
  346. status: 1,
  347. },
  348. // 主播
  349. anchorOptions: [],
  350. // 弹窗
  351. dialogVisible: false,
  352. // 弹窗表单
  353. dialogForm: {
  354. pageNum: 1,
  355. pageSize: 10,
  356. status: 1,
  357. platformId: null,
  358. },
  359. // 总数据
  360. total: 0,
  361. // 弹窗列表
  362. dialogTableData: [],
  363. // 只读
  364. disabled: false,
  365. // 校验
  366. rules: {
  367. name: [
  368. {
  369. required: true,
  370. message: "请输入播客专辑名称",
  371. trigger: "blur",
  372. },
  373. ],
  374. podcasterIds: [
  375. {
  376. required: true,
  377. message: "请输入主播名称",
  378. trigger: "blur",
  379. },
  380. ],
  381. categoryIds: [
  382. {
  383. required: true,
  384. message: "请选择播客分类",
  385. trigger: "change",
  386. },
  387. ],
  388. platformId: [
  389. {
  390. required: true,
  391. message: "请选择资源平台",
  392. trigger: "change",
  393. },
  394. ],
  395. charging: [
  396. {
  397. required: true,
  398. message: "请选择付费类型",
  399. trigger: "change",
  400. },
  401. ],
  402. price: [
  403. {
  404. required: true,
  405. validator: checkPrice,
  406. trigger: "blur",
  407. },
  408. ],
  409. discountedPrice: [
  410. {
  411. validator: checkDiscount,
  412. trigger: "blur",
  413. },
  414. ],
  415. thumb: [
  416. {
  417. required: true,
  418. message: "请上传播客封面",
  419. trigger: "change",
  420. },
  421. ],
  422. adminPodCastProgramDetailResp: [
  423. {
  424. required: true,
  425. message: "请关联节目",
  426. trigger: "change",
  427. },
  428. ],
  429. },
  430. // 解除关联
  431. ids: [],
  432. // 是否已选
  433. disabledChecked: false,
  434. ///被选中数据是否加载完
  435. isLoad: false,
  436. ///是否可以调整顺序
  437. canOrder: true,
  438. };
  439. },
  440. mounted() {
  441. // 获取资源平台
  442. this.getPlatform({
  443. audioType: 8,
  444. });
  445. if (this.$route.query.id) {
  446. this.form.id = this.$route.query.id;
  447. this.disabled = Boolean(this.$route.query.disabled);
  448. this.getDetail();
  449. }
  450. },
  451. methods: {
  452. // 删除已选歌曲
  453. getDeletePlus(index) {
  454. this.form.adminPodCastProgramDetailResp.splice(index, 1);
  455. this.form.adminPodCastProgramDetailResp =
  456. this.form.adminPodCastProgramDetailResp.filter((i) => i);
  457. },
  458. // 排序
  459. getChange(top, index, laterIndex) {
  460. var row = this.form.adminPodCastProgramDetailResp[index];
  461. var laterRow = this.form.adminPodCastProgramDetailResp[laterIndex];
  462. if (top) {
  463. this.form.adminPodCastProgramDetailResp[index] = laterRow;
  464. this.form.adminPodCastProgramDetailResp[laterIndex] = row;
  465. } else {
  466. this.form.adminPodCastProgramDetailResp[laterIndex] = row;
  467. this.form.adminPodCastProgramDetailResp[index] = laterRow;
  468. }
  469. this.form.adminPodCastProgramDetailResp =
  470. this.form.adminPodCastProgramDetailResp.filter((i) => i);
  471. },
  472. tableKey(row) {
  473. return row.id;
  474. },
  475. handleSelectionChange(val) {
  476. if (this.isLoad) {
  477. if (this.form.adminPodCastProgramDetailResp.length == 0) {
  478. this.form.adminPodCastProgramDetailResp = JSON.parse(
  479. JSON.stringify(val)
  480. );
  481. } else {
  482. ///查找dialogTableData里面有的
  483. var tempDialogHas = [];
  484. for (var i = 0; i < this.dialogTableData.length; i++) {
  485. for (var j = 0; j < val.length; j++) {
  486. if (this.dialogTableData[i].id === val[j].id) {
  487. tempDialogHas.push(this.dialogTableData[i]);
  488. break;
  489. }
  490. }
  491. }
  492. ///查找dialogTableData里面没有的
  493. var tempDialogNot = [];
  494. if (tempDialogHas.length == 0) {
  495. tempDialogNot = JSON.parse(JSON.stringify(this.dialogTableData));
  496. } else {
  497. for (var i = 0; i < this.dialogTableData.length; i++) {
  498. var has = false;
  499. for (var j = 0; j < tempDialogHas.length; j++) {
  500. if (this.dialogTableData[i].id === tempDialogHas[j].id) {
  501. has = true;
  502. break;
  503. }
  504. }
  505. if (!has) {
  506. tempDialogNot.push(this.dialogTableData[i]);
  507. }
  508. }
  509. }
  510. ///减少val没有的
  511. if (tempDialogNot.length > 0) {
  512. for (var i = 0; i < tempDialogNot.length; i++) {
  513. for (
  514. var j = 0;
  515. j < this.form.adminPodCastProgramDetailResp.length;
  516. j++
  517. ) {
  518. if (
  519. tempDialogNot[i].id ===
  520. this.form.adminPodCastProgramDetailResp[j].id
  521. ) {
  522. this.form.adminPodCastProgramDetailResp.splice(j, 1);
  523. break;
  524. }
  525. }
  526. }
  527. }
  528. ///添加adminPodCastProgramDetailResp没有的
  529. for (var i = 0; i < val.length; i++) {
  530. var isHas = false;
  531. for (
  532. var j = 0;
  533. j < this.form.adminPodCastProgramDetailResp.length;
  534. j++
  535. ) {
  536. if (val[i].id === this.form.adminPodCastProgramDetailResp[j].id) {
  537. isHas = true;
  538. break;
  539. }
  540. }
  541. if (!isHas) {
  542. this.form.adminPodCastProgramDetailResp.push(val[i]);
  543. }
  544. }
  545. }
  546. this.form.adminPodCastProgramDetailResp =
  547. this.form.adminPodCastProgramDetailResp.filter((i) => i);
  548. this.$message.success("操作成功!");
  549. }
  550. },
  551. // 详情
  552. getDetail() {
  553. detail(this.form.id).then((res) => {
  554. if (res.code === 0) {
  555. this.form = res.data;
  556. console.log("gadsfqwerqwerqr====" + this.form.platformId);
  557. ///qq音乐和喜马拉雅
  558. if (this.form.platformId == 6 || this.form.platformId == 12) {
  559. this.canOrder = false;
  560. }
  561. this.anchorOptions = [];
  562. res.data.adminPrdCasterResp.map((i) => {
  563. this.anchorOptions.push({
  564. value: i.podcasterId,
  565. label: i.podcasterName,
  566. });
  567. });
  568. this.form.podcasterIds = res.data.podcasterIds.split(",");
  569. }
  570. });
  571. },
  572. // 查询主播
  573. getSelect(e) {
  574. if (e) {
  575. setTimeout(() => {
  576. this.anchorOptions = [];
  577. selectAnchor(e).then((res) => {
  578. if (res.code === 0) {
  579. res.data.map((i) => {
  580. this.anchorOptions.push({
  581. value: i.id,
  582. label: i.nickname,
  583. });
  584. });
  585. }
  586. }, 500);
  587. });
  588. }
  589. },
  590. // 上传
  591. upload(e) {
  592. this.form.thumb = e.file;
  593. },
  594. // 弹窗
  595. getDialog() {
  596. this.dialogVisible = true;
  597. this.dialogForm.platformId = this.platformOptions.filter(
  598. (i) => !i.joinType.includes("1")
  599. )[0].value;
  600. this.getList();
  601. },
  602. // 节目列表
  603. getList() {
  604. this.loading = true;
  605. checkList(this.dialogForm).then((res) => {
  606. if (res.code === 0) {
  607. this.dialogTableData = res.data.records;
  608. this.total = res.data.total;
  609. this.loading = false;
  610. this.isLoad = false;
  611. this.$refs.multipleTable.clearSelection();
  612. if (this.form.adminPodCastProgramDetailResp.length > 0) {
  613. var temp = [];
  614. for (var i = 0; i < this.dialogTableData.length; i++) {
  615. for (
  616. var j = 0;
  617. j < this.form.adminPodCastProgramDetailResp.length;
  618. j++
  619. ) {
  620. if (
  621. this.form.adminPodCastProgramDetailResp[j].id ===
  622. this.dialogTableData[i].id
  623. ) {
  624. temp.push(this.dialogTableData[i]);
  625. break;
  626. }
  627. }
  628. }
  629. if (temp.length > 0) {
  630. temp.forEach((item) => {
  631. this.$refs.multipleTable.toggleRowSelection(item, true);
  632. });
  633. }
  634. }
  635. this.isLoad = true;
  636. }
  637. });
  638. },
  639. // 搜索
  640. getSearch() {
  641. this.dialogForm.pageNum = 1;
  642. this.getList();
  643. },
  644. // 重置
  645. getRefresh() {
  646. this.dialogForm = {
  647. pageNum: 1,
  648. pageSize: 10,
  649. status: 1,
  650. platformId: this.platformOptions[0].value,
  651. };
  652. this.getList();
  653. },
  654. // 选择
  655. getChecked(row) {
  656. this.form.adminPodCastProgramDetailResp.push(row);
  657. this.$message.success("选择成功!");
  658. },
  659. // 解除关联
  660. getDelete() {
  661. if (this.form.id) {
  662. relieve({
  663. id: this.form.id,
  664. podcastProgramIds: this.ids,
  665. }).then((res) => {
  666. if (res.code === 0) {
  667. this.$message.success("解除成功!");
  668. this.getDetail();
  669. }
  670. });
  671. } else {
  672. this.ids.map((i) => {
  673. this.form.adminPodCastProgramDetailResp.map((j, index) => {
  674. if (j.id === i) {
  675. this.form.adminPodCastProgramDetailResp.splice(index, 1);
  676. this.$message.success("解除成功!");
  677. }
  678. });
  679. });
  680. }
  681. },
  682. // 确定
  683. getSubmit() {
  684. this.$refs.form.validate((valid) => {
  685. if (valid) {
  686. let title = this.form.id ? "编辑成功!" : "新增成功!";
  687. this.form.podcastProgramIds = [];
  688. this.form.adminPodCastProgramDetailResp.map((i) => {
  689. this.form.podcastProgramIds.push(i.id);
  690. });
  691. submit(this.form).then((res) => {
  692. // if (res.code === 0) {
  693. // this.$message.success(title);
  694. // this.cancel();
  695. // }
  696. if (res.code === 0) {
  697. this.$message.success(`${title}`);
  698. if (this.form.id) {
  699. delete this.form.adminPodCastProgramDetailResp;
  700. this.getDetail();
  701. } else {
  702. this.cancel();
  703. }
  704. }
  705. });
  706. } else {
  707. return false;
  708. }
  709. });
  710. },
  711. // 多选
  712. handleSelect(e) {
  713. this.ids = [];
  714. e.map((i) => {
  715. this.ids.push(i.id);
  716. });
  717. },
  718. // 取消
  719. cancel() {
  720. this.$tab.closeOpenPage("/music/blog");
  721. },
  722. // 字典翻译
  723. platformFormatter(row) {
  724. return this.selectDictLabel(this.platformOptions, row.platformId);
  725. },
  726. statusFormatter(row) {
  727. return this.selectDictLabel(this.onOrOffOptions, row.status);
  728. },
  729. freeFormatter(row) {
  730. return this.selectDictLabel(this.freeOptions, row.isFree);
  731. },
  732. },
  733. };
  734. </script>
  735. <style lang="scss" scoped>
  736. .form {
  737. .el-form-item {
  738. width: 500px;
  739. }
  740. }
  741. </style>