map.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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" @click="cancelSearch">
  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" @click="cancelSearch">
  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" @click="cancelSearch">
  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="bottomScroll" -->
  148. <scroll-view style="width: calc(100% + 16px);height:318rpx;white-space: nowrap;margin-left: -8px;"
  149. @scrolltolower="scrollTolower"
  150. @scroll="bottomScroll"
  151. :scroll-x="true"
  152. :scroll-left="scrolls.scrollX"
  153. :scroll-with-animation="true"
  154. :show-scrollbar="false"
  155. >
  156. <view style="width: 8px;display: inline-block;"></view>
  157. <view class="address-detail" v-for="(item,index) in hotelList" :key="index">
  158. <view class="mark">
  159. <image style=""
  160. :src="item.bg_img" mode="aspectFill"></image>
  161. </view>
  162. <view class="inner">
  163. <view class="address-detail-main">
  164. <view class="address-detail-main-left">
  165. <text class="title">{{item.name}}</text>
  166. <view class="content">
  167. <text>{{item.label}}</text>
  168. </view>
  169. <view class="bottom" v-if="item.min_price">
  170. <text class="bottom-left">¥</text>
  171. <text class="bottom-right">{{item.min_price}}起</text>
  172. </view>
  173. </view>
  174. <view class="address-detail-main-right" @click="goBook(index)">
  175. <text>预订</text>
  176. </view>
  177. </view>
  178. <view class="address-detail-position">
  179. <image style="width: 18rpx;height: 22rpx;" src="/static/icon/address02.png" mode="">
  180. </image>
  181. <text style="margin-left:4rpx ;">{{item.distanceToMe}}km</text>
  182. </view>
  183. </view>
  184. </view>
  185. <view style="width: 1px;display: inline-block;"></view>
  186. </scroll-view>
  187. <view class="address-nav-button" @click="goLocation">
  188. <image style="width: 84rpx;height: 84rpx;" src="/static/icon/location.png" mode=""></image>
  189. </view>
  190. <view class="address-nav-button" @click="goHotelList">
  191. <image style="width: 84rpx;height: 84rpx;" src="/static/icon/list.png" mode=""></image>
  192. </view>
  193. </view>
  194. </view>
  195. <!-- 酒店列表 -->
  196. <view class="hotel-list" style="position: absolute;" v-if="!isShow">
  197. <view class="hotel-list-item" v-for="(item,index) in hotelList" :key="index" @click="goBook(item.id)">
  198. <view class="wrap">
  199. <view class="mark">
  200. <image style="width: 694rpx;height: 318rpx;border-radius: 10rpx;" :src="item.bg_img"
  201. mode=""></image>
  202. </view>
  203. <view class="inner">
  204. <view class="address-detail-main">
  205. <view class="address-detail-main-left">
  206. <text class="title">{{item.name}}</text>
  207. <view class="content">
  208. <text>{{item.label}}</text>
  209. </view>
  210. <view class="bottom" v-if="item.min_price">
  211. <text class="bottom-left">¥</text>
  212. <text class="bottom-right">{{item.min_price}}起</text>
  213. </view>
  214. </view>
  215. <view class="address-detail-main-right" @click.stop="goBook(index)">
  216. <text>预订</text>
  217. </view>
  218. </view>
  219. <view class="address-detail-position">
  220. <image style="width: 18rpx;height: 22rpx;" src="/static/icon/address02.png" mode=""></image>
  221. <text style="margin-left:4rpx ;">{{item.distanceToMe}}km</text>
  222. </view>
  223. </view>
  224. </view>
  225. </view>
  226. <!-- 触底 -->
  227. <view class="home-bottom">
  228. <uni-load-more :status="status" color="#CCCCCC" :content-text="contentText" />
  229. </view>
  230. <view class="return-btn" @click="returnBtn">
  231. <image style="width: 132rpx;height: 132rpx;border-radius: 50%;" src="/static/icon/return01.png" mode="">
  232. </image>
  233. </view>
  234. </view>
  235. <view style="height: 110rpx;"></view>
  236. <tab-bar></tab-bar>
  237. </view>
  238. </template>
  239. <script>
  240. import TabBar from '../../components/TabBar/tabbar.vue'
  241. import HchPosition from '../../components/hch-position/hch-position.vue'
  242. import MyNav from "@/components/my-nav/my-nav.vue"
  243. export default {
  244. components: {
  245. TabBar,
  246. HchPosition,
  247. MyNav
  248. },
  249. data() {
  250. return {
  251. scrolls:{scrollX: 0},
  252. hotelList:[],
  253. hotelListBase:[],
  254. //门店在地图上的标记 以下字段必填
  255. markers: [],
  256. //经纬度
  257. latitude:'',
  258. longitude:'',
  259. //暂无数据
  260. status: 'noMore',
  261. contentText: {
  262. contentdown: '查看更多',
  263. contentrefresh: '加载中',
  264. contentnomore: '—— 已经到底啦 ——'
  265. },
  266. //是否展示地图
  267. isShow: true,
  268. value: [0],
  269. //地区
  270. search:{
  271. area: "",
  272. brand: "",
  273. coop: [],
  274. league: [],
  275. isActiveIds:[],
  276. content: {
  277. area: [],
  278. brand: [],
  279. coop: [],
  280. league: [],
  281. }
  282. },
  283. areaList: [],
  284. //激活指定table菜单
  285. isActive: 0,
  286. //展开搜索
  287. isopenSearch: false,
  288. //选择地区
  289. isSelectArea: true,
  290. //选择品牌
  291. isSelectBrand: true,
  292. //刷选
  293. isSelectSift: true,
  294. //是否展示合作伙伴
  295. isPartner: false,
  296. //是否展示加盟品牌
  297. isJoin: false,
  298. //滚动参数
  299. scrollData:{
  300. direct: -1,
  301. isScroll:false,
  302. spa: false,
  303. activeIndex:0
  304. },
  305. beginConfig:{
  306. first: true,
  307. hotel_id: 0
  308. }
  309. }
  310. },
  311. onLoad(e) {
  312. const {hotel_id,category_ids} = e;
  313. this.beginConfig.hotel_id = hotel_id;
  314. if(category_ids){
  315. this.search.isActiveIds = category_ids.split(",")
  316. }
  317. //获取经纬度
  318. this.getHotelCategory()
  319. uni.getSystemInfo({
  320. success:(res)=>{
  321. this.screenWidth = res.screenWidth
  322. }
  323. })
  324. },
  325. methods: {
  326. //获取筛选数据
  327. getHotelCategory(){
  328. this.$api.hotel.getHotelCategory().then(res=>{
  329. if(res.code !== 0) return;
  330. this.search.content.area = res.data[0]?.sub;
  331. this.search.content.brand = res.data[1]?.sub;
  332. this.search.content.coop = res.data[2]?.sub;
  333. this.search.content.league = res.data[3]?.sub;
  334. this.updated()
  335. })
  336. },
  337. goLocation(){
  338. let _this = this
  339. uni.getLocation({
  340. type: "gcj02", //返回可以用于wx.openLocation的经纬度
  341. success: function(res) {
  342. _this.latitude = res.latitude
  343. _this.longitude = res.longitude
  344. _this.$refs.map.goLocation(res.latitude,res.longitude)
  345. // //获取酒店列表
  346. // _this.getList()
  347. },
  348. fail: function(res) {
  349. console.log(res)
  350. }
  351. })
  352. },
  353. //在地图渲染更新完成时触发的方法
  354. updated() {
  355. let _this = this
  356. uni.getLocation({
  357. type: "gcj02", //返回可以用于wx.openLocation的经纬度
  358. success: function(res) {
  359. _this.latitude = res.latitude
  360. _this.longitude = res.longitude
  361. _this.$refs.map.goLocation(res.latitude,res.longitude)
  362. _this.toSearchList()
  363. //获取酒店列表
  364. },
  365. fail: function(res) {
  366. }
  367. })
  368. },
  369. space(lat1, lng1, lat2, lng2) {
  370. var radLat1 = lat1 * Math.PI / 180.0;
  371. var radLat2 = lat2 * Math.PI / 180.0;
  372. var a = radLat1 - radLat2;
  373. var b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
  374. var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
  375. Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
  376. s = s * 6378.137;
  377. s = Math.round(s * 10000) / 10000;
  378. return s;
  379. },
  380. //-------------------------------------
  381. //菜单index切换
  382. checked(id,categoreName) {
  383. this.search[categoreName] = id;
  384. },
  385. toSearchList(param={}){
  386. if(this.beginConfig.first){
  387. this.beginConfig.first = false;
  388. this.getList(param);
  389. return;
  390. }
  391. this.isSelectArea = true
  392. this.isSelectBrand = true
  393. this.isSelectSift = true
  394. this.search.isActiveIds = [...this.search.coop,...this.search.league]
  395. this.search.area && this.search.isActiveIds.push(this.search.area)
  396. this.search.brand && this.search.isActiveIds.push(this.search.brand)
  397. this.getList(param);
  398. },
  399. getList(param={}) {
  400. const tempobj = {};
  401. if(this.search.isActiveIds.length){
  402. tempobj['category_ids[0]'] = this.search.isActiveIds;
  403. }
  404. this.$api.hotel.getHotelList({
  405. page: 1,
  406. ...tempobj,
  407. ...param
  408. }).then(res => {
  409. this.hotelList = res.data.data.map(item=>{
  410. item.logo = this.$utils.toHttps(item.logo);
  411. return {
  412. ...item,
  413. marker:{
  414. id:item.id,
  415. latitude: item.latitude,
  416. longitude: item.longitude,
  417. width:'34rpx',
  418. height:'40rpx',
  419. iconPath:'../../static/icon/late02.png' ,
  420. active: {
  421. width: '90rpx',
  422. height: '100rpx',
  423. iconPath: item.logo,
  424. },
  425. noActive:{
  426. width:'34rpx',
  427. height:'40rpx',
  428. iconPath:'../../static/icon/late02.png' ,
  429. },
  430. callout1: {
  431. content:item.name,
  432. borderRadius: 10,
  433. padding: 10,
  434. display: "ALWAYS",
  435. },
  436. }
  437. }
  438. })
  439. if(res.data.data.length <= 0) return;
  440. this.hotelList.map(item=>{
  441. item.distanceToMe=this.space(this.latitude,this.longitude,item.latitude,item.longitude).toFixed(1);
  442. return item;
  443. })
  444. this.hotelList.sort((prev,next)=>{
  445. return prev.distanceToMe-next.distanceToMe;
  446. })
  447. setTimeout(()=>{
  448. if(this.beginConfig.hotel_id==0){
  449. this.$refs.map.markertap({markerId: this.hotelList[0].id})
  450. }else{
  451. this.localToMark(this.beginConfig.hotel_id);
  452. // this.$refs.map.markertap({markerId: this.beginConfig.hotel_id})
  453. this.beginConfig.hotel_id = 0
  454. }
  455. }, 300)
  456. })
  457. },
  458. //去预定页面
  459. goBook(index) {
  460. if(!this.$store.getters.userInfo){
  461. uni.navigateTo({
  462. url: '/pages/login/login'
  463. })
  464. }
  465. const hotel = this.hotelList[index];
  466. uni.navigateTo({
  467. url: `/pages/map/hotel-book/index?hotel_id=${hotel.id}&latitude=${hotel.latitude}&longitude=${hotel.longitude}&name=${hotel.name}&address=${hotel.address}`
  468. })
  469. },
  470. //返回上一级
  471. returnBtn() {
  472. this.isShow = !this.isShow
  473. },
  474. //打开酒店列表
  475. goHotelList() {
  476. this.isShow = !this.isShow
  477. },
  478. //是否展示加盟品牌
  479. selectJoin() {
  480. this.isJoin = !this.isJoin
  481. },
  482. //是否展示合作伙伴
  483. selectPartner() {
  484. this.isPartner = !this.isPartner
  485. },
  486. //合作伙伴刷选
  487. change(e) {
  488. },
  489. //展开地区选择
  490. openArea() {
  491. this.isSelectArea = !this.isSelectArea
  492. this.isSelectBrand = true
  493. this.isSelectSift = true
  494. },
  495. //展开品牌选择
  496. openBrand() {
  497. this.isSelectBrand = !this.isSelectBrand
  498. this.isSelectArea = true
  499. this.isSelectSift = true
  500. },
  501. //展开筛选选择
  502. openSift() {
  503. this.isSelectSift = !this.isSelectSift
  504. this.isSelectBrand = true
  505. this.isSelectArea = true
  506. },
  507. cancelSearch(){
  508. this.isSelectSift = true
  509. this.isSelectBrand = true
  510. this.isSelectArea = true
  511. },
  512. //下面酒店位移
  513. moveToMarkId(markId){
  514. this.hotelList.forEach((item,index) => {
  515. if(markId == item.id){
  516. this.scrollData.spa = true;
  517. this.scrolls.scrollX = (256 * index) - (this.screenWidth-256)/2 + 'px';
  518. setTimeout(()=>{
  519. this.scrollData.spa = false
  520. },500)
  521. return;
  522. }
  523. })
  524. },
  525. localToMark(markId){
  526. // this.moveToMarkId(markId)
  527. this.$refs.map.markertap({markerId: markId}, true)
  528. },
  529. bottomScroll(e){
  530. if(this.scrollData.spa) return;
  531. const moveX = e.detail.scrollLeft;
  532. this.scrollData.activeIndex = Math.floor((moveX + this.screenWidth) / 256) - 1;
  533. if(this.$refs.map.isActiveMarker == this.hotelList[this.scrollData.activeIndex].id) return;
  534. this.$refs.map.markertap({markerId: this.hotelList[this.scrollData.activeIndex].id}, false)
  535. this.scrollData.spa = true;
  536. setTimeout(()=>{
  537. this.scrollData.spa = false;
  538. }, 10)
  539. },
  540. moveToTabX(e){
  541. console.log(this.scrolls.scrollX)
  542. this.scrollData.spa = true;
  543. this.scrolls.scrollX = (256 * this.scrollData.activeIndex+1) - (this.screenWidth-256)/2 + 'px';
  544. console.log(this.scrolls.scrollX)
  545. setTimeout(()=>{
  546. this.scrollData.spa = false;
  547. }, 500)
  548. },
  549. scrollTolower(){
  550. this.$refs.map.markertap({markerId: this.hotelList[this.hotelList.length-1].id}, false)
  551. this.scrollData.spa = true;
  552. setTimeout(()=>{
  553. this.scrollData.spa = false;
  554. }, 10)
  555. }
  556. },
  557. }
  558. </script>
  559. <style lang="scss" src="./map.scss" scoped></style>