floorCascader.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div id="buildFloor">
  3. <span class="buildFloor" style="margin-right: 12px;">建筑楼层</span>
  4. <el-cascader 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: 500,
  66. Projection: [
  67. "BuildID",
  68. "BuildLocalName"
  69. ]
  70. }, floorParams = {
  71. Orders: "FloorSequenceID desc",
  72. PageNumber: 1,
  73. PageSize: 500,
  74. Projection: [
  75. "BuildID",
  76. "FloorID",
  77. "FloorLocalName",
  78. "FloorSequenceID"
  79. ]
  80. }
  81. let promise1 = new Promise((resolve, reject) => {
  82. buildingQuery(buildParams, res => {
  83. resolve(res)
  84. })
  85. })
  86. let promise2 = new Promise((resolve, reject) => {
  87. floorQuery(floorParams, res => {
  88. resolve(res)
  89. })
  90. })
  91. Promise.all([promise1, promise2]).then(values => {
  92. let builData = values[0].Content, floorData = values[1].Content
  93. data = builData.map(build => {
  94. return {
  95. value: build.BuildID,
  96. label: build.BuildLocalName
  97. }
  98. })
  99. data.unshift({
  100. value: "all",
  101. label: "全部"
  102. }, {
  103. value: "noKnow",
  104. label: "未明确建筑的设备"
  105. })
  106. data.forEach(build => {
  107. floorData.forEach(floor => {
  108. if (build.value == floor.BuildID && floor.FloorID && floor.FloorLocalName && this.type == "yes") {
  109. if (build.children) {
  110. build.children.push({
  111. value: floor.FloorID,
  112. label: floor.FloorLocalName,
  113. FloorSequenceID: floor.FloorSequenceID
  114. })
  115. } else {
  116. build.children = []
  117. build.children.push({
  118. value: "all",
  119. label: "全部"
  120. },{
  121. value: 'noKnow',
  122. label: "未明确楼层的设备"
  123. },{
  124. value: floor.FloorID,
  125. label: floor.FloorLocalName,
  126. FloorSequenceID: floor.FloorSequenceID
  127. })
  128. }
  129. }
  130. })
  131. })
  132. this.options = data
  133. })
  134. },
  135. //改变item
  136. changeCascader(value) {
  137. this.$emit("change", value)
  138. }
  139. }
  140. };
  141. </script>
  142. <style lang="less">
  143. .el-cascader .el-input .el-input__inner {
  144. vertical-align: bottom;
  145. }
  146. </style>
  147. <style lang="less" scoped>
  148. #buildFloor {
  149. margin-left: 10px;
  150. float: left;
  151. .buildFloor {
  152. color: #999999;
  153. font-size: 14px;
  154. }
  155. }
  156. </style>