seatTemplateEdit.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. <!--
  2. * @Description: 新增/编辑弹框
  3. * @Author: Sugar.
  4. * @Date: 2023-11-24 13:55:00
  5. * @LastEditors: Sugar.
  6. * @LastEditTime: 22023-11-24 13:55:00
  7. * @FilePath: \cattle_webui\src\views\performanceHallMr\dialog\seatTemplateEdit.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. append-to-body
  16. :close-on-click-modal="false"
  17. @close="cancel"
  18. >
  19. <div class="dialog">
  20. <el-row>
  21. <el-col :span="16" style="padding-right: 15px">
  22. <div class="title-class">
  23. <el-row>
  24. <el-col :span="8" style="padding-right: 15px">
  25. <el-input placeholder="请输入" v-model.number="seatMapRow">
  26. <template slot="append">行</template>
  27. </el-input>
  28. </el-col>
  29. <el-col :span="8" style="padding-left: 15px">
  30. <el-input placeholder="请输入" v-model.number="seatMapCol">
  31. <template slot="append">列</template>
  32. </el-input>
  33. </el-col>
  34. <el-col :span="8" style="padding-left: 15px">
  35. <el-button @click="setRowCol(seatMapRow, seatMapCol)" style="width: 100%;" type="primary">生成模板</el-button>
  36. </el-col>
  37. </el-row>
  38. </div>
  39. <div class="box-class">
  40. <div class="box-top-class">
  41. <div class="stage-class">舞台</div>
  42. </div>
  43. <div class="box-bottom-class" ref="seatBox" v-if="seatType">
  44. <div v-for="row in seatMap.row" :key="row">
  45. <div class="seat-tag"
  46. @click="setSeatTemplateMap(row, col)"
  47. v-for="col in seatMap.col"
  48. :key="col"
  49. :style="{
  50. width: seatWidth,
  51. height: seatWidth,
  52. backgroundColor: colSeatMap[row+'_'+col] && colSeatMap[row+'_'+col].color ? colSeatMap[row+'_'+col].color : ''}"
  53. ></div>
  54. </div>
  55. </div>
  56. </div>
  57. </el-col>
  58. <el-col :span="8" style="padding-left: 15px">
  59. <div class="title-class">座位设置</div>
  60. <div class="box-class">
  61. <el-form :model="form" ref="form" label-width="100px" label-position="top">
  62. <el-form-item label="是否可售">
  63. <el-radio v-model="form.status" label="1">可售</el-radio>
  64. <el-radio v-model="form.status" label="2">不可售</el-radio>
  65. </el-form-item>
  66. <el-form-item label="座位类型">
  67. <el-select
  68. v-model="form.seatTypeId"
  69. placeholder="座位类型"
  70. clearable
  71. style="width: 100%"
  72. @change="seatTypeChange"
  73. >
  74. <el-option
  75. v-for="dict in seatList"
  76. :key="dict.id"
  77. :label="dict.name"
  78. :value="dict.id"
  79. />
  80. </el-select>
  81. </el-form-item>
  82. <el-form-item label="座位自动分配优先级">
  83. <el-input
  84. v-model.number="form.priority"
  85. placeholder="优先级"
  86. clearable
  87. style="width: 100%;"
  88. />
  89. </el-form-item>
  90. <el-form-item label="自定义座位名">
  91. <el-input
  92. v-model="form.name"
  93. placeholder="自定义座位名"
  94. clearable
  95. style="width: 100%;"
  96. />
  97. </el-form-item>
  98. <el-form-item >
  99. <el-button @click="setSeatMap" style="width: 100%; margin-top: 20px" type="primary">确 定</el-button>
  100. </el-form-item>
  101. </el-form>
  102. </div>
  103. </el-col>
  104. </el-row>
  105. </div>
  106. <span slot="footer" class="dialog-footer">
  107. <el-button @click="cancel">取消</el-button>
  108. <el-button
  109. type="primary"
  110. @click="submitForm"
  111. v-loading.fullscreen.lock="loading"
  112. element-loading-text="提交中..."
  113. element-loading-spinner="el-icon-loading"
  114. element-loading-background="rgba(0, 0, 0, 0.8)"
  115. >
  116. <span v-if="loading">提交中...</span>
  117. <span v-else>保存</span>
  118. </el-button>
  119. </span>
  120. </el-dialog>
  121. </template>
  122. <script>
  123. import { pageList } from '@/api/seatTypeMr/seatTypeMr'
  124. import { seatSaveAndEdit, saveAndEdit, getSelectById } from "@/api/performanceHallMr/performanceHallMr";
  125. import { getToken } from "@/utils/auth";
  126. export default {
  127. name: "seatTemplateEdit",
  128. data() {
  129. return {
  130. title: "编辑",
  131. model: "EDIT",
  132. activeName: '01',
  133. open: false,
  134. seatType: false,
  135. loading: false,
  136. seatWidth: null,
  137. seatMap: {
  138. row: 0,
  139. col: 0,
  140. },
  141. seatMapRow: '',
  142. seatMapCol: '',
  143. seatSetMap: {},
  144. seatTemplateMap: [],
  145. colSeatMap: {},
  146. form: {
  147. id: undefined,
  148. status: "1",
  149. content: "",
  150. },
  151. seatList: [],
  152. auditoriumId: '',
  153. };
  154. },
  155. methods: {
  156. /**
  157. * 打开弹框
  158. * @date 2023-11-22
  159. * @param {any} obj
  160. * @returns {any}
  161. */
  162. openDialog(title, obj) {
  163. this.open = true;
  164. this.seatType = false;
  165. this.getSeatTypeList();
  166. this.colSeatMap = {};
  167. if (obj){
  168. this.title = "座位模板";
  169. this.auditoriumId = obj.id;
  170. this.$set(this.seatMap, 'row', obj.rows);
  171. this.$set(this.seatMap, 'col', obj.cols);
  172. this.$set(this, 'seatMapRow', obj.rows);
  173. this.$set(this, 'seatMapCol', obj.cols);
  174. this.getSelectByIdApi(obj)
  175. }else{
  176. this.seatType = true;
  177. this.title = "座位模板";
  178. this.$nextTick(() => {
  179. this.$refs["form"].clearValidate();
  180. });
  181. }
  182. },
  183. /** 获取详情 */
  184. getSelectByIdApi(row) {
  185. const id = row.id
  186. getSelectById(id).then(response => {
  187. const dataList = response.data;
  188. this.$nextTick(() =>{
  189. dataList.forEach(item => {
  190. if(item.status == 2){
  191. item.color = '#7d7d7e';
  192. }
  193. this.$set(this.colSeatMap, item.rowNo + '_' + item.columnNo, item);
  194. })
  195. this.seatType = true;
  196. this.$nextTick(() =>{
  197. this.seatWidth = ((this.$refs.seatBox.offsetWidth - 10 - (this.seatMap.col * 2))/this.seatMap.col) + 'px';
  198. })
  199. })
  200. });
  201. },
  202. /** 设置座位模板行列 */
  203. setRowCol(row, col) {
  204. if(!row || !col){
  205. this.$message.error("请输入行和列!");
  206. return false;
  207. }
  208. if(row <= 0 || col <= 0){
  209. this.$message.error("请输入大于0的行和列!");
  210. return false;
  211. }
  212. if(this.colSeatMap) {
  213. this.$confirm('此操作将重置座位模板, 是否继续?', '提示', {
  214. confirmButtonText: '确定',
  215. cancelButtonText: '取消',
  216. type: 'warning'
  217. }).then(() => {
  218. this.seatMap.row = row;
  219. this.seatMap.col = col;
  220. this.seatType = false;
  221. this.seatType = true;
  222. this.colSeatMap = {}
  223. for (let i = 1; i < this.seatMap.row + 1; i++) {
  224. for (let j = 1; j < this.seatMap.col + 1; j++) {
  225. let rowColMap = {
  226. "auditoriumId": this.auditoriumId,
  227. "name": "",
  228. "rowNo": i,
  229. "columnNo": j,
  230. "seatTypeColor": '#fdfdfd',
  231. "seatTypeId": "",
  232. "seatLabel": "",
  233. "priority": "",
  234. "status": 2
  235. };
  236. this.$set(this.colSeatMap, i + '_' + j, rowColMap);
  237. }
  238. }
  239. this.$nextTick(() =>{
  240. this.seatWidth = ((this.$refs.seatBox.offsetWidth - 10 - (this.seatMap.col * 2))/this.seatMap.col) + 'px';
  241. })
  242. }).catch(() => {
  243. });
  244. }
  245. },
  246. /** 座位类型列表 */
  247. getSeatTypeList() {
  248. pageList(this.addDateRange({pageNum: 1, pageSize: 100}))
  249. .then(response => {
  250. this.seatList = response.data.rows;
  251. }
  252. );
  253. },
  254. /** 座位类型选择事件 */
  255. seatTypeChange(val) {
  256. this.seatList.forEach(item => {
  257. if(val == item.id){
  258. this.form.seat = item
  259. }
  260. })
  261. },
  262. /** 座位设置确认事件 */
  263. setSeatMap() {
  264. this.seatSetMap = {};
  265. this.seatSetMap.status = this.form.status;
  266. this.seatSetMap.color = this.form.seat.color;
  267. this.seatSetMap.seatTypeId = this.form.seat.id;
  268. this.seatSetMap.seatLabel = this.form.seat.name;
  269. this.seatSetMap.name = this.form.name;
  270. this.seatSetMap.priority = this.form.priority;
  271. if(this.seatSetMap.status == 2) {
  272. this.seatSetMap.color = '#7d7d7e';
  273. this.seatSetMap.seatTypeId = '';
  274. this.seatSetMap.seatLabel = '';
  275. }
  276. },
  277. // 点击座位放置参数
  278. setSeatTemplateMap(row, col) {
  279. let map = this.colSeatMap[row + '_' +col];
  280. map.status = this.seatSetMap.status;
  281. map.color = this.seatSetMap.color;
  282. map.seatTypeId = this.seatSetMap.seatTypeId;
  283. map.seatLabel = this.seatSetMap.seatLabel;
  284. map.name = this.seatSetMap.name;
  285. map.priority = this.seatSetMap.priority;
  286. this.$set(this.colSeatMap, row + '_' +col, map);
  287. },
  288. /**
  289. * 保存
  290. * @date 2023-11-22
  291. * @returns {any}
  292. */
  293. submitForm() {
  294. let that = this;
  295. this.$refs["form"].validate(async (valid) => {
  296. if (valid) {
  297. let postList = []
  298. for (const codeKey in this.colSeatMap) {
  299. postList.push(this.colSeatMap[codeKey])
  300. }
  301. try {
  302. this.loading = true;
  303. const { code } = await saveAndEdit({ id: this.auditoriumId, rows: this.seatMap.row, cols: this.seatMap.col });
  304. if (code === 200) {
  305. let postList = []
  306. for (const codeKey in this.colSeatMap) {
  307. postList.push(this.colSeatMap[codeKey])
  308. }
  309. const { code } = await seatSaveAndEdit(postList);
  310. if (code === 200) {
  311. that.$message.success("修改成功!");
  312. that.$emit("getList");
  313. that.cancel();
  314. }
  315. }
  316. } catch (error) {
  317. } finally {
  318. this.loading = false;
  319. }
  320. }
  321. });
  322. },
  323. /**
  324. * 重置
  325. * @date 2023-11-22
  326. * @returns {any}
  327. */
  328. reset() {
  329. this.$refs["form"].resetFields();
  330. this.form.id = undefined;
  331. },
  332. /**
  333. * 关闭弹框
  334. * @date 2023-11-22
  335. * @returns {any}
  336. */
  337. cancel() {
  338. this.reset();
  339. this.open = false;
  340. },
  341. /**
  342. * 上传成功
  343. * @date 2023-11-22
  344. * @param {any} res
  345. * @returns {any}
  346. */
  347. handleAvatarSuccess(res) {
  348. if (res.code === 200) {
  349. // this.form.mainImg = res?.data?.url;
  350. this.$set(this.form, 'mainImg', res?.data?.url)
  351. }
  352. },
  353. /**
  354. * 上传文件之前之前
  355. * @date 2023-11-22
  356. * @param {any} file
  357. * @returns {any}
  358. */
  359. beforeAvatarUpload(file) {
  360. const isJPG = file.type === "image/jpeg" || "image/png";
  361. if (!isJPG) {
  362. this.$message.error("上传头像图片只能是jpg或png格式!");
  363. }
  364. return isJPG;
  365. },
  366. },
  367. };
  368. </script>
  369. <style lang="scss" scoped>
  370. .dialog {
  371. padding: 0 30px;
  372. max-height: 65vh;
  373. overflow-y: auto;
  374. }
  375. .dialog {
  376. padding: 0 30px;
  377. .title-class{
  378. text-align: center;
  379. color: #6e6e6e;
  380. margin: 10px auto;
  381. }
  382. .box-class{
  383. width: 100%;
  384. height: 100%;
  385. border: 2px solid #7d7d7e;
  386. border-radius: 4px;
  387. padding: 10px;
  388. .box-top-class{
  389. .stage-class{
  390. margin: 10px auto;
  391. width: 160px;
  392. height: 80px;
  393. border: 2px solid #7d7d7e;
  394. text-align: center;
  395. line-height: 80px;
  396. }
  397. }
  398. .box-bottom-class{
  399. //border: 2px solid #5656c2;
  400. margin-top: 15px;
  401. padding-left: 4px;
  402. .seat-tag{
  403. display: inline-block;
  404. border: 1px solid #7d7d7e;
  405. margin-right: 2px;
  406. cursor: pointer;
  407. background: url("../../../../assets/images/seat-icon.png") no-repeat;
  408. background-size: 100% 100%;
  409. &:hover{
  410. opacity: 0.8;
  411. }
  412. }
  413. }
  414. }
  415. .upload-btn {
  416. width: 100px;
  417. height: 100px;
  418. background-color: #fbfdff;
  419. border: dashed 1px #c0ccda;
  420. border-radius: 5px;
  421. i {
  422. font-size: 30px;
  423. margin-top: 20px;
  424. }
  425. &-text {
  426. margin-top: -10px;
  427. }
  428. }
  429. .avatar {
  430. cursor: pointer;
  431. }
  432. }
  433. </style>