map.vue 19 KB

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