manageTenantZone.vue 19 KB

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