map.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. <template>
  2. <view class="map">
  3. <MyNav title="IHG地图" bgColor="" :backIcon="false"></MyNav>
  4. <!-- 查询 -->
  5. <view class="search" v-if="true">
  6. <view class="search-top" style="padding: 16rpx 30rpx 0rpx;margin-bottom: 20rpx;">
  7. <view class="search-loupe" @click="isopenSearch = !isopenSearch">
  8. <image style="width: 32rpx;height: 32rpx;" src="/static/icon/search02.png" mode=""></image>
  9. </view>
  10. <view class="search-area-all">
  11. <view :class="isSelectArea?'search-area':'search-areaClick'" @click="openArea">
  12. <text>地区</text>
  13. <image v-if="isSelectArea" style="width: 16rpx;height: 10rpx;" src="/static/icon/down01.png"
  14. mode="">
  15. </image>
  16. <image v-if="!isSelectArea" style="width: 16rpx;height: 10rpx;" src="/static/icon/up01.png"
  17. mode="">
  18. </image>
  19. </view>
  20. <view :class="isSelectBrand?'search-area':'search-areaClick'" @click="openBrand">
  21. <text>品牌</text>
  22. <image v-if="isSelectBrand" style="width: 16rpx;height: 10rpx;" src="/static/icon/down01.png"
  23. mode="">
  24. </image>
  25. <image v-if="!isSelectBrand" style="width: 16rpx;height: 10rpx;" src="/static/icon/up01.png"
  26. mode="">
  27. </image>
  28. </view>
  29. <view class="search-area" :class="isSelectSift?'search-area':'search-areaClick'" @click="openSift">
  30. <text>更多筛选</text>
  31. <image v-if="isSelectSift" style="width: 16rpx;height: 10rpx;" src="/static/icon/down01.png"
  32. mode="">
  33. </image>
  34. <image v-if="!isSelectSift" style="width: 16rpx;height: 10rpx;" src="/static/icon/up01.png"
  35. mode="">
  36. </image>
  37. </view>
  38. </view>
  39. <image style=" flex: none; width: 52rpx;height: 46rpx;" src="/static/icon/vip.png" mode=""></image>
  40. </view>
  41. <view class="search-detail" v-if="isopenSearch">
  42. <u-input placeholder="输入酒店/城市名称搜索酒店" border='none'>
  43. <template slot="suffix" style='margin-right:40rpx;'>
  44. <u-image :showLoading="true" :showError='true' src="/static/icon/search.png" width="40rpx"
  45. height="32rpx"></u-image>
  46. </template>
  47. </u-input>
  48. </view>
  49. <!-- 选择地区 -->
  50. <view class="search-detail" v-if="!isSelectArea">
  51. <view class="search-detail-area">
  52. <view class="areaTitle" v-for="(item,index) in search.content.area" :key="item.id" @click="checked(item.id,'area')">
  53. <view :class="{'active-area':search.area === item.id}">
  54. {{item.name}}
  55. </view>
  56. </view>
  57. </view>
  58. <view class="search-detail-btn">
  59. <view class="search-detail-btn-left">
  60. <text>取消</text>
  61. </view>
  62. <view class="search-detail-btn-right" @click="toSearchList">
  63. <text>确认</text>
  64. </view>
  65. </view>
  66. </view>
  67. <!-- 选择品牌-->
  68. <view class="search-detail" v-if="!isSelectBrand">
  69. <view class="search-detail-area">
  70. <view class="areaTitle" v-for="(item,index) in search.content.brand" :key="item.id" @click="checked(item.id,'brand')">
  71. <view :class="{'active-area':search.brand === item.id}">
  72. {{item.name}}
  73. </view>
  74. </view>
  75. </view>
  76. <view class="search-detail-btn">
  77. <view class="search-detail-btn-left">
  78. <text>取消</text>
  79. </view>
  80. <view class="search-detail-btn-right" @click="toSearchList">
  81. <text>确认</text>
  82. </view>
  83. </view>
  84. </view>
  85. <!-- 筛选-->
  86. <view class="search-detail" v-if="!isSelectSift">
  87. <view class="partner">
  88. <view class="partner-top" @click="selectPartner">
  89. <text>合作伙伴</text>
  90. <image v-if="isPartner" style=" width: 20rpx; height: 12rpx; " src="/static/icon/up02.png"
  91. mode=""></image>
  92. <image v-if="!isPartner" style=" width: 20rpx; height: 12rpx; " src="/static/icon/down02.png"
  93. mode=""></image>
  94. </view>
  95. <view class="partner-main" v-if="isPartner">
  96. <uni-data-checkbox multiple
  97. v-model="search.coop"
  98. :localdata="search.content.coop"
  99. emptyText="无"
  100. :map="{text: 'name',value: 'id'}"
  101. />
  102. </view>
  103. <view class="partner-top" style="border-top: none;" @click="selectJoin">
  104. <text>加盟品牌</text>
  105. <image v-if="isJoin" style=" width: 20rpx; height: 12rpx; " src="/static/icon/up02.png" mode="">
  106. </image>
  107. <image v-if="!isJoin" style=" width: 20rpx; height: 12rpx; " src="/static/icon/down02.png"
  108. mode=""></image>
  109. </view>
  110. <view class="partner-main" v-if="isJoin">
  111. <uni-data-checkbox multiple
  112. v-model="search.league"
  113. :localdata="search.content.league"
  114. emptyText="无"
  115. :map="{text: 'name',value: 'id'}"
  116. />
  117. </view>
  118. <view class="search-detail-btn">
  119. <view class="search-detail-btn-left">
  120. <text>取消</text>
  121. </view>
  122. <view class="search-detail-btn-right" @click="toSearchList">
  123. <text>确认</text>
  124. </view>
  125. </view>
  126. </view>
  127. </view>
  128. </view>
  129. <view class="address">
  130. <view style="height:1232rpx;">
  131. <hch-position ref="map" :markers="hotelList" @moveToMarkId="moveToMarkId"/>
  132. </view>
  133. <view class="address-nav" style="overflow-x: visible; height:318rpx;">
  134. <!-- 遮挡地图修正
  135. <view class="address-nav-btn">
  136. <view class="" @click="goLocation">
  137. <image style="width: 84rpx;height: 84rpx;" src="/static/icon/location.png" mode=""></image>
  138. </view>
  139. <view class="" @click="goHotelList">
  140. <image style="width: 84rpx;height: 84rpx;" src="/static/icon/list.png" mode=""></image>
  141. </view>
  142. </view>
  143. -->
  144. <view id="switch-container"
  145. style="width: 100%; overflow-x: scroll; display: none;align-items: center;justify-content: space-between;">
  146. </view>
  147. <scroll-view style="width: calc(100% + 16px);height:318rpx;white-space: nowrap;margin-left: -8px;"
  148. @scroll="bottomScroll" @scrolltolower="scrollTolower"
  149. :scroll-x="true" :scroll-left="scrolls.scrollX" :scroll-with-animation="true">
  150. <view style="width: 8px;display: inline-block;"></view>
  151. <view class="address-detail" v-for="(item,index) in hotelList" :key="index">
  152. <view class="mark">
  153. <image style=""
  154. :src="item.bg_img" mode="aspectFill"></image>
  155. </view>
  156. <view class="inner">
  157. <view class="address-detail-main">
  158. <view class="address-detail-main-left">
  159. <text class="title">{{item.name}}</text>
  160. <view class="content">
  161. <text>{{item.label}}</text>
  162. </view>
  163. <view class="bottom" v-if="item.min_price">
  164. <text class="bottom-left">¥</text>
  165. <text class="bottom-right">{{item.min_price}}起</text>
  166. </view>
  167. </view>
  168. <view class="address-detail-main-right" @click="goBook(index)">
  169. <text>预订</text>
  170. </view>
  171. </view>
  172. <view class="address-detail-position">
  173. <image style="width: 18rpx;height: 22rpx;" src="/static/icon/address02.png" mode="">
  174. </image>
  175. <text style="margin-left:4rpx ;">{{item.distanceToMe}}km</text>
  176. </view>
  177. </view>
  178. </view>
  179. <view style="width: 1px;display: inline-block;"></view>
  180. </scroll-view>
  181. <view class="address-nav-button" @click="goLocation">
  182. <image style="width: 84rpx;height: 84rpx;" src="/static/icon/location.png" mode=""></image>
  183. </view>
  184. <view class="address-nav-button" @click="goHotelList">
  185. <image style="width: 84rpx;height: 84rpx;" src="/static/icon/list.png" mode=""></image>
  186. </view>
  187. </view>
  188. </view>
  189. <!-- 酒店列表 -->
  190. <view class="hotel-list" style="position: absolute;" v-if="!isShow">
  191. <view class="hotel-list-item" v-for="(item,index) in hotelList" :key="index" @click="goBook(item.id)">
  192. <view class="wrap">
  193. <view class="mark">
  194. <image style="width: 694rpx;height: 318rpx;border-radius: 10rpx;" :src="item.bg_img"
  195. mode=""></image>
  196. </view>
  197. <view class="inner">
  198. <view class="address-detail-main">
  199. <view class="address-detail-main-left">
  200. <text class="title">{{item.name}}</text>
  201. <view class="content">
  202. <text>{{item.label}}</text>
  203. </view>
  204. <view class="bottom" v-if="item.min_price">
  205. <text class="bottom-left">¥</text>
  206. <text class="bottom-right">{{item.min_price}}起</text>
  207. </view>
  208. </view>
  209. <view class="address-detail-main-right" @click.stop="goBook(index)">
  210. <text>预订</text>
  211. </view>
  212. </view>
  213. <view class="address-detail-position">
  214. <image style="width: 18rpx;height: 22rpx;" src="/static/icon/address02.png" mode=""></image>
  215. <text style="margin-left:4rpx ;">{{item.distanceToMe}}km</text>
  216. </view>
  217. </view>
  218. </view>
  219. </view>
  220. <!-- 触底 -->
  221. <view class="home-bottom">
  222. <uni-load-more :status="status" color="#CCCCCC" :content-text="contentText" />
  223. </view>
  224. <view class="return-btn" @click="returnBtn">
  225. <image style="width: 132rpx;height: 132rpx;border-radius: 50%;" src="/static/icon/return01.png" mode="">
  226. </image>
  227. </view>
  228. </view>
  229. <view style="height: 110rpx;"></view>
  230. <tab-bar></tab-bar>
  231. </view>
  232. </template>
  233. <script>
  234. import TabBar from '../../components/TabBar/tabbar.vue'
  235. import HchPosition from '../../components/hch-position/hch-position.vue'
  236. import MyNav from "@/components/my-nav/my-nav.vue"
  237. export default {
  238. components: {
  239. TabBar,
  240. HchPosition,
  241. MyNav
  242. },
  243. data() {
  244. return {
  245. scrolls:{scrollX: 0},
  246. hotelList:[],
  247. hotelListBase:[],
  248. //门店在地图上的标记 以下字段必填
  249. markers: [],
  250. //经纬度
  251. latitude:'',
  252. longitude:'',
  253. //暂无数据
  254. status: 'noMore',
  255. contentText: {
  256. contentdown: '查看更多',
  257. contentrefresh: '加载中',
  258. contentnomore: '—— 已经到底啦 ——'
  259. },
  260. //是否展示地图
  261. isShow: true,
  262. value: [0],
  263. //合作伙伴
  264. partner: [{
  265. text: '足球',
  266. value: 0
  267. }, {
  268. text: '篮球',
  269. value: 1
  270. }, {
  271. text: '游泳',
  272. value: 2
  273. }, {
  274. text: '游泳',
  275. value: 3
  276. }, {
  277. text: '游泳',
  278. value: 4
  279. }, {
  280. text: '游泳',
  281. value: 5
  282. }, {
  283. text: '游泳',
  284. value: 6
  285. }, {
  286. text: '游泳',
  287. value: 7
  288. }, ],
  289. //品牌
  290. brandList: [{
  291. title: '谷歌'
  292. }, {
  293. title: '微软'
  294. }, {
  295. title: 'iphone'
  296. }, {
  297. title: '新希望'
  298. }, {
  299. title: '三江重工'
  300. }, {
  301. title: 'JavaScript'
  302. }],
  303. //地区
  304. search:{
  305. area: "",
  306. brand: "",
  307. coop: [],
  308. league: [],
  309. isActiveIds:[],
  310. content: {
  311. area: [],
  312. brand: [],
  313. coop: [],
  314. league: [],
  315. }
  316. },
  317. areaList: [],
  318. //激活指定table菜单
  319. isActive: 0,
  320. //展开搜索
  321. isopenSearch: false,
  322. //选择地区
  323. isSelectArea: true,
  324. //选择品牌
  325. isSelectBrand: true,
  326. //刷选
  327. isSelectSift: true,
  328. //是否展示合作伙伴
  329. isPartner: false,
  330. //是否展示加盟品牌
  331. isJoin: false,
  332. //滚动参数
  333. scrollData:{
  334. spa: false
  335. },
  336. }
  337. },
  338. onLoad() {
  339. //获取经纬度
  340. this.getHotelCategory()
  341. uni.getSystemInfo({
  342. success:(res)=>{
  343. this.screenWidth = res.screenWidth
  344. }
  345. })
  346. },
  347. methods: {
  348. //获取筛选数据
  349. getHotelCategory(){
  350. this.$api.hotel.getHotelCategory().then(res=>{
  351. if(res.code !== 0) return;
  352. this.search.content.area = res.data[0]?.sub;
  353. this.search.content.brand = res.data[1]?.sub;
  354. this.search.content.coop = res.data[2]?.sub;
  355. this.search.content.league = res.data[3]?.sub;
  356. this.updated()
  357. })
  358. },
  359. getArround(){
  360. },
  361. goLocation(){
  362. let _this = this
  363. uni.getLocation({
  364. type: "gcj02", //返回可以用于wx.openLocation的经纬度
  365. success: function(res) {
  366. _this.latitude = res.latitude
  367. _this.longitude = res.longitude
  368. _this.$refs.map.goLocation(res.latitude,res.longitude)
  369. // //获取酒店列表
  370. // _this.getList()
  371. },
  372. fail: function(res) {
  373. console.log(res)
  374. }
  375. })
  376. },
  377. //在地图渲染更新完成时触发的方法
  378. updated() {
  379. let _this = this
  380. uni.getLocation({
  381. type: "gcj02", //返回可以用于wx.openLocation的经纬度
  382. success: function(res) {
  383. _this.latitude = res.latitude
  384. _this.longitude = res.longitude
  385. _this.$refs.map.goLocation(res.latitude,res.longitude)
  386. _this.toSearchList(_this.latitude,_this.longitude)
  387. //获取酒店列表
  388. _this.getList()
  389. },
  390. fail: function(res) {
  391. }
  392. })
  393. },
  394. space(lat1, lng1, lat2, lng2) {
  395. var radLat1 = lat1 * Math.PI / 180.0;
  396. var radLat2 = lat2 * Math.PI / 180.0;
  397. var a = radLat1 - radLat2;
  398. var b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
  399. var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
  400. Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
  401. s = s * 6378.137;
  402. s = Math.round(s * 10000) / 10000;
  403. return s // 单位千米
  404. },
  405. //-------------------------------------
  406. //菜单index切换
  407. checked(id,categoreName) {
  408. this.search[categoreName] = id;
  409. },
  410. toSearchList(latitude, longitude){
  411. this.search.isActiveIds = [this.search.area,this.search.brand,...this.search.coop,...this.search.league]
  412. this.getList({latitude: latitude, longitude: longitude});
  413. },
  414. getList(param={}) {
  415. this.$api.hotel.getHotelList({
  416. page: 1,
  417. // 'category_ids[0]':this.search.isActiveIds,
  418. ...param
  419. }).then(res => {
  420. this.hotelList = res.data.data.map(item=>{
  421. return {
  422. ...item,
  423. marker:{
  424. id:item.id,
  425. latitude: item.latitude,
  426. longitude: item.longitude,
  427. width:'34rpx',
  428. height:'40rpx',
  429. iconPath:'../../static/icon/late02.png' ,
  430. active: {
  431. width: '90rpx',
  432. height: '100rpx',
  433. iconPath: item.logo,
  434. },
  435. noActive:{
  436. width:'34rpx',
  437. height:'40rpx',
  438. iconPath:'../../static/icon/late02.png' ,
  439. },
  440. callout1: {
  441. content:item.name,
  442. borderRadius: 10,
  443. padding: 10,
  444. display: "ALWAYS",
  445. },
  446. }
  447. }
  448. })
  449. this.hotelList.map(item=>{
  450. item.distanceToMe=this.space(this.latitude,this.longitude,item.latitude,item.longitude).toFixed(1);
  451. return item;
  452. })
  453. this.hotelList.sort((prev,next)=>{
  454. return prev.distanceToMe-next.distanceToMe;
  455. })
  456. console.log(this.hotelList[0].id)
  457. setTimeout(()=>{
  458. this.$refs.map.markertap({markerId: this.hotelList[0].id})
  459. }, 300)
  460. })
  461. },
  462. //去预定页面
  463. goBook(index) {
  464. if(!this.$store.getters.userInfo){
  465. uni.navigateTo({
  466. url: '/pages/login/login'
  467. })
  468. }
  469. const hotel = this.hotelList[index];
  470. uni.navigateTo({
  471. url: `/pages/map/hotel-book/index?hotel_id=${hotel.id}&latitude=${hotel.latitude}&longitude=${hotel.longitude}&name=${hotel.name}&address=${hotel.address}`
  472. })
  473. },
  474. //返回上一级
  475. returnBtn() {
  476. this.isShow = !this.isShow
  477. },
  478. //打开酒店列表
  479. goHotelList() {
  480. this.isShow = !this.isShow
  481. },
  482. //是否展示加盟品牌
  483. selectJoin() {
  484. this.isJoin = !this.isJoin
  485. },
  486. //是否展示合作伙伴
  487. selectPartner() {
  488. this.isPartner = !this.isPartner
  489. },
  490. //合作伙伴刷选
  491. change(e) {
  492. },
  493. //展开地区选择
  494. openArea() {
  495. this.isSelectArea = !this.isSelectArea
  496. this.isSelectBrand = true
  497. this.isSelectSift = true
  498. },
  499. //展开品牌选择
  500. openBrand() {
  501. this.isSelectBrand = !this.isSelectBrand
  502. this.isSelectArea = true
  503. this.isSelectSift = true
  504. },
  505. //展开筛选选择
  506. openSift() {
  507. this.isSelectSift = !this.isSelectSift
  508. this.isSelectBrand = true
  509. this.isSelectArea = true
  510. },
  511. //下面酒店位移
  512. moveToMarkId(markId){
  513. this.hotelList.forEach((item,index) => {
  514. if(markId == item.id){
  515. this.scrollData.spa = true;
  516. this.scrolls.scrollX = (256 * index) - (this.screenWidth-256)/2 + 'px';
  517. setTimeout(()=>{
  518. this.scrollData.spa = false
  519. },500)
  520. return;
  521. }
  522. })
  523. },
  524. bottomScroll(e){
  525. if(this.scrollData.spa) return;
  526. const moveX = e.detail.scrollLeft;
  527. const index = Math.floor((moveX + this.screenWidth) / 256) - 1;
  528. if(this.$refs.map.isActiveMarker == this.hotelList[index].id) return;
  529. this.$refs.map.markertap({markerId: this.hotelList[index].id}, false)
  530. this.scrollData.spa = true;
  531. setTimeout(()=>{
  532. this.scrollData.spa = false;
  533. }, 10)
  534. },
  535. scrollTolower(){
  536. this.$refs.map.markertap({markerId: this.hotelList[this.hotelList.length-1].id}, false)
  537. this.scrollData.spa = true;
  538. setTimeout(()=>{
  539. this.scrollData.spa = false;
  540. }, 10)
  541. }
  542. },
  543. }
  544. </script>
  545. <style lang="scss" src="./map.scss" scoped></style>