linkassets.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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:350px;">
  6. <el-option v-for="item in deviceTypeList" :key="item.Category" :label="item.CategoryName" :value="item.Category"></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:350px;"></el-cascader>
  12. </el-row>
  13. <el-row style="margin-top:30px;" v-show="spaceShow">
  14. <span class="condition-title">分区类型:</span>
  15. <el-select v-model="zone" filterable size="small" @change="handleChangeZone" style="width:350px;">
  16. <el-option v-for="item in zoneList" :key="item.Code" :label="item.Name" :value="item.Code"></el-option>
  17. </el-select>
  18. </el-row>
  19. <el-row style="margin-top:30px;" v-show="spaceShow && zone != 'all' && zone != 'noKnow'">
  20. <span class="condition-title">空间实例:</span>
  21. <el-select v-model="space" multiple filterable collapse-tags style="width:350px;" placeholder="请选择">
  22. <el-option v-for="item in spaceList" :key="item.value" :label="item.label" :value="item.value">
  23. </el-option>
  24. </el-select>
  25. </el-row>
  26. <span slot="footer" class="dialog-footer">
  27. <el-button @click="handleClickClose">取 消</el-button>
  28. <el-button type="primary" @click="toLinkAssets">确 认</el-button>
  29. </span>
  30. </el-dialog>
  31. </template>
  32. <script>
  33. import { floorQuery, buildingQuery, queryDictionaryHead, queryZone, TypePartsDie } from '@/api/scan/request'
  34. import { mapGetters } from "vuex"
  35. export default {
  36. props: {
  37. dialog: {
  38. type: Object,
  39. default: function () {
  40. return {
  41. linkAssets: false
  42. };
  43. }
  44. }
  45. },
  46. computed: {
  47. ...mapGetters("layout", ["projectId", "secret", "userId"])
  48. },
  49. data() {
  50. return {
  51. bfoptions: [], //建筑楼层列表
  52. buildFloor: ['all'], //选择的建筑楼层
  53. deviceTypeList: [], //未关联资产的设备或部件列表
  54. deviceType: '', //选择的设备类型
  55. zone: 'all', //空间分区
  56. zoneList: [], //空间分区列表
  57. spaceList: [], //空间实例列表
  58. space: [], //选择的空间实例
  59. spaceShow: false
  60. };
  61. },
  62. created() {
  63. this.getPartsDieType() //获取未关联资产的设备或部件类型
  64. this.getBuildFloorData() //获取建筑楼层数据
  65. this.getSpaceData() //获取分区类型数据
  66. },
  67. mounted() { },
  68. methods: {
  69. //获取未关联资产的设备或部件类型
  70. getPartsDieType() {
  71. TypePartsDie(res => {
  72. this.deviceTypeList = res.Content.filter(item => {
  73. return item.CategoryName
  74. })
  75. })
  76. },
  77. //获取建筑楼层数据
  78. getBuildFloorData() {
  79. let data, buildParams = {
  80. PageNumber: 1,
  81. PageSize: 1000,
  82. Projection: [
  83. "BuildID",
  84. "BuildLocalName"
  85. ]
  86. }, floorParams = {
  87. Orders: "FloorSequenceID desc",
  88. PageNumber: 1,
  89. PageSize: 1000,
  90. Projection: [
  91. "BuildID",
  92. "FloorID",
  93. "FloorLocalName",
  94. "FloorSequenceID"
  95. ]
  96. }
  97. let promise1 = new Promise((resolve, reject) => {
  98. buildingQuery(buildParams, res => {
  99. resolve(res)
  100. })
  101. })
  102. let promise2 = new Promise((resolve, reject) => {
  103. floorQuery(floorParams, res => {
  104. resolve(res)
  105. })
  106. })
  107. Promise.all([promise1, promise2]).then(values => {
  108. let builData = values[0].Content, floorData = values[1].Content
  109. data = builData.map(build => {
  110. return {
  111. value: build.BuildID,
  112. label: build.BuildLocalName
  113. }
  114. })
  115. data.unshift({
  116. value: "all",
  117. label: "全部"
  118. }, {
  119. value: "noKnow",
  120. label: "不在建筑内"
  121. })
  122. data.forEach(build => {
  123. floorData.forEach(floor => {
  124. if (build.value == floor.BuildID && floor.FloorID && floor.FloorLocalName) {
  125. if (build.children) {
  126. build.children.push({
  127. value: floor.FloorID,
  128. label: floor.FloorLocalName,
  129. FloorSequenceID: floor.FloorSequenceID
  130. })
  131. } else {
  132. build.children = []
  133. build.children.push({
  134. value: "all",
  135. label: "全部"
  136. }, {
  137. value: 'noKnow',
  138. label: "不在楼层内"
  139. }, {
  140. value: floor.FloorID,
  141. label: floor.FloorLocalName,
  142. FloorSequenceID: floor.FloorSequenceID
  143. })
  144. }
  145. }
  146. })
  147. })
  148. this.bfoptions = data
  149. })
  150. },
  151. //获取空间分区数据
  152. getSpaceData(){
  153. let params = {
  154. Filters: "parentId = 'Space'",
  155. PageNumber: 1,
  156. PageSize: 1000,
  157. Projection: [ "Code", "Name" ]
  158. }
  159. queryDictionaryHead(params, res => {
  160. this.zoneList = res.Content
  161. this.zoneList.unshift({
  162. Name: '全部',
  163. Code: 'all'
  164. })
  165. this.zoneList.push({
  166. Name: '不在任何业务空间内',
  167. Code: 'noKnow'
  168. })
  169. })
  170. },
  171. // 修改设备类型
  172. handleChangeDevice(val) {
  173. this.zoneListIsShow()
  174. },
  175. // 修改建筑楼层
  176. handleChangeBf(val) {
  177. this.zoneListIsShow()
  178. },
  179. //判断是否显示空间分区选择
  180. zoneListIsShow(){
  181. let lastVal = this.buildFloor.slice(-1)[0]
  182. if(!lastVal || lastVal == 'noKnow' || this.buildFloor[0] == 'all' || this.deviceType.length != 4) {
  183. this.spaceShow = false
  184. } else {
  185. this.spaceShow = true
  186. }
  187. },
  188. //修改分区类型
  189. handleChangeZone() {
  190. // 重置空间实例选择
  191. this.space = []
  192. this.spaceList = []
  193. this.handleChangeSpaceItem()
  194. },
  195. // 获取空间实例
  196. handleChangeSpaceItem() {
  197. if(this.zone != 'all' && this.zone != 'noKnow') {
  198. let nodes = []
  199. let recursionGetData = (pageNum, zone) => {
  200. pageNum = pageNum ? pageNum : 1
  201. let params = {
  202. zone: zone,
  203. data: {
  204. Orders: "CreateTime desc, RoomID asc",
  205. PageNumber: pageNum,
  206. PageSize: 1000,
  207. Projection: ["RoomID", "RoomName", "RoomLocalName", "CreateTime"]
  208. },
  209. }
  210. if(this.spaceShow) {
  211. if(this.buildFloor.length == 2 && this.buildFloor[1] != 'all') {
  212. params.data.Filters = `buildingId='${this.buildFloor[0]}';floorId='${this.buildFloor[1]}'`
  213. } else {
  214. params.data.Filters = `buildingId='${this.buildFloor[0]}'`
  215. }
  216. }
  217. queryZone(params, res => {
  218. nodes = nodes.concat(res.Content.map(item => ({
  219. value: item.RoomID,
  220. label: item.RoomLocalName?item.RoomLocalName:item.RoomName
  221. })))
  222. if (res.Total / (res.PageSize * res.PageNumber) > 1) {
  223. recursionGetData(res.PageNumber + 1, zone)
  224. } else {
  225. this.spaceList = nodes
  226. }
  227. })
  228. }
  229. recursionGetData(1, this.zone)
  230. }
  231. },
  232. // 点击取消关闭弹窗
  233. handleClickClose() {
  234. this.dialog.linkAssets = false
  235. },
  236. // 批量关联资产详情页
  237. toLinkAssets() {
  238. let query = {}
  239. // 校验必填项
  240. if(!this.deviceType) {
  241. this.$message.info('请选择设备类型!')
  242. return false
  243. } else if (!this.buildFloor.length) {
  244. this.$message.info('请选择建筑楼层!')
  245. return false
  246. }
  247. if(this.spaceShow) { //选择了空间
  248. if(this.zone == 'all'){//全部空间
  249. query = {
  250. deviceType: this.deviceType,
  251. buildFloor: this.buildFloor
  252. }
  253. } else if (this.zone == 'noKnow'){//不在空间内
  254. query = {
  255. deviceType: this.deviceType,
  256. buildFloor: this.buildFloor,
  257. spaceList: this.zone
  258. }
  259. } else {
  260. if(this.space.length){//选择了具体的空间实例
  261. query = {
  262. deviceType: this.deviceType,
  263. buildFloor: this.buildFloor,
  264. spaceList: this.space
  265. }
  266. } else {
  267. this.$message.info('请选择空间实例!')
  268. return false
  269. }
  270. }
  271. } else {
  272. query = {
  273. deviceType: this.deviceType,
  274. buildFloor: this.buildFloor
  275. }
  276. }
  277. this.$router.push({
  278. name: "batchlinkAssets",
  279. params: query
  280. })
  281. }
  282. },
  283. watch: {
  284. }
  285. };
  286. </script>
  287. <style lang="less" scoped>
  288. .condition-title{
  289. width: 100px;
  290. display: inline-block;
  291. text-align: right;
  292. margin-left: 10px;
  293. margin-right: 12px;
  294. color: #999999;
  295. font-size: 14px;
  296. vertical-align: top;
  297. }
  298. /deep/ .el-dialog__body {
  299. max-height: 420px;
  300. overflow-y: auto;
  301. }
  302. </style>