addAndEdit.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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="剧目海报">
  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: "blur" }],
  338. sponsorId: [{ required: true, message: "请选择主办方", trigger: "blur" }],
  339. goodsIdList: [{ required: true, message: "请选择票务信息", trigger: "blur" }],
  340. showImg: [{ required: true, message: "请上传剧目封面", trigger: "blur" }],
  341. status: [{ required: true, message: "请选择是否启用状态", trigger: "blur" }]
  342. },
  343. uploadObj: {
  344. url: process.env.VUE_APP_UPLOAD_FILE_API + "/upload/single/minio",
  345. Headers: { Authorization: "Bearer " + getToken() },
  346. },
  347. statusList: [
  348. {id: 1, name: '是', value: 1},
  349. {id: 2, name: '否', value: 2},
  350. ],
  351. performList: [],
  352. ticketList: []
  353. };
  354. },
  355. created() {
  356. this.getList();
  357. this.ticketPageListApi();
  358. },
  359. methods: {
  360. /** 查询主办方列表 */
  361. getList() {
  362. pageList({pageNum: 1, pageSize: 100})
  363. .then(response => {
  364. this.performList = response.data.rows;
  365. }
  366. );
  367. },
  368. /** 查询票务列表 */
  369. ticketPageListApi() {
  370. ticketPageList({pageNum: 1, pageSize: 100, goodsType: 2, classifyId: 1, status: 0})
  371. .then(response => {
  372. this.ticketList = response.data.rows;
  373. }
  374. );
  375. },
  376. /** 主办方选择事件 */
  377. changePerform(val) {
  378. this.performList.forEach(item => {
  379. if(item.id == val){
  380. this.form.sponsorName = item.name
  381. }
  382. })
  383. },
  384. /** 价格输入事件 */
  385. changePriceAmount(key) {
  386. if(this.form[key] * 1 < 0){
  387. this.$message.error("输入需大于或等于0!");
  388. this.$set(this.form, key, '');
  389. return false
  390. }
  391. },
  392. /**
  393. * 打开弹框
  394. * @date 2023-11-22
  395. * @param {any} obj
  396. * @returns {any}
  397. */
  398. openDialog(title, obj) {
  399. this.open = true;
  400. this.reset();
  401. this.activeName = '01';
  402. if (obj){
  403. this.title = "编辑剧目管理";
  404. this.getSelectByIdApi(obj)
  405. }else{
  406. this.title = "添加剧目管理";
  407. this.$nextTick(() => {
  408. this.$refs["form"].clearValidate();
  409. });
  410. }
  411. },
  412. /** 获取详情 */
  413. getSelectByIdApi(row) {
  414. const id = row.id
  415. getSelectById(id).then(response => {
  416. const obj = response.data;
  417. this.$nextTick(() => {
  418. this.$set(this.form, 'id', obj.id);
  419. // 基础信息
  420. this.$set(this.form, 'name', obj.name);
  421. this.$set(this.form, 'sponsorId', obj.sponsorId);
  422. this.$set(this.form, 'sponsorName', obj.sponsorName);
  423. let goodsIdList = []
  424. obj.goodsList.forEach(item => {
  425. goodsIdList.push(item.goodsId);
  426. })
  427. this.$set(this.form, 'goodsIdList', goodsIdList);
  428. this.$set(this.form, 'status', obj.status);
  429. // 演出信息
  430. this.$set(this.form, 'releaseDate', obj.releaseDate);
  431. this.$set(this.form, 'showDuration', obj.showDuration);
  432. this.$set(this.form, 'peopleNum', obj.peopleNum);
  433. this.$set(this.form, 'posterImg', obj.posterImg);
  434. this.$set(this.form, 'showImg', obj.showImg);
  435. this.$set(this.form, 'performSnapshot', obj.performSnapshot);
  436. // this.performerList = obj.performerList || [];
  437. this.$set(this.form, 'performerList', obj.performerList || []);
  438. obj.photoList.forEach(item => {
  439. item.url = item.imageUrl
  440. })
  441. this.$set(this.form, 'photoList', obj.photoList);
  442. // 观影须知
  443. this.$set(this.form, 'performNotice', obj.performNotice);
  444. });
  445. });
  446. },
  447. /**
  448. * 保存
  449. * @date 2023-11-22
  450. * @returns {any}
  451. */
  452. submitForm() {
  453. this.$refs["form"].validate(async (valid) => {
  454. if (valid) {
  455. if(this.form.photoList && this.form.photoList.length > 0 && this.form.photoList.length < 3) {
  456. this.$message.error("上传的宣传图不能少于三张!");
  457. return false
  458. }
  459. // if(this.form.photoList && this.form.photoList.length > 2) {
  460. // this.form.showImg = this.form.photoList[0].url
  461. // }
  462. try {
  463. this.loading = true;
  464. const { code } = await saveAndEdit({ ...this.form });
  465. if (code === 200) {
  466. this.$message.success("操作成功!");
  467. this.$emit("getList");
  468. this.cancel();
  469. }
  470. } catch (error) {
  471. } finally {
  472. this.loading = false;
  473. }
  474. }
  475. });
  476. },
  477. /**
  478. * 演员信息添加
  479. * @date 2023-11-22
  480. * @returns {any}
  481. */
  482. performerEven() {
  483. let target=[...this.performerList];
  484. this.form.performerList = JSON.parse(JSON.stringify(target));
  485. this.performerVisible = false;
  486. },
  487. /**
  488. * 重置
  489. * @date 2023-11-22
  490. * @returns {any}
  491. */
  492. reset() {
  493. this.$set(this.form, 'id', '');
  494. // 基础信息
  495. this.$set(this.form, 'name', '');
  496. this.$set(this.form, 'sponsorId', '');
  497. this.$set(this.form, 'sponsorName', '');
  498. let goodsIdList = []
  499. this.$set(this.form, 'goodsIdList', []);
  500. this.$set(this.form, 'status', '');
  501. // 演出信息
  502. this.$set(this.form, 'releaseDate', '');
  503. this.$set(this.form, 'showDuration', '');
  504. this.$set(this.form, 'peopleNum', '');
  505. this.$set(this.form, 'posterImg', '');
  506. this.$set(this.form, 'showImg', '');
  507. this.$set(this.form, 'performSnapshot', '');
  508. this.$set(this.form, 'photoList', []);
  509. // 观影须知
  510. this.$set(this.form, 'performNotice', '');
  511. },
  512. /**
  513. * 关闭弹框
  514. * @date 2023-11-22
  515. * @returns {any}
  516. */
  517. cancel() {
  518. this.reset();
  519. this.open = false;
  520. },
  521. /**
  522. * 上传成功
  523. * @date 2023-11-22
  524. * @param {any} res
  525. * @returns {any}
  526. */
  527. handleAvatarSuccess(res) {
  528. if (res.code === 200) {
  529. // this.form.mainImg = res?.data?.url;
  530. this.$set(this.form, 'posterImg', res?.data?.url)
  531. }
  532. console.log(this.form.photoList)
  533. },
  534. handleFMSuccess(res) {
  535. if (res.code === 200) {
  536. // this.form.mainImg = res?.data?.url;
  537. this.$set(this.form, 'showImg', res?.data?.url)
  538. }
  539. },
  540. /**
  541. * 剧目海报上传成功
  542. * @date 2023-11-22
  543. * @param {any} res
  544. * @returns {any}
  545. */
  546. handlePhotoListSuccess(res) {
  547. if (res.code === 200) {
  548. let photo = {
  549. imageUrl: res?.data?.url,
  550. url: res?.data?.url,
  551. photoType: '2'
  552. }
  553. if(!this.form.photoList){
  554. this.form.photoList = []
  555. }
  556. // this.form.photoList.push(photo);
  557. this.$set(this.form.photoList, this.form.photoList.length, photo);
  558. }
  559. },
  560. handleRemove(file, fileList) {
  561. this.form.photoList.forEach((item, index) => {
  562. if(item.uid == file.uid){
  563. this.form.photoList.splice(index, 1)
  564. }
  565. })
  566. },
  567. /**
  568. * 上传文件之前之前
  569. * @date 2023-11-22
  570. * @param {any} file
  571. * @returns {any}
  572. */
  573. beforeAvatarUpload(file) {
  574. const isJPG = file.type === "image/jpeg" || "image/png";
  575. if (!isJPG) {
  576. this.$message.error("上传头像图片只能是jpg或png格式!");
  577. }
  578. return isJPG;
  579. },
  580. /**
  581. * 演员新增
  582. * @date 2023-11-22
  583. */
  584. handleAdd() {
  585. if(!this.performerList){
  586. this.performerList = []
  587. }
  588. this.performerList.push({})
  589. },
  590. /**
  591. * 演员删除
  592. * @date 2023-11-22
  593. */
  594. handleDelete(row, index) {
  595. this.$confirm('是否确认删当前数据?', '提示', {
  596. confirmButtonText: '确定',
  597. cancelButtonText: '取消',
  598. type: 'warning'
  599. }).then(() => {
  600. this.performerList.splice(index, 1);
  601. this.$message({
  602. type: 'success',
  603. message: '删除成功!'
  604. });
  605. }).catch(() => {
  606. this.$message({
  607. type: 'info',
  608. message: '已取消删除'
  609. });
  610. });
  611. },
  612. /**
  613. * 演员弹窗打开
  614. * @date 2023-11-22
  615. */
  616. performerOpen() {
  617. if(!this.form.performerList){
  618. this.form.performerList = []
  619. }
  620. let target=[...this.form.performerList];
  621. this.performerList = JSON.parse(JSON.stringify(target));
  622. this.performerVisible = true;
  623. },
  624. /**
  625. * 演员图片上传成功
  626. * @date 2023-11-22
  627. * @param {any} res
  628. * @returns {any}
  629. */
  630. handlePerformerAvatarSuccess(res) {
  631. if (res.code === 200) {
  632. // this.form.mainImg = res?.data?.url;
  633. this.$set(this.performerList[this.performerIndex], 'performerHead', res?.data?.url);
  634. }
  635. },
  636. /**
  637. * 演员图片上传点击记录当前索引
  638. * @date 2023-11-22
  639. * @param {any} row
  640. * @returns {any}
  641. */
  642. changeIndexEven(row) {
  643. this.performerIndex = row.$index;
  644. }
  645. },
  646. };
  647. </script>
  648. <style lang="scss" scoped>
  649. .dialog {
  650. padding: 0 30px;
  651. max-height: 65vh;
  652. overflow-y: auto;
  653. }
  654. .dialog {
  655. padding: 0 30px;
  656. .upload-btn {
  657. width: 100px;
  658. height: 100px;
  659. background-color: #fbfdff;
  660. border: dashed 1px #c0ccda;
  661. border-radius: 5px;
  662. i {
  663. font-size: 30px;
  664. margin-top: 20px;
  665. }
  666. &-text {
  667. margin-top: -10px;
  668. }
  669. }
  670. .avatar {
  671. cursor: pointer;
  672. }
  673. }
  674. .el-table{
  675. .upload-btn {
  676. width: 100px;
  677. height: 100px;
  678. background-color: #fbfdff;
  679. border: dashed 1px #c0ccda;
  680. border-radius: 5px;
  681. i {
  682. font-size: 30px;
  683. margin-top: 20px;
  684. }
  685. &-text {
  686. margin-top: -10px;
  687. }
  688. }
  689. .avatar {
  690. cursor: pointer;
  691. }
  692. }
  693. </style>