map.vue 17 KB

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