map.vue 18 KB

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