index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <template>
  2. <view class="map-box">
  3. <search ref="searchRef" @handleSearch="handleSearch" v-if="showMap" />
  4. <tiandituMap ref="tiandituMapRefs" @handleSearch="$refs.searchRef.onSearchFocus()" @clickMap="handleClickMap"
  5. @moveMap="moveMapSearch" @onLoadTianDiTu="initMaps" @onSelect="selectPoint" :apiKey="apiKey"
  6. @handleMapSite="handleMapSite" @centre-text-callback="e => centreText = e" :siteListArr='siteListArr'
  7. :searchDot="searchDot" @openHint="$refs.HintContentRef.open()" @openFeedback="goPages('feedback')" />
  8. <Touchbox ref="TouchboxRef" :maxHeight="0.8" v-if="showMap && siteListArr && siteListArr.length > 0"
  9. :zIndex="1001" @currentHeight="e => TouchHeight = e">
  10. <template #touchSlot>
  11. <!-- <view class="centre-box" v-if="SearchText">
  12. <text class="text">为您展示</text>
  13. <text class="text-val one-row">{{SearchText}}</text>
  14. <text class="text">相关的大厅</text>
  15. </view> -->
  16. <view class="centre-box" v-if="SearchText || centreText">
  17. <svg t="1734080022350" class="position-icon" viewBox="0 0 1024 1024" version="1.1"
  18. xmlns="http://www.w3.org/2000/svg" p-id="4287" xmlns:xlink="http://www.w3.org/1999/xlink">
  19. <path d="M512 512m-80 0a80 80 0 1 0 160 0 80 80 0 1 0-160 0Z" p-id="4288"></path>
  20. <path
  21. d="M960 480h-33.632C910.752 276.16 747.84 113.248 544 97.632V64a32 32 0 1 0-64 0v33.632C276.16 113.248 113.248 276.16 97.632 480H64a32 32 0 0 0 0 64h33.632C113.248 747.84 276.16 910.752 480 926.368V960a32 32 0 1 0 64 0v-33.632C747.84 910.752 910.752 747.84 926.368 544H960a32 32 0 1 0 0-64zM544 862.368V800a32 32 0 1 0-64 0v62.368C311.424 847.104 176.896 712.576 161.632 544H224a32 32 0 1 0 0-64H161.632C176.896 311.424 311.424 176.896 480 161.632V224a32 32 0 0 0 64 0V161.632c168.576 15.296 303.104 149.792 318.368 318.368H800a32 32 0 1 0 0 64h62.368c-15.264 168.576-149.792 303.104-318.368 318.368z"
  22. p-id="4289"></path>
  23. </svg>
  24. <text class="text">为您展示</text>
  25. <text class="text-val one-row">{{SearchText || centreText}}</text>
  26. <text class="text">{{ SearchText ? '相关的大厅' : '附近的大厅'}}</text>
  27. </view>
  28. </template>
  29. <template #contentSlot>
  30. <!-- <scroll-view :style="{'height': getScrollHeight(TouchHeight , centreText)}" scroll-y="true" -->
  31. <scroll-view :style="{'height': TouchHeight + 'px'}" scroll-y="true" :show-scrollbar="false">
  32. <template v-for="(item , index) in siteListArr">
  33. <siteListModel :index="index" :info="item" @checkSiteDetails="handleMapSite" />
  34. </template>
  35. </scroll-view>
  36. </template>
  37. </Touchbox>
  38. <siteDetails ref="siteDetailsRef" />
  39. <!-- 提示 -->
  40. <HintContent ref="HintContentRef" />
  41. </view>
  42. </template>
  43. <script>
  44. import search from "./model/search.vue"
  45. import siteListModel from "./model/siteList.vue";
  46. import tools from '@/components/tiandituMap/tools.js'
  47. import { getMapCenterPoint_Api, getMapList_Api, getVisituvpv_Api } from "@/api/map.js"
  48. import siteDetails from "./model/siteDetails.vue"
  49. import $config from "@/config/index.js"
  50. import { EventBus } from "@/utils/vueBus.js"
  51. import { getLocation } from "@/utils/tool.js"
  52. import serviceCenter from "./model/service-center.vue"
  53. import HintContent from "./model/hint.vue"
  54. import { getUUID } from "@/utils/tool.js";
  55. export default {
  56. name: 'tdtmap',
  57. components: {
  58. search,
  59. siteListModel,
  60. serviceCenter,
  61. siteDetails,
  62. HintContent,
  63. },
  64. data() {
  65. return {
  66. //是否通过搜索查询点位
  67. searchDot: false,
  68. // 是否显示地图
  69. showMap: false,
  70. SearchText: '',
  71. longitude: undefined,
  72. latitude: undefined,
  73. apiKey: $config.tianKey,
  74. winWidth: 0,
  75. winHeight: 0,
  76. winTop: 0,
  77. datalist: [],
  78. startY: 0,
  79. selectItem: {},
  80. iStatusBarHeight: 0,
  81. siteListArr: [],
  82. TouchHeight: 0,
  83. centreText: null,
  84. centreTextHeight: uni.upx2px(80),
  85. searchContent: null
  86. }
  87. },
  88. created() {
  89. getLocation();
  90. this.getMapCenterPoint()
  91. },
  92. mounted() {
  93. const userLabel = getUUID();
  94. const refererStr = document.referrer;
  95. getVisituvpv_Api({
  96. userLabel,
  97. refererStr,
  98. })
  99. // setTimeout(() => {
  100. // console.log("this.$refs.SelectMapNavigationRef = " , this.$refs.SelectMapNavigationRef)
  101. // this.$refs.SelectMapNavigationRef.open()
  102. // }, 3000)
  103. this.disableScroll()
  104. },
  105. beforeDestroy() {
  106. try {
  107. document.removeEventListener('touchmove');
  108. document.body.removeEventListener('mousewheel');
  109. document.body.removeEventListener('DOMMouseScroll');
  110. document.removeEventListener('onmousewheel', function() {
  111. window.event.returnValue = false;
  112. });
  113. } catch (error) {
  114. //TODO handle the exception
  115. }
  116. },
  117. watch: {
  118. },
  119. methods: {
  120. // 获取地图中心点
  121. getMapCenterPoint() {
  122. uni.showLoading()
  123. this.showMap = false;
  124. getMapCenterPoint_Api().then(res => {
  125. const { longitude, latitude, mapTypeIcon } = res || {};
  126. this.longitude = longitude;
  127. this.latitude = latitude;
  128. this.open(longitude, latitude, mapTypeIcon);
  129. }).catch(err => { this.open(null, null) }).finally(() => {
  130. uni.hideLoading()
  131. })
  132. },
  133. open(lon, lat, mapTypeIcon) {
  134. if (lon && lat) {
  135. this.$nextTick(() => {
  136. this.$refs.tiandituMapRefs.initCharts(lon, lat, mapTypeIcon)
  137. this.showMap = true;
  138. })
  139. } else {
  140. uni.showModal({
  141. title: '提示',
  142. content: '地图中心点获取错误,请联系管理员!',
  143. success: res => {
  144. // console.log("showModal == ", res)
  145. if (res.confirm) {}
  146. }
  147. })
  148. }
  149. },
  150. handleSearch(val = {}) {
  151. const parms = {
  152. ...val,
  153. longitude: this.longitude,
  154. latitude: this.latitude,
  155. radius: 5000
  156. };
  157. // 记录搜索框中的内容
  158. this.SearchText = parms.locationName;
  159. // 判断是否通过收索
  160. this.searchDot = parms.search
  161. // 如果存在收索条件,则去掉 范围 和 中心点
  162. if (parms.locationName || parms.mapTypeId || parms.areaCode) {
  163. delete parms.radius
  164. // delete parms.latitude
  165. // delete parms.longitude
  166. }
  167. delete parms.search;
  168. this.searchContent = parms
  169. getMapList_Api(parms).then(res => {
  170. if (!res || res.length === 0) {
  171. uni.showToast({
  172. title: "当前区域无办理点位",
  173. icon: 'none'
  174. })
  175. }
  176. this.siteListArr = res || [];
  177. // this.$store.dispatch('map/updateDotInfo')
  178. // this.$store.dispatch('updateDotInfo')
  179. }).catch(err => {
  180. this.siteListArr = [];
  181. }).finally(() => {
  182. clearTimeout(this.SearchTimeout)
  183. this.SearchTimeout = null;
  184. })
  185. },
  186. getScrollHeight(TouchHeight, centreText) {
  187. const h = centreText ? this.centreTextHeight : 0
  188. return TouchHeight - h - 15 + 'px'
  189. },
  190. disableScroll() {
  191. if (typeof window.addEventListener === 'function') {
  192. document.addEventListener('touchmove', function(e) {
  193. e.preventDefault();
  194. }, { passive: false });
  195. document.body.addEventListener('mousewheel', function(e) {
  196. e.preventDefault();
  197. });
  198. document.body.addEventListener('DOMMouseScroll', function(e) {
  199. e.preventDefault();
  200. });
  201. } else {
  202. document.attachEvent('onmousewheel', function() {
  203. window.event.returnValue = false;
  204. });
  205. }
  206. },
  207. // 点击地图
  208. handleClickMap() {
  209. if (this.$refs.TouchboxRef) {
  210. this.$refs.TouchboxRef.concealList()
  211. }
  212. },
  213. // 点击地图标注点位
  214. handleMapSite(parmas = {}) {
  215. // const { Lng, Lat } = parmas;
  216. const Lng = parmas.Lng || parmas.longitude;
  217. const Lat = parmas.Lat || parmas.latitude;
  218. // const item = (this.siteListArr || []).find(el => el.longitude == Lng && el.latitude == Lat);
  219. // this.checkSiteDetails(item)
  220. const item = (this.siteListArr || []).find(el => el.longitude == Lng && el.latitude == Lat);
  221. if (item) {
  222. this.checkSiteDetails(item);
  223. this.$refs.tiandituMapRefs.Trenderjs.handleSiteList(this.siteListArr)
  224. }
  225. },
  226. // 查看点位详情
  227. checkSiteDetails(info) {
  228. if (info) {
  229. this.$refs.tiandituMapRefs.Trenderjs.SelectedDot(info, true)
  230. this.handleClickMap();
  231. this.$refs.siteDetailsRef.openDetails(info)
  232. }
  233. },
  234. moveMapSearch(parms) {
  235. const { Lng, Lat } = parms;
  236. this.longitude = Lng;
  237. this.latitude = Lat;
  238. this.$refs.searchRef.onSearchFocus()
  239. // console.log("moveMapSearch", Lng, Lat)
  240. },
  241. // //普通搜索
  242. // handleSearch(val = {}) {
  243. // const parms = {
  244. // ...val,
  245. // longitude: this.longitude,
  246. // latitude: this.latitude,
  247. // radius: 5000
  248. // };
  249. // getMapList_Api(parms).then(res => {
  250. // if (!res || res.length === 0) {
  251. // uni.showToast({
  252. // title: "当前区域无办理点位",
  253. // icon: 'none'
  254. // })
  255. // }
  256. // this.siteListArr = res || [];
  257. // }).catch(err => {
  258. // this.siteListArr = [];
  259. // })
  260. // },
  261. close() {
  262. this.visible = false
  263. },
  264. onConfirm() {
  265. if (Object.keys(this.selectItem).length) {
  266. this.visible = false
  267. this.$emit('onSelect', this.selectItem)
  268. } else {
  269. tools.createMessage('请选择位置')
  270. }
  271. },
  272. upDateLonLat(lon, lat) {
  273. if (lon && lat) {
  274. this.$refs.tiandituMapRefs.upDataCharts(lon, lat)
  275. } else {
  276. console.error('请传入lon, lat')
  277. }
  278. },
  279. tianidtuSearch(value) {
  280. if (value.city) {
  281. this.cityInfoSearch(value)
  282. } else {
  283. this.infoSearch(value)
  284. }
  285. },
  286. async infoSearch(value) { // 地理编码查询
  287. let params = {
  288. ds: {
  289. "keyWord": value.keyword,
  290. },
  291. tk: this.apiKey,
  292. }
  293. let resData = await tools.createRequest('https://api.tianditu.gov.cn/geocoder', params, true)
  294. if (resData.status === '0') {
  295. const location = resData.location
  296. const formateOne = tools.formatterAdressLocation(resData, 3)
  297. this.datalist = [formateOne]
  298. this.selectItem = datalist
  299. this.$refs.tiandituMapRefs.upDataCharts(location.lon, location.lat)
  300. }
  301. },
  302. async cityInfoSearch(value) { // 地名搜索2.0
  303. let params = {
  304. postStr: {
  305. "keyWord": value.keyword,
  306. "queryType": 12,
  307. "start": 0,
  308. "count": 10,
  309. "specify": value.city.value
  310. },
  311. type: 'query',
  312. tk: this.apiKey,
  313. }
  314. let resData = await tools.createRequest('https://api.tianditu.gov.cn/v2/search', params, true)
  315. if (resData.status.infocode === 1000) {
  316. const {
  317. pois: aPoints,
  318. count
  319. } = resData
  320. if (count === '0' || !aPoints || !aPoints.length) {
  321. return tools.createMessage('没有找到该地址')
  322. }
  323. const {
  324. pois,
  325. keyWord,
  326. lonlat
  327. } = aPoints[0]
  328. const formateData = aPoints.map((item) => tools.formatterAdressLocation(item, 2))
  329. this.datalist = formateData
  330. this.selectItem = formateData[0]
  331. const [lon, lat] = lonlat.split(',')
  332. this.$refs.tiandituMapRefs.upDataCharts(lon, lat)
  333. } else {
  334. tools.createMessage('数据异常', 1000, false, 'error')
  335. }
  336. },
  337. selectListItem(item) {
  338. this.$refs.tiandituMapRefs.upDataCharts(item.location.lon, item.location.lat)
  339. },
  340. selectPoint(e) {
  341. this.domMinHeight = '0vh'
  342. this.datalist = [e]
  343. this.selectItem = e
  344. },
  345. initMaps() {
  346. console.warn('--------天地图加载完成--------');
  347. this.$emit('onLoad')
  348. },
  349. // start(e) {
  350. // const clientY = e.changedTouches[0].clientY
  351. // this.startY = clientY
  352. // },
  353. // end(e) {
  354. // const transformY = e.changedTouches[0].clientY - this.startY;
  355. // switch (true) {
  356. // case transformY > 50:
  357. // console.log('下划')
  358. // this.domMaxHeight = '20vh'
  359. // this.domMinHeight = '0vh'
  360. // break;
  361. // case transformY < -50:
  362. // console.log('上划')
  363. // this.domMaxHeight = '50vh'
  364. // this.domMinHeight = '50vh'
  365. // break;
  366. // default:
  367. // break;
  368. // }
  369. // },
  370. selectCard(item) {
  371. this.domMaxHeight = '20vh'
  372. this.domMinHeight = '0vh'
  373. this.selectItem = item
  374. this.selectListItem(item)
  375. },
  376. setTouchHeight(val) {
  377. // console.log('setScrollHeight = ', val)
  378. // 实时返回的滑动组件高度
  379. this.TouchHeight = val;
  380. },
  381. setScrollMaxHeight(val) {
  382. //最大高度
  383. this.scrollMaxHeight = val;
  384. },
  385. // 页面跳转
  386. goPages() {
  387. // 'feedback'
  388. uni.navigateTo({
  389. url: "/pages/feedback/feedback"
  390. })
  391. }
  392. }
  393. }
  394. </script>
  395. <style lang="scss" scope>
  396. .map-box {
  397. width: 100vw;
  398. height: 100vh;
  399. /* position: fixed;
  400. left: 0;
  401. top:0;
  402. right: 0;
  403. bottom: 0; */
  404. }
  405. .mask {
  406. /* overflow: hidden; */
  407. position: fixed;
  408. left: 0;
  409. background-color: #FFFFFF;
  410. z-index: 399;
  411. }
  412. /* footer */
  413. .list-boxd {
  414. position: absolute;
  415. bottom: 0;
  416. left: 0;
  417. z-index: 401;
  418. right: 0;
  419. border-radius: 14px 14px 0 0;
  420. background: #FFFFFF;
  421. transition: all 1s;
  422. }
  423. .list-header {
  424. height: 20px;
  425. position: relative;
  426. border-bottom: 1px solid #f3f4f6;
  427. cursor: pointer;
  428. }
  429. .list-header::after {
  430. position: absolute;
  431. left: 50%;
  432. top: 50%;
  433. transform: translate(-50%, -50%);
  434. content: '';
  435. height: 6px;
  436. width: 60px;
  437. border-top: 1px solid #e8e8e8;
  438. border-bottom: 1px solid #e8e8e8;
  439. }
  440. .list-content {
  441. max-height: 50vh;
  442. overflow-y: scroll;
  443. }
  444. .card {
  445. min-height: 44px;
  446. padding: 12px;
  447. position: relative;
  448. display: flex;
  449. justify-content: space-between;
  450. align-items: center;
  451. }
  452. .card-left {
  453. display: flex;
  454. flex-direction: column;
  455. justify-content: center;
  456. }
  457. .card-right {
  458. padding-right: 10px;
  459. }
  460. .arrow {
  461. border-top: 2px solid #666666;
  462. border-right: 2px solid #666666;
  463. width: 10px;
  464. height: 10px;
  465. transform: rotate(45deg);
  466. }
  467. .card:active {
  468. background-color: #f3f4f6;
  469. }
  470. .card::after {
  471. position: absolute;
  472. content: '';
  473. bottom: 0;
  474. height: 1px;
  475. background-color: #e8e8e8;
  476. width: 90%;
  477. }
  478. .card:last-child::after {
  479. height: 0;
  480. background-color: #FFFFFF;
  481. }
  482. .card-title {
  483. font-size: 18px;
  484. }
  485. .card-text {
  486. color: #e8e8e8;
  487. font-size: 13px;
  488. }
  489. .centre-box {
  490. max-width: 100%;
  491. height: 77rpx;
  492. padding: 0 30rpx;
  493. display: inline-flex;
  494. align-items: center;
  495. .position-icon {
  496. flex-shrink: 0;
  497. width: 36rpx;
  498. margin-right: 10rpx;
  499. path {
  500. fill: #929292;
  501. }
  502. }
  503. text {
  504. flex-shrink: 0;
  505. font-size: 26rpx;
  506. color: #666666;
  507. font-weight: 700;
  508. }
  509. .text-val {
  510. flex: 1;
  511. flex-shrink: 0;
  512. color: #0090FF;
  513. padding: 0 5rpx;
  514. // display: flex;
  515. // align-items: center;
  516. // .text {
  517. // flex-shrink: 0;
  518. // flex: 1;
  519. // color: #329BF9;
  520. // padding: 0 5rpx;
  521. // }
  522. // font-size: 24rpx;
  523. // color: #329BF9;
  524. // padding: 0 5rpx;
  525. // // .one-row{
  526. // // width: auto;
  527. // // flex: 1;
  528. // // }
  529. }
  530. }
  531. </style>