index.vue 14 KB

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