index.vue 14 KB

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