roomNumList.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <div>
  3. <div class="page-wrapper">
  4. <div class="left-wrapper-1">
  5. <div>
  6. <a-input style="width: 140px; margin-right: 10px" v-model="newBuildingName" placeholder="请填写楼栋名称"></a-input>
  7. <a-button :disabled="saveBtnLoading" :loading="saveBtnLoading" @click="saveNewBuilding"
  8. type="primary">新增楼栋</a-button>
  9. </div>
  10. <div class="building-tree">
  11. <div v-if="buildingTree && buildingTree.length > 0">
  12. <a-tree class="draggable-tree" :tree-data="buildingTree" :default-expand-all="true" blockNode
  13. style="width: 100%" :replaceFields="{
  14. children: 'children',
  15. title: 'name',
  16. key: 'id',
  17. }">
  18. <div slot="title" slot-scope="item"
  19. style="display: flex;align-items: center;height: 100%;overflow: hidden;">
  20. <a-button style="font-size: 12px" type="link" @click="filterSearch(item)">{{ item.name }}</a-button>
  21. <div style="flex: 1; height: 1px"></div>
  22. <a-button style="font-size: 12px; padding: 0 5px" type="link" v-if="item.parentId == 0"
  23. @click="onAddFlowerClick(item)">添加楼层</a-button>
  24. <a-button style="font-size: 12px; padding: 0 5px" type="link" @click="onTreeEditClick(item)">编辑</a-button>
  25. <a-popconfirm placement="topLeft" ok-text="是的" cancel-text="取消" @confirm="onTreeDeleteClick(item)">
  26. <template slot="title">
  27. 确定删除吗?
  28. </template>
  29. <a-button style="font-size: 12px; padding: 0 5px" type="link">删除</a-button>
  30. </a-popconfirm>
  31. </div>
  32. </a-tree>
  33. </div>
  34. <div v-else class="empty-data"></div>
  35. </div>
  36. </div>
  37. <div class="right-wrapper">
  38. <room-num-table ref="numtable"></room-num-table>
  39. </div>
  40. </div>
  41. <!-- 添加楼层 -->
  42. <a-modal width="300px" title="楼栋楼层编辑" :visible.sync="fVisible" :confirm-loading="fSaveLoading" @ok="saveFlow"
  43. @cancel="fVisible = false">
  44. <a-input style="width: 240px; margin-right: 10px" v-model="flowData.name" placeholder="请填写楼层/楼栋名称"></a-input>
  45. </a-modal>
  46. </div>
  47. </template>
  48. <script>
  49. import { save, buildingTree, modify, remove } from "@/api/roomBuildingApi";
  50. import roomNumTable from './roomNumTable.vue'
  51. export default {
  52. components: {
  53. roomNumTable
  54. },
  55. data() {
  56. return {
  57. currentFilterId: null,
  58. flowData: {
  59. id: null,
  60. hotelId: null,
  61. name: "",
  62. parentId: null,
  63. type: 2,
  64. },
  65. currentBuildingId: null,
  66. fVisible: false,
  67. fSaveLoading: false,
  68. currentHotel: JSON.parse(localStorage.getItem("storeInfo")),
  69. newBuildingName: "",
  70. saveBtnLoading: false,
  71. model: {
  72. dis: 1,
  73. },
  74. buildingTree: [],
  75. };
  76. },
  77. mounted() {
  78. this.loadBuildingTreeData();
  79. },
  80. methods: {
  81. // 点击 触发搜索
  82. filterSearch(item) {
  83. this.currentFilterId = item.id
  84. this.$refs.numtable.ipagination.current = 1
  85. this.$refs.numtable.searchParam(item.id, item.name, item.parentId == "0")
  86. },
  87. // 获取楼栋树
  88. loadBuildingTreeData() {
  89. buildingTree().then((res) => {
  90. this.buildingTree = res.result;
  91. });
  92. },
  93. // 点击楼栋添加楼层事件
  94. onAddFlowerClick(building) {
  95. this.currentBuildingId = building.id;
  96. this.flowData.parentId = building.id;
  97. this.flowData.name = '';
  98. this.flowData.hotelId = this.currentHotel.id;
  99. this.flowData.type = 2;
  100. this.flowData.id = null;
  101. this.fVisible = true;
  102. },
  103. // 点击tree节点编辑事件
  104. onTreeEditClick(item) {
  105. if (item.parentId == 0) {
  106. this.flowData.type = 1;
  107. this.flowData.name = item.name;
  108. } else {
  109. this.flowData.type = 2;
  110. this.flowData.name = item.name;
  111. }
  112. this.flowData.id = item.id;
  113. this.flowData.hotelId = this.currentHotel.id;
  114. this.flowData.parentId = item.parentId;
  115. this.fVisible = true;
  116. },
  117. // 确定删除楼层/楼栋
  118. onTreeDeleteClick(item) {
  119. remove({
  120. id: item.id
  121. }).then(res => {
  122. if (res.code == 200) {
  123. this.$message.success('删除成功')
  124. this.loadBuildingTreeData()
  125. this.$refs.numtable.ipagination.current = 1
  126. this.$refs.numtable.ipagination.pageSize = 10
  127. if (this.currentFilterId == item.id) {
  128. if (item.parentId == "0")
  129. this.$refs.numtable.filters['buildId'] = null
  130. else
  131. this.$refs.numtable.filters['floorId'] = null
  132. }
  133. this.$refs.numtable.loadData()
  134. }
  135. })
  136. },
  137. // 保存楼栋信息
  138. saveNewBuilding() {
  139. if (!this.newBuildingName) {
  140. this.$message.error("名称不能为空");
  141. return;
  142. }
  143. this.saveBtnLoading = true;
  144. save({
  145. hotelId: this.currentHotel.id,
  146. name: this.newBuildingName,
  147. parentId: "0",
  148. type: 1,
  149. })
  150. .then((res) => {
  151. if (res.code == 200) {
  152. this.newBuildingName = "";
  153. this.$message.success("楼栋保存成功");
  154. this.loadBuildingTreeData();
  155. }
  156. })
  157. .finally((_) => {
  158. this.saveBtnLoading = false;
  159. });
  160. },
  161. // 保存楼栋都层信息
  162. saveFlow() {
  163. if (!this.flowData.name) {
  164. this.$message.error("名称不能为空");
  165. return;
  166. }
  167. this.fSaveLoading = true;
  168. if (this.flowData.id) {
  169. // edit
  170. modify(this.flowData).then((res) => {
  171. if (res.code == 200) {
  172. this.flowData.name = "";
  173. this.flowData.type = 1;
  174. this.flowData.parentId = null;
  175. this.flowData.id = null;
  176. this.$message.success("保存成功");
  177. this.loadBuildingTreeData();
  178. this.fVisible = false;
  179. }
  180. }).finally(_ => {
  181. this.fSaveLoading = false;
  182. });
  183. return;
  184. }
  185. // add flow
  186. save(this.flowData)
  187. .then((res) => {
  188. if (res.code == 200) {
  189. this.flowData.name = "";
  190. this.$message.success("楼层保存成功");
  191. this.loadBuildingTreeData();
  192. this.fVisible = false;
  193. }
  194. })
  195. .finally((_) => {
  196. this.fSaveLoading = false;
  197. });
  198. },
  199. },
  200. };
  201. </script>
  202. <style scoped>
  203. .page-wrapper {
  204. display: flex;
  205. }
  206. .right-wrapper {
  207. flex: 1;
  208. }
  209. .left-wrapper-1 {
  210. width: 30%;
  211. display: flex;
  212. flex-direction: column;
  213. }
  214. .building-tree {
  215. width: 100%;
  216. flex: 1;
  217. overflow-y: auto;
  218. }
  219. .empty-data {
  220. height: 100%;
  221. }
  222. </style>