linkassets.vue 9.6 KB

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