index.vue 14 KB

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