detail.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <!-- 音乐专辑 详情 -->
  2. <template>
  3. <div class="app-container">
  4. <el-form class="form" :model="form" ref="form" :rules="rules" label-width="100px" :disabled="disabled">
  5. <el-form-item label="专辑名称:" prop="name">
  6. <el-input v-model="form.name" placeholder="请输入专辑名称" />
  7. </el-form-item>
  8. <el-form-item label="专辑介绍" prop="description">
  9. <el-input v-model="form.description" type="textarea" :autosize="{ minRows: 5, maxRows: 10 }" maxlength="300"
  10. show-word-limit placeholder="请输入专辑介绍" />
  11. </el-form-item>
  12. <el-form-item label="专辑类型:" prop="albumType">
  13. <el-select v-model="form.albumType" placeholder="请选择专辑类型">
  14. <el-option v-for="item in albumTypeOptions" :key="item.value" :value="item.value" :label="item.label" />
  15. </el-select>
  16. </el-form-item>
  17. <el-form-item label="资源平台:" prop="platformId">
  18. <el-select v-model="form.platformId" placeholder="请选择资源平台" :disabled="disabledPlatformId(form.platformId)">
  19. <el-option v-for="item in platformOptions" :key="item.value" :value="item.value" :label="item.label"
  20. :disabled="disabledJoinType(item.joinType)" />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item label="付费类型:" prop="payType">
  24. <el-select v-model="form.payType" placeholder="请选择付费类型">
  25. <el-option v-for="item in payTypeOptions" :key="item.value" :value="item.value" :label="item.label" />
  26. </el-select>
  27. </el-form-item>
  28. <el-form-item v-if="form.payType !== 1" label="原价:" prop="price">
  29. <el-input-number v-model="form.price" placeholder="请输入原价" :min="1" :precision="2" :controls="false" />
  30. </el-form-item>
  31. <el-form-item v-if="form.payType !== 1" label="折扣价:" prop="discount">
  32. <el-input-number v-model="form.discount" placeholder="请输入折扣价" :min="1" :precision="2" :controls="false" />
  33. </el-form-item>
  34. <el-form-item label="专辑封面:" prop="coverUrl">
  35. <Upload listType="picture-card" :url="form.coverUrl" @upload="upload($event, 'coverUrl')"
  36. :disabled="disabled" />
  37. </el-form-item>
  38. <el-form-item label="歌曲列表:" style="width: 100%">
  39. <el-button type="primary" icon="el-icon-plus" @click="getDialog">添加歌曲</el-button>
  40. <!-- 列表 -->
  41. <el-table :data="form.programList" v-loading="form_loading">
  42. <el-table-column label="ID" prop="id" align="center" />
  43. <el-table-column label="歌曲名称" prop="name" align="center" show-overflow-tooltip />
  44. <el-table-column label="歌手名称" prop="singerName" align="center" show-overflow-tooltip />
  45. <el-table-column label="播放时长" prop="playTime" align="center" />
  46. <el-table-column label="当前状态" prop="status" align="center" :formatter="statusFormatter" />
  47. <el-table-column label="序号" align="center">
  48. <template slot-scope="scope">
  49. <div v-if="currentEditIndex !== scope.$index">
  50. <span :style="{ marginRight: (!disabled || !canOrder) ? '0px' : '8px' }">
  51. {{ (dialogForm.pageNum - 1) * dialogForm.pageSize + scope.$index + 1 }}
  52. </span>
  53. <svg-icon v-if="!disabled || !canOrder" icon-class="edit"
  54. @click.native="handleEditClick(scope.row, scope.$index)" />
  55. </div>
  56. <el-input v-else v-model="editData.sortIndex" size="mini" style="width:60px;" type="number"
  57. @blur="onNumberBlur(scope.row, scope.$index)" placeholder="序号" ref="numberInput" />
  58. </template>
  59. </el-table-column>
  60. <el-table-column label="操作" align="center">
  61. <template slot-scope="scope">
  62. <Audio :src="scope.row.progaramUrl" />
  63. <el-button type="delete" :disabled="disabled" @click="getDelete(scope.$index)">删除</el-button>
  64. <!-- 向上移动 -->
  65. <el-button type="text" icon="el-icon-caret-top" @click="getChange(true, scope.$index, scope.$index - 1)"
  66. :disabled="(scope.$index < 1 && !disabled) ||
  67. disabledPlatformId(form.platformId)
  68. " />
  69. <!-- 向下移动 -->
  70. <el-button type="text" icon="el-icon-caret-bottom"
  71. @click="getChange(false, scope.$index, scope.$index + 1)" :disabled="(scope.$index > form.programList.length - 2 && !disabled) ||
  72. disabledPlatformId(form.platformId)
  73. " />
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. </el-form-item>
  78. </el-form>
  79. <div class="form-btn">
  80. <el-button @click="cancel">取消</el-button>
  81. <el-button v-if="!disabled" type="primary" @click="getSubmit">确定</el-button>
  82. </div>
  83. <!-- 弹窗 -->
  84. <el-dialog :visible.sync="dialogVisible" title="添加歌曲" width="1100px">
  85. <el-form inline size="mini" style="width: 100%">
  86. <el-form-item label="歌曲名称:">
  87. <el-input v-model="dialogForm.name" placeholder="请输入歌曲名称" clearable />
  88. </el-form-item>
  89. <el-form-item label="歌手名称:">
  90. <el-input v-model="dialogForm.singerName" placeholder="请输入歌手名称" clearable />
  91. </el-form-item>
  92. <el-form-item label="资源平台:">
  93. <el-select v-model="dialogForm.platformId" placeholder="请选择资源平台">
  94. <el-option v-for="item in platformOptions.filter(
  95. (i) => !i.joinType.includes('1')
  96. )" :key="item.value" :value="item.value" :label="item.label" />
  97. </el-select>
  98. </el-form-item>
  99. <el-form-item>
  100. <el-button type="primary" icon="el-icon-search" @click="getSearch">搜索</el-button>
  101. <el-button icon="el-icon-refresh" @click="getRefresh">重置</el-button>
  102. </el-form-item>
  103. </el-form>
  104. <el-table :data="tableData" ref="multipleTable" :row-key="tableKey" v-loading="loading"
  105. @selection-change="handleSelectionChange">
  106. <el-table-column type="selection" align="center" key="selection" reserve-selection />
  107. <el-table-column label="ID" prop="id" align="center" />
  108. <el-table-column label="歌曲名称" prop="name" align="center" show-overflow-tooltip />
  109. <el-table-column label="歌手名称" prop="singerName" align="center" show-overflow-tooltip />
  110. <el-table-column label="播放时长" prop="playTime" align="center" />
  111. <!-- <el-table-column label="操作" align="center">
  112. <template slot-scope="scope">
  113. <el-button
  114. type="text"
  115. @click="getChecked(scope.row)"
  116. :disabled="
  117. form.programList.findIndex((i) => i.id === scope.row.id) === -1
  118. ? false
  119. : true
  120. "
  121. >
  122. 选择
  123. </el-button>
  124. </template>
  125. </el-table-column> -->
  126. </el-table>
  127. <pagination v-show="total > 0" :total="total" :page.sync="dialogForm.pageNum" :limit.sync="dialogForm.pageSize"
  128. @pagination="getList" />
  129. </el-dialog>
  130. </div>
  131. </template>
  132. <script>
  133. import { list } from "@/api/music/list";
  134. import { detail, submit } from "@/api/music/menu";
  135. import Audio from "@/components/Audio/index.vue";
  136. import {
  137. albumTypeMixin,
  138. onOrOffMixin,
  139. payTypeMixin,
  140. platformMixin,
  141. } from "@/mixin/index";
  142. export default {
  143. name: "musicAlbumDetail",
  144. mixins: [platformMixin, onOrOffMixin, payTypeMixin, albumTypeMixin],
  145. components: {
  146. Audio,
  147. },
  148. data() {
  149. // 判断原价是否大于折扣价
  150. var checkPrice = (rule, value, callback) => {
  151. if (!value) {
  152. callback(new Error("请输入原价"));
  153. } else {
  154. if (this.form.discount && value <= this.form.discount) {
  155. callback(new Error("原价必须大于折扣价"));
  156. }
  157. callback();
  158. }
  159. };
  160. // 判断折扣价是否小于原价
  161. var checkDiscount = (rule, value, callback) => {
  162. if (this.form.price && value >= this.form.price) {
  163. callback(new Error("折扣价必须小于原价"));
  164. } else {
  165. callback();
  166. }
  167. };
  168. return {
  169. // 遮罩层
  170. form_loading: false,
  171. loading: false,
  172. // 表单
  173. form: {
  174. programList: [], // 歌曲列表
  175. status: 1,
  176. type: 1,
  177. },
  178. editData: {},
  179. currentEditIndex: -1,
  180. // 校验
  181. rules: {
  182. name: [
  183. {
  184. required: true,
  185. message: "请输入歌单名称",
  186. trigger: "blur",
  187. },
  188. ],
  189. description: [
  190. {
  191. required: true,
  192. message: "请输入歌单介绍",
  193. trigger: "blur",
  194. },
  195. ],
  196. albumType: [
  197. {
  198. required: true,
  199. message: "请选择专辑类型",
  200. trigger: "blur",
  201. },
  202. ],
  203. avatarNickName: [
  204. {
  205. required: true,
  206. message: "请输入歌单创建者名称",
  207. trigger: "blur",
  208. },
  209. ],
  210. platformId: [
  211. {
  212. required: true,
  213. message: "请选择资源平台",
  214. trigger: "change",
  215. },
  216. ],
  217. payType: [
  218. {
  219. required: true,
  220. message: "请选择付费类型",
  221. trigger: "change",
  222. },
  223. ],
  224. price: [
  225. {
  226. required: true,
  227. validator: checkPrice,
  228. trigger: "blur",
  229. },
  230. ],
  231. discount: [
  232. {
  233. validator: checkDiscount,
  234. trigger: "blur",
  235. },
  236. ],
  237. coverUrl: [
  238. {
  239. required: true,
  240. message: "请上传歌单封面",
  241. trigger: "change",
  242. },
  243. ],
  244. avatarNickHead: [
  245. {
  246. required: true,
  247. message: "请上传创建者头像",
  248. trigger: "change",
  249. },
  250. ],
  251. },
  252. // 弹窗
  253. dialogVisible: false,
  254. // 弹窗表单
  255. dialogForm: {
  256. pageNum: 1,
  257. pageSize: 10,
  258. status: 1,
  259. platformId: null,
  260. },
  261. // 总数据
  262. total: 0,
  263. // 弹窗列表
  264. tableData: [],
  265. // 只读
  266. disabled: false,
  267. // 是否已选
  268. disabledChecked: false,
  269. ///被选中数据是否加载完
  270. isLoad: false,
  271. ///是否可以调整顺序
  272. canOrder: true,
  273. };
  274. },
  275. mounted() {
  276. // 获取资源平台
  277. this.getPlatform({
  278. audioType: 15,
  279. });
  280. if (this.$route.query.id) {
  281. this.form.id = this.$route.query.id;
  282. this.disabled = Boolean(this.$route.query.disabled);
  283. this.getDetail();
  284. }
  285. },
  286. methods: {
  287. tableKey(row) {
  288. return row.id;
  289. },
  290. // 输入框失去焦点时隐藏
  291. onNumberBlur(row, index) {
  292. let newValue = Number(this.editData.sortIndex);
  293. const maxLen = this.form.programList.length;
  294. if (isNaN(newValue) || newValue === null || newValue === undefined) {
  295. console.log('序号未修改:', newValue);
  296. return;
  297. }
  298. if (newValue < 1) {
  299. this.$message.warning('序号必须大于0');
  300. this.currentEditIndex = -1;
  301. return;
  302. }
  303. if (newValue > maxLen) {
  304. // 超出就是最后一位
  305. newValue = maxLen
  306. }
  307. if (newValue === -1 || newValue === '') {
  308. // 新值为空时处理
  309. this.currentEditIndex = -1;
  310. console.log('序号未修改:', newValue);
  311. return
  312. }
  313. console.log('序号修改:', newValue, '当前索引:', index, this.currentEditIndex);
  314. // 计算目标下标
  315. const targetIndex = newValue - 1;
  316. if (targetIndex === index) {
  317. // this.currentEditIndex = -1;
  318. return;
  319. }
  320. // 交换两个元素
  321. // ...existing code...
  322. // 插入到目标位置,原本序号顺延
  323. const movingItem = this.form.programList.splice(index, 1)[0];
  324. this.form.programList.splice(targetIndex, 0, movingItem);
  325. // ...existing code...
  326. this.currentEditIndex = -1;
  327. this.$message.success("操作成功!");
  328. },
  329. // 点击编辑图标显示输入框
  330. handleEditClick(row, index) {
  331. if (this.disabled || !this.canOrder) {
  332. return;
  333. }
  334. this.editData = {
  335. sortIndex: row.index,
  336. };
  337. this.currentEditIndex = index;
  338. this.$nextTick(() => {
  339. this.$refs.numberInput.focus();
  340. });
  341. },
  342. handleSelectionChange(val) {
  343. if (this.isLoad) {
  344. if (this.form.programList.length == 0) {
  345. this.form.programList = JSON.parse(JSON.stringify(val));
  346. } else {
  347. ///查找dialogTableData里面有的
  348. var tempDialogHas = [];
  349. for (var i = 0; i < this.tableData.length; i++) {
  350. for (var j = 0; j < val.length; j++) {
  351. if (this.tableData[i].id === val[j].id) {
  352. tempDialogHas.push(this.tableData[i]);
  353. break;
  354. }
  355. }
  356. }
  357. ///查找dialogTableData里面没有的
  358. var tempDialogNot = [];
  359. if (tempDialogHas.length == 0) {
  360. tempDialogNot = JSON.parse(JSON.stringify(this.tableData));
  361. } else {
  362. for (var i = 0; i < this.tableData.length; i++) {
  363. var has = false;
  364. for (var j = 0; j < tempDialogHas.length; j++) {
  365. if (this.tableData[i].id === tempDialogHas[j].id) {
  366. has = true;
  367. break;
  368. }
  369. }
  370. if (!has) {
  371. tempDialogNot.push(this.tableData[i]);
  372. }
  373. }
  374. }
  375. ///减少val没有的
  376. if (tempDialogNot.length > 0) {
  377. for (var i = 0; i < tempDialogNot.length; i++) {
  378. for (var j = 0; j < this.form.programList.length; j++) {
  379. if (tempDialogNot[i].id === this.form.programList[j].id) {
  380. this.form.programList.splice(j, 1);
  381. break;
  382. }
  383. }
  384. }
  385. }
  386. ///添加adminPodCastProgramDetailResp没有的
  387. for (var i = 0; i < val.length; i++) {
  388. var isHas = false;
  389. for (var j = 0; j < this.form.programList.length; j++) {
  390. if (val[i].id === this.form.programList[j].id) {
  391. isHas = true;
  392. break;
  393. }
  394. }
  395. if (!isHas) {
  396. this.form.programList.push(val[i]);
  397. }
  398. }
  399. }
  400. this.form.programList = this.form.programList.filter((i) => i);
  401. this.$message.success("操作成功!");
  402. }
  403. },
  404. //是否展示排序
  405. // isShowSort() {
  406. // if (this.form) {
  407. // if (!disabledPlatformId(form.platformId)) {
  408. // return ture;
  409. // }
  410. // }
  411. // return false;
  412. // },
  413. // 排序
  414. getChange(top, index, laterIndex) {
  415. var row = this.form.programList[index];
  416. var laterRow = this.form.programList[laterIndex];
  417. if (top) {
  418. this.form.programList[index] = laterRow;
  419. this.form.programList[laterIndex] = row;
  420. } else {
  421. this.form.programList[laterIndex] = row;
  422. this.form.programList[index] = laterRow;
  423. }
  424. this.form.programList = this.form.programList.filter((i) => i);
  425. },
  426. // 详情
  427. getDetail() {
  428. this.form_loading = true;
  429. detail(this.form.id).then((res) => {
  430. if (res.code === 0) {
  431. this.form = res.data;
  432. ///qq音乐和喜马拉雅
  433. if (this.form.platformId == 6 || this.form.platformId == 12) {
  434. this.canOrder = false;
  435. }
  436. this.form_loading = false;
  437. }
  438. });
  439. },
  440. // 上传
  441. upload(e, key) {
  442. this.form[key] = e.file;
  443. },
  444. // 添加歌曲
  445. getDialog() {
  446. this.dialogVisible = true;
  447. this.dialogForm.platformId = this.platformOptions.filter(
  448. (i) => !i.joinType.includes("1")
  449. )[0].value;
  450. this.getList();
  451. },
  452. // 列表
  453. getList() {
  454. this.loading = true;
  455. list(this.dialogForm).then((res) => {
  456. if (res.code === 0) {
  457. this.tableData = res.data.records;
  458. this.total = res.data.total;
  459. this.loading = false;
  460. this.isLoad = false;
  461. this.$refs.multipleTable.clearSelection();
  462. if (this.form.programList.length > 0) {
  463. var temp = [];
  464. for (var i = 0; i < this.tableData.length; i++) {
  465. for (var j = 0; j < this.form.programList.length; j++) {
  466. if (this.form.programList[j].id === this.tableData[i].id) {
  467. temp.push(this.tableData[i]);
  468. break;
  469. }
  470. }
  471. }
  472. if (temp.length > 0) {
  473. temp.forEach((item) => {
  474. this.$refs.multipleTable.toggleRowSelection(item, true);
  475. });
  476. }
  477. }
  478. this.isLoad = true;
  479. }
  480. });
  481. },
  482. // 搜索
  483. getSearch() {
  484. this.dialogForm.pageNum = 1;
  485. this.getList();
  486. },
  487. // 重置
  488. getRefresh() {
  489. this.dialogForm = {
  490. pageNum: 1,
  491. pageSize: 10,
  492. status: 1,
  493. platformId: this.platformOptions[0].value,
  494. };
  495. this.getList();
  496. },
  497. // 选择
  498. getChecked(row) {
  499. this.form.programList.push({
  500. id: row.id,
  501. name: row.name,
  502. singerName: row.singerName,
  503. playTime: row.playTime,
  504. status: row.status,
  505. progaramUrl: row.progaramUrl,
  506. });
  507. this.$message.success("添加成功!");
  508. },
  509. // 删除已选歌曲
  510. getDelete(index) {
  511. this.form.programList.splice(index, 1);
  512. },
  513. // 确定
  514. getSubmit() {
  515. this.$refs.form.validate((valid) => {
  516. if (valid) {
  517. if (this.form.programList) {
  518. let arr = [];
  519. this.form.programList.map((i) => {
  520. arr.push(i.id);
  521. });
  522. this.form.programList = arr;
  523. }
  524. this.form_loading = true;
  525. let title = this.form.id ? "编辑成功!" : "新增成功!";
  526. submit(this.form).then((res) => {
  527. if (res.code === 0) {
  528. this.$message.success(title);
  529. this.cancel();
  530. }
  531. // if (res.code === 0) {
  532. // this.$message.success(`${title}`);
  533. // if (!this.form.id) {
  534. // this.cancel();
  535. // } else {
  536. // this.getDetail();
  537. // }
  538. // }
  539. });
  540. } else {
  541. return false;
  542. }
  543. });
  544. },
  545. // 取消
  546. cancel() {
  547. this.$tab.closeOpenPage("/music/musicAlbum");
  548. },
  549. // 字典翻译
  550. statusFormatter(row) {
  551. return this.selectDictLabel(this.onOrOffOptions, row.status);
  552. },
  553. },
  554. };
  555. </script>
  556. <style lang="scss" scoped>
  557. .form {
  558. .el-form-item {
  559. width: 500px;
  560. }
  561. }
  562. </style>