index.vue 14 KB

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