roomGen.vue 17 KB

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