linkassets.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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.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. handleOpenReset(){
  71. this.deviceType = ''
  72. this.buildFloor = ['all']
  73. this.zone = 'all'
  74. this.space = []
  75. this.spaceShow = false
  76. },
  77. //获取未关联资产的设备或部件类型
  78. getPartsDieType() {
  79. TypePartsDie(res => {
  80. this.deviceTypeList = res.Content.filter(item => {
  81. return item.CategoryName
  82. })
  83. })
  84. },
  85. //获取建筑楼层数据
  86. getBuildFloorData() {
  87. let data, buildParams = {
  88. PageNumber: 1,
  89. PageSize: 1000,
  90. Projection: [
  91. "BuildID",
  92. "BuildLocalName"
  93. ]
  94. }, floorParams = {
  95. Orders: "FloorSequenceID desc",
  96. PageNumber: 1,
  97. PageSize: 1000,
  98. Projection: [
  99. "BuildID",
  100. "FloorID",
  101. "FloorLocalName",
  102. "FloorSequenceID"
  103. ]
  104. }
  105. let promise1 = new Promise((resolve, reject) => {
  106. buildingQuery(buildParams, res => {
  107. resolve(res)
  108. })
  109. })
  110. let promise2 = new Promise((resolve, reject) => {
  111. floorQuery(floorParams, res => {
  112. resolve(res)
  113. })
  114. })
  115. Promise.all([promise1, promise2]).then(values => {
  116. let builData = values[0].Content, floorData = values[1].Content
  117. data = builData.map(build => {
  118. return {
  119. value: build.BuildID,
  120. label: build.BuildLocalName
  121. }
  122. })
  123. data.unshift({
  124. value: "all",
  125. label: "全部"
  126. }, {
  127. value: "noKnow",
  128. label: "不在建筑内"
  129. })
  130. data.forEach(build => {
  131. floorData.forEach(floor => {
  132. if (build.value == floor.BuildID && floor.FloorID && floor.FloorLocalName) {
  133. if (build.children) {
  134. build.children.push({
  135. value: floor.FloorID,
  136. label: floor.FloorLocalName,
  137. FloorSequenceID: floor.FloorSequenceID
  138. })
  139. } else {
  140. build.children = []
  141. build.children.push({
  142. value: "all",
  143. label: "全部"
  144. }, {
  145. value: 'noKnow',
  146. label: "不在楼层内"
  147. }, {
  148. value: floor.FloorID,
  149. label: floor.FloorLocalName,
  150. FloorSequenceID: floor.FloorSequenceID
  151. })
  152. }
  153. }
  154. })
  155. })
  156. this.bfoptions = data
  157. })
  158. },
  159. //获取空间分区数据
  160. getSpaceData(){
  161. let params = {
  162. Filters: "parentId = 'Space'",
  163. PageNumber: 1,
  164. PageSize: 1000,
  165. Projection: [ "Code", "Name" ]
  166. }
  167. queryDictionaryHead(params, res => {
  168. this.zoneList = res.Content.filter(item => {
  169. if(item.Code != 'Ispace'){
  170. return item
  171. }
  172. })
  173. this.zoneList.unshift({
  174. Name: '全部',
  175. Code: 'all'
  176. })
  177. this.zoneList.push({
  178. Name: '不在任何业务空间内',
  179. Code: 'noKnow'
  180. })
  181. })
  182. },
  183. // 修改设备类型
  184. handleChangeDevice(val) {
  185. this.zoneListIsShow()
  186. },
  187. // 修改建筑楼层
  188. handleChangeBf(val) {
  189. this.zoneListIsShow()
  190. // 重置空间实例选择
  191. this.space = []
  192. this.spaceList = []
  193. this.handleChangeSpaceItem()
  194. },
  195. //判断是否显示空间分区选择
  196. zoneListIsShow(){
  197. let lastVal = this.buildFloor.slice(-1)[0]
  198. if(!lastVal || lastVal == 'noKnow' || this.buildFloor[0] == 'all' || this.deviceType.length != 4) {
  199. this.spaceShow = false
  200. } else {
  201. this.spaceShow = true
  202. }
  203. },
  204. //修改分区类型
  205. handleChangeZone() {
  206. // 重置空间实例选择
  207. this.space = []
  208. this.spaceList = []
  209. this.handleChangeSpaceItem()
  210. },
  211. // 获取空间实例
  212. handleChangeSpaceItem() {
  213. if(this.zone != 'all' && this.zone != 'noKnow') {
  214. let nodes = []
  215. let recursionGetData = (pageNum, zone) => {
  216. pageNum = pageNum ? pageNum : 1
  217. let params = {
  218. zone: zone,
  219. data: {
  220. Orders: "CreateTime desc, RoomID asc",
  221. PageNumber: pageNum,
  222. PageSize: 1000,
  223. Projection: ["RoomID", "RoomName", "RoomLocalName", "CreateTime"]
  224. },
  225. }
  226. if(this.spaceShow) {
  227. if(this.buildFloor.length == 2 && this.buildFloor[1] != 'all') {
  228. params.data.Filters = `buildingId='${this.buildFloor[0]}';floorId='${this.buildFloor[1]}'`
  229. } else {
  230. params.data.Filters = `buildingId='${this.buildFloor[0]}'`
  231. }
  232. }
  233. queryZone(params, res => {
  234. nodes = nodes.concat(res.Content.map(item => ({
  235. value: item.RoomID,
  236. label: item.RoomLocalName?item.RoomLocalName:item.RoomName
  237. })))
  238. if (res.Total / (res.PageSize * res.PageNumber) > 1) {
  239. recursionGetData(res.PageNumber + 1, zone)
  240. } else {
  241. this.spaceList = nodes
  242. }
  243. })
  244. }
  245. recursionGetData(1, this.zone)
  246. }
  247. },
  248. // 点击取消关闭弹窗
  249. handleClickClose() {
  250. this.dialog.linkAssets = false
  251. },
  252. // 批量关联资产详情页
  253. toLinkAssets() {
  254. let query = {}
  255. // 校验必填项
  256. if(!this.deviceType) {
  257. this.$message.info('请选择设备类型!')
  258. return false
  259. } else if (!this.buildFloor.length) {
  260. this.$message.info('请选择建筑楼层!')
  261. return false
  262. }
  263. if(this.spaceShow) { //选择了空间
  264. if(this.zone == 'all'){//全部空间
  265. query = {
  266. deviceType: this.deviceType,
  267. buildFloor: this.buildFloor
  268. }
  269. } else {
  270. if(this.space.length){//选择了具体的空间实例
  271. query = {
  272. deviceType: this.deviceType,
  273. buildFloor: this.buildFloor,
  274. spaceList: this.space
  275. }
  276. } else {
  277. query = {
  278. deviceType: this.deviceType,
  279. buildFloor: this.buildFloor,
  280. spaceList: this.zone //(包含具体的业务空间分区和不在任何分区两种情况)
  281. }
  282. }
  283. }
  284. } else {
  285. query = {
  286. deviceType: this.deviceType,
  287. buildFloor: this.buildFloor
  288. }
  289. }
  290. this.$router.push({
  291. name: "batchlinkAssets",
  292. params: query
  293. })
  294. }
  295. },
  296. watch: {
  297. }
  298. };
  299. </script>
  300. <style lang="less" scoped>
  301. .condition-title{
  302. width: 100px;
  303. display: inline-block;
  304. text-align: right;
  305. margin-left: 10px;
  306. margin-right: 12px;
  307. color: #999999;
  308. font-size: 14px;
  309. vertical-align: top;
  310. }
  311. /deep/ .el-dialog__body {
  312. max-height: 420px;
  313. overflow-y: auto;
  314. }
  315. </style>