SelectRoomForm.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <template>
  2. <a-spin :spinning="confirmLoading">
  3. <j-form-container :disabled="formDisabled">
  4. <a-form-model
  5. ref="form"
  6. :model="model"
  7. :rules="validatorRules"
  8. slot="detail"
  9. >
  10. <a-row>
  11. <a-col :span="24">
  12. <a-form-model-item
  13. label="房型"
  14. :labelCol="labelCol"
  15. :wrapperCol="wrapperCol"
  16. >
  17. <a-checkbox-group @change="checkChange" v-model="checkLayoutList">
  18. <a-row>
  19. <a-col
  20. :span="6"
  21. v-for="(item, index) in roomLayoutList"
  22. :key="item.id"
  23. >
  24. <a-checkbox :value="item.id">
  25. {{ item.name }}
  26. </a-checkbox>
  27. </a-col>
  28. </a-row>
  29. </a-checkbox-group>
  30. </a-form-model-item>
  31. </a-col>
  32. <a-col :span="24">
  33. <a-form-model-item
  34. label="房态"
  35. :labelCol="labelCol"
  36. :wrapperCol="wrapperCol"
  37. prop="roomStatus"
  38. >
  39. <!-- <a-checkbox-group
  40. v-model="checkedRoomStatusList"
  41. :options="roomStatusOptions"
  42. @change="checkChange"
  43. /> -->
  44. <div style="display:flex;flex-wrap:wrap;">
  45. <div v-for="(item, index) in roomStatusOptions" :class="{'check':checkedRoomStatusList.some(ele=> ele==item.value)}" :key="index" class="nocheck room-status" :style="{borderLeft:`2px solid ${item.extend}`}" @click="roomStatusChange(item, index)">
  46. {{item.label}}
  47. </div>
  48. </div>
  49. </a-form-model-item>
  50. </a-col>
  51. <a-col :span="24">
  52. <a-form-model-item
  53. label="已选"
  54. :labelCol="labelCol"
  55. :wrapperCol="{
  56. xs: { span: 24 },
  57. sm: { span: 20 },
  58. }"
  59. prop="roomStatus"
  60. >
  61. <a-tag
  62. color="blue"
  63. closable
  64. :visible="visible"
  65. @close.stop="tagClose2(index, item.name)"
  66. v-for="(item, index) in model.rooms"
  67. :key="index"
  68. >{{ item.name }}</a-tag
  69. >
  70. </a-form-model-item>
  71. </a-col>
  72. <a-col :span="24">
  73. <a-form-model-item
  74. label="房间"
  75. :labelCol="labelCol"
  76. :wrapperCol="{
  77. xs: { span: 24 },
  78. sm: { span: 20 },
  79. }"
  80. >
  81. <a-tabs
  82. default-active-key="room-all"
  83. tab-position="left"
  84. :style="{ height: '300px' }"
  85. >
  86. <a-tab-pane
  87. tab="全部"
  88. key="room-all"
  89. >
  90. <div>
  91. <a-row :gutter="[8, 8]" style="overflow: auto;height:300px;">
  92. <a-col
  93. :span="24"
  94. v-for="(item, index) in (roomList || [])"
  95. :key="index"
  96. >
  97. <div>{{item.buildingName + item.floorName}}</div>
  98. <div style="display:flex;flex-wrap:wrap;">
  99. <div v-for="(r, rIndex) in item.floorRooms" :style="{'border-left-color':filterColor(r.roomStatus)}" @click="checkRoomClick(r)" :key="'floorRooms' + rIndex" :class="[r.check == 1 ? 'check' : 'nocheck', r.kz == 1 ? 'kz' : '',]" class="nocheck room-status">
  100. <!-- <div
  101. :class="[
  102. r.check == 1 ? 'check' : 'nocheck',
  103. r.kz == 1 ? 'kz' : '',
  104. ]"
  105. style="display:flex;flex-wrap:wrap;"
  106. @click="checkRoomClick(r)"
  107. >
  108. <div class="nocheck room-status">
  109. {{ r.name }}
  110. </div>
  111. </div> -->
  112. {{ r.name }}
  113. </div>
  114. </div>
  115. </a-col>
  116. </a-row>
  117. </div>
  118. </a-tab-pane>
  119. <a-tab-pane
  120. v-for="(room, index) in roomList"
  121. :key="'room' + index"
  122. :tab="room.floorName"
  123. >
  124. <div
  125. id="components-grid-demo-playground"
  126. style="height: 300px; overflow: hidden auto"
  127. >
  128. <a-row :gutter="[8, 8]">
  129. <a-col
  130. :span="3"
  131. v-for="(r, rIndex) in room.floorRooms"
  132. :key="'floorRooms' + rIndex"
  133. >
  134. <div
  135. :class="[
  136. r.check == 1 ? 'check' : 'nocheck',
  137. r.kz == 1 ? 'kz' : '',
  138. ]"
  139. :style="{'border-left-color':filterColor(r.roomStatus)}"
  140. @click="checkRoomClick(r)"
  141. >
  142. {{ r.name }}
  143. </div></a-col
  144. >
  145. </a-row>
  146. </div>
  147. </a-tab-pane>
  148. </a-tabs>
  149. </a-form-model-item>
  150. </a-col>
  151. </a-row>
  152. </a-form-model>
  153. </j-form-container>
  154. </a-spin>
  155. </template>
  156. <script>
  157. import { httpAction, getAction } from "@/api/manage";
  158. import { validateDuplicateValue } from "@/utils/util";
  159. export default {
  160. name: "SelectRoomForm",
  161. components: {},
  162. props: {
  163. //表单禁用
  164. disabled: {
  165. type: Boolean,
  166. default: false,
  167. required: false,
  168. },
  169. },
  170. data() {
  171. const rooms = [];
  172. for (let i = 0; i < 100; i++) {
  173. rooms.push({
  174. id: "100" + i,
  175. roomNo: 1000 + i,
  176. check: 0,
  177. kz: i == 1 ? 1 : 0,
  178. });
  179. }
  180. const rooms2 = [];
  181. for (let i = 0; i < 50; i++) {
  182. rooms2.push({
  183. id: "200" + i,
  184. roomNo: 2000 + i,
  185. check: 0,
  186. kz: i == 5 ? 1 : 0,
  187. });
  188. }
  189. return {
  190. visible: true,
  191. roomList: [
  192. // { key: "1层", child: rooms },
  193. // { key: "2层", child: rooms2 },
  194. ],
  195. roomStatusList: [],
  196. checkedRoomStatusList: [],
  197. roomTypeOptions: [],
  198. roomStatusOptions: [],
  199. model: { roomType: "", rooms: [] },
  200. labelCol: {
  201. xs: { span: 24 },
  202. sm: { span: 2 },
  203. },
  204. wrapperCol: {
  205. xs: { span: 24 },
  206. sm: { span: 16 },
  207. },
  208. confirmLoading: false,
  209. validatorRules: {
  210. dateRange: [{ required: true, message: "请选择维修时间!" }],
  211. remark: [{ required: true, message: "请输入维修原因!" }],
  212. },
  213. url: {
  214. add: "/business/busMeetingRoom/add",
  215. edit: "/business/busMeetingRoom/edit",
  216. queryById: "/business/busMeetingRoom/queryById",
  217. },
  218. layoutName: "",
  219. presetNum: 0,
  220. canUserRooms: [],
  221. oldcanUserRooms: [],
  222. checkLayoutList: [],
  223. roomLayoutList: [],
  224. oldroomList: [],
  225. kzfLiving: false,
  226. };
  227. },
  228. computed: {
  229. formDisabled() {
  230. return this.disabled;
  231. },
  232. },
  233. created() {
  234. var _info = JSON.parse(localStorage.getItem("storeInfo"));
  235. if (_info) {
  236. this.model.hotelId = _info.id;
  237. }
  238. //备份model原始值
  239. this.modelDefault = JSON.parse(JSON.stringify(this.model));
  240. getAction("/rooms/cesRoomLayout/list", { pageSize: 99999, pageNo: 1 }).then(
  241. (res) => {
  242. if (res.success) {
  243. this.roomLayoutList = res.result.records;
  244. if (this.roomLayoutList && this.roomLayoutList.length > 0) {
  245. this.roomLayoutList.forEach((item) => {
  246. this.checkLayoutList.push(item.id);
  247. });
  248. }
  249. }
  250. }
  251. );
  252. getAction("/rooms/cesRooms/room-status-color", {}).then((res) => {
  253. if (res.success) {
  254. // this.roomStatusColorList = res.result;
  255. var list = [];
  256. res.result.forEach((item) => {
  257. list.push(item);
  258. });
  259. list = list.filter(item => item.label == '空净' || item.label == '空脏')
  260. console.log(list);
  261. this.roomStatusOptions = list;
  262. this.checkChange('',[this.roomStatusOptions[0].value,this.roomStatusOptions[1].value])
  263. }
  264. });
  265. getAction("/business/busOtherEmptyDirtyRoom/queryByHotelId", {}).then(
  266. (res) => {
  267. if (res.success) {
  268. this.kzfLiving = res.result.status === 1;
  269. }
  270. }
  271. );
  272. },
  273. methods: {
  274. filterColor(state){
  275. var color = '';
  276. let arr = this.roomStatusOptions.filter(item => item.value == state);
  277. color = arr[0] ? arr[0].extend : '';
  278. return color;
  279. },
  280. roomStatusChange(item, index){
  281. console.log('roomStatusChange');
  282. if (this.checkedRoomStatusList.some(ele=> ele==item.value)) {
  283. var index = this.checkedRoomStatusList.findIndex((t) => t == item.value);
  284. this.checkedRoomStatusList.splice(index, 1);
  285. } else {
  286. this.checkedRoomStatusList.push(item.value);
  287. }
  288. this.checkChange()
  289. },
  290. checkChange(e,stateList) {
  291. console.log("e", e);
  292. var list = this.oldroomList;
  293. console.log(list);
  294. if (this.checkLayoutList.length > 0) {
  295. list = this.oldroomList.reduce((acc, curr) => {
  296. const floorRooms = curr.floorRooms.filter((room) =>
  297. this.checkLayoutList.includes(room.layoutId)
  298. );
  299. acc.push({
  300. ...curr,
  301. floorRooms
  302. });
  303. return acc;
  304. }, []);
  305. }
  306. if (this.checkedRoomStatusList.length > 0) {
  307. list = list.reduce((acc, curr) => {
  308. const floorRooms = curr.floorRooms.filter((room) =>
  309. this.checkedRoomStatusList.includes(
  310. room.roomStatus.toString()
  311. )
  312. );
  313. acc.push({
  314. ...curr,
  315. floorRooms
  316. });
  317. return acc;
  318. }, []);
  319. }
  320. if (this.checkedRoomStatusList.length == 0) {
  321. let arr = []
  322. this.roomStatusOptions.forEach(ele=>{
  323. arr.push(ele.value)
  324. })
  325. list = list.reduce((acc, curr) => {
  326. const floorRooms = curr.floorRooms.filter((room) =>
  327. arr.includes(
  328. room.roomStatus.toString()
  329. )
  330. );
  331. acc.push({
  332. ...curr,
  333. floorRooms
  334. });
  335. return acc;
  336. }, []);
  337. }
  338. if (stateList && stateList.length > 0) {
  339. list = list.reduce((acc, curr) => {
  340. const floorRooms = curr.floorRooms.filter((room) =>
  341. stateList.includes(room.roomStatus.toString())
  342. );
  343. acc.push({
  344. ...curr,
  345. floorRooms
  346. });
  347. return acc;
  348. }, []);
  349. }
  350. console.log("list2", list);
  351. this.roomList = list;
  352. },
  353. checkRoomClick(row) {
  354. console.log(row);
  355. if (!this.kzfLiving && row.roomStatus === 2) {
  356. this.$message.warning("空脏房不允许入住");
  357. return;
  358. }
  359. if (row.check === 1) {
  360. row.check = 0;
  361. var index = this.model.rooms.findIndex((t) => t.key1 == row.key1);
  362. this.model.rooms.splice(index, 1);
  363. } else {
  364. row.check = 1;
  365. this.model.rooms.push(row);
  366. }
  367. },
  368. tagClose2(index, key1) {
  369. this.model.rooms.splice(index, 1);
  370. this.roomList.some((t) => {
  371. var r = t.floorRooms.some((c) => {
  372. if (c.name === key1) {
  373. c.check = 0;
  374. return true;
  375. }
  376. return false;
  377. });
  378. if (r === true) {
  379. return true;
  380. }
  381. });
  382. },
  383. onChange(e) {
  384. console.log(e);
  385. var list = [];
  386. this.oldroomList.forEach((item) => {
  387. var floorRooms = [];
  388. item.floorRooms.forEach((f) => {
  389. if (e.includes(f.layoutId)) {
  390. floorRooms.push(f);
  391. }
  392. });
  393. var itemd = JSON.parse(JSON.stringify(item));
  394. itemd.floorRooms = floorRooms;
  395. list.push(itemd);
  396. });
  397. this.roomList = list;
  398. // result = this.oldcustomerList.filter((t) => t.name.includes(value));
  399. console.log("this.oldroomList", this.oldroomList);
  400. console.log("this.roomList", this.roomList);
  401. this.checkChange()
  402. },
  403. add(row) {
  404. console.log("canUserRooms", row);
  405. // this.canUserRooms = row;
  406. this.oldroomList = JSON.parse(JSON.stringify(row[0].buildingRooms));
  407. // this.layoutName = row.layout.name;
  408. // this.presetNum = row.layout.presetNum;
  409. this.roomList = row[0].buildingRooms;
  410. this.edit(this.modelDefault);
  411. },
  412. edit(record) {
  413. this.model = Object.assign({}, record);
  414. this.roomList.forEach((t) => {
  415. t.floorRooms.forEach((f) => {
  416. if (f.check && f.check == 1) {
  417. this.model.rooms.push(f);
  418. }
  419. });
  420. });
  421. this.visible = true;
  422. },
  423. submitForm() {
  424. const that = this;
  425. if (that.model.rooms.length === 0) {
  426. that.$message.warning("请先选择房间");
  427. return;
  428. }
  429. that.$emit("ok", that.model.rooms);
  430. },
  431. },
  432. };
  433. </script>
  434. <style scoped>
  435. #components-grid-demo-playground [class~="ant-col"] {
  436. background: transparent;
  437. border: 0;
  438. }
  439. #components-grid-demo-playground [class~="ant-col"] > div {
  440. /* background: #00a0e9; */
  441. height: 28px;
  442. line-height: 28px;
  443. font-size: 13px;
  444. text-align: center;
  445. cursor: pointer;
  446. border-radius: 5px;
  447. }
  448. #components-grid-demo-playground .check {
  449. border: 1px solid #00a0e9;
  450. }
  451. #components-grid-demo-playground .kz {
  452. background: rgba(166, 166, 166, 1);
  453. }
  454. #components-grid-demo-playground pre {
  455. background: #f9f9f9;
  456. border-radius: 6px;
  457. font-size: 13px;
  458. padding: 8px 16px;
  459. }
  460. #components-grid-demo-playground .nocheck {
  461. border: 1px solid #cccccc;
  462. border-left-width: 2px;
  463. }
  464. .check {
  465. border: 1px solid #00a0e9 !important;
  466. }
  467. .nocheck {
  468. border: 1px solid #cccccc;
  469. }
  470. .room-status{
  471. /* height: 100%; */
  472. /* line-height: 100%; */
  473. font-size: 13px;
  474. text-align: center;
  475. cursor: pointer;
  476. border-radius: 5px;
  477. margin-right: 10px;
  478. border: 1px solid #cccccc;
  479. padding: 0px 16px;
  480. margin-top: 5px;
  481. border-left-width: 2px;
  482. border-left-style: solid;
  483. }
  484. </style>