addAndEdit.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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\venue\schedulingMr\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="900px"
  15. class="text-dia-log-class"
  16. append-to-body
  17. :close-on-click-modal="false"
  18. @close="cancel"
  19. >
  20. <div class="dialog">
  21. <el-form :model="form" ref="form" :rules="rules" label-width="120px">
  22. <el-form-item label="选择场馆" prop="venueId">
  23. <el-select
  24. v-model="form.venueId"
  25. placeholder="选择场馆"
  26. clearable
  27. @change="changeTheatre"
  28. style="width: 100%"
  29. >
  30. <el-option
  31. v-for="dict in theatreList"
  32. :key="dict.id"
  33. :label="dict.name"
  34. :value="dict.id"
  35. />
  36. </el-select>
  37. </el-form-item>
  38. <el-form-item label="选择演出厅" prop="auditoriumId">
  39. <el-select
  40. v-model="form.auditoriumId"
  41. placeholder="选择演出厅"
  42. clearable
  43. style="width: 100%"
  44. >
  45. <el-option
  46. v-for="dict in merchantList"
  47. :key="dict.id"
  48. :label="dict.name"
  49. :value="dict.id"
  50. />
  51. </el-select>
  52. </el-form-item>
  53. <el-form-item label="选择剧目" prop="performId">
  54. <el-select
  55. v-model="form.performId"
  56. placeholder="选择剧目"
  57. clearable
  58. @change="changePerform"
  59. style="width: 100%"
  60. >
  61. <el-option
  62. v-for="dict in goodsList"
  63. :key="dict.id"
  64. :label="dict.name"
  65. :value="dict.id"
  66. />
  67. </el-select>
  68. </el-form-item>
  69. <el-form-item label="选择日期" prop="performDate">
  70. <el-date-picker
  71. v-model="form.performDate"
  72. v-if="form.insertType == '2'"
  73. type="daterange"
  74. range-separator="至"
  75. @change="performDateEven('list')"
  76. value-format="yyyy-MM-dd"
  77. start-placeholder="开始日期"
  78. end-placeholder="结束日期">
  79. </el-date-picker>
  80. <el-date-picker
  81. v-if="form.insertType == '1'"
  82. v-model="form.performDate"
  83. type="date"
  84. @change="performDateEven"
  85. value-format="yyyy-MM-dd"
  86. placeholder="选择日期">
  87. </el-date-picker>
  88. </el-form-item>
  89. <!-- <el-form-item label="选择日期" v-if="form.insertType == '1'" prop="performDate">-->
  90. <!-- -->
  91. <!-- </el-form-item>-->
  92. <el-form-item label="场次排期" prop="timeList" v-if="!editType">
  93. <el-button type="primary" size="small" @click="addTable">添加</el-button>
  94. </el-form-item>
  95. <el-form-item label="" v-if="form.timeList && form.timeList.length > 0">
  96. <el-table ref="tables" v-loading="loading" :data="form.timeList" border>
  97. <el-table-column label="序号" align="center" type="index" width="50"></el-table-column>
  98. <el-table-column label="场次名称" align="center">
  99. <template slot-scope="scope">
  100. <el-input v-model="scope.row.name" placeholder="请输入内容"></el-input>
  101. </template>
  102. </el-table-column>
  103. <el-table-column label="开始时间" align="center">
  104. <template slot-scope="scope">
  105. <el-time-select
  106. v-model="scope.row.performTimeStart"
  107. style="width: 100%"
  108. @change="changValue(scope.row, 'start', scope.$index)"
  109. :picker-options="{ start: '08:00', step: '00:15', end: '23:30'}"
  110. placeholder="选择时间">
  111. </el-time-select>
  112. </template>
  113. </el-table-column>
  114. <el-table-column label="结束时间" align="center">
  115. <template slot-scope="scope">
  116. <el-time-select
  117. v-model="scope.row.performTimeEnd"
  118. style="width: 100%"
  119. @change="changValue(scope.row, 'end', scope.$index)"
  120. :picker-options="{ start: '08:00', step: '00:15', end: '23:30'}"
  121. placeholder="选择时间">
  122. </el-time-select>
  123. </template>
  124. </el-table-column>
  125. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  126. <template slot-scope="scope">
  127. <el-button
  128. size="mini"
  129. type="text"
  130. @click="handleDelete(scope.row,scope.$index)"
  131. >删除</el-button>
  132. </template>
  133. </el-table-column>
  134. </el-table>
  135. </el-form-item>
  136. </el-form>
  137. </div>
  138. <span slot="footer" class="dialog-footer">
  139. <el-button @click="cancel">取消</el-button>
  140. <el-button
  141. type="primary"
  142. @click="submitForm"
  143. v-loading.fullscreen.lock="loading"
  144. element-loading-text="提交中..."
  145. element-loading-spinner="el-icon-loading"
  146. element-loading-background="rgba(0, 0, 0, 0.8)"
  147. >
  148. <span v-if="loading">提交中...</span>
  149. <span v-else>保存</span>
  150. </el-button>
  151. </span>
  152. </el-dialog>
  153. </template>
  154. <script>
  155. import { saveAndEdit, addSave } from "@/api/schedulingMr/schedulingMr";
  156. import { pageList } from "@/api/venueMr/venueMr";
  157. import { goodsPageList } from '@/api/programmeMr/programmeMr'
  158. import { merchantPageList } from '@/api/performanceHallMr/performanceHallMr'
  159. import Editor from "@/components/Editor";
  160. import { getToken } from "@/utils/auth";
  161. export default {
  162. name: "addAndEdit",
  163. props: {
  164. dict: {
  165. type: Object,
  166. default: () => [],
  167. },
  168. },
  169. components: {
  170. Editor,
  171. },
  172. data() {
  173. return {
  174. title: "编辑",
  175. model: "EDIT",
  176. open: false,
  177. loading: false,
  178. tableType: false,
  179. form: {
  180. id: undefined,
  181. timeList: [],
  182. insertType: '1'
  183. },
  184. rules: {
  185. venueId: [{ required: true, message: "请选择场馆", trigger: ["change","blur"] }],
  186. auditoriumId: [{ required: true, message: "请选择演出厅", trigger: ["change","blur"] }],
  187. performId: [{ required: true, message: "请选择剧目", trigger: ["change","blur"] }],
  188. performDate: [{ required: true, message: "请选择日期", trigger: ["change","blur"] }],
  189. timeList: [{ required: true, message: "请添加场次", trigger: ["change","blur"] }],
  190. },
  191. uploadObj: {
  192. url: process.env.VUE_APP_UPLOAD_FILE_API + "/upload/single/minio",
  193. Headers: { Authorization: "Bearer " + getToken() },
  194. },
  195. theatreList: [],
  196. goodsList: [],
  197. merchantList: [],
  198. editType: false,
  199. selectPerform: {}
  200. };
  201. },
  202. methods: {
  203. /**
  204. * 打开弹框
  205. * @date 2023-11-22
  206. * @param {any} obj
  207. * @returns {any}
  208. */
  209. openDialog(title, obj, type) {
  210. this.open = true;
  211. this.editType = false;
  212. this.reset();
  213. this.getList();
  214. this.goodsPageList();
  215. // this.merchantPageList();
  216. if (obj){
  217. this.title = "编辑排期";
  218. this.$set(this.form, 'insertType', '1');
  219. this.editType = true;
  220. this.$nextTick(() => {
  221. this.$set(this.form, 'id', obj.id);
  222. this.$set(this.form, 'performId', obj.performId);
  223. this.$set(this.form, 'performDate', obj.performDate);
  224. this.$set(this.form, 'auditoriumId', obj.auditoriumId);
  225. this.$set(this.form, 'theatreName', obj.theatreName);
  226. this.getList(obj.theatreName);
  227. let map = {
  228. name: obj.timeSnapshot,
  229. performTimeStart: obj.performTimeStart,
  230. performTimeEnd: obj.performTimeEnd,
  231. }
  232. this.form.timeList = []
  233. this.$set(this.form.timeList, 0, map);
  234. });
  235. }else{
  236. this.title = "新增排期";
  237. this.form = {
  238. id: undefined,
  239. timeList: []
  240. };
  241. if(type){
  242. this.$set(this.form, 'insertType', '2');
  243. } else {
  244. this.$set(this.form, 'insertType', '1');
  245. }
  246. this.$nextTick(() => {
  247. this.$refs["form"].clearValidate();
  248. });
  249. }
  250. },
  251. /** 场馆列表查询 */
  252. getList(name) {
  253. pageList(this.addDateRange({pageNum: 1, pageSize: 100}))
  254. .then(response => {
  255. this.theatreList = response.data.rows;
  256. this.theatreList.forEach(item => {
  257. if(name == item.name){
  258. this.$set(this.form, 'venueId', item.id)
  259. }
  260. })
  261. this.merchantPageList(this.form.venueId)
  262. }
  263. );
  264. },
  265. /** 场馆选择 */
  266. changeTheatre(id) {
  267. this.merchantPageList(id)
  268. },
  269. /** 剧目选择 */
  270. changePerform(id) {
  271. this.goodsList.forEach(item => {
  272. if(id == item.id){
  273. this.selectPerform = item;
  274. }
  275. })
  276. this.$set(this.form, 'performDate' , '')
  277. },
  278. // yyyy-mm-dd 转时时间戳
  279. dateToTimestamp(year, month, day) {
  280. const date = new Date(year, month - 1, day);
  281. return date.getTime();
  282. },
  283. // 时间选择
  284. performDateEven(key) {
  285. if(!this.form.performId){
  286. this.$message.error("请选择剧目!");
  287. this.$set(this.form, 'performDate', '');
  288. return false;
  289. }
  290. let newTime = ''
  291. if(key == 'list'){
  292. newTime = this.form.performDate[0]
  293. } else {
  294. newTime = this.form.performDate;
  295. }
  296. let newTimeArr = newTime.split('-');
  297. let letTiemArr = this.selectPerform.releaseDate.split('-');
  298. if(this.dateToTimestamp(newTimeArr[0], newTimeArr[1], newTimeArr[2]) < this.dateToTimestamp(letTiemArr[0], letTiemArr[1], letTiemArr[2])){
  299. this.$message.error("开始时间不能小于剧目上映时间" + this.selectPerform.releaseDate);
  300. this.$set(this.form, 'performDate' , '')
  301. return false
  302. }
  303. },
  304. /** 剧目列表查询 */
  305. goodsPageList() {
  306. goodsPageList(this.addDateRange({pageNum: 1, pageSize: 100, status: 1}))
  307. .then(response => {
  308. this.goodsList = response.data.rows;
  309. });
  310. },
  311. /** 演出厅列表查询 */
  312. merchantPageList(id) {
  313. merchantPageList(this.addDateRange({theatreId: id, pageNum: 1, pageSize: 100}))
  314. .then(response => {
  315. this.merchantList = response.data.rows;
  316. });
  317. },
  318. /**
  319. * 保存
  320. * @date 2023-11-22
  321. * @returns {any}
  322. */
  323. submitForm() {
  324. this.$refs["form"].validate(async (valid) => {
  325. if (valid) {
  326. try {
  327. if(this.form.insertType == '2') {
  328. this.form.performStartDate = this.form.performDate[0];
  329. this.form.performEndDate = this.form.performDate[1];
  330. }
  331. let postEdit = {}
  332. if(this.editType) {
  333. postEdit.id = this.form.id
  334. }
  335. postEdit.performTimeStart = this.form.timeList[0].performTimeStart
  336. postEdit.performTimeEnd = this.form.timeList[0].performTimeEnd
  337. postEdit.timeSnapshot = this.form.timeList[0].name
  338. postEdit.performId = this.form.performId
  339. postEdit.auditoriumId = this.form.auditoriumId
  340. postEdit.performDate = this.form.performDate
  341. postEdit.timeList = this.form.timeList
  342. this.loading = true;
  343. // const { code } = this.form.insertType == '2' ? await addSave({ ...this.form }) : this.form.id ? await saveAndEdit({ ...postEdit }) : await addSave({ ...this.form });
  344. const { code } = this.form.insertType == '2' ? await addSave({ ...this.form }) : await saveAndEdit({ ...postEdit });
  345. if (code === 200) {
  346. this.$message.success("操作成功!");
  347. this.$emit("getList");
  348. this.cancel();
  349. }
  350. } catch (error) {
  351. } finally {
  352. this.loading = false;
  353. }
  354. }
  355. });
  356. },
  357. /**
  358. * 重置
  359. * @date 2023-11-22
  360. * @returns {any}
  361. */
  362. reset() {
  363. this.$set(this.form, 'id', '');
  364. this.$set(this.form, 'performId', '');
  365. this.$set(this.form, 'performDate', '');
  366. this.$set(this.form, 'auditoriumId', '');
  367. this.$set(this.form, 'theatreName', '');
  368. this.$set(this.form, 'timeList', []);
  369. },
  370. /**
  371. * 关闭弹框
  372. * @date 2023-11-22
  373. * @returns {any}
  374. */
  375. cancel() {
  376. this.reset();
  377. this.open = false;
  378. },
  379. /**
  380. * 上传成功
  381. * @date 2023-11-22
  382. * @param {any} res
  383. * @returns {any}
  384. */
  385. handleAvatarSuccess(res) {
  386. if (res.code === 200) {
  387. // this.form.mainImg = res?.data?.url;
  388. this.$set(this.form, 'mainImg', res?.data?.url)
  389. }
  390. },
  391. /**
  392. * 上传文件之前之前
  393. * @date 2023-11-22
  394. * @param {any} file
  395. * @returns {any}
  396. */
  397. beforeAvatarUpload(file) {
  398. const isJPG = file.type === "image/jpeg" || "image/png";
  399. if (!isJPG) {
  400. this.$message.error("上传头像图片只能是jpg或png格式!");
  401. }
  402. return isJPG;
  403. },
  404. /** 点击添加排期 */
  405. addTable() {
  406. if(!this.form.performId){
  407. this.$message.error("请选择剧目!");
  408. return false;
  409. }
  410. if(this.form.insertType == '1' && this.form.timeList && this.form.timeList.length >= 1) {
  411. this.$message.error("只能添加单场次!");
  412. return false;
  413. }
  414. let map = {
  415. name: '',
  416. performTimeStart: '',
  417. startM: '',
  418. performTimeEnd: '',
  419. endM: '',
  420. err: false,
  421. }
  422. this.form.timeList.push(map)
  423. },
  424. /** 开始时间和结束时间大小判断 */
  425. changValue(row, key, $index) {
  426. let start = '', startTime = '', end = '', endTime;
  427. if(row.performTimeStart && row.performTimeStart.length > 0) {
  428. start = row.performTimeStart.split(":");
  429. startTime = (start[0] * 3600) + (start[1] * 60);
  430. row.startM = startTime;
  431. }
  432. if(row.performTimeEnd && row.performTimeEnd.length > 0) {
  433. // if(this.selectPerform)
  434. end = row.performTimeEnd.split(":");
  435. endTime = (end[0] * 3600) + (end[1] * 60);
  436. let showDuration = this.selectPerform.showDuration * 60;
  437. if(endTime - row.startM < showDuration) {
  438. this.$message.error("选择时间不能小于剧目时长," + this.selectPerform.showDuration + "分钟!");
  439. row.performTimeEnd = ""
  440. return false
  441. }
  442. row.endM = endTime;
  443. }
  444. // 判断场次时间段是否存在冲突
  445. let status = false;
  446. this.form.timeList.forEach((item, index) => {
  447. if($index != index) {
  448. if(key == 'start') {
  449. if(item.startM <= startTime && startTime <= item.endM) {
  450. status = true;
  451. }
  452. }
  453. if (key == 'end') {
  454. if(item.startM <= endTime && endTime <= item.endM) {
  455. status = true;
  456. }
  457. }
  458. }
  459. })
  460. if(status) {
  461. this.$message.error("该场次的时间和其它场次时间段冲突!");
  462. if(key == 'start') {
  463. row.performTimeStart = ""
  464. row.startM = ""
  465. } else if (key == 'end') {
  466. row.performTimeEnd = ""
  467. row.endM = ""
  468. }
  469. return false;
  470. }
  471. if(key == 'start') {
  472. if(endTime && startTime >= endTime) {
  473. row.startTime = ""
  474. row.startM = ""
  475. }
  476. } else if (key == 'end') {
  477. if(startTime && startTime >= endTime) {
  478. row.endTime = ""
  479. row.endM = ""
  480. }
  481. }
  482. },
  483. /** 删除按钮操作 */
  484. handleDelete(row, index) {
  485. if(this.form.timeList && this.form.timeList.length == 1){
  486. this.$message.error("只剩一场次, 不能删除!");
  487. return false;
  488. }
  489. this.$confirm('是否确认删除数据场次名称为"' + row.name + '"的数据项?', '提示', {
  490. confirmButtonText: '确定',
  491. cancelButtonText: '取消',
  492. type: 'warning'
  493. }).then(() => {
  494. this.form.timeList.splice(index, 1)
  495. }).catch(() => {
  496. });
  497. },
  498. },
  499. };
  500. </script>
  501. <style lang="scss" scoped>
  502. .dialog {
  503. padding: 0 30px;
  504. max-height: 65vh;
  505. overflow-y: auto;
  506. }
  507. .dialog {
  508. padding: 0 30px;
  509. .upload-btn {
  510. width: 100px;
  511. height: 100px;
  512. background-color: #fbfdff;
  513. border: dashed 1px #c0ccda;
  514. border-radius: 5px;
  515. i {
  516. font-size: 30px;
  517. margin-top: 20px;
  518. }
  519. &-text {
  520. margin-top: -10px;
  521. }
  522. }
  523. .avatar {
  524. cursor: pointer;
  525. }
  526. }
  527. </style>