linkassets.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <el-dialog title="批量关联资产" :visible.sync="dialog.linkAssets" width="700px">
  3. <el-row>
  4. <span class="condition-title">设备类型:</span>
  5. <el-select v-model="deviceType" filterable size="small" @change="handleChangeDevice" style="width:250px;">
  6. <el-option v-for="item in deviceTypeList" :key="item.code" :label="item.facility" :value="item.code"></el-option>
  7. </el-select>
  8. </el-row>
  9. <el-row style="margin-top:30px;">
  10. <span class="condition-title">建筑楼层:</span>
  11. <el-cascader :options="bfoptions" v-model="buildFloor" filterable size="small" @change="handleChangeBf" style="width:250px;"></el-cascader>
  12. </el-row>
  13. <el-row style="margin-top:30px;" v-if="spaceShow">
  14. <span class="condition-title">分区类型空间实例:</span>
  15. <el-cascader v-model="space" filterable clearable collapse-tags size="small" :options="spaceList" :props="props" @change="handleChangeSpace" @active-item-change='handleChangeSpaceItem' style="width:250px;"></el-cascader>
  16. </el-row>
  17. <span slot="footer" class="dialog-footer">
  18. <el-button @click="handleClickClose">取 消</el-button>
  19. <el-button type="primary" @click="toLinkAssets">确 认</el-button>
  20. </span>
  21. </el-dialog>
  22. </template>
  23. <script>
  24. import { floorQuery, buildingQuery, queryDictionaryHead, queryZone } from '@/api/scan/request'
  25. import { mapGetters } from "vuex"
  26. export default {
  27. props: {
  28. dialog: {
  29. type: Object,
  30. default: function () {
  31. return {
  32. linkAssets: false
  33. };
  34. }
  35. }
  36. },
  37. computed: {
  38. ...mapGetters("layout", ["projectId", "secret", "userId"])
  39. },
  40. data() {
  41. return {
  42. bfoptions: [], //建筑楼层列表
  43. buildFloor: ['all'], //选择的建筑楼层
  44. deviceTypeList: [], //未关联资产的设备或部件列表
  45. deviceType: '', //选择的设备类型
  46. spaceList: [], //空间实例列表
  47. space: [], //选择的空间实例
  48. spaceShow: false,
  49. props: {
  50. multiple: true,
  51. children: 'children'
  52. }, //多选级联配置
  53. };
  54. },
  55. created() {
  56. this.getBuildFloorData() //获取建筑楼层数据
  57. this.getSpaceData() //获取分区类型数据
  58. },
  59. mounted() { },
  60. methods: {
  61. //获取建筑楼层数据
  62. getBuildFloorData() {
  63. let data, buildParams = {
  64. PageNumber: 1,
  65. PageSize: 1000,
  66. Projection: [
  67. "BuildID",
  68. "BuildLocalName"
  69. ]
  70. }, floorParams = {
  71. Orders: "FloorSequenceID desc",
  72. PageNumber: 1,
  73. PageSize: 1000,
  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) {
  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.bfoptions = data
  133. })
  134. },
  135. //获取空间分区数据
  136. getSpaceData(){
  137. let params = {
  138. Filters: "parentId = 'Space'",
  139. PageNumber: 1,
  140. PageSize: 1000,
  141. Projection: [ "Code", "Name" ]
  142. }
  143. queryDictionaryHead(params, res => {
  144. this.spaceList = res.Content.map((item) => {
  145. return {
  146. label: item.Name,
  147. value: item.Code,
  148. children: []
  149. }
  150. })
  151. })
  152. },
  153. // 修改设备类型
  154. handleChangeDevice() {
  155. },
  156. // 修改建筑楼层
  157. handleChangeBf(val) {
  158. let lastVal = val.slice(-1)[0]
  159. // 重置空间实例选择
  160. this.space = []
  161. this.spaceList.map(item => {
  162. if (item.children)
  163. item.children = []
  164. })
  165. if(!lastVal || lastVal == 'noKnow' || val[0] == 'all') {
  166. this.spaceShow = false
  167. } else {
  168. this.spaceShow = false
  169. this.$nextTick(() => {
  170. this.spaceShow = true
  171. })
  172. }
  173. },
  174. // 获取空间实例
  175. handleChangeSpaceItem(val) {
  176. let type = val[0]
  177. if(val.length == 1) {
  178. if(type) {
  179. let zone = type,
  180. nodes = []
  181. let recursionGetData = (pageNum, zone) => {
  182. pageNum = pageNum ? pageNum : 1
  183. let params = {
  184. zone: zone,
  185. data: {
  186. Orders: "CreateTime desc, RoomID asc",
  187. PageNumber: pageNum,
  188. PageSize: 1000,
  189. Projection: ["RoomID", "RoomName", "RoomLocalName", "CreateTime"]
  190. },
  191. }
  192. if(this.spaceShow) {
  193. if(this.buildFloor.length == 2 && this.buildFloor[1] != 'all') {
  194. params.data.Filters = `buildingId='${this.buildFloor[0]}';floorId='${this.buildFloor[1]}'`
  195. } else {
  196. params.data.Filters = `buildingId='${this.buildFloor[0]}'`
  197. }
  198. }
  199. queryZone(params, res => {
  200. nodes = nodes.concat(res.Content.map(item => ({
  201. value: item.RoomID,
  202. label: item.RoomLocalName?item.RoomLocalName:item.RoomName
  203. })))
  204. if (res.Total / (res.PageSize * res.PageNumber) > 1) {
  205. recursionGetData(res.PageNumber + 1, zone)
  206. } else {
  207. this.spaceList.map(item => {
  208. if(item.value == type) {
  209. item.children = nodes
  210. }
  211. })
  212. }
  213. })
  214. }
  215. recursionGetData(1, zone)
  216. }
  217. }
  218. },
  219. // 点击取消关闭弹窗
  220. handleClickClose() {
  221. this.dialog.linkAssets = false
  222. },
  223. // 批量关联资产详情页
  224. toLinkAssets() {
  225. let query = {}
  226. // 校验必填项
  227. if(!this.deviceType) {
  228. this.$messge.info('请选择设备类型!')
  229. } else if (!this.buildFloor.length) {
  230. this.$messge.info('请选择建筑楼层!')
  231. }
  232. if(this.spaceShow) {
  233. } else {
  234. query = {
  235. deviceType: this.deviceType
  236. }
  237. }
  238. }
  239. },
  240. watch: {
  241. }
  242. };
  243. </script>
  244. <style lang="less" scoped>
  245. .condition-title{
  246. width: 200px;
  247. display: inline-block;
  248. text-align: right;
  249. margin-left: 10px;
  250. margin-right: 12px;
  251. color: #999999;
  252. font-size: 14px;
  253. }
  254. /deep/ .el-dialog__body {
  255. max-height: 420px;
  256. overflow-y: auto;
  257. }
  258. </style>