map.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  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 @click="goJoin" style=" flex: none; width: 60rpx;height: 60rpx;border-radius: 50%;" :src="indexVipImg" mode=""></image>
  34. </view>
  35. <view class="search-detail search-detail-input" style="z-index:9" v-if="search.openId==-2">
  36. <u-input placeholderStyle='color:#999' 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="index >= 2 && 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:1300rpx;">
  99. <hch-position ref="map" :geo="geo" @moveToMarkId="moveToMarkId" @rendered="mapRendered"/>
  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. <view style="width: calc(100% + 32rpx);margin-left: -16rpx;z-index:10">
  117. <scroll-hotel ref="scrollHotel" :hotelList="hotelList" @updateIndex="updateMapIndex" @goBook="goBook"/>
  118. </view>
  119. <view class="address-nav-button" @click="goLocation">
  120. <image style="width: 100rpx;height: 100rpx;" src="/static/icon/location.png" mode=""></image>
  121. </view>
  122. <view class="address-nav-button" @click="goHotelList">
  123. <image style="width: 100rpx;height: 100rpx;" src="/static/icon/list.png" mode=""></image>
  124. </view>
  125. </view>
  126. </view>
  127. <!-- 酒店列表 -->
  128. <view class="hotel-list" style="position: absolute;z-index:11;min-height:100%;padding-bottom: 80px;" v-if="!isShow">
  129. <view class="hotel-list-item" v-for="(item,index) in hotelList" :key="index" @click="goBook(item.id)">
  130. <view class="wrap">
  131. <view class="mark">
  132. <image style="width: 694rpx;height: 318rpx;border-radius: 10rpx;" :src="item.bg_img"
  133. mode=""></image>
  134. </view>
  135. <view class="inner">
  136. <view class="address-detail-main">
  137. <view class="address-detail-main-left">
  138. <text class="title">{{item.name}}</text>
  139. <view class="content" :style="{opacity: item.label?1:0}">
  140. <template v-if="item.label">
  141. <text v-for="(v,k) in item.label.split(',')" :key="k">{{v}}</text>
  142. </template>
  143. </view>
  144. <view class="bottom" :style="{opacity: item.min_price?1:0}">
  145. <text class="bottom-left">¥</text>
  146. <text class="bottom-right">{{item.min_price}}起</text>
  147. </view>
  148. </view>
  149. <view class="address-detail-main-right" @click.stop="goBook(index)">
  150. <text>预订</text>
  151. </view>
  152. </view>
  153. <view class="address-detail-position" v-if="item.distanceToMe">
  154. <image style="width: 18rpx;height: 22rpx;" src="/static/icon/address02.png" mode=""></image>
  155. <text style="margin-left:4rpx ;">{{item.distanceToMe}}km</text>
  156. </view>
  157. </view>
  158. </view>
  159. </view>
  160. <!-- 触底 -->
  161. <view class="home-bottom">
  162. <uni-load-more :status="status" color="#CCCCCC" :content-text="contentText" />
  163. </view>
  164. <view class="return-btn" @click="returnBtn">
  165. <image style="width: 100rpx;height: 100rpx;border-radius: 50%;" src="/static/icon/return01.png" mode="">
  166. </image>
  167. </view>
  168. </view>
  169. <view style="height: 110rpx;"></view>
  170. <tab-bar></tab-bar>
  171. </view>
  172. </template>
  173. <script>
  174. import TabBar from '../../components/TabBar/tabbar.vue'
  175. import HchPosition from '../../components/hch-position/hch-position.vue'
  176. import MyNav from "@/components/my-nav/my-nav.vue"
  177. import scrollHotel from "./scrollHotel.vue"
  178. import dialogPanel from "@/components/dialogPanel/dialogPanel.vue"
  179. export default {
  180. components: {
  181. TabBar,
  182. HchPosition,
  183. MyNav,
  184. scrollHotel,
  185. dialogPanel
  186. },
  187. data() {
  188. return {
  189. //vip图标
  190. indexVipImg:'',
  191. //跳转h5,小程序,其他页面
  192. jump_type: '',
  193. jump_config: {},
  194. //加入会员广告配置
  195. advise: '',
  196. scrolls:{scrollX: 0},
  197. hotelList:[],
  198. hotelListBase:[],
  199. //门店在地图上的标记 以下字段必填
  200. markers: [],
  201. //经纬度
  202. geo:{
  203. latitude: 30.6034799,
  204. longitude: 104.1132550,
  205. },
  206. latitude: 30.6034799,
  207. longitude: 104.1132550,
  208. //暂无数据
  209. status: 'noMore',
  210. contentText: {
  211. contentdown: '查看更多',
  212. contentrefresh: '加载中',
  213. contentnomore: '—— 已经到底啦 ——'
  214. },
  215. //是否展示地图
  216. isShow: true,
  217. value: [0],
  218. //搜索
  219. search:{
  220. content: {},
  221. text: "",
  222. openId:0,
  223. isSearch:false,
  224. selected:[],
  225. currentSelected:[],
  226. partner:0,
  227. checkedselected:[],
  228. },
  229. areaList: [],
  230. //激活指定table菜单
  231. isActive: 0,
  232. //展开搜索
  233. isopenSearch: false,
  234. //选择地区
  235. isSelectArea: true,
  236. //选择品牌
  237. isSelectBrand: true,
  238. //刷选
  239. isSelectSift: true,
  240. //是否展示合作伙伴
  241. isPartner: false,
  242. //是否展示加盟品牌
  243. isJoin: false,
  244. //滚动参数
  245. scrollData:{
  246. direct: -1,
  247. isScroll:false,
  248. spa: false,
  249. activeIndex:0
  250. },
  251. beginConfig:{
  252. isBegin: true,
  253. hotel_id: 0
  254. },
  255. randomNum: 0
  256. }
  257. },
  258. onShow() {
  259. this.admin = this.$store.getters.userInfo
  260. },
  261. onLoad(e) {
  262. const {hotel_id,category_ids} = e;
  263. this.beginConfig.hotel_id = hotel_id;
  264. if(category_ids){
  265. this.search.currentSelected = category_ids.split(",")
  266. this.search.selected = Object.assign(this.search.currentSelected)
  267. }
  268. //获取经纬度
  269. this.getHotelCategory()
  270. //vip跳转
  271. this.advise = this.$store.getters.allset.add_member
  272. this.indexVipImg = this.advise.value.map
  273. this.jump_type = this.advise.value.map_jump_type
  274. if (this.jump_type == 1) {
  275. this.jump_config = this.advise.value.map_h5_url
  276. } else if (this.jump_type == 2) {
  277. this.jump_config.appid = this.advise.value.map_appid
  278. this.jump_config.path = this.advise.value.map_path
  279. } else if (this.jump_type == 3) {
  280. this.jump_config = this.advise.value.map_other_path
  281. }
  282. },
  283. methods: {
  284. syncSearchInput(e){
  285. this.search.text = e
  286. },
  287. syncSelected(e){
  288. if(this.search.checkedselected.length > e.length){
  289. const resArr = this.$utils.arrayDiff(this.search.checkedselected, e)
  290. const tempSet = new Set(this.search.selected);
  291. resArr.forEach(i=>{
  292. tempSet.delete(i)
  293. })
  294. this.search.selected = Array.from(tempSet);
  295. }else{
  296. this.search.selected = Array.from(new Set([...this.search.selected, ...e]));
  297. }
  298. this.search.checkedselected = e;
  299. },
  300. checked(id) {
  301. if(this.search.selected.includes(id)){
  302. const tempSet = new Set(this.search.selected)
  303. tempSet.delete(id)
  304. this.search.selected = Array.from(tempSet)
  305. }else{
  306. this.search.selected.push(id)
  307. }
  308. },
  309. confirmSearch(){
  310. this.search.currentSelected = Object.assign(this.search.selected);
  311. this.getList();
  312. this.search.isSearch = true;
  313. this.search.openId = 0;
  314. },
  315. cancelSearch(){
  316. this.search.selected = Object.assign(this.search.currentSelected);
  317. this.search.openId = 0;
  318. },
  319. //打开选择器
  320. openSelector(id){
  321. if(this.search.openId == id){
  322. this.cancelSearch()
  323. }else{
  324. this.search.openId = id
  325. }
  326. },
  327. //获取筛选数据
  328. getHotelCategory(){
  329. this.$api.hotel.getHotelCategory().then(res=>{
  330. if(res.code !== 0) return;
  331. this.search.content = res.data;
  332. this.updated()
  333. })
  334. },
  335. goLocation(){
  336. uni.getLocation({
  337. type: "gcj02", //返回可以用于wx.openLocation的经纬度
  338. success: (res) => {
  339. this.randomNum = Math.floor(Math.random() * 100) / 1000000;
  340. this.geo = {
  341. latitude: res.latitude + this.randomNum,
  342. longitude: res.longitude
  343. }
  344. },
  345. fail: function(res) {
  346. console.log(res)
  347. }
  348. })
  349. },
  350. //在地图渲染更新完成时触发的方法
  351. updated() {
  352. uni.getLocation({
  353. type: "gcj02", //返回可以用于wx.openLocation的经纬度
  354. success: (res) => {
  355. this.randomNum = Math.floor(Math.random() * 100) / 1000000;
  356. this.geo = {
  357. latitude: res.latitude + this.randomNum,
  358. longitude: res.longitude
  359. }
  360. this.getList(true)
  361. //获取酒店列表
  362. },
  363. fail: function(res) {
  364. }
  365. })
  366. },
  367. //-------------------------------------
  368. requestHotelPage(tempobj){
  369. tempobj.page = tempobj.page + 1;
  370. this.$api.hotel.getHotelList({
  371. ...tempobj,
  372. }).then(res => {
  373. const tempHotelList = res.data.data.map(item=>{
  374. item.logo = this.$utils.toHttps(item.logo);
  375. return {
  376. ...item,
  377. marker:{
  378. id:item.id,
  379. latitude: item.latitude,
  380. longitude: item.longitude,
  381. iconPath: '../../static/icon/late02.png',
  382. activeIconPath: item.logo,
  383. width: '34rpx',
  384. height: '40rpx',
  385. }
  386. }
  387. })
  388. tempHotelList.map(item=>{
  389. item.distanceToMe=this.$utils.calcDistance(this.geo.latitude,this.geo.longitude,item.latitude,item.longitude).toFixed(1);
  390. return item;
  391. })
  392. this.hotelList.push(...tempHotelList)
  393. this.$refs.map.updateContent(tempHotelList, false);
  394. if(res.data.data.length >= 15){
  395. this.requestHotelPage(tempobj);
  396. }else if(this.beginConfig.hotel_id&&this.beginConfig.isBegin){
  397. let targetIndex = 0;
  398. for(const k in this.hotelList){
  399. if(this.hotelList[k].id == this.beginConfig.hotel_id){
  400. targetIndex = k;
  401. break;
  402. }
  403. }
  404. setTimeout(()=>{
  405. this.$refs.map.markertap(targetIndex, true, true);
  406. }, 1000)
  407. }
  408. })
  409. },
  410. getList(islocal = false) {
  411. const tempobj = {type: 1,page: 1,};
  412. if(this.search.currentSelected.length){
  413. this.search.currentSelected.forEach((item,index) => {
  414. tempobj[`category_ids[${index}]`] = item
  415. })
  416. }
  417. if(this.geo.latitude&&this.geo.longitude){
  418. tempobj['latitude'] = this.geo.latitude - this.randomNum;
  419. tempobj['longitude'] = this.geo.longitude;
  420. }
  421. if(this.search.text){
  422. tempobj['name'] = this.search.text;
  423. }
  424. this.$api.hotel.getHotelList({
  425. ...tempobj,
  426. }).then(res => {
  427. this.hotelList = res.data.data.map(item=>{
  428. item.logo = this.$utils.toHttps(item.logo);
  429. return {
  430. ...item,
  431. marker:{
  432. id:item.id,
  433. latitude: item.latitude,
  434. longitude: item.longitude,
  435. iconPath: '../../static/icon/late02.png',
  436. activeIconPath: item.logo,
  437. width: '34rpx',
  438. height: '40rpx',
  439. }
  440. }
  441. })
  442. this.hotelList.map((item,index)=>{
  443. item.distanceToMe = this.$utils.calcDistance(this.geo.latitude,this.geo.longitude,item.latitude,item.longitude).toFixed(1);
  444. return item;
  445. })
  446. this.$refs.map.updateContent(this.hotelList, true);
  447. if(res.data.data.length >= 15){
  448. this.requestHotelPage(tempobj)
  449. }else if(this.beginConfig.hotel_id&&this.beginConfig.isBegin){
  450. let targetIndex = 0;
  451. for(const k in this.hotelList){
  452. if(this.hotelList[k].id == this.beginConfig.hotel_id){
  453. targetIndex = k;
  454. break;
  455. }
  456. }
  457. setTimeout(()=>{
  458. this.$refs.map.markertap(targetIndex, true, true);
  459. }, 500)
  460. }
  461. })
  462. },
  463. mapRendered(){
  464. if((this.beginConfig.isBegin && !this.beginConfig.hotel_id)||this.search.isSearch){
  465. this.beginConfig.isBegin = false
  466. this.$refs.map.markertap(0,true,this.search.isSearch)
  467. this.search.isSearch = false
  468. }
  469. },
  470. //去预定页面
  471. goBook(index) {
  472. const hotel = this.hotelList[index];
  473. uni.navigateTo({
  474. url: `/pages/map/hotel-book/index?hotel_id=${hotel.id}&latitude=${hotel.latitude}&longitude=${hotel.longitude}&name=${hotel.name}&address=${hotel.address}`
  475. })
  476. },
  477. //返回上一级
  478. returnBtn() {
  479. this.isShow = !this.isShow
  480. },
  481. //打开酒店列表
  482. goHotelList() {
  483. this.isShow = !this.isShow
  484. },
  485. //是否展示加盟品牌
  486. selectJoin() {
  487. this.isJoin = !this.isJoin
  488. },
  489. //是否展示合作伙伴
  490. selectPartner() {
  491. this.isPartner = !this.isPartner
  492. },
  493. //合作伙伴刷选
  494. change(e) {
  495. },
  496. //展开筛选选择
  497. openSift() {
  498. this.isSelectSift = !this.isSelectSift
  499. },
  500. //下面酒店位移
  501. moveToMarkId(index){
  502. this.$refs.scrollHotel.setActiveIndex(index);
  503. },
  504. localToMark(markId,index){
  505. // this.moveToMarkId(markId)
  506. this.$refs.map.markertap({markerId: markId,index:index}, true)
  507. },
  508. bottomScroll(e){
  509. if(this.scrollData.spa) return;
  510. const moveX = e.detail.scrollLeft;
  511. this.scrollData.activeIndex = Math.floor((moveX + this.screenWidth) / 256) - 1;
  512. if(this.$refs.map.isActiveMarker == this.hotelList[this.scrollData.activeIndex].id) return;
  513. this.$refs.map.markertap({markerId: this.hotelList[this.scrollData.activeIndex].id,index: this.scrollData.activeIndex}, false)
  514. this.scrollData.spa = true;
  515. setTimeout(()=>{
  516. this.scrollData.spa = false;
  517. }, 300)
  518. },
  519. updateMapIndex(index){
  520. this.$refs.map.markertap(index, false)
  521. },
  522. moveToTabX(e){
  523. this.scrollData.spa = true;
  524. this.scrolls.scrollX = (256 * this.scrollData.activeIndex+1) - (this.screenWidth-256)/2 + 'px';
  525. setTimeout(()=>{
  526. this.scrollData.spa = false;
  527. }, 500)
  528. },
  529. scrollTolower(index){
  530. this.$refs.map.markertap({index:index}, false)
  531. this.scrollData.spa = true;
  532. setTimeout(()=>{
  533. this.scrollData.spa = false;
  534. }, 10)
  535. },
  536. //获取当前页面路径
  537. getPageUrl() {
  538. const pages = getCurrentPages();
  539. if(pages.length==1){
  540. const currentPage = pages[0];
  541. let pageUrl = `/${currentPage.route}`;
  542. return pageUrl
  543. }else{
  544. const currentPage = pages[pages.length - 1];
  545. let pageUrl = `/${currentPage.route}`;
  546. return pageUrl
  547. }
  548. },
  549. // 跳转其他小程序
  550. jumpHAppID(id, urls) {
  551. if (id == 1) {
  552. const url = urls; // 跳转的外链
  553. const navtitle = 'H5'; // 这个标题是你自己可以设置的
  554. uni.navigateTo({
  555. // 跳转到webview页面
  556. url: `/pages/webview/webview?url=${url}&nav=${navtitle}`,
  557. success: () => {
  558. console.log('成功')
  559. },
  560. fail: (e) => {
  561. console.log(e, "失败")
  562. }
  563. });
  564. } else if (id == 2) {
  565. let _this = this
  566. let obj = urls;
  567. console.log(obj, '----->obj');
  568. wx.navigateToMiniProgram({
  569. appId: `${obj.appid}`, //appid
  570. path: `${obj.path}`, //path
  571. extraData: { //参数
  572. foo: 'bar'
  573. },
  574. // envVersion: 'develop', //开发版develop 开发版 trial 体验版 release 正式版
  575. success(res) {
  576. let page = _this.getPageUrl()
  577. let user_id = ''
  578. if (_this.admin != null) {
  579. user_id = _this.admin.id
  580. } else {
  581. user_id = 0
  582. }
  583. _this.$api.my.userMemberAdd({
  584. user_id,
  585. page,
  586. }).then(res => {
  587. console.log(res.data);
  588. })
  589. // 打开成功
  590. },
  591. fail(e) {
  592. console.log(e, '失败')
  593. }
  594. })
  595. } else if (id == 3) {
  596. uni.redirectTo({
  597. url: urls,
  598. fail: (err) => {
  599. uni.reLaunch({
  600. url: urls
  601. })
  602. }
  603. })
  604. }
  605. },
  606. // 跳转其他小程序
  607. goJoin() {
  608. let _this = this
  609. this.jumpHAppID(this.jump_type, this.jump_config)
  610. },
  611. },
  612. }
  613. </script>
  614. <style lang="scss" src="./map.scss" scoped></style>