addAndEdit.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. <!--
  2. * @Description: 新增/编辑弹框
  3. * @Author: Sugar.
  4. * @Date: 2023-11-24 13:55:00
  5. * @LastEditors: Sugar.
  6. * @LastEditTime: 2023-11-24 13:55:00
  7. * @FilePath: \cattle_webui\src\views\perform\programmeMr\dialog\AddOrEditDialog.vue
  8. * @Copyright: Copyright (c) 2016~2023 by Sugar., All Rights Reserved.
  9. -->
  10. <template>
  11. <el-dialog
  12. :title="title"
  13. :visible.sync="open"
  14. width="700px"
  15. append-to-body
  16. :close-on-click-modal="false"
  17. @close="cancel"
  18. >
  19. <div class="dialog">
  20. <el-form :model="form" ref="form" :rules="rules" label-width="80px">
  21. <el-tabs v-model="activeName">
  22. <!-- 基础信息 -->
  23. <el-tab-pane label="基础信息" name="01">
  24. <el-form-item label="剧目名称" prop="name" style="margin-top: 20px">
  25. <el-input
  26. v-model="form.name"
  27. placeholder="剧目名称"
  28. clearable
  29. />
  30. </el-form-item>
  31. <el-form-item label="主办方" prop="sponsorId">
  32. <el-select
  33. v-model="form.sponsorId"
  34. placeholder="主办方"
  35. clearable
  36. style="width: 100%"
  37. @change="changePerform"
  38. >
  39. <el-option
  40. v-for="dict in performList"
  41. :key="dict.id"
  42. :label="dict.name"
  43. :value="dict.id"
  44. />
  45. </el-select>
  46. </el-form-item>
  47. <el-form-item label="票务选择" prop="goodsIdList">
  48. <el-select
  49. v-model="form.goodsIdList"
  50. placeholder="票务选择"
  51. clearable
  52. multiple
  53. style="width: 100%"
  54. @change="changePerform"
  55. >
  56. <el-option
  57. v-for="dict in ticketList"
  58. :key="dict.id"
  59. :label="dict.goodsName"
  60. :value="dict.id"
  61. />
  62. </el-select>
  63. </el-form-item>
  64. <el-form-item label="是否启用" prop="status">
  65. <el-select
  66. v-model="form.status"
  67. placeholder="状态"
  68. clearable
  69. style="width: 100%"
  70. >
  71. <el-option
  72. v-for="dict in statusList"
  73. :key="dict.value"
  74. :label="dict.name"
  75. :value="dict.value"
  76. />
  77. </el-select>
  78. </el-form-item>
  79. </el-tab-pane>
  80. <!-- 演出信息 -->
  81. <el-tab-pane label="演出信息" name="02">
  82. <el-form-item label="上映日期" style="margin-top: 20px">
  83. <el-date-picker
  84. v-model="form.releaseDate"
  85. type="date"
  86. value-format="yyyy-MM-dd"
  87. style="width: 240px;"
  88. placeholder="选择上映日期">
  89. </el-date-picker>
  90. </el-form-item>
  91. <el-form-item label="演出时长">
  92. <el-input
  93. placeholder="演出时长"
  94. type="number"
  95. v-model="form.showDuration"
  96. @change="changePriceAmount('showDuration')"
  97. clearable
  98. style="width: 240px;margin-right: 10px"
  99. />
  100. <span>分钟</span>
  101. </el-form-item>
  102. <el-form-item label="演出人数">
  103. <el-input
  104. type="number"
  105. v-model="form.peopleNum"
  106. placeholder="演出人数"
  107. @change="changePriceAmount('peopleNum')"
  108. clearable
  109. style="width: 240px;margin-right: 10px"
  110. />
  111. <span>人</span>
  112. </el-form-item>
  113. <el-form-item label="演员信息">
  114. <el-button type="text" @click="performerOpen">添加</el-button>
  115. </el-form-item>
  116. <el-form-item label="剧目海报" prop="posterImg">
  117. <el-upload
  118. ref="upload"
  119. class="avatar-uploader"
  120. :action="uploadObj.url"
  121. :headers="uploadObj.headers"
  122. :show-file-list="false"
  123. accept=".jpg,.png"
  124. :on-success="handleAvatarSuccess"
  125. :before-upload="beforeAvatarUpload"
  126. >
  127. <div class="avatar" v-if="form.posterImg">
  128. <el-image
  129. style="width: 100px; height: 100px"
  130. :src="form.posterImg"
  131. fit="cover"
  132. />
  133. </div>
  134. <div class="upload-btn" v-else>
  135. <i class="el-icon-plus"></i>
  136. <div class="upload-btn-text">上传照片</div>
  137. </div>
  138. <div class="el-upload__tip" slot="tip">只能上传.jpg或.png格式</div>
  139. </el-upload>
  140. </el-form-item>
  141. <el-form-item label="剧目封面" prop="showImg">
  142. <el-upload
  143. ref="upload"
  144. class="avatar-uploader"
  145. :action="uploadObj.url"
  146. :headers="uploadObj.headers"
  147. :show-file-list="false"
  148. accept=".jpg,.png"
  149. :on-success="handleFMSuccess"
  150. :before-upload="beforeAvatarUpload"
  151. >
  152. <div class="avatar" v-if="form.showImg">
  153. <el-image
  154. style="width: 100px; height: 100px"
  155. :src="form.showImg"
  156. fit="cover"
  157. />
  158. </div>
  159. <div class="upload-btn" v-else>
  160. <i class="el-icon-plus"></i>
  161. <div class="upload-btn-text">上传照片</div>
  162. </div>
  163. <div class="el-upload__tip" slot="tip">只能上传.jpg或.png格式</div>
  164. </el-upload>
  165. </el-form-item>
  166. <el-form-item label="宣传图">
  167. <el-upload
  168. ref="upload"
  169. :action="uploadObj.url"
  170. :headers="uploadObj.headers"
  171. accept=".jpg,.png"
  172. :on-success="handlePhotoListSuccess"
  173. :before-upload="beforeAvatarUpload"
  174. list-type="picture-card"
  175. :file-list="form.photoList"
  176. :on-remove="handleRemove"
  177. >
  178. <i class="el-icon-plus"></i>
  179. </el-upload>
  180. </el-form-item>
  181. <el-form-item label="剧情介绍">
  182. <editor v-model="form.performSnapshot" :fileSize="20" :min-height="200" />
  183. </el-form-item>
  184. </el-tab-pane>
  185. <!-- 观影须知 -->
  186. <el-tab-pane label="观影须知" name="03">
  187. <el-form-item label="观影须知" style="margin-top: 20px">
  188. <editor v-model="form.performNotice" :fileSize="20" :min-height="200" />
  189. </el-form-item>
  190. </el-tab-pane>
  191. </el-tabs>
  192. </el-form>
  193. </div>
  194. <span slot="footer" class="dialog-footer">
  195. <el-button @click="cancel">取消</el-button>
  196. <el-button
  197. type="primary"
  198. @click="submitForm"
  199. v-loading.fullscreen.lock="loading"
  200. element-loading-text="提交中..."
  201. element-loading-spinner="el-icon-loading"
  202. element-loading-background="rgba(0, 0, 0, 0.8)"
  203. >
  204. <span v-if="loading">提交中...</span>
  205. <span v-else>保存</span>
  206. </el-button>
  207. </span>
  208. <el-dialog
  209. title="添加演员信息"
  210. :visible.sync="performerVisible"
  211. width="800px"
  212. append-to-body
  213. :destroy-on-close="true"
  214. :close-on-click-modal="false"
  215. >
  216. <div>
  217. <el-row :gutter="10" class="mb8">
  218. <el-col :span="1.5">
  219. <el-button
  220. type="primary"
  221. plain
  222. icon="el-icon-plus"
  223. size="mini"
  224. @click="handleAdd"
  225. >新增</el-button>
  226. </el-col>
  227. </el-row>
  228. <el-table ref="tables" :data="performerList" border>
  229. <el-table-column label="序号" align="center" type="index" width="50"></el-table-column>
  230. <el-table-column label="姓名" align="center">
  231. <template slot-scope="scope">
  232. <el-input
  233. v-model="scope.row.performerName"
  234. placeholder="姓名"
  235. clearable
  236. />
  237. </template>
  238. </el-table-column>
  239. <el-table-column label="图片" align="center">
  240. <template slot-scope="scope">
  241. <el-upload
  242. ref="upload"
  243. class="avatar-uploader"
  244. :action="uploadObj.url"
  245. :headers="uploadObj.headers"
  246. :show-file-list="false"
  247. accept=".jpg,.png"
  248. :on-success="handlePerformerAvatarSuccess"
  249. :before-upload="beforeAvatarUpload"
  250. >
  251. <div class="avatar" v-if="scope.row.performerHead" @click="changeIndexEven(scope)">
  252. <el-image
  253. style="width: 100px; height: 100px"
  254. :src="scope.row.performerHead"
  255. fit="cover"
  256. />
  257. </div>
  258. <div class="upload-btn" v-else @click="changeIndexEven(scope)">
  259. <i class="el-icon-plus"></i>
  260. <div class="upload-btn-text">上传照片</div>
  261. </div>
  262. <div class="el-upload__tip" slot="tip">只能上传.jpg或.png格式</div>
  263. </el-upload>
  264. </template>
  265. </el-table-column>
  266. <el-table-column label="角色名" align="center">
  267. <template slot-scope="scope">
  268. <el-input
  269. v-model="scope.row.performerRole"
  270. placeholder="角色名"
  271. clearable
  272. />
  273. </template>
  274. </el-table-column>
  275. <el-table-column label="演员简介" width="200" align="center">
  276. <template slot-scope="scope">
  277. <el-input
  278. type="textarea"
  279. :rows="4"
  280. maxlength="500"
  281. show-word-limit
  282. v-model="scope.row.performerSnapshot"
  283. placeholder="演员简介"
  284. clearable
  285. />
  286. </template>
  287. </el-table-column>
  288. <el-table-column label="操作" align="center" width="80" class-name="small-padding fixed-width">
  289. <template slot-scope="scope">
  290. <el-button
  291. size="mini"
  292. type="text"
  293. @click="handleDelete(scope.row,scope.$index)"
  294. >删除</el-button>
  295. </template>
  296. </el-table-column>
  297. </el-table>
  298. </div>
  299. <div slot="footer" class="dialog-footer">
  300. <el-button @click="performerVisible = false">取 消</el-button>
  301. <el-button type="primary" @click="performerEven">确 定</el-button>
  302. </div>
  303. </el-dialog>
  304. </el-dialog>
  305. </template>
  306. <script>
  307. // import { updateNoticeMgr } from "@/api/system/noticeMgr";
  308. import { saveAndEdit, getSelectById } from '@/api/programmeMr/programmeMr'
  309. import { ticketPageList } from '@/api/ticketMr/ticketMr'
  310. import Editor from "@/components/Editor";
  311. import { getToken } from "@/utils/auth";
  312. import { pageList } from '@/api/performMr/performMr'
  313. export default {
  314. name: "addAndEdit",
  315. components: {
  316. Editor,
  317. },
  318. data() {
  319. return {
  320. title: "编辑",
  321. model: "EDIT",
  322. activeName: '01',
  323. // 演员信息弹窗
  324. performerVisible: false,
  325. // 演员信息
  326. performerList: [],
  327. // 演员上传图片索引
  328. performerIndex: 0,
  329. open: false,
  330. loading: false,
  331. form: {
  332. id: undefined,
  333. type: "",
  334. content: "",
  335. },
  336. rules: {
  337. name: [{ required: true, message: "请输入剧目名称", trigger: ["change","blur"] }],
  338. sponsorId: [{ required: true, message: "请选择主办方", trigger: ["change","blur"] }],
  339. goodsIdList: [{ required: true, message: "请选择票务信息", trigger: ["change","blur"] }],
  340. posterImg: [{ required: true, message: "请上传剧目海报", trigger: ["change","blur"] }],
  341. showImg: [{ required: true, message: "请上传剧目封面", trigger: ["change","blur"] }],
  342. status: [{ required: true, message: "请选择是否启用状态", trigger: ["change","blur"] }]
  343. },
  344. uploadObj: {
  345. url: process.env.VUE_APP_UPLOAD_FILE_API + "/upload/single/minio",
  346. Headers: { Authorization: "Bearer " + getToken() },
  347. },
  348. statusList: [
  349. {id: 1, name: '是', value: 1},
  350. {id: 2, name: '否', value: 2},
  351. ],
  352. performList: [],
  353. ticketList: []
  354. };
  355. },
  356. created() {
  357. this.getList();
  358. this.ticketPageListApi();
  359. },
  360. methods: {
  361. /** 查询主办方列表 */
  362. getList() {
  363. pageList({pageNum: 1, pageSize: 100})
  364. .then(response => {
  365. this.performList = response.data.rows;
  366. }
  367. );
  368. },
  369. /** 查询票务列表 */
  370. ticketPageListApi() {
  371. ticketPageList({pageNum: 1, pageSize: 100, goodsType: 2, classifyId: 1, status: 0})
  372. .then(response => {
  373. this.ticketList = response.data.rows;
  374. }
  375. );
  376. },
  377. /** 主办方选择事件 */
  378. changePerform(val) {
  379. this.performList.forEach(item => {
  380. if(item.id == val){
  381. this.form.sponsorName = item.name
  382. }
  383. })
  384. },
  385. /** 价格输入事件 */
  386. changePriceAmount(key) {
  387. if(this.form[key] * 1 < 0){
  388. this.$message.error("输入需大于或等于0!");
  389. this.$set(this.form, key, '');
  390. return false
  391. }
  392. },
  393. /**
  394. * 打开弹框
  395. * @date 2023-11-22
  396. * @param {any} obj
  397. * @returns {any}
  398. */
  399. openDialog(title, obj) {
  400. this.open = true;
  401. this.reset();
  402. this.activeName = '01';
  403. if (obj){
  404. this.title = "编辑剧目管理";
  405. this.getSelectByIdApi(obj)
  406. }else{
  407. this.title = "添加剧目管理";
  408. this.$nextTick(() => {
  409. this.$refs["form"].clearValidate();
  410. });
  411. }
  412. },
  413. /** 获取详情 */
  414. getSelectByIdApi(row) {
  415. const id = row.id
  416. getSelectById(id).then(response => {
  417. const obj = response.data;
  418. this.$nextTick(() => {
  419. this.$set(this.form, 'id', obj.id);
  420. // 基础信息
  421. this.$set(this.form, 'name', obj.name);
  422. this.$set(this.form, 'sponsorId', obj.sponsorId);
  423. this.$set(this.form, 'sponsorName', obj.sponsorName);
  424. let goodsIdList = []
  425. obj.goodsList.forEach(item => {
  426. goodsIdList.push(item.goodsId);
  427. })
  428. this.$set(this.form, 'goodsIdList', goodsIdList);
  429. this.$set(this.form, 'status', obj.status);
  430. // 演出信息
  431. this.$set(this.form, 'releaseDate', obj.releaseDate);
  432. this.$set(this.form, 'showDuration', obj.showDuration);
  433. this.$set(this.form, 'peopleNum', obj.peopleNum);
  434. this.$set(this.form, 'posterImg', obj.posterImg);
  435. this.$set(this.form, 'showImg', obj.showImg);
  436. this.$set(this.form, 'performSnapshot', obj.performSnapshot);
  437. // this.performerList = obj.performerList || [];
  438. this.$set(this.form, 'performerList', obj.performerList || []);
  439. obj.photoList.forEach(item => {
  440. item.url = item.imageUrl
  441. })
  442. this.$set(this.form, 'photoList', obj.photoList);
  443. // 观影须知
  444. this.$set(this.form, 'performNotice', obj.performNotice);
  445. });
  446. });
  447. },
  448. /**
  449. * 保存
  450. * @date 2023-11-22
  451. * @returns {any}
  452. */
  453. submitForm() {
  454. this.$refs["form"].validate(async (valid) => {
  455. if (valid) {
  456. if(this.form.photoList && this.form.photoList.length > 0 && this.form.photoList.length < 3) {
  457. this.$message.error("上传的宣传图不能少于三张!");
  458. return false
  459. }
  460. // if(this.form.photoList && this.form.photoList.length > 2) {
  461. // this.form.showImg = this.form.photoList[0].url
  462. // }
  463. try {
  464. this.loading = true;
  465. const { code } = await saveAndEdit({ ...this.form });
  466. if (code === 200) {
  467. this.$message.success("操作成功!");
  468. this.$emit("getList");
  469. this.cancel();
  470. }
  471. } catch (error) {
  472. } finally {
  473. this.loading = false;
  474. }
  475. }
  476. });
  477. },
  478. /**
  479. * 演员信息添加
  480. * @date 2023-11-22
  481. * @returns {any}
  482. */
  483. performerEven() {
  484. let target=[...this.performerList];
  485. this.form.performerList = JSON.parse(JSON.stringify(target));
  486. this.performerVisible = false;
  487. },
  488. /**
  489. * 重置
  490. * @date 2023-11-22
  491. * @returns {any}
  492. */
  493. reset() {
  494. this.$set(this.form, 'id', '');
  495. // 基础信息
  496. this.$set(this.form, 'name', '');
  497. this.$set(this.form, 'sponsorId', '');
  498. this.$set(this.form, 'sponsorName', '');
  499. let goodsIdList = []
  500. this.$set(this.form, 'goodsIdList', []);
  501. this.$set(this.form, 'status', '');
  502. // 演出信息
  503. this.$set(this.form, 'releaseDate', '');
  504. this.$set(this.form, 'showDuration', '');
  505. this.$set(this.form, 'peopleNum', '');
  506. this.$set(this.form, 'posterImg', '');
  507. this.$set(this.form, 'showImg', '');
  508. this.$set(this.form, 'performSnapshot', '');
  509. this.$set(this.form, 'photoList', []);
  510. // 观影须知
  511. this.$set(this.form, 'performNotice', '');
  512. },
  513. /**
  514. * 关闭弹框
  515. * @date 2023-11-22
  516. * @returns {any}
  517. */
  518. cancel() {
  519. this.reset();
  520. this.open = false;
  521. },
  522. /**
  523. * 上传成功
  524. * @date 2023-11-22
  525. * @param {any} res
  526. * @returns {any}
  527. */
  528. handleAvatarSuccess(res) {
  529. if (res.code === 200) {
  530. // this.form.mainImg = res?.data?.url;
  531. this.$set(this.form, 'posterImg', res?.data?.url)
  532. }
  533. console.log(this.form.photoList)
  534. },
  535. handleFMSuccess(res) {
  536. if (res.code === 200) {
  537. // this.form.mainImg = res?.data?.url;
  538. this.$set(this.form, 'showImg', res?.data?.url)
  539. }
  540. },
  541. /**
  542. * 剧目海报上传成功
  543. * @date 2023-11-22
  544. * @param {any} res
  545. * @returns {any}
  546. */
  547. handlePhotoListSuccess(res) {
  548. if (res.code === 200) {
  549. let photo = {
  550. imageUrl: res?.data?.url,
  551. url: res?.data?.url,
  552. photoType: '2'
  553. }
  554. if(!this.form.photoList){
  555. this.form.photoList = []
  556. }
  557. // this.form.photoList.push(photo);
  558. this.$set(this.form.photoList, this.form.photoList.length, photo);
  559. }
  560. },
  561. handleRemove(file, fileList) {
  562. this.form.photoList.forEach((item, index) => {
  563. if(item.uid == file.uid){
  564. this.form.photoList.splice(index, 1)
  565. }
  566. })
  567. },
  568. /**
  569. * 上传文件之前之前
  570. * @date 2023-11-22
  571. * @param {any} file
  572. * @returns {any}
  573. */
  574. beforeAvatarUpload(file) {
  575. const isJPG = file.type === "image/jpeg" || "image/png";
  576. if (!isJPG) {
  577. this.$message.error("上传头像图片只能是jpg或png格式!");
  578. }
  579. return isJPG;
  580. },
  581. /**
  582. * 演员新增
  583. * @date 2023-11-22
  584. */
  585. handleAdd() {
  586. if(!this.performerList){
  587. this.performerList = []
  588. }
  589. this.performerList.push({})
  590. },
  591. /**
  592. * 演员删除
  593. * @date 2023-11-22
  594. */
  595. handleDelete(row, index) {
  596. this.$confirm('是否确认删当前数据?', '提示', {
  597. confirmButtonText: '确定',
  598. cancelButtonText: '取消',
  599. type: 'warning'
  600. }).then(() => {
  601. this.performerList.splice(index, 1);
  602. this.$message({
  603. type: 'success',
  604. message: '删除成功!'
  605. });
  606. }).catch(() => {
  607. this.$message({
  608. type: 'info',
  609. message: '已取消删除'
  610. });
  611. });
  612. },
  613. /**
  614. * 演员弹窗打开
  615. * @date 2023-11-22
  616. */
  617. performerOpen() {
  618. if(!this.form.performerList){
  619. this.form.performerList = []
  620. }
  621. let target=[...this.form.performerList];
  622. this.performerList = JSON.parse(JSON.stringify(target));
  623. this.performerVisible = true;
  624. },
  625. /**
  626. * 演员图片上传成功
  627. * @date 2023-11-22
  628. * @param {any} res
  629. * @returns {any}
  630. */
  631. handlePerformerAvatarSuccess(res) {
  632. if (res.code === 200) {
  633. // this.form.mainImg = res?.data?.url;
  634. this.$set(this.performerList[this.performerIndex], 'performerHead', res?.data?.url);
  635. }
  636. },
  637. /**
  638. * 演员图片上传点击记录当前索引
  639. * @date 2023-11-22
  640. * @param {any} row
  641. * @returns {any}
  642. */
  643. changeIndexEven(row) {
  644. this.performerIndex = row.$index;
  645. }
  646. },
  647. };
  648. </script>
  649. <style lang="scss" scoped>
  650. .dialog {
  651. padding: 0 30px;
  652. max-height: 65vh;
  653. overflow-y: auto;
  654. }
  655. .dialog {
  656. padding: 0 30px;
  657. .upload-btn {
  658. width: 100px;
  659. height: 100px;
  660. background-color: #fbfdff;
  661. border: dashed 1px #c0ccda;
  662. border-radius: 5px;
  663. i {
  664. font-size: 30px;
  665. margin-top: 20px;
  666. }
  667. &-text {
  668. margin-top: -10px;
  669. }
  670. }
  671. .avatar {
  672. cursor: pointer;
  673. }
  674. }
  675. .el-table{
  676. .upload-btn {
  677. width: 100px;
  678. height: 100px;
  679. background-color: #fbfdff;
  680. border: dashed 1px #c0ccda;
  681. border-radius: 5px;
  682. i {
  683. font-size: 30px;
  684. margin-top: 20px;
  685. }
  686. &-text {
  687. margin-top: -10px;
  688. }
  689. }
  690. .avatar {
  691. cursor: pointer;
  692. }
  693. }
  694. </style>