roomGen.vue 17 KB

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