UserRoomRelationModal.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <a-modal
  3. title="关联房间"
  4. :width="800"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. @ok="handleSubmit"
  8. @cancel="handleCancel"
  9. cancelText="关闭"
  10. style="top: 20px"
  11. >
  12. <a-spin :spinning="confirmLoading">
  13. <div class="relation-wrapper">
  14. <a-row>
  15. <a-col :span="12" style="height: 500px; overflow-y: auto">
  16. <div class="wrapper-floor" v-for="item in roomTree" :key="item.id">
  17. <div>{{ item.name }}</div>
  18. <div class="wrapper-room">
  19. <div
  20. @click="onRoomClick(room)"
  21. class="wrapper-room-item"
  22. :class="[
  23. selectedRooms.findIndex((s) => s.id == room.id) > -1
  24. ? 'selected-class'
  25. : '',
  26. ]"
  27. v-for="room in item.rooms"
  28. :key="room.id"
  29. >
  30. {{ room.name }}
  31. </div>
  32. </div>
  33. </div>
  34. </a-col>
  35. <a-col :span="12" style="height: 500px; overflow-y: auto">
  36. <div style="margin: 10px">已关联房间</div>
  37. <div style="display: flex; flex-wrap: wrap; height: max-content">
  38. <div
  39. @click="delSelectedRoom(room)"
  40. class="wrapper-room-item-1"
  41. v-for="room in selectedRooms"
  42. :key="room.id"
  43. >
  44. {{ room.name }}
  45. </div>
  46. </div>
  47. </a-col>
  48. </a-row>
  49. </div>
  50. </a-spin>
  51. </a-modal>
  52. </template>
  53. <script>
  54. import { putAction, getAction, postAction } from "@/api/manage";
  55. import { min } from "lodash";
  56. export default {
  57. name: "UserRoomRelation",
  58. data() {
  59. return {
  60. confirmLoading: false,
  61. visible: false,
  62. roomTree: [],
  63. selectedRooms: [],
  64. userId: null,
  65. yezhuId: "",
  66. };
  67. },
  68. created() {},
  69. methods: {
  70. delSelectedRoom(r) {
  71. let findIndex = this.selectedRooms.findIndex((s) => s.id == r.id);
  72. if (findIndex > -1) {
  73. this.selectedRooms.splice(findIndex, 1);
  74. }
  75. },
  76. onRoomClick(r) {
  77. let findIndex = this.selectedRooms.findIndex((s) => s.id == r.id);
  78. if (findIndex > -1) {
  79. this.selectedRooms.splice(findIndex, 1);
  80. } else {
  81. this.selectedRooms.push(r);
  82. }
  83. },
  84. show(record) {
  85. this.selectedRooms = JSON.parse(JSON.stringify(record.inRoomList));
  86. this.selectedRooms = this.selectedRooms.map((t) => {
  87. return {
  88. id: t.roomId,
  89. name: t.roomName,
  90. };
  91. });
  92. this.yezhuId = record.id;
  93. getAction("/business/busRoomBookingOrders/rili-fangtai", {
  94. start: "2023-05-19",
  95. end: "2023-06-18",
  96. }).then((res) => {
  97. if (res.success) {
  98. this.roomTree = res.result.floorRoomVos;
  99. }
  100. });
  101. this.visible = true;
  102. },
  103. close() {
  104. this.$emit("close");
  105. this.visible = false;
  106. },
  107. handleSubmit() {
  108. // 触发表单验证
  109. let bodyData = this.selectedRooms.map((s) => {
  110. return {
  111. roomId: s.id,
  112. busYezhuId: this.yezhuId,
  113. };
  114. });
  115. postAction(
  116. "/business/busYezhuInRoom/add?userId=" + this.userId,
  117. bodyData
  118. ).then((res) => {
  119. if (res.success) {
  120. this.$message.success("保存成功!");
  121. this.$emit("ok");
  122. this.visible = false;
  123. }
  124. });
  125. },
  126. handleCancel() {
  127. this.close();
  128. },
  129. },
  130. };
  131. </script>
  132. <style>
  133. .wrapper-room {
  134. display: flex;
  135. flex-wrap: wrap;
  136. }
  137. .wrapper-room-item:hover {
  138. border: 1px solid #f00;
  139. color: #fff;
  140. background-color: #ff000088;
  141. }
  142. .selected-class,
  143. .wrapper-room-item-1 {
  144. border: 1px solid #f00 !important;
  145. color: #fff !important;
  146. background-color: #ff000088 !important;
  147. }
  148. .wrapper-room-item,
  149. .wrapper-room-item-1 {
  150. width: fit-content;
  151. padding: 5px 8px;
  152. border: 1px solid #1890ff;
  153. background-color: #1890ff88;
  154. margin-left: 10px;
  155. margin-top: 5px;
  156. color: white;
  157. border-radius: 6px;
  158. cursor: pointer;
  159. }
  160. </style>