HorFloorSpace.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. <template>
  2. <div class="floorSpace" ref="floorSpace">
  3. <div class="leftChange">
  4. <div>{{nowBuildName}}</div>
  5. <div class="allIndicator">
  6. <div
  7. class="eachItem "
  8. v-for="(item,index) in allIndicator"
  9. @click="clickIndicator(index)"
  10. v-bind:class="{'select':item.id==selIndicator.id}"
  11. >
  12. <div class="title">{{item.name}}</div>
  13. <div
  14. class="textCont"
  15. v-show="item.id==selIndicator.id"
  16. ><span class="value">{{totalAvgValues}}{{selIndicator.unit}}</span><br /><span class="name">平均{{selIndicator.name}}</span></div>
  17. <img
  18. v-show="item.id==selIndicator.id"
  19. class="img"
  20. :src="selIndicator.img"
  21. ></img>
  22. </div>
  23. </div>
  24. </div>
  25. <div class="floorWrap">
  26. <div
  27. class="floor-item"
  28. v-for="(item,index) in showFloors"
  29. :key="index" v-bind:style="{ height: item.floorHeight + 'px' }"
  30. >
  31. <div class="floor-num"><span>{{item.localName}}</span></div>
  32. <div class="floor-space">
  33. <div
  34. class="space-box"
  35. v-for="(childItem,id) in item.dataSpaces"
  36. :key="id"
  37. v-bind:style="{ width: item.spacewidth + '%' ,height: item.spaceheight + '%' }"
  38. >
  39. <div class="space-name" v-bind:style="{backgroundColor:selectColor(childItem.avgValues,selIndicatorId,true)}">{{childItem.localName}}</div>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. </template>
  46. <script>
  47. import moment from "moment";
  48. import { selectColor } from "@/utils/publicMethod";
  49. export default {
  50. name: 'FloorSpace',
  51. data() {
  52. return {
  53. selIndicator: {},
  54. selIndicatorId:'',//为了颜色用
  55. // 温度
  56. // 二氧化碳
  57. // 湿度
  58. //
  59. // pm2.5
  60. nowIndicatorIndex:null,//现在选中的指标 index
  61. allIndicator: [{
  62. id: 'temp',
  63. code:'Tdb',
  64. name: '温度',
  65. img: require('../../assets/horImg/wendu.svg'),
  66. unit: '℃',
  67. fixed:1
  68. }, {
  69. id: 'humidity',
  70. code:'RH',
  71. name: '湿度',
  72. img: require('../../assets/horImg/shidu.svg'),
  73. unit: '%',
  74. fixed:0
  75. }, {
  76. id: 'co2',
  77. code:'CO2',
  78. name: 'CO₂',
  79. img: require('../../assets/horImg/co2.svg'),
  80. unit: 'ppm',
  81. fixed:0
  82. }, {
  83. id: 'methanal',
  84. code:'HCHO',
  85. name: '甲醛',
  86. img: require('../../assets/horImg/jiaquan.svg'),
  87. unit: 'mg/m³',
  88. fixed:2
  89. }, {
  90. id: 'pm25',
  91. code:'PM2d5',
  92. name: 'PM2.5',
  93. img: require('../../assets/horImg/pm25.svg'),
  94. unit: 'ug/m³',
  95. fixed:0
  96. }],
  97. allBuild: [],
  98. nowBuildName: '',
  99. nowBuildPage: 1, //目前是第几个建筑
  100. allFloor: [],
  101. firstPageParams: [],
  102. secondPageParams: [],
  103. nowPage: 1, //当前哪一屏幕
  104. pageNum:0,
  105. showFloors: [],
  106. totalAvgValues:null
  107. }
  108. },
  109. props: {
  110. showPing: {
  111. type: Number,
  112. default: () => {
  113. return 0;
  114. },
  115. },
  116. },
  117. watch:{
  118. showPing(newv,oldv){
  119. //当前展示为第二屏时
  120. if(newv==2){
  121. this.nowPage = 1;
  122. this.queryBuild();
  123. }
  124. }
  125. },
  126. mounted() {
  127. },
  128. destroyed(){
  129. console.log("horfloorspace---destroyed");
  130. },
  131. methods: {
  132. selectColor:selectColor,
  133. clickIndicator(index) {
  134. this.nowIndicatorIndex = index;
  135. },
  136. getTimeFloorParam() {
  137. //第一屏的参数 第二屏的参数
  138. var floorparam =
  139. this.nowPage == 1
  140. ? this.firstPageParams
  141. : this.secondPageParams;
  142. var _this = this;
  143. this.queryParam(floorparam).then(() => {
  144. var timeoutsign = setTimeout(() => {
  145. _this.nowIndicatorIndex = _this.nowIndicatorIndex + 1;//湿度等指标的轮询变化
  146. if (_this.nowIndicatorIndex == 5) {//指标切换完毕
  147. //debugger;
  148. if (_this.pageNum == _this.nowPage) {
  149. //一个建筑的所有楼层 切换完毕
  150. _this.nowIndicatorIndex = 0;
  151. _this.nowPage = 1;
  152. //所有建筑指标轮询结束 通知切换
  153. if (_this.nowBuildPage == _this.allBuild.length) {
  154. //_this.$emit("donetowpage");
  155. clearTimeout(timeoutsign);
  156. } else {
  157. //换下一个建筑
  158. _this.nowBuildPage = _this.nowBuildPage + 1;
  159. _this.queryFs();
  160. }
  161. return;
  162. }
  163. //如果是两页 并且nowPage是第一页
  164. if (_this.pageNum == 2 && _this.nowPage == 1) {
  165. _this.nowPage = 2;
  166. _this.nowIndicatorIndex = 0;
  167. }
  168. }
  169. this.getTimeFloorParam();
  170. }, 1200);
  171. });
  172. },
  173. queryBuild() {
  174. var _this = this;
  175. this.$axios
  176. .post(this.$api.queryBuilding, {
  177. criteria: {
  178. projectId: projectId,
  179. },
  180. })
  181. .then((res) => {
  182. debugger;
  183. var data = (res.data || {}).content || [];
  184. _this.allBuild = data;
  185. _this.nowBuildPage = 1;
  186. _this.queryFs();
  187. })
  188. .catch((res) => {
  189. // loading.close();
  190. });
  191. },
  192. queryFs() {
  193. //var loading = this.$loading({ fullscreen: true });
  194. var _this=this;
  195. var buildId= (this.allBuild[this.nowBuildPage - 1]||{}).id;
  196. if(!buildId){return;}
  197. this.$axios
  198. .post(this.$api.queryFs, {
  199. criteria: {
  200. projectId: projectId,
  201. buildingId: buildId,
  202. },
  203. size: 14,//最多14层
  204. page: 1,
  205. orders: [
  206. {
  207. column: "floorSequenceId",
  208. asc: true,
  209. },
  210. ],
  211. })
  212. .then((res) => {
  213. // loading.close();
  214. var allFloor = res.data.content || [];
  215. allFloor = allFloor.filter(function(item) {
  216. return item.spaceNum > 0;
  217. });
  218. debugger;
  219. //如果该建筑的所有楼层 没有空间 则请求下一个建筑
  220. if (allFloor.length == 0) {
  221. _this.nowBuildPage = _this.nowBuildPage + 1;
  222. if (_this.nowBuildPage > _this.allBuild.length) {
  223. //_this.$emit("donetowpage");
  224. return;
  225. }
  226. _this.queryFs();
  227. return;
  228. }
  229. _this.nowBuildName = _this.allBuild[_this.nowBuildPage - 1].localName;
  230. this.allFloor = allFloor;
  231. var allFloorNum = allFloor.length;
  232. //如果超过7层 就显示两屏幕 第一屏 firstPageNum
  233. //如果超过7层 就显示两屏幕 第二屏 secondPageNum
  234. var firstPageNum, secondPageNum;
  235. if (allFloorNum <= 7) {
  236. firstPageNum = allFloorNum;
  237. secondPageNum = 0;
  238. this.pageNum=1;
  239. } else {
  240. firstPageNum = Math.ceil(allFloorNum / 2);
  241. secondPageNum = Math.floor(allFloorNum / 2);
  242. this.pageNum=2;
  243. }
  244. var firstMaxSpace = this.floorHandle(firstPageNum); //第一屏 一层最多空间
  245. var sendMaxSpace = this.floorHandle(secondPageNum);
  246. var firstPageFloors = allFloor.slice(0, firstPageNum); //第一屏 所有楼层
  247. var secondPageFloors = allFloor.slice(firstPageNum);//第二屏 所有楼层
  248. //第一屏的参数 第二屏的参数
  249. this.firstPageParams = firstPageFloors.map((item) => {
  250. var obj = {};
  251. obj.id = item.id;
  252. obj.projectId = projectId;
  253. obj.spaceNum = firstMaxSpace;//最多空间数
  254. return obj;
  255. });
  256. this.secondPageParams = secondPageFloors.map((item) => {
  257. var obj = {};
  258. obj.id = item.id;
  259. obj.projectId = projectId;
  260. obj.spaceNum = sendMaxSpace;
  261. return obj;
  262. });
  263. debugger;
  264. this.nowIndicatorIndex=0;
  265. this.getTimeFloorParam();
  266. }).catch(function(res){
  267. // loading.close();
  268. });
  269. },
  270. queryParam(floorparam) {
  271. //var loading = this.$loading({ fullscreen: true });
  272. var endTime = moment();
  273. var startTime = moment().subtract(30, "minutes");//往前取15分钟
  274. var startStr = startTime.format("YYYYMMDDHHmmss");
  275. var endStr = endTime.format("YYYYMMDDHHmmss");
  276. var newv=this.nowIndicatorIndex;
  277. this.selIndicator = this.allIndicator[newv];
  278. var param = this.selIndicator.code;
  279. return this.$axios
  280. .post(
  281. `${this.$api.queryParam}?endTime=${endStr}&startTime=${startStr}&param=${param}`,
  282. floorparam
  283. )
  284. .then((res) => {
  285. // loading.close();
  286. //console.log("queryParam", res);
  287. var showFloors = res.data.data.floors || [];
  288. this.totalAvgValues = res.data.data.avgValues || null;
  289. var wrapHeight= document.getElementsByTagName("body")[0].offsetHeight-164;
  290. wrapHeight=Math.max(wrapHeight,730);//730是楼层区域的最小高度
  291. this.totalAvgValues&&(this.totalAvgValues=this.totalAvgValues.toFixed(this.selIndicator.fixed));
  292. showFloors.forEach((ele) => {
  293. var filterFloorarr = this.allFloor.filter((item) => {
  294. return item.id == ele.id;
  295. });
  296. var filterFloor = filterFloorarr[0] || {};
  297. ele.name = filterFloor.name;
  298. ele.localId = filterFloor.localId;
  299. ele.localName = filterFloor.localName;
  300. var dataSpacesNum = ele.dataSpaces.length;//一层的空间数
  301. var floorParam = this.spaceHandle(dataSpacesNum,showFloors.length) ; //一行的个数
  302. ele.spacewidth = 100 / floorParam.lineNum;
  303. ele.spaceheight = 100 / floorParam.floorline;//每一行的高度占比
  304. ele.floorHeight= wrapHeight/showFloors.length;//每一层的高度
  305. });
  306. this.showFloors = showFloors;
  307. this.selIndicatorId=this.selIndicator.id;
  308. }).catch((err)=>{});
  309. },
  310. spaceHandle(spaceNum,floorNum){//返回一层 的每一行 几个房间
  311. var lineNum = spaceNum; //一行的房间数
  312. var floorline=1;//一层几行
  313. if (floorNum == 1) {//最多一层时
  314. if (spaceNum > 2 && spaceNum <= 24 ) {
  315. floorline=2;
  316. lineNum = spaceNum / 2;
  317. }else if (spaceNum > 24 && spaceNum <= 36) {
  318. floorline=3;
  319. lineNum = Math.ceil(spaceNum / 3);
  320. } else if (spaceNum > 36 && spaceNum <= 48) {
  321. floorline=4;
  322. lineNum = Math.ceil(spaceNum / 4);
  323. } else if (spaceNum > 48 && spaceNum <= 60) {//48-60个 5行
  324. floorline=5;
  325. lineNum = Math.ceil(spaceNum / 5);
  326. }
  327. }else{
  328. floorline = Math.ceil(spaceNum / 16); //20-30 3排 30-40个 4排 一层排数
  329. lineNum = Math.ceil(spaceNum / floorline);
  330. }
  331. return {lineNum,floorline};
  332. },
  333. floorHandle(floorNum) {
  334. var maxFloorSpace = 1;//一层 最多显示房间数
  335. switch (floorNum) {
  336. case 1:
  337. maxFloorSpace = 60;
  338. break;
  339. case 2:
  340. maxFloorSpace = 48;
  341. break;
  342. case 3:
  343. case 4:
  344. maxFloorSpace = 32;
  345. break;
  346. case 5:
  347. case 6:
  348. case 7:
  349. maxFloorSpace = 16;
  350. break;
  351. }
  352. return maxFloorSpace;
  353. // if(floorNum == 2) {
  354. // if (spaceNum > 16 && spaceNum < = 32 ) {
  355. // lineNum = Math.ceil(spaceNum / 2);
  356. // }else if (spaceNum > 32 && spaceNum < = 48 ) {
  357. // lineNum = Math.ceil(spaceNum / 3);
  358. // }
  359. // maxFloorSpace=48;
  360. // }
  361. // if(floorNum ==3||floorNum ==4) {
  362. // if (spaceNum > 16 && spaceNum < = 32 ) {
  363. // lineNum = Math.ceil(spaceNum / 2);
  364. // }
  365. // maxFloorSpace=32;
  366. // }
  367. }
  368. }
  369. }
  370. </script>
  371. <style lang="less" scoped>
  372. .floorSpace {
  373. width: 100%;
  374. // height: 910px;
  375. display: flex;
  376. //min-height: 730px;
  377. background: #ffffff;
  378. border-radius: 16px;
  379. overflow: hidden;
  380. }
  381. .leftChange {
  382. height: 100%;
  383. width: 154px;
  384. margin: 0 auto;
  385. //min-height: 730px;
  386. .allIndicator {
  387. padding-top: 32px;
  388. //padding-bottom: 20px;
  389. // display: flex;
  390. // align-items: center;
  391. // justify-content: center;
  392. .eachItem {
  393. cursor: pointer;
  394. margin-bottom: 56px;
  395. padding: 0;
  396. text-align: center;
  397. font-family: PingFang SC;
  398. .title {
  399. color: #9b98ad;
  400. font-size: 24px;
  401. font-weight: 600;
  402. }
  403. &.select {
  404. border-left: 4px solid #46ccf6;
  405. .title {
  406. color: #3b3558;
  407. font-size: 24px;
  408. }
  409. .textCont {
  410. color: #3b3558;
  411. font-size: 20px;
  412. padding-top: 16px;
  413. padding-bottom: 20px;
  414. line-height: 20px;
  415. .value{
  416. font-weight: 600;
  417. }
  418. .name {
  419. font-size: 14px;
  420. }
  421. }
  422. .img {
  423. height: 196px;
  424. padding: 0;
  425. margin: 0;
  426. }
  427. }
  428. }
  429. .eachItem:last-child{
  430. margin-bottom:0;
  431. }
  432. }
  433. // .allIndicator {
  434. // padding-top: 32px;
  435. // padding-bottom: 20px;
  436. // display: flex;
  437. // align-items: center;
  438. // justify-content: center;
  439. // .eachItem {
  440. // font-size: 24px;
  441. // color: #9b98ad;
  442. // margin-right: 60px;
  443. // display: flex;
  444. // flex-direction: column;
  445. // align-items: center;
  446. // .bar {
  447. // width: 24px;
  448. // height: 6px;
  449. // display: inline-block;
  450. // }
  451. // &.select {
  452. // color: #3b3558;
  453. // .bar {
  454. // background: #46ccf6;
  455. // }
  456. // }
  457. // }
  458. // }
  459. // .imageDiv {
  460. // height: 32px;
  461. // margin: 0 32px;
  462. // }
  463. // .textCont {
  464. // color: #3b3558;
  465. // font-size: 20px;
  466. // font-weight: 600;
  467. // text-align: center;
  468. // padding-top: 16px;
  469. // .value {
  470. // margin-left: 4px;
  471. // }
  472. // }
  473. }
  474. .floorWrap {
  475. // width: 1000px;
  476. flex: 1;
  477. margin: 0 auto;
  478. background: #ffffff;
  479. border-top-right-radius: 16px;
  480. border-bottom-right-radius: 16px;
  481. // padding-right:20px;
  482. box-sizing: border-box;
  483. .floor-item {
  484. display: flex;
  485. padding: 18px 20px 18px 0;
  486. box-sizing: border-box;
  487. background: linear-gradient(
  488. 186deg,
  489. rgba(50, 129, 246, 0.1) 6.16%,
  490. rgba(50, 129, 246, 0) 81.03%
  491. );
  492. }
  493. .floor-num {
  494. display: flex;
  495. justify-content: center;
  496. align-items: center;
  497. font-family: Persagy;
  498. font-size: 36px;
  499. font-weight: 700;
  500. line-height: 43px;
  501. color: #3b3558;
  502. width: 80px;
  503. flex-shrink: 0;
  504. }
  505. .floor-space {
  506. display: flex;
  507. flex: 1;
  508. flex-wrap: wrap;
  509. .space-box {
  510. padding: 4px;
  511. box-sizing: border-box;
  512. .space-name {
  513. display: flex;
  514. justify-content: center;
  515. align-items: center;
  516. //height: 86px;
  517. height: 100%;
  518. min-width: 20px;
  519. border-radius: 8px;
  520. background: #d9f5d6;
  521. text-align: center;
  522. padding:0 8px;
  523. box-sizing: border-box;
  524. }
  525. }
  526. }
  527. }
  528. </style>