roomGen.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. <template>
  2. <div style="display: flex" v-if="step == 1">
  3. <div style="flex: 3">
  4. <a-form :form="form">
  5. <!-- <a-form-model-item
  6. label="酒店名称"
  7. :labelCol="labelCol"
  8. :wrapperCol="wrapperCol"
  9. prop="layoutId"
  10. >
  11. <a-select
  12. show-search
  13. placeholder="请选择酒店"
  14. option-filter-prop="children"
  15. @change="hotelChange"
  16. >
  17. <a-select-option v-for="(item, index) in hotelId" :key="index">
  18. {{ item.name }}
  19. </a-select-option>
  20. </a-select>
  21. </a-form-model-item> -->
  22. <a-form-model-item label="楼栋名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="layoutId">
  23. <a-select show-search placeholder="请选择楼栋" v-model="buildingId" option-filter-prop="children"
  24. @change="onBuildChange">
  25. <a-select-option v-for="item in buildingTreeData" :key="item.id">
  26. {{ item.name }}
  27. </a-select-option>
  28. </a-select>
  29. </a-form-model-item>
  30. <a-form-model-item label="起始层数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="layoutId">
  31. <a-input-number placeholder="输入起始层数" v-model="model.floorCount" :min="1" style="width: 120px" />层
  32. </a-form-model-item>
  33. <a-form-model-item label="最高层数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="layoutId">
  34. <a-input-number placeholder="输入最高层数" v-model="model.floorCountMax" :min="1" style="width: 120px" />层
  35. </a-form-model-item>
  36. <a-form-model-item label="每层房间数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="layoutId">
  37. <a-input-number placeholder="输入每层房间数" v-model="model.roomCount" :min="1" style="width: 120px" />间
  38. </a-form-model-item>
  39. <a-form-model-item label="设置前缀" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="layoutId">
  40. <a-input placeholder="输入房号前缀" v-model="model.prefix" />
  41. </a-form-model-item>
  42. <a-form-model-item label="尾号排除" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="layoutId">
  43. <a-checkbox v-model="model.isExpectEnd"> 尾号排除 </a-checkbox>
  44. <a-input :disabled="!model.isExpectEnd" placeholder="输入排除的其他尾号" v-model="tailNumber" />
  45. </a-form-model-item>
  46. <a-button type="primary" @click="genRooms"> 批量生成 </a-button>
  47. </a-form>
  48. </div>
  49. <div style="flex: 7;">
  50. <div v-if="roomTree.length > 0" style="height: calc(100vh - (52px + 59px + 100px));overflow-y: auto;">
  51. <div v-for="(item, index) in roomTree" :key="index" style="width: 100%">
  52. <div style="font-width: 600; font-size: 20px" @click="sele(item)">
  53. <a-input placeholder="请填写楼层名" v-model="item.name" class="floor-input"></a-input>
  54. <a-button @click="delFloor(index)" type="danger" shape="circle" size="small" icon="minus"
  55. style="margin-left: 5px" />
  56. </div>
  57. <div style="color:red;" v-if="isExistNames(item.name)">名称已存在</div>
  58. <div style="display: flex;justify-content: start;margin: 20px;flex-wrap: wrap;">
  59. <div v-for="(room, indexs) in item.children" :key="indexs" style="width: 15%; margin-top: 10px">
  60. <input v-model="room.name" style="width: 50%; margin: auto" />
  61. <a-button @click="delRoom(index, indexs)" type="danger" shape="circle" size="small" icon="minus"
  62. style="margin-left: 5px" />
  63. <div style="color:red;" v-if="repeatName(item.children, indexs)">房名重复</div>
  64. </div>
  65. </div>
  66. <div>
  67. <a-button @click="addRoom(index)" type="primary" shape="circle" size="small" icon="plus"
  68. style="margin-left: 20px; margin: 0 20px 20px" />
  69. </div>
  70. </div>
  71. </div>
  72. <div v-else class="empty-tree">
  73. <a-empty description="请在左侧生成房间" />
  74. </div>
  75. <div class="bottom-btns">
  76. <a-button @click="back">取消</a-button>
  77. <a-button @click="save" type="primary">保存</a-button>
  78. </div>
  79. </div>
  80. </div>
  81. <div v-else class="room-layout-settings">
  82. <div style="flex:1;position: relative;">
  83. <div class="wait-select-title" style="display: flex; position: absolute;top: 0;width: 98%;">
  84. <div class="color-title">待配置房间</div>
  85. <div class="bottom-sele-btn">
  86. <a-popover placement="topRight" v-if="canMove.can">
  87. <template slot="content">
  88. <a-button type="link" v-for="(item, index) in layouts" :key="item.id" @click="moveTo(index)">
  89. {{ item.name }}
  90. </a-button>
  91. </template>
  92. <template slot="title">
  93. <span>要移动到的目标房型</span>
  94. </template>
  95. <a-button :disabled="false" type="primary">移动到房型({{ canMove.count }})</a-button>
  96. </a-popover>
  97. <a-button v-else :disabled="true" type="primary">移动到房型(0)</a-button>
  98. <a-button :disabled="saveLoading" :loading="saveLoading" @click="back" type="primary">取消</a-button>
  99. <a-button :disabled="saveLoading" :loading="saveLoading" @click="save" type="primary">保存并查看房间列表</a-button>
  100. </div>
  101. </div>
  102. <div style="flex:1;height: calc(100vh - 180px);overflow-y: auto;">
  103. <div style="height: 34px;width: 1px;"></div>
  104. <div v-for="(item, index) in roomTree" :key="index" style="width: 100%; padding-left: 30px">
  105. <div style="font-width: 600; font-size: 20px" @click="sele(item)">
  106. {{ item.name }}
  107. </div>
  108. <div style="display: flex;justify-content: start;margin: 20px;flex-wrap: wrap;">
  109. <div v-for="(room, indexs) in item.children" :key="indexs" class="select-room-item"
  110. :class="[room.checked ? 'checked-room' : '']" @click="room.checked = !room.checked"
  111. style="width: 80px; margin-top: 10px">
  112. {{ room.name }}
  113. </div>
  114. </div>
  115. </div>
  116. </div>
  117. </div>
  118. <div style="flex:1;height: calc(100vh - 180px); overflow-y: auto;">
  119. <div class="layout-rooms-item" v-for="(item, layoutIndex) in layouts" :key="item.id">
  120. <div class="title-laytou">
  121. {{ item.name }}
  122. </div>
  123. <div class="room-items">
  124. <div v-for="(element, roomIndex) in item.rooms" :key="element.id" class="layout-room-item">
  125. {{ element.name }}
  126. <a-button @click="delLayoutRoom(element, layoutIndex, roomIndex)" type="danger" shape="circle" size="small"
  127. icon="minus" style="margin-left: 5px" />
  128. </div>
  129. </div>
  130. </div>
  131. </div>
  132. </div>
  133. </template>
  134. <script>
  135. import draggable from "vuedraggable";
  136. import { buildingTree, saveBatch } from "@/api/roomBuildingApi";
  137. import { getAllLayouts } from "@/api/roomLayout";
  138. export default {
  139. name: "HotelSaasTenantFrontendRoomGen",
  140. inject: ["closeCurrent"],
  141. components: {
  142. draggable,
  143. },
  144. data() {
  145. return {
  146. floorNames: [],
  147. saveLoading: false,
  148. myArray: [
  149. {
  150. id: 1,
  151. name: "12",
  152. },
  153. {
  154. id: 2,
  155. name: "33",
  156. },
  157. ],
  158. step: 1,
  159. layouts: [],
  160. buildingId: undefined,
  161. buildingTreeData: [],
  162. hotelId: [{ name: "A酒店" }, { name: "B酒店" }, { name: "C酒店" }],
  163. labelCol: {
  164. xs: { span: 12 },
  165. sm: { span: 5 },
  166. },
  167. wrapperCol: {
  168. xs: { span: 10 },
  169. sm: { span: 16 },
  170. },
  171. roomTree: [],
  172. model: {
  173. floorCount: 1,
  174. floorCountMax: 2,
  175. roomCount: 10,
  176. prefix: "",
  177. isExpectEnd: false,
  178. },
  179. prefixName: "room",
  180. roomsFromOneFloor: 6,
  181. tailNumber: "",
  182. checkNick: false,
  183. form: this.$form.createForm(this, { name: "dynamic_rule" }),
  184. seleShow: "", // 用于切换折叠
  185. };
  186. },
  187. computed: {
  188. canMove() {
  189. let canMove = {
  190. can: false,
  191. count: 0,
  192. };
  193. this.roomTree.forEach((floor) => {
  194. floor.children.forEach((room) => {
  195. if (room.checked) {
  196. (canMove.can = true), canMove.count++;
  197. }
  198. });
  199. });
  200. return canMove;
  201. },
  202. },
  203. mounted() {
  204. buildingTree().then((res) => {
  205. if (res.code == 200) {
  206. this.buildingTreeData = res.result;
  207. if (res.result && res.result.length > 0) {
  208. this.buildingId = res.result[0].id
  209. }
  210. }
  211. });
  212. getAllLayouts().then((res) => {
  213. if (res.code == 200) {
  214. res.result.records.forEach((s) => {
  215. s["rooms"] = [];
  216. });
  217. this.layouts = res.result.records;
  218. }
  219. });
  220. },
  221. methods: {
  222. onBuildChange() {
  223. let bIndex = this.buildingTreeData.findIndex(s => s.id == this.buildingId)
  224. let currentFloorNames = (this.buildingTreeData[bIndex].children || []).map(s => s.name)
  225. this.floorNames = currentFloorNames
  226. // this.roomTree = JSON.parse(JSON.stringify(this.roomTree))
  227. },
  228. delLayoutRoom(item, layoutIndex, roomIndex) {
  229. this.roomTree[item.floorIndex].children.push({
  230. checked: false,
  231. name: item.name,
  232. floorIndex: item.floorIndex
  233. })
  234. this.layouts[layoutIndex].rooms.splice(roomIndex, 1)
  235. },
  236. moveTo(idx) {
  237. let roomItems = [];
  238. let rmvObject = {};
  239. this.roomTree.forEach((floor, floorIndex) => {
  240. rmvObject["" + floorIndex] = [];
  241. floor.children.forEach((room, roomIndex) => {
  242. if (room.checked) {
  243. rmvObject["" + floorIndex].push(roomIndex);
  244. roomItems.push({
  245. floorIndex: floorIndex,
  246. floorName: floor.name,
  247. name: room.name,
  248. });
  249. }
  250. });
  251. });
  252. let objKeys = Object.keys(rmvObject);
  253. objKeys.forEach((item) => {
  254. if (rmvObject[item].length > 0) {
  255. rmvObject[item].reverse().forEach((index) => {
  256. this.roomTree[parseInt(item)].children.splice(index, 1);
  257. });
  258. }
  259. });
  260. let origItems = JSON.parse(JSON.stringify(this.layouts[idx].rooms));
  261. origItems = origItems.concat(roomItems);
  262. this.$set(this.layouts[idx], "rooms", origItems);
  263. },
  264. onDrag(e) {
  265. debugger;
  266. },
  267. onRoomSelect(index, subIndex) {
  268. this.$set(this.roomTree[index].children[subIndex], "checked", true);
  269. },
  270. save() {
  271. let result = [];
  272. let param = {
  273. hotelId: null,
  274. buildId: null,
  275. children: [],
  276. };
  277. let hotelInfo = JSON.parse(localStorage.getItem("storeInfo"));
  278. if (!this.buildingId) {
  279. this.$message.error("请选择楼栋");
  280. return;
  281. }
  282. if (this.model.roomCount <= 0) {
  283. this.$message.error("房间数不正确");
  284. return;
  285. }
  286. let errMsg = '';
  287. for (let i = 0; i < this.roomTree.length; i++) {
  288. let s = this.roomTree[i]
  289. if (this.isExistNames(s.name)) {
  290. errMsg = '楼层名称有重复';
  291. break;
  292. }
  293. }
  294. if (errMsg == '') {
  295. for (let i = 0; i < this.roomTree.length; i++) {
  296. let s = this.roomTree[i]
  297. for (let j = 0; j < s.children.length; j++) {
  298. let room = s.children[j]
  299. if (!room.name) {
  300. errMsg = '存在空房名,请填写'
  301. break
  302. }
  303. if (this.repeatName(s.children, j)) {
  304. errMsg = '存在重复房名'
  305. break
  306. }
  307. }
  308. if (errMsg) break
  309. }
  310. }
  311. if (errMsg) {
  312. this.$message.error(errMsg)
  313. return
  314. }
  315. if (this.step == 1) {
  316. this.step = 2;
  317. return;
  318. }
  319. let treeData = this.getParams();
  320. this.saveLoading = true
  321. saveBatch(treeData).then(res => {
  322. if (res.code == 200) {
  323. this.$message.success("批量保存成功")
  324. this.closeCurrent()
  325. }
  326. }).finally(_ => {
  327. this.saveLoading = false
  328. })
  329. },
  330. getParams() {
  331. let param = {
  332. hotelId: null,
  333. buildId: null,
  334. children: [],
  335. };
  336. let hotelInfo = JSON.parse(localStorage.getItem("storeInfo"));
  337. param.buildId = this.buildingId;
  338. param.hotelId = hotelInfo.id;
  339. let roomTree = JSON.parse(JSON.stringify(this.roomTree))
  340. roomTree.forEach(a => {
  341. param.children.push({
  342. floorName: a.name,
  343. children: []
  344. })
  345. })
  346. this.layouts.forEach(layout => {
  347. layout.rooms.forEach(room => {
  348. param.children[room.floorIndex].children.push({
  349. hotelId: hotelInfo.id,
  350. buildId: this.buildingId,
  351. layoutId: layout.id,
  352. name: room.name,
  353. prefix: this.model.prefix,
  354. })
  355. })
  356. })
  357. return param
  358. },
  359. addRoom(index) {
  360. this.roomTree[index].children.push({
  361. name: "",
  362. floorIndex: index,
  363. checked: false,
  364. });
  365. },
  366. delFloor(index) {
  367. this.roomTree.splice(index, 1);
  368. },
  369. delRoom(index, roomIndex) {
  370. this.roomTree[index].children.splice(roomIndex, 1);
  371. },
  372. hotelChange(value) {
  373. console.log(`selected ${value}`);
  374. },
  375. tailNumberExclude() {
  376. console.log(`selected ${value}`);
  377. },
  378. sele(data) {
  379. data.show = !data.show;
  380. },
  381. back() {
  382. this.closeCurrent();
  383. },
  384. check() { },
  385. genRooms() {
  386. let model = this.model;
  387. if (!this.buildingId) {
  388. this.$message.error("请先选择楼栋")
  389. return
  390. }
  391. if (model.floorCount > model.floorCountMax) {
  392. this.$message.error("最低层数不能大于最高层数")
  393. return
  394. }
  395. let floors = [];
  396. for (let i = model.floorCount; i <= model.floorCountMax; i++) {
  397. let children = [];
  398. for (let r = 0; r < model.roomCount; r++) {
  399. let expectEndArr = [];
  400. if (model.isExpectEnd) {
  401. expectEndArr = (this.tailNumber || "").split(",");
  402. }
  403. let numStr = (r + 1).toString();
  404. let lastChar = numStr[numStr.length - 1];
  405. if (!expectEndArr.includes(lastChar)) {
  406. children.push({
  407. checked: false,
  408. floorIndex: i,
  409. name:
  410. + (i).toString() +
  411. "0" +
  412. numStr.padStart(this.model.roomCount.toString().length, "0"),
  413. });
  414. }
  415. }
  416. floors.push({
  417. name: `第${i}层`,
  418. children: children,
  419. });
  420. }
  421. this.roomTree = floors;
  422. let bIndex = this.buildingTreeData.findIndex(s => s.id == this.buildingId)
  423. let currentFloorNames = (this.buildingTreeData[bIndex].children || []).map(s => s.name)
  424. this.floorNames = currentFloorNames
  425. },
  426. isExistNames(name) {
  427. return this.floorNames.includes(name)
  428. },
  429. repeatName(items, index) {
  430. let name = items[index].name
  431. let newArr = JSON.parse(JSON.stringify(items)).map(s => s.name)
  432. newArr.splice(index, 1)
  433. if (newArr.includes(items[index].name)) {
  434. return true
  435. }
  436. return false
  437. }
  438. },
  439. };
  440. </script>
  441. <style lang="css" scoped>
  442. .empty-tree {
  443. width: 100%;
  444. height: 300px;
  445. display: flex;
  446. justify-content: center;
  447. align-items: center;
  448. }
  449. .bottom-btns {
  450. display: flex;
  451. justify-content: center;
  452. margin-bottom: 20px;
  453. }
  454. .floor-input {
  455. width: 200px;
  456. }
  457. .room-items {
  458. display: inline-block;
  459. border: 1px solid #cccccc77;
  460. height: 200px;
  461. overflow-y: auto;
  462. width: 90%;
  463. border-radius: 10px;
  464. margin-bottom: 30px;
  465. }
  466. .title-laytou {
  467. font-size: 17px;
  468. font-weight: bold;
  469. width: 100px;
  470. text-align: center;
  471. height: 25px;
  472. line-height: 25px;
  473. background-color: antiquewhite;
  474. }
  475. .room-items-dr {
  476. border: 1px solid #f00 !important;
  477. }
  478. .wait-select-title {
  479. border-bottom: 4px solid #1cb1ac;
  480. }
  481. .color-title {
  482. background-color: #1cb1ac;
  483. color: white;
  484. width: 100px;
  485. height: 30px;
  486. line-height: 30px;
  487. border-top-left-radius: 4px;
  488. border-top-right-radius: 4px;
  489. text-align: center;
  490. }
  491. .select-room-item {
  492. border: 1px solid #cccccc77;
  493. border-radius: 4px;
  494. margin-right: 4px;
  495. height: 80px;
  496. text-align: center;
  497. line-height: 80px;
  498. background-color: white;
  499. cursor: pointer;
  500. }
  501. .checked-room {
  502. background-color: #1cb1ac !important;
  503. color: white !important;
  504. border: none !important;
  505. }
  506. .bottom-sele-btn {
  507. height: 30px;
  508. }
  509. .layout-room-item {
  510. display: inline-block;
  511. width: fit-content;
  512. padding: 10px 12px;
  513. }
  514. .room-layout-settings {
  515. display: flex;
  516. }
  517. </style>