index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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. onLoad() {
  144. if(this.beginload) {
  145. this.getpicture(); // 开机广告
  146. //this.gethotelist(); // 酒店列表
  147. if(this.allow) {
  148. }else {
  149. this.gethotelist(); // 酒店列表
  150. }
  151. this.amapPlugin = new amap.AMapWX({
  152. key: this.key
  153. });
  154. this.isGetLocation(); // 检查是否开启定位权限
  155. this.isUserInfo(); // 检查是否允许获取用户授权
  156. // 用户授全
  157. this.getswiper(); // 获取首页轮播
  158. }
  159. },
  160. watch: {
  161. 'allow': function(val) {
  162. if(val) {
  163. }else {
  164. //this.gethotelist(); // 酒店列表
  165. }
  166. },
  167. 'beginload':function(val) {
  168. this.getpicture(); // 开机广告
  169. // if(this.allow) {
  170. // }else {
  171. // this.gethotelist(); // 酒店列表
  172. // }
  173. this.amapPlugin = new amap.AMapWX({
  174. key: this.key
  175. });
  176. this.isGetLocation(); // 检查是否开启定位权限
  177. this.isUserInfo(); // 检查是否允许获取用户授权
  178. // 用户授全
  179. this.getswiper(); // 获取首页轮播
  180. }
  181. },
  182. methods: {
  183. ...mapMutations(['login','showDialog']),
  184. // 刷星定位
  185. refeshadress() {
  186. this.isrefesh = false;
  187. this.getRegeo();
  188. },
  189. intToFloat(val) {
  190. // body...
  191. return new Number(val).toFixed(1);
  192. },
  193. getpicture() {
  194. this.request({
  195. url: '/v1/entry/poster',
  196. method: 'get',
  197. success: (res) => {
  198. let { data } = res.data;
  199. this.images = data.images;
  200. this.enable = data.enable;
  201. }
  202. })
  203. },
  204. handler() {
  205. this.getAuthorizeInfo();
  206. },
  207. goinfor() {
  208. if(this.successlogion && this.hasLogin) {
  209. uni.navigateTo({
  210. url: '../myCenter/information' ,// 我的消息通知
  211. })
  212. }else {
  213. uni.navigateTo({
  214. url:'/pages/myCenter/logion'
  215. })
  216. // this.showdialog = true;
  217. } },
  218. //
  219. // // 关闭弹窗
  220. // cancelDiaolog() {
  221. // this.showdialog = false;
  222. // },
  223. // // 确定
  224. // confirmDiaolog() {
  225. // this.showdialog = false;
  226. // uni.navigateTo({
  227. // url: '../myCenter/information' // 我的收藏
  228. // })
  229. // },
  230. goSearch() {
  231. let lat = this.lat;
  232. let lon = this.lot;
  233. uni.navigateTo({
  234. url: `/pages/index/searchresult?lat=${lat}&lon=${lon}`
  235. })
  236. },
  237. // 滚动到顶部
  238. upper(e) {
  239. },
  240. getop() {
  241.    this.scrollTop = this.old.scrollTop
  242.                 this.$nextTick(function(){
  243.                     this.scrollTop=0;
  244.                 });
  245. this.isTop = false;
  246. },
  247. // 滚到底部
  248. lower(e) {
  249. this.page = this.page + 1;
  250. if(this.ispull) {
  251. this.gethotelist();
  252. }
  253. },
  254. // 滚动时触发
  255. scroll(e) {
  256. if(e.detail.scrollTop > 400) {
  257. this.isTop = true;
  258. }else{ //当距离小于500时显示回到顶部按钮
  259. this.isTop = false;
  260. }
  261. this.old.scrollTop = e.detail.scrollTop
  262. },
  263. isGetLocation(a="scope.userLocation"){ // 检查当前是否已经授权访问scope属性W
  264. let _this=this;
  265. uni.getSetting({
  266. success(res) {
  267. // 用户定位接口
  268. if (!res.authSetting[a]) { // 每次进入程序判断当前是否获得授权,如果没有就去获得授权,如果获得授权,就直接获取当前地理位置
  269. _this.getAuthorizeInfo()
  270. }else{
  271. _this.getRegeo()
  272. }
  273. }
  274. });
  275. },
  276. // 进入判断是否授权
  277. isUserInfo(b='scope.userInfo') {
  278. let _this = this;
  279. uni.getSetting({
  280. success(res) {
  281. if(!res.authSetting[b]) {
  282. _this.showDialog(false);
  283. }else {
  284. _this.showDialog(true);
  285. let userInfo = uni.getStorageSync('userInfo');
  286. _this.login(userInfo);
  287. }
  288. }
  289. })
  290. },
  291. getAuthorizeInfo(a="scope.userLocation"){ //uniapp弹窗弹出获取授权弹窗
  292. let _this=this;
  293. uni.authorize({
  294. scope: a,
  295. success(res) { //允许授权
  296. _this.getRegeo();
  297. },
  298. fail(){ //拒绝授权
  299. _this.allow = true;
  300. _this.$msg("你拒绝了授权,无法获得周边信息")
  301. }
  302. })
  303. },
  304. getRegeo(){ //获取地理位置
  305. let _this=this;
  306. uni.showLoading({
  307. title: '获取位置中'
  308. });
  309. _this.amapPlugin.getRegeo({
  310. success: (data) => {
  311. console.log(data);
  312. console.log(data.formatted_address);
  313. this.isrefesh = true;
  314. this.location = data[0].name;
  315. this.lat = data[0].latitude; // 经度
  316. this.lot = data[0].longitude; // 纬度
  317. this.allow = false;
  318. this.gethotelist();
  319. uni.hideLoading();
  320. },
  321. fail: (res) => {
  322. this.allow = true;
  323. uni.hideLoading();
  324. }
  325. });
  326. },
  327. // 获取首页轮播
  328. getswiper() {
  329. this.request({
  330.                 url:"/v1/entry/adv",
  331.                 method:'get',
  332. success: (res) => {
  333. this.backgroundlist = res.data.data;
  334. }
  335. })
  336. },
  337. // 获取酒店列表
  338. gethotelist() {
  339. this.request({
  340.                 url:"/v2/entry/storeList",
  341.                 method:'get',
  342. data: {
  343. page: this.page,
  344. page_size: 10,
  345. lat: this.lat,
  346. lon: this.lot
  347. },
  348. success: (res) => {
  349. let { data,code } = res.data;
  350. if(code == 1000) {
  351. if(data.store_list.length<10) {
  352. this.ispull = false;
  353. }
  354. // data.store_list.forEach(item => {
  355. // item.tages = item.store_summary.split(' ');
  356. // }) .replace(/(^\s*)|(\s*$)/g, "")
  357. data.store_list.forEach((items,index) => {
  358. items.tages = items.store_summary.split(' ');
  359. items.tageslist = [];
  360. items.tages.forEach((item,index) => {
  361. if(item!='') {
  362. items.tageslist.push(item);
  363. }
  364. })
  365. })
  366. if(this.hotelist.length == 0) {
  367. this.hotelist = data.store_list
  368. }else {
  369. this.hotelist = this.hotelist.concat(data.store_list);
  370. }
  371. }else {
  372. this.$msg("网络错误稍后再试")
  373. }
  374. }
  375. })
  376. },
  377. // 点击扫码
  378. scan(){
  379. uni.scanCode({
  380. success: (res) => {
  381. }
  382. });
  383. },
  384. // 跳转到新页面 酒店详情
  385. openinfo(item) {
  386. let id = item.store_id;
  387. uni.navigateTo({
  388. url: `/pages/index/hotel?id=${id}`
  389. });
  390. },
  391. // 跳转到商品详情
  392. shopDetail(item) {
  393. let id = item.adv_target.goods_id;
  394. let store_id = item.adv_target.store_id;
  395. if(item.adv_target.type == 'goods') {
  396. uni.navigateTo({
  397. url: `/pages/index/shop?id=${id}&store_id=${store_id}`
  398. });
  399. }else if(item.adv_target.type == 'store') {
  400. let id = item.adv_target.store_id;
  401. let title = item.adv_target.store_name;
  402. uni.navigateTo({
  403. url: `/pages/index/hotel?id=${id}`
  404. });
  405. }
  406. }
  407. }
  408. }
  409. </script>
  410. <style>
  411. .top .uni-navbar__header-btns {
  412. width: 77%!important;
  413. }
  414. .top .uni-navbar__header-container {
  415. width: 50%!important;
  416. }
  417. .content {
  418. background: #fff;
  419. }
  420. .city {
  421. width: 100%;
  422. height: 100%;
  423. white-space:nowrap;
  424. overflow:hidden;
  425. text-overflow:ellipsis;
  426. }
  427. .logo {
  428. height: 200upx;
  429. width: 200upx;
  430. margin-top: 200upx;
  431. margin-left: auto;
  432. margin-right: auto;
  433. margin-bottom: 50upx;
  434. }
  435. .text-area {
  436. display: flex;
  437. justify-content: center;
  438. }
  439. .title {
  440. font-size: 36upx;
  441. color: #8f8f94;
  442. }
  443. .van-cell--borderless {
  444. background-color: #e7e7e7!important;
  445. }
  446. .searchType .input-view {
  447. width: 85%;
  448. display: flex;
  449. background-color: #e7e7e7;
  450. height: 30px;
  451. border-radius: 15px;
  452. padding: 0 4%;
  453. flex-wrap: nowrap;
  454. margin: 7px 0;
  455. line-height: 30px;
  456. margin: 10upx auto;
  457. display: flex;
  458. justify-content: center
  459. }
  460. .searchType .input-view .uni-icon {
  461. line-height: 30px !important;
  462. }
  463. .searchType .input-view .input {
  464. height: 30px;
  465. line-height: 30px;
  466. width: 94%;
  467. padding: 0 3%;
  468. }
  469. .uni-navbar--border::after {
  470. background: #fff!important;
  471. }
  472. .swiper {
  473. height: 300upx;
  474. border-radius: 10upx;
  475. }
  476. .swiper-item {
  477. display: block;
  478. height: 300upx;
  479. line-height: 300upx;
  480. text-align: center;
  481. border-radius: 10upx;
  482. }
  483. swiper-item {
  484. border-radius: 15upx;
  485. }
  486. .swiper-item image {
  487. border-radius: 10upx;
  488. }
  489. .scrollswiper {
  490. width: 90%;
  491. margin: 20upx auto;
  492. border-radius: 10upx;
  493. }
  494. .tips {
  495. /* color: #303133;
  496. font-size: 28upx;
  497. text-align: center;
  498. margin: 24upx 0; */
  499. padding: 20upx 32upx 0 32upx;
  500. display: flex;
  501. justify-content: space-between;
  502. font-size: 30upx;
  503. }
  504. .hotelList {
  505. display: flex;
  506. flex-direction: row;
  507. padding: 24upx 32upx;
  508. }
  509. .hotleLeft {
  510. width: 214upx;
  511. height: 152upx;
  512. }
  513. .hotelright {
  514. padding-left: 16upx;
  515. display: flex;
  516. flex-direction: column;
  517. width: 100%;
  518. }
  519. .undertip {
  520. display: flex;
  521. flex-direction: row;
  522. align-items: center;
  523. }
  524. .tipsTop {
  525. border: 1upx solid #606266;
  526. margin-right: 12upx;
  527. color: #606266;
  528. font-size: 22rpx;
  529. border-radius: 5rpx;
  530. padding: 0rpx 5rpx;
  531. }
  532. .placeholdercenter {
  533. text-align: center;
  534. }
  535. </style>