index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <template>
  2. <view class="content">
  3. <view style="postion: fixed;top:0;">
  4. <uniNavBar class="top" :shadow="false" :fixed="false" color="#333333" background-color="#FFFFFF">
  5. <block style="width: 70%;padding-left: 32upx;" slot="left">
  6. <view class="city" v-if="!allow">
  7. <view style="font-size: 35upx;">
  8. <image @click="refeshadress" v-if="isrefesh" src="../../static/home_local.png" style="width: 40rpx;height: 45rpx;vertical-align: middle;padding-right:10upx;" ></image>
  9. <image @click="refeshadress" v-if="!isrefesh" src="../../static/home_local2.png" style="width: 40rpx;height: 45rpx;vertical-align: middle;padding-right:10upx;" ></image>
  10. {{ location }}
  11. </view>
  12. </view>
  13. <button plain="true" style="border: none;"
  14. v-if="allow" @opensetting='handler'
  15. open-type="openSetting" >定位失败,点击刷新</button>
  16. </block>
  17. <view class="input-view" style="float: right;visibility: hidden;">
  18. <uni-icon color="#606266" size="22" @click="scan" type="scan"></uni-icon>
  19. </view>
  20. <block slot="right">
  21. <view @click="goinfor">
  22. <uni-icon color="#606266" size="22" type="chat"></uni-icon>
  23. </view>
  24. </block>
  25. </uniNavBar>
  26. <view @click="goSearch" class="searchType" style="background: #fff;">
  27. <view class="input-view">
  28. <uni-icon type="search" size="22" color="#666666" />
  29. <view style="color: #999;">搜索您入住的酒店</view>
  30. <!-- <input placeholder-style="text-align: center;" confirm-type="search" class="input" type="text" placeholder="搜索您入住的酒店" disabled="true" /> -->
  31. </view>
  32. </view>
  33. </view>
  34. <scroll-view class="floor-list" style="height: 95vh;"
  35. :scroll-top="scrollTop" scroll-y="true" @scroll="scroll" @scrolltoupper="upper" @scrolltolower="lower"
  36. :refresher-enabled="false">
  37. <view class="scrollswiper">
  38. <swiper class="swiper"
  39. indicator-dots circular=true
  40. :autoplay="autoplay"
  41. :interval="interval"
  42. :duration="duration"
  43. >
  44. <swiper-item v-for="(item,index) in backgroundlist" :key="index">
  45. <view class="swiper-item" @tap="shopDetail(item)" >
  46. <image style="height: 100%;width: 100%;border-radius: 10upx;" :src='pictureUrl +"/uploads/home/adv/"+item.adv_code' />
  47. </view>
  48. </swiper-item>
  49. </swiper>
  50. </view>
  51. <view class="tips">
  52. <view style="font-weight: bold;font-size: 34rpx;">附近酒店</view>
  53. <view style="color: #909399;">在此找到您入住的酒店</view>
  54. </view>
  55. <view style="border-bottom: 2upx solid #EEEEEE;width: 100%;margin-bottom: 24upx 0;"></view>
  56. <view v-if="!allow">
  57. <view class="hotelList" v-for='(item,index) in hotelist' :key="index" @click="openinfo(item)">
  58. <view class="hotleLeft">
  59. <image style="width: 214upx;height: 152upx;border-radius: 10upx;" :src="pictureUrl+'/uploads/home/store/'+item.store_id+'/'+item.store_banner" />
  60. </view>
  61. <view class="hotelright">
  62. <view style="font-size: 28upx;color: #303133;font-weight: bold;">{{item.store_name}}
  63. </view>
  64. <view style="display: flex;flex-direction: row;justify-content: space-between;align-items: center;padding: 2rpx 0;">
  65. <view style="font-size: 46upx; color: #303133;font-weight: 900;">{{intToFloat(item.store_servicecredit)}}</view>
  66. <view style="color: #606266;font-size: 24upx;">月访客{{item.store_visitor}}</view>
  67. <view style="color: #606266;font-size: 24upx;">{{item.distance}}</view>
  68. </view>
  69. <view class="undertip">
  70. <view v-for="(items,index) in item.tageslist" :key="index" class="tipsTop">{{items}}</view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <view v-if="allow" style="text-align: center;margin: 100upx 0;">
  76. 定位失败暂时获取不到周边酒店信息哦
  77. </view>
  78. </scroll-view>
  79. <!-- || !successlogion-->
  80. <unipopup :images="images" v-if="enable == 1" :show="ishow"/>
  81. <Gobacktop @getop="getop" v-if="isTop" />
  82. </view>
  83. </template>
  84. <script>
  85. import {
  86. mapMutations,mapState
  87. } from 'vuex'
  88. import unipopup from '@/component/popup.vue'
  89. import uniNavBar from '@/component/uni-nav-bar/uni-nav-bar.vue'
  90. import uniIcon from '@/component/uni-icon/uni-icon.vue'
  91. import logionDialog from '@/component/loginDialog.vue'
  92. import amap from '@/common/amap-wx.js'
  93. import Gobacktop from '@/component/Gobacktop.vue'
  94. export default {
  95. components: {
  96. unipopup,
  97. uniNavBar,
  98. uniIcon,
  99. logionDialog,
  100. Gobacktop
  101. },
  102. data() {
  103. return {
  104. isrefesh: true,
  105. lat:'', // 经度
  106. lot: '', // 维度
  107. ishow: true,
  108. firstpoint: true,
  109. page: 1,
  110. ispull: true,
  111. pagesize: 10,
  112. store_summary:[], // 标签数组
  113. pictureUrl: this.pictureUrl,
  114. amapPlugin: null,
  115. key: '7277de7a5833626b7da8f2496e9d6bf9',
  116. showdialog: false, // 点击确定显示弹窗
  117. backgroundlist: ['color1', 'color2', 'color3'], // 轮播数组
  118. hotelist:[], // 酒店数组
  119. indicatorDots: true,
  120. autoplay: true,
  121. interval: 2000,
  122. duration: 500,
  123. title: 'Hello',
  124. location:'正在定位...',
  125. scrollTop: 0,
  126. isTop: false,
  127. old: {
  128. scrollTop: 0
  129. },
  130. allow: true,
  131. images: '', // 开机图片广告
  132. enable: '', // 是否展示广告
  133. }
  134. },
  135. computed:{
  136. ...mapState([
  137. 'hasLogin',
  138. 'userInfo',
  139. 'successlogion',
  140. 'beginload'
  141. ]),
  142. },
  143. onShow() {
  144. //this.getpicture();
  145. },
  146. onLoad() {
  147. if(this.beginload) {
  148. this.getpicture(); // 开机广告
  149. //this.gethotelist(); // 酒店列表
  150. if(this.allow) {
  151. }else {
  152. this.gethotelist(); // 酒店列表
  153. }
  154. this.amapPlugin = new amap.AMapWX({
  155. key: this.key
  156. });
  157. this.isGetLocation(); // 检查是否开启定位权限
  158. this.isUserInfo(); // 检查是否允许获取用户授权
  159. // 用户授全
  160. this.getswiper(); // 获取首页轮播
  161. }
  162. },
  163. watch: {
  164. 'allow': function(val) {
  165. if(val) {
  166. }else {
  167. //this.gethotelist(); // 酒店列表
  168. }
  169. },
  170. 'beginload':function(val) {
  171. this.getpicture(); // 开机广告
  172. // if(this.allow) {
  173. // }else {
  174. // this.gethotelist(); // 酒店列表
  175. // }
  176. this.amapPlugin = new amap.AMapWX({
  177. key: this.key
  178. });
  179. this.isGetLocation(); // 检查是否开启定位权限
  180. this.isUserInfo(); // 检查是否允许获取用户授权
  181. // 用户授全
  182. this.getswiper(); // 获取首页轮播
  183. }
  184. },
  185. methods: {
  186. ...mapMutations(['login','showDialog']),
  187. // 刷星定位
  188. refeshadress() {
  189. this.isrefesh = false;
  190. this.getRegeo();
  191. },
  192. intToFloat(val) {
  193. // body...
  194. return new Number(val).toFixed(1);
  195. },
  196. getpicture() {
  197. console.log("jdjdj")
  198. this.request({
  199. url: '/v1/entry/poster',
  200. method: 'get',
  201. success: (res) => {
  202. let { data } = res.data;
  203. this.images = data.images;
  204. this.enable = data.enable;
  205. }
  206. })
  207. },
  208. handler() {
  209. this.getAuthorizeInfo();
  210. },
  211. goinfor() {
  212. if(this.successlogion && this.hasLogin) {
  213. uni.navigateTo({
  214. url: '../myCenter/information' ,// 我的消息通知
  215. })
  216. }else {
  217. uni.navigateTo({
  218. url:'/pages/myCenter/logion'
  219. })
  220. // this.showdialog = true;
  221. } },
  222. //
  223. // // 关闭弹窗
  224. // cancelDiaolog() {
  225. // this.showdialog = false;
  226. // },
  227. // // 确定
  228. // confirmDiaolog() {
  229. // this.showdialog = false;
  230. // uni.navigateTo({
  231. // url: '../myCenter/information' // 我的收藏
  232. // })
  233. // },
  234. goSearch() {
  235. let lat = this.lat;
  236. let lon = this.lot;
  237. uni.navigateTo({
  238. url: `/pages/index/searchresult?lat=${lat}&lon=${lon}`
  239. })
  240. },
  241. // 滚动到顶部
  242. upper(e) {
  243. },
  244. getop() {
  245.    this.scrollTop = this.old.scrollTop
  246.                 this.$nextTick(function(){
  247.                     this.scrollTop=0;
  248.                 });
  249. this.isTop = false;
  250. },
  251. // 滚到底部
  252. lower(e) {
  253. this.page = this.page + 1;
  254. if(this.ispull) {
  255. this.gethotelist();
  256. }
  257. },
  258. // 滚动时触发
  259. scroll(e) {
  260. if(e.detail.scrollTop > 400) {
  261. this.isTop = true;
  262. }else{ //当距离小于500时显示回到顶部按钮
  263. this.isTop = false;
  264. }
  265. this.old.scrollTop = e.detail.scrollTop
  266. },
  267. isGetLocation(a="scope.userLocation"){ // 检查当前是否已经授权访问scope属性W
  268. let _this=this;
  269. uni.getSetting({
  270. success(res) {
  271. // 用户定位接口
  272. if (!res.authSetting[a]) { // 每次进入程序判断当前是否获得授权,如果没有就去获得授权,如果获得授权,就直接获取当前地理位置
  273. _this.getAuthorizeInfo()
  274. }else{
  275. _this.getRegeo()
  276. }
  277. }
  278. });
  279. },
  280. // 进入判断是否授权
  281. isUserInfo(b='scope.userInfo') {
  282. let _this = this;
  283. uni.getSetting({
  284. success(res) {
  285. if(!res.authSetting[b]) {
  286. _this.showDialog(false);
  287. }else {
  288. _this.showDialog(true);
  289. let userInfo = uni.getStorageSync('userInfo');
  290. _this.login(userInfo);
  291. }
  292. }
  293. })
  294. },
  295. getAuthorizeInfo(a="scope.userLocation"){ //uniapp弹窗弹出获取授权弹窗
  296. let _this=this;
  297. uni.authorize({
  298. scope: a,
  299. success(res) { //允许授权
  300. _this.getRegeo();
  301. },
  302. fail(){ //拒绝授权
  303. _this.allow = true;
  304. _this.$msg("你拒绝了授权,无法获得周边信息")
  305. }
  306. })
  307. },
  308. getRegeo(){ //获取地理位置
  309. let _this=this;
  310. uni.showLoading({
  311. title: '获取位置中'
  312. });
  313. _this.amapPlugin.getRegeo({
  314. success: (data) => {
  315. console.log(data);
  316. console.log(data.formatted_address);
  317. this.isrefesh = true;
  318. this.location = data[0].name;
  319. this.lat = data[0].latitude; // 经度
  320. this.lot = data[0].longitude; // 纬度
  321. this.allow = false;
  322. this.gethotelist();
  323. uni.hideLoading();
  324. },
  325. fail: (res) => {
  326. this.allow = true;
  327. uni.hideLoading();
  328. }
  329. });
  330. },
  331. // 获取首页轮播
  332. getswiper() {
  333. this.request({
  334.                 url:"/v1/entry/adv",
  335.                 method:'get',
  336. success: (res) => {
  337. this.backgroundlist = res.data.data;
  338. }
  339. })
  340. },
  341. // 获取酒店列表
  342. gethotelist() {
  343. this.request({
  344.                 url:"/v2/entry/storeList",
  345.                 method:'get',
  346. data: {
  347. page: this.page,
  348. page_size: 10,
  349. lat: this.lat,
  350. lon: this.lot
  351. },
  352. success: (res) => {
  353. let { data,code } = res.data;
  354. if(code == 1000) {
  355. if(data.store_list.length<10) {
  356. this.ispull = false;
  357. }
  358. // data.store_list.forEach(item => {
  359. // item.tages = item.store_summary.split(' ');
  360. // }) .replace(/(^\s*)|(\s*$)/g, "")
  361. data.store_list.forEach((items,index) => {
  362. items.tages = items.store_summary.split(' ');
  363. items.tageslist = [];
  364. items.tages.forEach((item,index) => {
  365. if(item!='') {
  366. items.tageslist.push(item);
  367. }
  368. })
  369. })
  370. if(this.hotelist.length == 0) {
  371. this.hotelist = data.store_list
  372. }else {
  373. this.hotelist = this.hotelist.concat(data.store_list);
  374. }
  375. }else {
  376. this.$msg("网络错误稍后再试")
  377. }
  378. }
  379. })
  380. },
  381. // 点击扫码
  382. scan(){
  383. uni.scanCode({
  384. success: (res) => {
  385. }
  386. });
  387. },
  388. // 跳转到新页面 酒店详情
  389. openinfo(item) {
  390. let id = item.store_id;
  391. uni.navigateTo({
  392. url: `/pages/index/hotel?id=${id}`
  393. });
  394. },
  395. // 跳转到商品详情
  396. shopDetail(item) {
  397. let id = item.adv_target.goods_id;
  398. let store_id = item.adv_target.store_id;
  399. if(item.adv_target.type == 'goods') {
  400. uni.navigateTo({
  401. url: `/pages/index/shop?id=${id}&store_id=${store_id}`
  402. });
  403. }else if(item.adv_target.type == 'store') {
  404. let id = item.adv_target.store_id;
  405. let title = item.adv_target.store_name;
  406. uni.navigateTo({
  407. url: `/pages/index/hotel?id=${id}`
  408. });
  409. }
  410. }
  411. }
  412. }
  413. </script>
  414. <style>
  415. .top .uni-navbar__header-btns {
  416. width: 77%!important;
  417. }
  418. .top .uni-navbar__header-container {
  419. width: 50%!important;
  420. }
  421. .content {
  422. background: #fff;
  423. }
  424. .city {
  425. width: 100%;
  426. height: 100%;
  427. white-space:nowrap;
  428. overflow:hidden;
  429. text-overflow:ellipsis;
  430. }
  431. .logo {
  432. height: 200upx;
  433. width: 200upx;
  434. margin-top: 200upx;
  435. margin-left: auto;
  436. margin-right: auto;
  437. margin-bottom: 50upx;
  438. }
  439. .text-area {
  440. display: flex;
  441. justify-content: center;
  442. }
  443. .title {
  444. font-size: 36upx;
  445. color: #8f8f94;
  446. }
  447. .van-cell--borderless {
  448. background-color: #e7e7e7!important;
  449. }
  450. .searchType .input-view {
  451. width: 85%;
  452. display: flex;
  453. background-color: #e7e7e7;
  454. height: 30px;
  455. border-radius: 15px;
  456. padding: 0 4%;
  457. flex-wrap: nowrap;
  458. margin: 7px 0;
  459. line-height: 30px;
  460. margin: 10upx auto;
  461. display: flex;
  462. justify-content: center
  463. }
  464. .searchType .input-view .uni-icon {
  465. line-height: 30px !important;
  466. }
  467. .searchType .input-view .input {
  468. height: 30px;
  469. line-height: 30px;
  470. width: 94%;
  471. padding: 0 3%;
  472. }
  473. .uni-navbar--border::after {
  474. background: #fff!important;
  475. }
  476. .swiper {
  477. height: 300upx;
  478. border-radius: 10upx;
  479. }
  480. .swiper-item {
  481. display: block;
  482. height: 300upx;
  483. line-height: 300upx;
  484. text-align: center;
  485. border-radius: 10upx;
  486. }
  487. swiper-item {
  488. border-radius: 15upx;
  489. }
  490. .swiper-item image {
  491. border-radius: 10upx;
  492. }
  493. .scrollswiper {
  494. width: 90%;
  495. margin: 20upx auto;
  496. border-radius: 10upx;
  497. }
  498. .tips {
  499. /* color: #303133;
  500. font-size: 28upx;
  501. text-align: center;
  502. margin: 24upx 0; */
  503. padding: 20upx 32upx 0 32upx;
  504. display: flex;
  505. justify-content: space-between;
  506. font-size: 30upx;
  507. }
  508. .hotelList {
  509. display: flex;
  510. flex-direction: row;
  511. padding: 24upx 32upx;
  512. }
  513. .hotleLeft {
  514. width: 214upx;
  515. height: 152upx;
  516. }
  517. .hotelright {
  518. padding-left: 16upx;
  519. display: flex;
  520. flex-direction: column;
  521. width: 100%;
  522. }
  523. .undertip {
  524. display: flex;
  525. flex-direction: row;
  526. align-items: center;
  527. }
  528. .tipsTop {
  529. border: 1upx solid #606266;
  530. margin-right: 12upx;
  531. color: #606266;
  532. font-size: 22rpx;
  533. border-radius: 5rpx;
  534. padding: 0rpx 5rpx;
  535. }
  536. .placeholdercenter {
  537. text-align: center;
  538. }
  539. </style>