home2.wpy 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  1. <style lang="less">
  2. .page-intelligent-control {
  3. position: relative;
  4. // height: 100%;
  5. width: 100%;
  6. box-sizing: border-box;
  7. overflow: hidden;
  8. .top-bar {
  9. height: 96px;
  10. background: #f7f8fa;
  11. }
  12. }
  13. .page-intelligent-control .map-contanier {
  14. // height: 100%;
  15. width: 100%;
  16. // padding-bottom: 176rpx;
  17. //background: #ebeef5;
  18. background: #f7f8fa;
  19. box-sizing: border-box;
  20. }
  21. .page-intelligent-control .location-wrapper {
  22. position: absolute;
  23. bottom: 36rpx;
  24. right: 32rpx;
  25. }
  26. .page-intelligent-control .location-wrapper .search-btn {
  27. margin-bottom: 16rpx;
  28. width: 96rpx;
  29. height: 96rpx;
  30. display: block;
  31. background: #ffffff;
  32. border-radius: 16rpx;
  33. }
  34. .page-intelligent-control .location-wrapper.expand {
  35. bottom: 658rpx;
  36. }
  37. movable-area {
  38. width: 100%;
  39. height: 0;
  40. position: relative;
  41. }
  42. movable-view {
  43. color: #fff;
  44. }
  45. .room-item {
  46. position: absolute;
  47. box-shadow: 0px 1px 4px rgba(1, 1, 51, 0.01),
  48. 0px 16px 40px rgba(1, 1, 51, 0.03);
  49. border-radius: 4px;
  50. box-sizing: border-box;
  51. padding: 0 12rpx;
  52. transform-origin: center;
  53. z-index: 1;
  54. &.isAbnormity {
  55. padding: 0;
  56. }
  57. }
  58. .room-item.selected {
  59. border: 2px solid rgba(77, 148, 255, 0.8);
  60. }
  61. .room-item.transparent {
  62. box-shadow: none;
  63. }
  64. .room-item.selected.transparent {
  65. border: 0;
  66. }
  67. .room-item.clickDisabled {
  68. border: 2px solid #dfe3ed;
  69. box-sizing: border-box;
  70. background-repeat: repeat;
  71. }
  72. .room-item .bg-disabled {
  73. width: 100%;
  74. height: 100%;
  75. border-radius: 4px;
  76. }
  77. .room-item .icon {
  78. width: 72rpx;
  79. height: 40rpx;
  80. position: absolute;
  81. top: 50%;
  82. left: 50%;
  83. transform: translateX(-50%) translateY(-50%);
  84. }
  85. .room-item .circle {
  86. width: 8rpx;
  87. height: 8rpx;
  88. border-radius: 50%;
  89. position: absolute;
  90. top: 50%;
  91. left: 50%;
  92. transform: translateX(-50%) translateY(-50%);
  93. }
  94. .room-item .door {
  95. position: absolute;
  96. width: 48rpx;
  97. height: 24rpx;
  98. }
  99. .room-item .text {
  100. font-weight: 600;
  101. font-size: 20rpx;
  102. line-height: 24rpx;
  103. text-align: center;
  104. color: #8995ba;
  105. position: absolute;
  106. top: 50%;
  107. left: 50%;
  108. width: 100%;
  109. transform: translateX(-50%) translateY(32rpx);
  110. padding: 0 16rpx;
  111. box-sizing: border-box;
  112. word-break: break-all;
  113. }
  114. .area-items-wrapper{
  115. position: relative;
  116. width: 100%;
  117. height: 100%;
  118. }
  119. .selected-icon {
  120. height: 88rpx;
  121. width: 144rpx;
  122. position: absolute;
  123. z-index: 9999;
  124. transform-origin: 36px 54px;//偏移量决定的
  125. }
  126. .room-item.selected .text {
  127. font-weight: 600;
  128. font-size: 24rpx;
  129. line-height: 24rpx;
  130. text-align: center;
  131. white-space: nowrap;
  132. color: #515a76;
  133. top: 50%;
  134. left: 50%;
  135. z-index: 2;
  136. width: auto;
  137. padding: 0;
  138. text-shadow: #fff 1px 0 0, #fff 0 1px 0, #fff -1px 0 0, #fff 0 -1px 0;
  139. transform: translateX(-50%) translateY(-50%);
  140. }
  141. .room-item.selected.ConferenceRoom {
  142. box-shadow: 0px 0px 4px rgba(1, 1, 51, 0.01),
  143. 0px 0px 40px rgba(1, 1, 51, 0.03);
  144. border-radius: 2px;
  145. border: 2px solid rgba(77, 148, 255, 0.42);
  146. }
  147. .office-content-abstract {
  148. position: absolute;
  149. bottom: 0;
  150. left: 0;
  151. right: 0;
  152. height: 238rpx;
  153. box-shadow: 0px 0px 2rpx rgba(0, 0, 0, 0.05),
  154. 0px 8rpx 30rpx rgba(0, 0, 0, 0.15);
  155. border-radius: 50rpx 50rpx 0px 0px;
  156. box-sizing: border-box;
  157. padding: 48rpx 48rpx 0;
  158. background: #ffffff;
  159. .title {
  160. font-weight: 600;
  161. font-size: 36rpx;
  162. line-height: 50rpx;
  163. color: #000000;
  164. }
  165. .btn-switch {
  166. position: absolute;
  167. top: 40rpx;
  168. right: 48rpx;
  169. width: 148rpx;
  170. height: 64rpx;
  171. font-weight: 500;
  172. font-size: 28rpx;
  173. line-height: 64rpx;
  174. color: #000000;
  175. background: #ffe823;
  176. text-align: center;
  177. box-shadow: 0px 0px 2rpx rgba(0, 0, 0, 0.15),
  178. 0px 8rpx 12rpx rgba(0, 0, 0, 0.07);
  179. border-radius: 60rpx;
  180. }
  181. }
  182. </style>
  183. <template>
  184. <div class="page-intelligent-control" v-on:click="flodFloorFun">
  185. <div class="top-bar"></div>
  186. <div class="map-contanier">
  187. <movable-area
  188. :style="{'height':mapParentHeight+'px','width':mapParentWidth+'px'}"
  189. scale-area="true"
  190. >
  191. <movable-view
  192. x="{{x}}"
  193. y="{{y}}"
  194. style="height:{{mapHeight}}px;width:{{mapWidth}}px"
  195. direction="all"
  196. out-of-bounds="false"
  197. bindscale="onScale"
  198. scale="true"
  199. scale-min="0.5"
  200. scale-max="1"
  201. scale-value="1"
  202. >
  203. <div class="area-items-wrapper">
  204. <block
  205. v-for="(area, index) in mapAreasInfo"
  206. :key="index"
  207. wx:if="{{area.floorId == selectedFloor}}"
  208. >
  209. <div
  210. @tap="selectAreaFun(area)"
  211. class="room-item {{area.isAbnormity? 'isAbnormity': ''}}"
  212. style="{{'width:'+ (area.isAbnormity? '0px;':area.width*mapScale +'px;') + 'height:'+(area.isAbnormity? '0px;':area.height*mapScale +'px;')+'left:'+area.left*mapScale+'px;'+'top:'+area.top*mapScale+'px;'+(area.isAbnormity?'': 'background-color:'+ area.backgroundColor+';'+(!area.canClick?('background-image:url(' +h5StaticPath+ 'map-icon/bg_disable.png);'): '')) + (area.isAbnormity?('border-top:' + area['borderWidth'][0]*mapScale +'px solid ' +area['borderColor'][0]+ ';' + 'border-right:' + area['borderWidth'][1]*mapScale+'px solid ' + area['borderColor'][1] +';' +'border-bottom:' + area['borderWidth'][2]*mapScale +'px solid ' +area['borderColor'][2] + ';' + 'border-left:' + area['borderWidth'][3]*mapScale +'px solid ' +area['borderColor'][3] + ';'):'')+ (area['borderRadius'] && area['borderRadius'].length? 'border-radius:' + area['borderRadius'][0]*mapScale + 'px ' + area['borderRadius'][1]*mapScale + 'px ' + area['borderRadius'][2]*mapScale + 'px ' + area['borderRadius'][3]*mapScale + 'px;': '')+(area.rotate?'transform:rotate('+area.rotate+'deg)': '')}}"
  213. :class="{'selected': selectArea.id === area.id, 'clickDisabled': area.canClick !==true,'transparent': !area.backgroundColor}"
  214. >
  215. <block wx:if="{{selectArea.id === area.id}}"></block>
  216. <block
  217. wx:elif="{{area.width*mapScale*touchScale>24&&area.height*mapScale*touchScale>24}}"
  218. >
  219. <image
  220. wx:if="{{area.icon}}"
  221. class="icon"
  222. src="{{h5StaticPath+ 'map-icon/' + area.icon}}"
  223. />
  224. </block>
  225. <block
  226. wx:elif="{{area.width*mapScale*touchScale>=24 || area.height*mapScale*touchScale>=24}}"
  227. >
  228. <div class="circle" style="{{'background-color:'+ area.circleColor+';'}}"></div>
  229. </block>
  230. <div
  231. class="text"
  232. wx:if="{{selectArea.id === area.id || (area.roomFuncType>=300 &&area.height*mapScale>80 && (area.title.length*screenScale*10 +16*screenScale)<area.width*mapScale)}}"
  233. >{{area.title}}</div>
  234. <image
  235. wx:if="{{area.has_door===true && selectArea.id !== area.id}}"
  236. style="width:{{area.door_width*mapScale}}px;height:{{area.door_height*mapScale}}px;left:{{(area.door_left === '') ? '': area.door_left*mapScale}}px;top: {{(area.door_top === '') ? '': area.door_top*mapScale}}px;right: {{(area.door_right === '') ? '': area.door_right*mapScale}}px;bottom: {{(area.door_bottom === '') ? '': area.door_bottom*mapScale}}px;"
  237. class="door"
  238. mode="scaleToFill"
  239. src="{{h5StaticPath+ 'map-icon/' +area.door_icon}}"
  240. />
  241. </div>
  242. </block>
  243. <image
  244. class="selected-icon"
  245. wx:if="{{selectArea}}"
  246. mode="scaleToFill"
  247. :style="{top: selectArea.isAbnormity? ((selectArea['borderWidth'][0]+selectArea['borderWidth'][2])/2 - selectArea['borderWidth'][0])*mapScale +'px' : (selectArea.top*mapScale-54 + (selectArea.height*mapScale/2))+'px', left: selectArea.isAbnormity? ((selectArea['borderWidth'][1]+selectArea['borderWidth'][3])/2 - selectArea['borderWidth'][3])*mapScale +'px': (selectArea.left*mapScale+(selectArea.width*mapScale/2)-36)+'px', transform: 'rotate('+(selectArea.rotate)+'deg)' }"
  248. src="{{h5StaticPath + 'map-icon/' + selectArea.selectIcon}}"
  249. />
  250. </div>
  251. </movable-view>
  252. <div class="{{'location-wrapper ' + foldStatus}}">
  253. <image
  254. v-on:click="toSearchPage"
  255. class="search-btn"
  256. src="{{h5StaticPath}}icon-search-big.svg"
  257. />
  258. <!-- 博锐尚格正式环境暂不显示该入口 -->
  259. <location
  260. v-if="isShowLocationEntrance"
  261. @component-location-position="positionFun($event)"
  262. ></location>
  263. <floor
  264. status="{{floorStatus}}"
  265. :floors="floors"
  266. selectedFloor="{{selectedFloor}}"
  267. @component-floor-fold="flodFloorFun"
  268. @component-floor-change="changeFloorFun($event)"
  269. @component-floor-click="toggleFloorStatus"
  270. ></floor>
  271. </div>
  272. </movable-area>
  273. </div>
  274. <!-- <block v-if="query.from && query.from=='officehome'">
  275. <div class="office-content-abstract">
  276. <div class="title">{{selectArea.title}}</div>
  277. <div class="btn-switch" v-on:click="goBack">切换</div>
  278. </div>
  279. </block>-->
  280. </div>
  281. </template>
  282. <script>
  283. import wepy from '@wepy/core';
  284. import store from '@/store';
  285. import {
  286. getMapInfoHttp,
  287. getSpaceBytoothHttp,
  288. getMapDetailHttp
  289. } from '@/packagesEnv/api/intelligentControl';
  290. import { checkHasUserInfo } from '@/service/user';
  291. import utils from '@/common/utils';
  292. import config from '@/config';
  293. import { mapState } from '@wepy/x';
  294. import { saveCompanyConfig } from '@/service/companyConfig';
  295. import { getCompanyMapData } from '@/api/home';
  296. let h5StaticPath = config.h5StaticPath + '/page-intelligent-control/';
  297. const tarBarHeight = 96;
  298. const panelExpandHeight = 407; // 单位为px
  299. const panelFoldHeight = 96; // 单位为px
  300. const switchPanelHeight = 145; // 单位为px
  301. const standerScreenWidth = 375;
  302. const standerMapHeight = 812 - tarBarHeight - panelFoldHeight; // 在375*812屏幕下地图所能展示区域的大小px
  303. let screenInfo = {};
  304. let standerMapWidth = 2336;
  305. let mapScale;
  306. let screenScale;
  307. let foldPanelPXHeight; // 在不同的手机屏幕的实际高度
  308. let expandPXHeight;
  309. let pageSelectedAreaRecord = {
  310. // key为楼层ID,value 为spceId
  311. };
  312. let touchMapStartRecord = {
  313. timeStamp: 0,
  314. pageX: 0,
  315. pageY: 0
  316. };
  317. let touchMapEndRecord = {
  318. timeStamp: 0,
  319. pageX: 0,
  320. pageY: 0
  321. };
  322. let from = 'officehome';
  323. let CompanyMapData;
  324. let combinedData = [];
  325. wepy.component({
  326. props: {
  327. spaceIdProp: '',
  328. companyIdProp: ''
  329. },
  330. store,
  331. data: {
  332. currentSp: '', // 空间id 用于路由跳转
  333. h5StaticPath,
  334. mapAreasInfo: [],
  335. selectArea: {},
  336. x: 0,
  337. y: 0,
  338. selectedFloor: '',
  339. foldStatus: 'fold', // fold-最小化 expand-展开状态
  340. floorStatus: 'fold', // flod-收起楼层 expand-展开楼层选则
  341. mapHeight: 507,
  342. mapParentHeight: 607,
  343. mapParentWidth: 375,
  344. mapWidth: 2336,
  345. mapScale: 1,
  346. screenScale: 1,
  347. mapMoveByTouch: false,
  348. touchScale: 1,
  349. isShowLocationEntrance: false,
  350. canSearchPerson: true,
  351. canSlideExpanel: true,
  352. pageHide: false,
  353. query: {},
  354. floors: [],
  355. companyId: ''
  356. },
  357. computed: {
  358. ...mapState({ userInfo: state => state.user.userInfo })
  359. },
  360. // ready() {
  361. // // let from = query.from;
  362. // // 页面加载
  363. // // this.canSearchPerson = query.from !== 'visit'; // 从访客进入的页面无法搜索人
  364. // // 如果从博瑞尚格智慧空间过来,面板是折叠起来,并且不能滑动
  365. // if (from == 'officehome') {
  366. // this.foldStatus = 'fold';
  367. // this.canSlideExpanel = false;
  368. // }
  369. // let qrcodeUrl = '';
  370. // // if (query.q) {
  371. // // qrcodeUrl = decodeURIComponent(query.q);
  372. // // let params = utils.getUrlParams(qrcodeUrl);
  373. // // }
  374. // // this.query = { ...query };
  375. // let queryId = '';
  376. // checkLogin()
  377. // .then(() => {
  378. // return this.getHistorySelectedArea();
  379. // })
  380. // .then(historyArea => {
  381. // let historyAreaInfo = data.find(e => e.id == historyArea.spaceId);
  382. // return getMapInfoHttp().then(res => {
  383. // const result = JSON.parse(res.data);
  384. // const httpDdata = (result && result.content) || [];
  385. // return {
  386. // historyArea,
  387. // httpDdata
  388. // };
  389. // });
  390. // })
  391. // .then(res => {
  392. // const { httpDdata, historyArea } = res;
  393. // let historyAreaInfo;
  394. // let selectarea;
  395. // let selectAraeId = queryId || historyArea.spaceId;
  396. // console.log('httpDdata----', httpDdata);
  397. // console.log('historyArea----', historyArea);
  398. // const combinedData = httpDdata.reduce((acc, cur) => {
  399. // const target = acc.find(e => e.id == cur.id);
  400. // selectarea = acc.find(e => e.id == selectAraeId);
  401. // if (target) {
  402. // Object.assign(target, { title: cur.localName });
  403. // // console.log('找到了', cur, index);
  404. // } else {
  405. // // console.log('data有没找到', cur.id);
  406. // }
  407. // if (target && target.id == selectAraeId) {
  408. // selectarea = { ...target }; // 如果有新数据,则更新选中的数据
  409. // }
  410. // return acc;
  411. // }, data);
  412. // this.mapAreasInfo = data;
  413. // // 如果从博瑞尚格智慧空间过来,面板是折叠起来,并且不能滑动
  414. // // if (from == 'officehome' && queryId) {
  415. // if (from == 'officehome') {
  416. // // this.foldPanelFun();
  417. // this.doSelectArea(selectarea);
  418. // // this.getSpaceTem();
  419. // } else {
  420. // this.autoSelectArea(selectarea);
  421. // }
  422. // });
  423. // getScreenInfo().then(res => {
  424. // this.screenScale = res.screenScale;
  425. // });
  426. // this.getMapScale().then(res => {
  427. // this.mapScale = res.mapScale;
  428. // this.mapWidth = Math.ceil(res.mapScale * standerMapWidth); // 因为有小数点的误差,故增加一部分
  429. // this.mapHeight = res.mapHeight;
  430. // this.mapParentHeight = res.mapHeight;
  431. // this.mapParentWidth = res.screenWidth;
  432. // });
  433. // },
  434. ready() {
  435. // 页面加载
  436. // let from = query.from;
  437. // this.canSearchPerson = query.from !== 'visit'; // 从访客进入的页面无法搜索人
  438. // 如果从博瑞尚格智慧空间过来,面板是折叠起来,并且不能滑动
  439. if (from == 'officehome') {
  440. this.foldStatus = 'fold';
  441. this.canSlideExpanel = false;
  442. }
  443. // let qrcodeUrl = '';
  444. // if (query.q) {
  445. // qrcodeUrl = decodeURIComponent(query.q);
  446. // let params = utils.getUrlParams(qrcodeUrl);
  447. // }
  448. // this.query = { ...query };
  449. checkHasUserInfo()
  450. .then((userInfo) => {
  451. // let companyId =
  452. // query.from !== 'visit' ? userInfo.companyId : query.companyId;
  453. let companyId = this.companyIdProp || userInfo.companyId;
  454. this.companyId = companyId;
  455. return getCompanyMapData(companyId);
  456. })
  457. .then((res) => {
  458. CompanyMapData = JSON.parse(res.data);
  459. this.selectedFloor = CompanyMapData.floorInfo[0].floorId;
  460. this.floors = CompanyMapData.floorInfo;
  461. this.isShowLocationEntrance = CompanyMapData.sagaCareBluetooth || false;
  462. this.getMapSize();
  463. return this.getHistorySelectedArea();
  464. })
  465. .then((historyArea) => {
  466. let historyAreaInfo = CompanyMapData.mapInfo.find(
  467. (e) => e.id == historyArea.spaceId
  468. );
  469. return getMapInfoHttp(this.companyId).then((res) => {
  470. const result = JSON.parse(res.data);
  471. const httpDdata = (result && result.content) || [];
  472. return {
  473. historyArea,
  474. httpDdata
  475. };
  476. });
  477. })
  478. .then((res) => {
  479. const { httpDdata, historyArea } = res;
  480. let historyAreaInfo;
  481. let selectarea;
  482. let selectAraeId = null;
  483. if (from == 'officehome') {
  484. selectAraeId = this.spaceIdProp
  485. } else {
  486. selectAraeId = historyArea.spaceId;
  487. }
  488. CompanyMapData.mapInfo.forEach((item) => {
  489. item.canClick = typeof item.canClick === 'boolean' ? item.canClick : JSON.parse(item.canClick)
  490. item.borderRadius =
  491. item.borderRadius ? item.borderRadius instanceof Array
  492. ? item.borderRadius
  493. : item.borderRadius
  494. .slice(2, item.borderRadius.length - 2)
  495. .split(',') : undefined;
  496. });
  497. combinedData = httpDdata.reduce((acc, cur) => {
  498. let target = acc.find((e) => e.id == cur.id);
  499. selectarea = acc.find((e) => e.id == selectAraeId);
  500. if (target) {
  501. Object.assign(target, { title: cur.localName });
  502. } else {
  503. }
  504. if (target && target.id == selectAraeId) {
  505. selectarea = { ...target }; // 如果有新数据,则更新选中的数据
  506. }
  507. return acc;
  508. }, CompanyMapData.mapInfo);
  509. this.mapAreasInfo = combinedData;
  510. // 如果从博瑞尚格智慧空间过来,面板是折叠起来,并且不能滑动
  511. if (from == 'officehome') {
  512. this.foldPanelFun();
  513. this.doSelectArea(selectarea);
  514. // this.getSpaceTem();
  515. } else {
  516. this.autoSelectArea(selectarea);
  517. }
  518. });
  519. },
  520. watch: {
  521. // 父亲传过来的空间id 搜索返回才会有这个传递
  522. spaceIdProp: function(newSpaceId, oldSpaceId) {
  523. if (oldSpaceId !== newSpaceId && newSpaceId) {
  524. let area = this.mapAreasInfo.find(item => {
  525. return item.id == newSpaceId;
  526. });
  527. area && this.doSelectArea(area, true);
  528. }
  529. }
  530. },
  531. // onShow() {
  532. // const lastSearchedSpace = wx.getStorageSync('lastSearchedSpace');
  533. // // 从搜索页面返回且搜索有效
  534. // if (lastSearchedSpace) {
  535. // let area = this.mapAreasInfo.find(item => {
  536. // return item.id == lastSearchedSpace.spaceId;
  537. // });
  538. // this.foldPanelFun();
  539. // this.doSelectArea(area);
  540. // // 清空,以免每次onshow时都执行(只需在从搜索页面返回时执行)
  541. // wx.removeStorageSync('lastSearchedSpace');
  542. // }
  543. // if (this.pageHide) {
  544. // this.pageHide = false;
  545. // }
  546. // },
  547. // onHide() {
  548. // this.pageHide = true;
  549. // },
  550. // onUnload() {
  551. // this.pageHide = true;
  552. // },
  553. methods: {
  554. getMapSize() {
  555. getScreenInfo().then(res => {
  556. this.screenScale = res.screenScale;
  557. });
  558. this.getMapScale().then(res => {
  559. this.mapScale = res.mapScale;
  560. this.mapWidth = Math.ceil(res.mapScale * CompanyMapData.mapWidth); // 因为有小数点的误差,故增加一部分
  561. this.mapHeight = res.mapHeight;
  562. this.mapParentHeight = res.mapHeight;
  563. this.mapParentWidth = res.screenWidth;
  564. });
  565. },
  566. setCacheSelectedArea(area) {
  567. const { selectedFloor } = this;
  568. wx.setStorage({
  569. key: 'SelectedASpace',
  570. data: {
  571. spaceId: area.id,
  572. floorId: selectedFloor
  573. },
  574. success: function() {}
  575. });
  576. // 选中一个并记录
  577. pageSelectedAreaRecord = {
  578. ...pageSelectedAreaRecord,
  579. [selectedFloor]: area.id
  580. };
  581. },
  582. setCacheSelectedFloor(floorId) {
  583. const { selectArea } = this;
  584. wx.setStorage({
  585. key: 'SelectedASpace',
  586. data: {
  587. floorId: floorId,
  588. spaceId: selectArea.floorId == floorId ? selectArea.id : ''
  589. },
  590. success: function() {}
  591. });
  592. },
  593. getHistorySelectedArea() {
  594. return new Promise((resolve, reject) => {
  595. wx.getStorage({
  596. key: 'SelectedASpace',
  597. success: res => {
  598. if (res.data && res.data.spaceId) {
  599. pageSelectedAreaRecord = {
  600. ...CompanyMapData.defalutSelectedId,
  601. [res.data.floorId]: res.data.spaceId // 如果有历史记录选中,覆盖值
  602. };
  603. resolve(res.data);
  604. } else {
  605. pageSelectedAreaRecord = CompanyMapData.defalutSelectedId;
  606. resolve({
  607. spaceId: CompanyMapData.defalutSelectedId[this.selectedFloor],
  608. floorId: this.selectedFloor
  609. });
  610. }
  611. },
  612. fail: () => {
  613. pageSelectedAreaRecord = CompanyMapData.defalutSelectedId;
  614. resolve({
  615. spaceId: CompanyMapData.defalutSelectedId[this.selectedFloor],
  616. floorId: this.selectedFloor
  617. });
  618. }
  619. });
  620. });
  621. },
  622. doSelectArea(area, sign) {
  623. if (!area) {
  624. return;
  625. }
  626. this.selectArea = area;
  627. this.selectedFloor = area.floorId;
  628. // this.getSpaceTem();
  629. this.setCacheSelectedArea(area);
  630. this.setAreaCenter(area);
  631. if (!sign) {
  632. // 如果是父亲传进来的areaId 不执行下面的触发
  633. this.$emit('mapChangeSpaceInfo', area.id); // 传给父组件,以请求数据
  634. }
  635. },
  636. selectAreaFun(currentSelect) {
  637. if (!currentSelect.canClick) {
  638. wx.showToast({
  639. title: '不可选区域',
  640. duration: 1000,
  641. icon: 'none'
  642. });
  643. return;
  644. }
  645. this.doSelectArea(currentSelect);
  646. },
  647. setAreaCenter(area) {
  648. if (!area.id) {
  649. return;
  650. }
  651. if (this.touchScale !== 1) {
  652. return;
  653. }
  654. getExpandPXHeight()
  655. .then(res => {
  656. const { expandPXHeight, screenHeight, screenWidth } = res;
  657. return this.getMapScale().then(res => {
  658. return {
  659. ...res,
  660. expandPXHeight,
  661. screenHeight,
  662. screenWidth
  663. };
  664. });
  665. })
  666. .then(res => {
  667. const { foldStatus } = this;
  668. const {
  669. screenHeight,
  670. screenWidth,
  671. expandPXHeight,
  672. mapScale,
  673. mapHeight
  674. } = res;
  675. let viewHeight = screenHeight - tarBarHeight - expandPXHeight;
  676. let viewCenterX = screenWidth / 2,
  677. viewCenterY = viewHeight / 2,
  678. areaCenterX =
  679. (parseInt(area.left) + parseInt(area.width) / 2) * mapScale,
  680. areaCenterY =
  681. (parseInt(area.top) + parseInt(area.height) / 2) * mapScale;
  682. let x = parseInt(viewCenterX - areaCenterX);
  683. let y = parseInt(viewCenterY - areaCenterY);
  684. let max = expandPXHeight - foldPanelPXHeight + 20;
  685. this.mapMoveByTouch = false;
  686. this.x = x > 0 ? 0 : x; // 超过边线设置边线值
  687. this.y =
  688. foldStatus === 'expand' ? (Math.abs(y) > max ? -max : y) : this.y; // 当面板展开时候,才需垂直居中
  689. // wx.showModal({
  690. // title: '提示', //提示的标题,
  691. // content: `x值:${this.x} y值:${y}`, //提示的内容,
  692. // showCancel: true, //是否显示取消按钮,
  693. // cancelText: '取消', //取消按钮的文字,默认为取消,最多 4 个字符,
  694. // cancelColor: '#000000', //取消按钮的文字颜色,
  695. // confirmText: '确定', //确定按钮的文字,默认为取消,最多 4 个字符,
  696. // confirmColor: '#3CC51F', //确定按钮的文字颜色,
  697. // success: res => {}
  698. // });
  699. this.mapHeight = screenHeight - tarBarHeight - foldPanelPXHeight; // 相当于加入底部空白,让面板被顶起来
  700. });
  701. },
  702. onScale(e) {
  703. this.touchScale = e.$wx.detail.scale;
  704. },
  705. foldPanelFun() {
  706. this.getMapHeight().then(res => {
  707. this.mapHeight = res.mapHeight;
  708. this.y = 0;
  709. });
  710. if (this.foldStatus === 'expand') {
  711. this.foldStatus = 'fold';
  712. }
  713. },
  714. expandPanelFun() {
  715. if (this.foldStatus === 'fold') {
  716. this.foldStatus = 'expand';
  717. this.setAreaCenter(this.selectArea);
  718. }
  719. },
  720. flodFloorFun() {
  721. if (this.floorStatus !== 'fold') {
  722. this.floorStatus = 'fold';
  723. }
  724. },
  725. changeFloorFun(floor) {
  726. wx.uma.trackEvent('officeHome_map-floorchange', {
  727. key: '环境调节-地图-楼层切换'
  728. });
  729. this.selectedFloor = floor;
  730. let spaceId = pageSelectedAreaRecord[floor];
  731. let area = this.mapAreasInfo.find(item => item.id == spaceId);
  732. // console.log("home",floor,this.mapAreasInfo,pageSelectedAreaRecord,area);
  733. if (from == 'officehome') {
  734. area && this.doSelectArea(area);
  735. }
  736. },
  737. toggleFloorStatus() {
  738. this.floorStatus = this.floorStatus === 'expand' ? 'fold' : 'expand';
  739. },
  740. positionFun(devices) {
  741. wx.uma.trackEvent('officeHome_map-location', {
  742. key: '环境调节-地图-定位'
  743. });
  744. getSpaceBytoothHttp(devices, this.companyId).then(res => {
  745. const result = JSON.parse(res.data || '{}');
  746. const data = (result && result.content && result.content[0]) || {};
  747. if (!data || (data && !data.id)) {
  748. wx.showToast({
  749. title: '未定位到空间', // 提示的内容,
  750. icon: 'none', // 图标,
  751. duration: 2000 // 延迟时间
  752. });
  753. return;
  754. }
  755. let mapInfo = this.mapAreasInfo.find(item => {
  756. return item.id === data.id;
  757. });
  758. this.doSelectArea({
  759. ...mapInfo,
  760. title: data.localName
  761. });
  762. });
  763. },
  764. toSearchPage() {
  765. wx.uma.trackEvent('officeHome_map-find', { key: '环境调节-地图-找找' });
  766. wx.navigateTo({
  767. url: `/packagesEnv/pages/intelligentControl/search/search?canSearchPerson=${this.canSearchPerson}&companyId=${this.companyId}&from=officehome`
  768. });
  769. },
  770. goBack() {
  771. wx.navigateBack({
  772. delta: 1 // 返回的页面数,如果 delta 大于现有页面数,则返回到首页,
  773. });
  774. },
  775. getfoldPanelPXHeight() {
  776. if (
  777. foldPanelPXHeight &&
  778. screenInfo &&
  779. screenInfo.screenWidth &&
  780. screenInfo.screenHeight
  781. ) {
  782. return Promise.resolve({
  783. foldPanelPXHeight,
  784. screenWidth: screenInfo.screenWidth,
  785. screenHeight: screenInfo.screenHeight
  786. });
  787. }
  788. return getScreenInfo().then(res => {
  789. let foldHeight =
  790. from == 'officehome' ? switchPanelHeight : panelFoldHeight;
  791. // foldPanelPXHeight = parseInt(res.screenScale * foldHeight);
  792. foldPanelPXHeight = parseInt(foldHeight);
  793. return {
  794. screenWidth: res.screenWidth,
  795. screenHeight: res.screenHeight,
  796. foldPanelPXHeight
  797. };
  798. });
  799. },
  800. getMapHeight() {
  801. return this.getfoldPanelPXHeight().then(res => {
  802. let mapHeight = res.screenHeight - tarBarHeight - res.foldPanelPXHeight;
  803. return {
  804. ...res,
  805. mapHeight
  806. };
  807. });
  808. },
  809. getMapScale() {
  810. return this.getMapHeight().then(res => {
  811. mapScale = Math.floor((res.mapHeight / standerMapHeight) * 10) / 10;
  812. return {
  813. ...res,
  814. mapScale
  815. };
  816. });
  817. }
  818. }
  819. });
  820. function getScreenInfo() {
  821. if (
  822. screenScale &&
  823. screenInfo &&
  824. screenInfo.screenWidth &&
  825. screenInfo.screenHeight
  826. ) {
  827. return Promise.resolve({
  828. ...screenInfo,
  829. screenScale
  830. });
  831. }
  832. return new Promise((resolve, reject) => {
  833. wx.getSystemInfo({
  834. success: res => {
  835. screenInfo.screenHeight = res.screenHeight;
  836. screenInfo.screenWidth = res.screenWidth;
  837. screenScale = res.screenWidth / standerScreenWidth;
  838. resolve({
  839. screenWidth: res.screenWidth,
  840. screenHeight: res.screenHeight,
  841. screenScale
  842. });
  843. }
  844. });
  845. });
  846. }
  847. function getExpandPXHeight() {
  848. if (
  849. expandPXHeight &&
  850. screenInfo &&
  851. screenInfo.screenWidth &&
  852. screenInfo.screenHeight
  853. ) {
  854. return Promise.resolve({
  855. expandPXHeight,
  856. screenWidth: screenInfo.screenWidth,
  857. screenHeight: screenInfo.screenHeight
  858. });
  859. }
  860. return getScreenInfo().then(res => {
  861. expandPXHeight = parseInt(res.screenScale * panelExpandHeight);
  862. return {
  863. screenWidth: res.screenWidth,
  864. screenHeight: res.screenHeight,
  865. expandPXHeight
  866. };
  867. });
  868. }
  869. </script>
  870. <config>
  871. {
  872. "navigationBarBackgroundColor": "#EBEEF5",
  873. "backgroundColor": "#EBEEF5",
  874. "disableScroll": true,
  875. "usingComponents": {
  876. "control-panel": "./components/controlpanel/controlpanel",
  877. "temperture-control-panel": "./components/temperturecontrolpanel/temperturecontrolpanel",
  878. "floor": "./components/floor/floor",
  879. "location": "./components/location/location"
  880. }
  881. }
  882. </config>