floorCascader.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <div id="buildFloor">
  3. <span class="buildFloor">建筑楼层</span>
  4. <el-cascader ref="floorCascader" placeholder="请选择建筑楼层" :options="options" v-model="value" filterable size="small" :style="isWidth ? '' : 'width:160px;'" @change="changeCascader"></el-cascader>
  5. </div>
  6. </template>
  7. <script>
  8. import tools from "@/utils/scan/tools"
  9. import { floorQuery, buildingQuery } from '@/api/scan/request'
  10. import { mapGetters, mapActions } from "vuex"
  11. export default {
  12. props: {
  13. isWidth: {
  14. type: Boolean,
  15. default: true
  16. },
  17. type: {
  18. type: String,
  19. default: "yes"
  20. }
  21. },
  22. computed: {
  23. ...mapGetters("layout", [
  24. "projectId",
  25. "secret",
  26. "userId"
  27. ])
  28. },
  29. data() {
  30. return {
  31. options: [],
  32. param: {
  33. ProjId: '',
  34. secret: ''
  35. },
  36. value: ['all']
  37. };
  38. },
  39. created() {
  40. this.param.ProjId = this.projectId
  41. this.param.secret = this.secret
  42. this.getData()
  43. },
  44. watch: {
  45. projectId() {
  46. this.value = ['all'];
  47. this.options = [];
  48. this.param.ProjId = this.projectId
  49. this.param.secret = this.secret
  50. this.getData()
  51. this.changeCascader(['all'])
  52. }
  53. },
  54. methods: {
  55. //设置默认选项
  56. setValue(val) {
  57. if (val && val.length) {
  58. this.value = val
  59. }
  60. },
  61. //获取数据
  62. getData() {
  63. let data, buildParams = {
  64. PageNumber: 1,
  65. PageSize: 1000,
  66. Orders: "BuildLocalName asc",
  67. Projection: [
  68. "BuildID",
  69. "BuildLocalName"
  70. ]
  71. }, floorParams = {
  72. Orders: "FloorSequenceID desc",
  73. PageNumber: 1,
  74. PageSize: 1000,
  75. Projection: [
  76. "BuildID",
  77. "FloorID",
  78. "FloorLocalName",
  79. "FloorSequenceID",
  80. "StructureInfo",
  81. "Outline",
  82. "Properties"
  83. ]
  84. }
  85. let promise1 = new Promise((resolve, reject) => {
  86. buildingQuery(buildParams, res => {
  87. resolve(res)
  88. })
  89. })
  90. let promise2 = new Promise((resolve, reject) => {
  91. floorQuery(floorParams, res => {
  92. resolve(res)
  93. })
  94. })
  95. Promise.all([promise1, promise2]).then(values => {
  96. let builData = values[0].Content, floorData = values[1].Content
  97. data = builData.map(build => {
  98. return {
  99. value: build.BuildID,
  100. label: build.BuildLocalName
  101. }
  102. })
  103. data.unshift({
  104. value: "all",
  105. label: "全部"
  106. }, {
  107. value: "noKnow",
  108. label: "未明确建筑"
  109. })
  110. data.forEach(build => {
  111. floorData.forEach(floor => {
  112. if (build.value == floor.BuildID && floor.FloorID && floor.FloorLocalName && this.type == "yes") {
  113. if (build.children) {
  114. build.children.push({
  115. value: floor.FloorID,
  116. label: floor.FloorLocalName,
  117. FloorSequenceID: floor.FloorSequenceID,
  118. StructureInfo: floor.StructureInfo || {},
  119. Outline: floor.Outline || null,
  120. Properties: floor.Properties || null
  121. })
  122. } else {
  123. build.children = []
  124. build.children.push({
  125. value: "all",
  126. label: "全部"
  127. },{
  128. value: 'noKnow',
  129. label: "未明确楼层"
  130. },{
  131. value: floor.FloorID,
  132. label: floor.FloorLocalName,
  133. FloorSequenceID: floor.FloorSequenceID,
  134. StructureInfo: floor.StructureInfo || {},
  135. Outline: floor.Outline || null,
  136. Properties: floor.Properties || null
  137. })
  138. }
  139. }
  140. })
  141. })
  142. this.options = data
  143. })
  144. },
  145. //改变item
  146. changeCascader(value) {
  147. let node = this.$refs.floorCascader.getCheckedNodes();
  148. this.$emit("change", value, node[0].data);
  149. }
  150. }
  151. };
  152. </script>
  153. <style lang="less">
  154. .el-cascader .el-input .el-input__inner {
  155. vertical-align: bottom;
  156. }
  157. </style>
  158. <style lang="less" scoped>
  159. #buildFloor {
  160. margin-left: 10px;
  161. float: left;
  162. }
  163. .buildFloor {
  164. color: #999999;
  165. font-size: 14px;
  166. margin-right: 12px;
  167. }
  168. </style>