map.vue 18 KB

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