manageTenantZone.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. <template>
  2. <div id="manageTenantZone">
  3. <!-- 数据字典设备类型 -->
  4. <el-row>
  5. <el-button size="small" type="default" icon="el-icon-back" @click="goback"></el-button>
  6. <div style="display:inline-block;margin:10px 0 0 10px;">
  7. <label style="margin-right:10px;">业务空间类型</label>
  8. <el-badge :is-dot="onlyRead&&options.length>1">
  9. <el-select v-model="value" placeholder="请选择" @change="getTnRelatFloor">
  10. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
  11. </el-option>
  12. </el-select>
  13. </el-badge>
  14. </div>
  15. </el-row>
  16. <el-row class="main-container">
  17. <el-col :span="3" class="main-left">
  18. <div style="padding:10px;border-bottom:1px solid #e4e4e4;">
  19. <el-input :placeholder="`请输入租户名称`" @keyup.enter.native="getTenant" v-model="keyWord">
  20. <i slot="suffix" class="el-input__icon el-icon-search" @click="getTenant"></i>
  21. </el-input>
  22. </div>
  23. <div style="overflow-y:auto;height: calc(100% - 53px);">
  24. <div v-for="(item,i) in tenantList" :key="item.TenantID" :class="{'tenantItem':true, 'active':item.active}" @click="tenantChange(i)">
  25. {{item.TenantLocalName||item.TenantName}}
  26. </div>
  27. </div>
  28. </el-col>
  29. <el-col :span="21" style="height:100%;">
  30. <div style="height:52px;border-bottom:1px solid #e4e4e4;">
  31. <div v-if="onlyRead===true||onlyRead==='true'">
  32. <div v-for="(bd,i) in allBuilding" :key="bd.BuildID" :class="{'building':true,'active':bd.active}" @click="changeBuildSelect(i)">
  33. {{bd.BuildLocalName||bd.BuildName}}
  34. </div>
  35. </div>
  36. <div v-else style="line-height: 52px;padding:0 10px;">
  37. <label style="margin-right:10px;">所属建筑</label>
  38. <el-select v-model="buildSelect" placeholder="请选择" @change="changeBuildSelect">
  39. <el-option v-for="(item,i) in allBuilding" :key="item.BuildID" :label="item.BuildLocalName || item.BuildName" :value="i">
  40. </el-option>
  41. </el-select>
  42. <div style="float:right;">
  43. <el-button size="small" type="default" @click="editCanvas" v-if="!isEdit">编辑</el-button>
  44. <el-button size="small" type="default" @click="cancel" v-if="isEdit">取消</el-button>
  45. <el-button size="small" type="primary" @click="save" v-if="isEdit">确认</el-button>
  46. </div>
  47. </div>
  48. </div>
  49. <div class="canvas-container" ref="graphy" v-loading="canvasLoading">
  50. <div class="floor-container" v-show="floorList.length">
  51. <div class="before" @click="toBefore">
  52. <div><i class="el-icon-caret-top"></i></div>
  53. </div>
  54. <div class="floor">
  55. <div v-for="(fl,i) in floorList" :key="fl.id" :class="{'active':fl.active,'textParent':true}" @click="floorChange(i)">
  56. <div class="text" :title="fl.FloorLocalID || fl.FloorLocalName">
  57. {{fl.FloorLocalID || fl.FloorLocalName}}
  58. <span v-if="fl.Count">{{fl.Count>9?'9+':fl.Count}}</span>
  59. </div>
  60. </div>
  61. </div>
  62. <div class="after" @click="toNext">
  63. <div><i class="el-icon-caret-bottom"></i></div>
  64. </div>
  65. <div class="border"></div>
  66. </div>
  67. <canvas id="floorCanvas" :width="canvasWidth" :height="canvasHeight" v-show="hasMap"></canvas>
  68. <div class="canvas-fun" v-show="hasMap">
  69. <canvasFun @scale="scale" @fit="fit" @savePng="savePng" @saveSvg="saveSvg" @saveJson="saveJson" :config="config"
  70. @groupSelect="groupSelect" ref="canvasFun">
  71. </canvasFun>
  72. </div>
  73. <div class="center" v-show="!hasMap">
  74. <i class="icon-wushuju iconfont"></i>
  75. 暂无数据
  76. </div>
  77. </div>
  78. </el-col>
  79. </el-row>
  80. </div>
  81. </template>
  82. <script>
  83. import canvasFun from "@/components/business_space/newGraphy/canvasFun";
  84. import { mapGetters } from "vuex";
  85. import { SColor, SPoint } from "@saga-web/draw/lib";
  86. import { DivideFloorScene, SpaceItem, ZoneItem, FloorView, Opt } from "@saga-web/cad-engine/lib";
  87. import { colorArr } from "@/utils/spaceColor"
  88. import {
  89. // buildingQuery,
  90. queryTnRelateFloor,
  91. queryRentTableData,
  92. tnRelateZone,
  93. zoneQueryOutline
  94. } from '@/api/scan/request'
  95. import { buildingQuery } from '@/api/object/build';
  96. export default {
  97. data() {
  98. return {
  99. options: [{ value: 'GeneralZone', label: '默认分区' }, { value: 'TenantZone', label: '租户分区' }],
  100. value: 'TenantZone',
  101. tenantList: [],
  102. floorList: [],
  103. canvasWidth: 800,
  104. canvasHeight: 800,
  105. onlyRead: false,
  106. allBuilding: [],
  107. buildSelect: 0,
  108. activeFloor: 0,
  109. activeTentanIndex: 0,
  110. canvasLoading: false,
  111. isEdit: false,
  112. view: '',
  113. scene: '',
  114. config: {
  115. isEdit: false,
  116. groupSelect: true
  117. },
  118. hasMap: true,
  119. keyWord: '', // 查询租户名称
  120. Cascade: {
  121. GeneralZone: 'zoneGeneraltList',
  122. TenantZone: 'zoneTenantList'
  123. }
  124. }
  125. },
  126. components: {
  127. canvasFun
  128. },
  129. computed: {
  130. ...mapGetters("layout", ["projectId","projects"]),
  131. projectName() {
  132. let projectObj = this.projects.find(item => {
  133. return item.id == this.projectId
  134. })
  135. return projectObj?projectObj.name?projectObj.name:projectObj.id:this.projectId
  136. },
  137. buildFloorName() {
  138. let buildObj = this.allBuilding[this.buildSelect],
  139. floorObj = this.floorList[this.activeFloor];
  140. console.log(buildObj,floorObj)
  141. return `${buildObj.BuildLocalName?buildObj.BuildLocalName:
  142. buildObj.BuildName?buildObj.BuildName:""}-${floorObj.FloorLocalID?
  143. floorObj.FloorLocalID:floorObj.FloorLocalName?floorObj.FloorLocalName:FloorName}`
  144. },
  145. },
  146. created() {
  147. this.onlyRead = this.$route.query.onlyRead;
  148. this.init();
  149. Opt.sceneMarkColor = new SColor('#ffffff');
  150. },
  151. mounted() {
  152. this.canvasWidth = this.$refs.graphy.offsetWidth;
  153. this.canvasHeight = this.$refs.graphy.offsetHeight;
  154. },
  155. methods: {
  156. init() {
  157. this.getTenant();
  158. },
  159. // 返回
  160. goback() {
  161. this.$router.push({ name: 'rentlist', query: { onlyRead: this.onlyRead } })
  162. },
  163. // 适配底图到窗口
  164. fit() {
  165. if (this.scene.sceneMark) {
  166. this.view.fitItemToView([this.scene.sceneMark])
  167. return
  168. }
  169. this.view.fitSceneToView()
  170. },
  171. // 缩放
  172. scale(val) {
  173. if (!this.view) {
  174. return;
  175. }
  176. let scale = this.view.scale;
  177. this.view.scaleByPoint(val / scale, this.canvasWidth / 2, this.canvasHeight / 2);
  178. },
  179. // 保存为png
  180. savePng() {
  181. this.view.saveImage(`${this.projectName}-${this.buildFloorName}.png`, 'png');
  182. },
  183. // 保存为svg
  184. saveSvg() {
  185. this.view.saveSceneSvg(`${this.projectName}-${this.buildFloorName}.svg`, 6400, 4800);
  186. },
  187. // 保存json
  188. saveJson() {
  189. this.view.saveFloorJson(`${this.projectName}-${this.buildFloorName}.json`)
  190. },
  191. // 框选
  192. groupSelect() {
  193. this.scene.isRectSelection = 2;
  194. },
  195. // 上一个
  196. toBefore() {
  197. if (this.activeFloor > 0) {
  198. let index = this.activeFloor - 1;
  199. this.floorChange(index)
  200. }
  201. },
  202. // 下一个
  203. toNext() {
  204. if (this.activeFloor < this.floorList.length - 1) {
  205. let index = this.activeFloor + 1;
  206. this.floorChange(index)
  207. }
  208. },
  209. // 建筑修改
  210. changeBuildSelect(val) {
  211. this.allBuilding.map(t => {
  212. t.active = false;
  213. })
  214. this.allBuilding[val].active = true;
  215. if (this.allBuilding[val].Floor && this.allBuilding[val].Floor.length) {
  216. this.floorList = this.allBuilding[val].Floor
  217. this.floorChange(0);
  218. } else {
  219. this.floorList = []
  220. }
  221. },
  222. // 租户修改
  223. tenantChange(index) {
  224. this.tenantList.map(t => {
  225. t.active = false;
  226. })
  227. this.curTenantId = this.tenantList[index].TenantID;
  228. this.tenantList[index].active = true;
  229. this.activeTentanIndex = index;
  230. this.tenantChangeInflu(index);
  231. },
  232. // 租户更改引起的修改
  233. tenantChangeInflu(i) {
  234. if (this.onlyRead === true || this.onlyRead === 'true') { // 只读模式-对空间类型处理
  235. let g = this.tenantList[i].ZoneGeneraltList;
  236. let t = this.tenantList[i].ZoneTenantList;
  237. let gFlag = g && g.length;
  238. let tFlag = t && t.length;
  239. if (gFlag) {
  240. if (tFlag) {
  241. this.options = [{ value: 'GeneralZone', label: '默认分区' }, { value: 'TenantZone', label: '租户分区' }]
  242. this.value = 'TenantZone';
  243. } else {
  244. this.options = [{ value: 'GeneralZone', label: '默认分区' }];
  245. this.value = 'GeneralZone';
  246. }
  247. } else {
  248. if (tFlag) {
  249. this.options = [{ value: 'TenantZone', label: '租户分区' }];
  250. this.value = 'TenantZone';
  251. } else {
  252. this.options = [];
  253. this.value = '';
  254. }
  255. }
  256. }
  257. this.getTnRelatFloor();
  258. },
  259. // 楼层修改
  260. floorChange(index) {
  261. this.floorList.map(t => {
  262. t.active = false;
  263. })
  264. this.activeFloor = index;
  265. this.floorList[index].active = true;
  266. this.getGraphy(index)
  267. },
  268. // canvas点击事件
  269. canvasClick(item, event) {
  270. if (!this.isEdit) {
  271. item.selected = false;
  272. }
  273. },
  274. // 编辑
  275. editCanvas() {
  276. this.isEdit = true;
  277. this.config.isEdit = true;
  278. this.scene.zoneList.map(t => {
  279. t.selected = t.highLightFlag;
  280. t.transparency = 20;
  281. t.highLightFlag = false;
  282. })
  283. },
  284. // 取消
  285. cancel() {
  286. this.isEdit = false;
  287. this.config.isEdit = false;
  288. this.scene.clearZoneSelection();
  289. this.getBusinessSpace();
  290. },
  291. // 清除canvas
  292. clearGraphy() {
  293. if (this.view) {
  294. this.view.scene = null;
  295. return
  296. }
  297. this.view = new FloorView('floorCanvas')
  298. },
  299. // 获取列表
  300. getTenant() {
  301. let pa = {
  302. Cascade: [
  303. { Name: 'zoneTenantList' },
  304. // , Cascade: [{ Name: 'building' }, { Name: 'floor' }]
  305. { Name: 'zoneGeneraltList' }
  306. ],
  307. Orders: "TenantID asc",
  308. PageSize: 1000
  309. }
  310. if (this.keyWord) {
  311. pa.Filters = `TenantLocalName contain '${this.keyWord}'`
  312. }
  313. queryRentTableData(pa, res => {
  314. this.tenantList = res.Content.map(t => {
  315. t.active = false;
  316. return t;
  317. })
  318. if (this.tenantList.length) {
  319. this.tenantChange(0)
  320. }
  321. })
  322. },
  323. // 获取业务空间
  324. getBusinessSpace() {
  325. let buildid = this.floorList[this.activeFloor].BuildID;
  326. let floorid = this.floorList[this.activeFloor].FloorID;
  327. let TenantID = this.tenantList[this.activeTentanIndex].TenantID
  328. if (buildid && floorid && this.value) {
  329. this.canvasLoading = true
  330. let pa = {
  331. Filters: `not RoomID isNull`,
  332. Orders: "createTime desc, RoomID asc",
  333. PageSize: 1000,
  334. ZoneType: this.value,
  335. BuildingId: buildid,
  336. FloorId: floorid
  337. }
  338. this.canvasLoading = false;
  339. let promise1 = new Promise((resolve) => {
  340. zoneQueryOutline(pa, res => {
  341. resolve(res);
  342. })
  343. })
  344. let pa2 = {
  345. Cascade: [
  346. { Name: this.Cascade[this.value], Filters: `FloorId='${floorid}'` }
  347. ],
  348. Filters: `TenantID='${TenantID}'`
  349. }
  350. let promise2 = new Promise((resolve) => {
  351. queryRentTableData(pa2, res => {
  352. resolve(res);
  353. })
  354. })
  355. Promise.all([promise1, promise2]).then(response => {
  356. let res1 = response[0];
  357. let res2 = response[1];
  358. let key = 'Z' + this.Cascade[this.value].substring(1);
  359. let relationList = res2.Content[0][key] || [];
  360. this.businessSpaceList = res1.Content;
  361. // 已关联元空间的业务空间
  362. this.BSPRelaISPList = [];
  363. res1.Content.map(t => {
  364. if (t.Outline && t.Outline.length) {
  365. this.BSPRelaISPList.push(t)
  366. }
  367. })
  368. // 绘制业务空间
  369. let tempArr = this.BSPRelaISPList.map((t, i) => {
  370. if (t.FloorId == this.floorList[this.activeFloor].FloorID && t.ObjectType == this.value) {
  371. return {
  372. RoomLocalName: t.RoomLocalName,
  373. OutLine: t.Outline,
  374. RoomID: t.RoomID,
  375. Color: colorArr[i % colorArr.length],
  376. HighLightFlag: relationList.findIndex((item) => (item.RoomID == t.RoomID)) > -1,
  377. Transparency: relationList.findIndex((item) => (item.RoomID == t.RoomID)) > -1 ? 20 : 1
  378. }
  379. } else {
  380. return undefined;
  381. }
  382. }).filter(item => item)
  383. this.scene.removeAllZone();
  384. this.scene.addZoneList(tempArr);
  385. this.scene.click(this, this.canvasClick);
  386. })
  387. }
  388. },
  389. // 初始化底图
  390. getGraphy(index) {
  391. if (this.floorList[index].StructureInfo && this.floorList[index].StructureInfo.FloorMap) {
  392. let floorMap = this.floorList[index].StructureInfo.FloorMap;
  393. this.clearGraphy();
  394. this.scene = new DivideFloorScene();
  395. this.hasMap = true;
  396. this.canvasLoading = true;
  397. this.scene.loadUrl(`/image-service/common/file_get?systemId=revit&key=${floorMap}`).then(res => {
  398. if (res == 'error') {
  399. this.$message.warning('数据解析异常');
  400. this.hasMap = false;
  401. this.canvasLoading = false;
  402. return;
  403. }
  404. this.view.scene = this.scene;
  405. if (this.floorList[index].Outline) {
  406. let newArr = this.floorList[index].Outline.map(t => {
  407. return new SPoint(t.X, t.Y);
  408. })
  409. this.scene.addSceneMark(newArr)
  410. }
  411. this.scene.isSpaceSelectable = false;
  412. // 绘制业务空间
  413. this.getBusinessSpace();
  414. this.fit();
  415. this.view.minScale = this.view.scale;
  416. if (this.$refs.canvasFun) {
  417. this.$refs.canvasFun.everyScale = this.view.scale;
  418. }
  419. })
  420. } else {
  421. this.hasMap = false;
  422. }
  423. },
  424. // 查询租户关联的业务空间所在建筑楼层,分区修改也会触发
  425. getTnRelatFloor() {
  426. if (this.value) {
  427. let pa = {
  428. objectType: this.value,
  429. tenantId: this.curTenantId
  430. }
  431. queryTnRelateFloor(pa, res => {
  432. this.allBuilding = res.Content.map(t => {
  433. t.active = false;
  434. if (t.Floor) {
  435. t.Floor.map(item => {
  436. item.active = false;
  437. })
  438. }
  439. return t;
  440. });
  441. if (this.onlyRead === true || this.onlyRead === 'true') {
  442. this.allBuilding = this.allBuilding.filter(item => item.Count > 0)
  443. this.allBuilding.map(t => {
  444. if (t.Floor) {
  445. t.Floor = t.Floor.filter(item => item.Count > 0)
  446. }
  447. })
  448. }
  449. if (this.allBuilding.length) {
  450. this.changeBuildSelect(this.buildSelect);
  451. }
  452. })
  453. } else {
  454. this.hasMap = false;
  455. this.canvasLoading = false;
  456. this.allBuilding = [];
  457. this.floorList = [];
  458. }
  459. },
  460. // 保存关系
  461. save() {
  462. let arr = this.scene.getSelectedZone();
  463. let pa = {
  464. data: {
  465. SpaceIdList: [],
  466. FloorId: this.floorList[this.activeFloor].FloorID,
  467. TenantId: this.curTenantId
  468. },
  469. type: this.value
  470. }
  471. pa.data.SpaceIdList = arr.map(t => {
  472. return t.data.RoomID;
  473. })
  474. tnRelateZone(pa, res => {
  475. this.isEdit = false;
  476. this.config.isEdit = false;
  477. this.$message.success('关联成功');
  478. this.getTnRelatFloor();
  479. })
  480. },
  481. },
  482. watch: {
  483. projectId() {
  484. this.init()
  485. },
  486. "view.scale": {
  487. handler(n) {
  488. if (this.$refs.canvasFun) {
  489. let s = n * 10 / this.view.minScale
  490. this.$refs.canvasFun.sliderVal = s > 1000 ? 1000 : s;
  491. }
  492. }
  493. },
  494. "scene.isRectSelection": {
  495. handler(n) {
  496. if (!n) {
  497. this.$refs.canvasFun.active = '';
  498. }
  499. }
  500. },
  501. }
  502. }
  503. </script>
  504. <style lang="less" scoped>
  505. @normal-border-color: #e4e4e4;
  506. @normal-border-active-color: #e8e8e8;
  507. #manageTenantZone {
  508. height: 100%;
  509. .main-container {
  510. margin-top: 10px;
  511. background: #fff;
  512. border: 1px solid @normal-border-color;
  513. height: calc(100% - 53px);
  514. overflow: hidden;
  515. .main-left {
  516. height: 100%;
  517. border-right: 1px solid @normal-border-color;
  518. .tenantItem {
  519. border-bottom: 1px solid @normal-border-color;
  520. text-align: center;
  521. line-height: 40px;
  522. color: #2b2b2b;
  523. cursor: pointer;
  524. &.active {
  525. background-color: @normal-border-active-color;
  526. }
  527. }
  528. }
  529. }
  530. .building {
  531. display: inline-block;
  532. margin: 7px 10px;
  533. border: 1px solid @normal-border-color;
  534. color: #2b2b2b;
  535. border-radius: 28px;
  536. padding: 4px 16px;
  537. cursor: pointer;
  538. &.active {
  539. border: 1px solid #409eff;
  540. color: #409eff;
  541. }
  542. }
  543. .canvas-container {
  544. position: relative;
  545. width: 100%;
  546. height: calc(100% - 53px);
  547. display: flex;
  548. align-items: center;
  549. justify-content: center;
  550. .floor-container {
  551. position: absolute;
  552. width: 60px;
  553. height: 260px;
  554. top: 20px;
  555. left: 20px;
  556. z-index: 2;
  557. background-color: #fff;
  558. .before,
  559. .after {
  560. div {
  561. width: 52px;
  562. height: 23px;
  563. margin: 0 auto;
  564. text-align: center;
  565. font-size: 24px;
  566. line-height: 1;
  567. color: #2b2b2b;
  568. border: 1px solid @normal-border-color;
  569. cursor: pointer;
  570. }
  571. }
  572. .floor {
  573. position: relative;
  574. height: 210px;
  575. overflow-y: auto;
  576. &::-webkit-scrollbar {
  577. display: none;
  578. }
  579. .textParent {
  580. cursor: pointer;
  581. &.active {
  582. background-image: url(~@/assets/image/floorBG.png);
  583. div.text {
  584. border: none;
  585. }
  586. }
  587. div.text {
  588. position: relative;
  589. width: 54px;
  590. height: 30px;
  591. line-height: 30px;
  592. white-space: nowrap;
  593. overflow: hidden;
  594. text-overflow: ellipsis;
  595. text-align: center;
  596. color: #2b2b2b;
  597. margin: 0 auto;
  598. padding: 0 10px;
  599. box-sizing: border-box;
  600. &:hover {
  601. background-color: #409eff1a;
  602. }
  603. b {
  604. font-weight: normal;
  605. }
  606. span {
  607. position: absolute;
  608. display: block;
  609. height: 10px;
  610. border-radius: 14px;
  611. line-height: 10px;
  612. text-align: center;
  613. top: 0;
  614. right: -2px;
  615. color: #fff;
  616. background-color: #f56c6c;
  617. padding: 5px;
  618. font-size: 12px;
  619. transform: scale(0.7, 0.7);
  620. }
  621. }
  622. }
  623. }
  624. div.border {
  625. position: absolute;
  626. width: 52px;
  627. height: 100%;
  628. left: 50%;
  629. top: 0;
  630. z-index: -1;
  631. transform: translateX(-50%);
  632. border-left: 1px solid @normal-border-color;
  633. border-right: 1px solid @normal-border-color;
  634. }
  635. }
  636. .canvas-fun {
  637. position: absolute;
  638. bottom: 20px;
  639. left: 50%;
  640. z-index: 3;
  641. transform: translateX(-50%;);
  642. }
  643. }
  644. }
  645. </style>