index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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" style="padding-top: 8upx;">
  22. <van-icon v-if="successlogion && hasLogin && msg_count>0" name="chat-o" color="#606266" size="24px" dot />
  23. <van-icon v-else name="chat-o" color="#606266" size="24px" />
  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 v-if="item.adv_code" 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 v-if="item.store_banner" 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. <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. msg_count: 0,
  134. timer:''
  135. }
  136. },
  137. computed:{
  138. ...mapState([
  139. 'hasLogin',
  140. 'userInfo',
  141. 'successlogion',
  142. 'beginload'
  143. ]),
  144. },
  145. onShow() {
  146. if(this.successlogion && this.hasLogin) {
  147. this.getuserinfo();
  148. this.firstget()
  149. }
  150. },
  151. onHide() {
  152. clearInterval(this.timer);
  153. this.timer = null;
  154. },
  155. onLoad() {
  156. if(this.beginload) {
  157. this.getpicture(); // 开机广告
  158. if(this.allow) {
  159. }else {
  160. this.gethotelist(); // 酒店列表
  161. }
  162. this.amapPlugin = new amap.AMapWX({
  163. key: this.key
  164. });
  165. this.isGetLocation(); // 检查是否开启定位权限
  166. this.isUserInfo(); // 检查是否允许获取用户授权
  167. this.getswiper(); // 获取首页轮播
  168. }
  169. if(this.successlogion && this.hasLogin) {
  170. this.firstget();
  171. this.getuserinfo();
  172. }
  173. },
  174. watch: {
  175. 'beginload':function(val) {
  176. this.getpicture(); // 开机广告
  177. this.amapPlugin = new amap.AMapWX({
  178. key: this.key
  179. });
  180. this.isGetLocation(); // 检查是否开启定位权限
  181. this.isUserInfo(); // 检查是否允许获取用户授权
  182. this.getswiper(); // 获取首页轮播
  183. },
  184. 'hasLogin':function(val) {
  185. if(val) {
  186. this.firstget();
  187. this.getuserinfo();
  188. }
  189. },
  190. },
  191. methods: {
  192. ...mapMutations(['login','showDialog']),
  193. firstget() {
  194. this.request({
  195. url:'/v2/member/info',
  196. method:'GET',
  197. success: (res)=>{
  198. this.msg_count = res.data.data.msg_count;
  199. }
  200. })
  201. },
  202. getuserinfo() {
  203. // let second = Math.round((Math.random()+1)*3);
  204. this.timer = setInterval(()=>{
  205. this.request({
  206. url:'/v2/member/info',
  207. method:'GET',
  208. success: (res)=>{
  209. this.msg_count = res.data.data.msg_count;
  210. }
  211. })
  212. }, 180000);
  213. },
  214. refeshadress() {
  215. this.isrefesh = false;
  216. this.getRegeo();
  217. },
  218. intToFloat(val) {
  219. return new Number(val).toFixed(1);
  220. },
  221. getpicture() {
  222. this.request({
  223. url: '/v1/entry/poster',
  224. method: 'get',
  225. success: (res) => {
  226. let { data } = res.data;
  227. this.images = data.images;
  228. this.enable = data.enable;
  229. }
  230. })
  231. },
  232. handler() {
  233. this.getAuthorizeInfo();
  234. },
  235. goinfor() {
  236. if(this.successlogion && this.hasLogin) {
  237. uni.navigateTo({
  238. url: '../myCenter/information' ,// 我的消息通知
  239. })
  240. }else {
  241. uni.navigateTo({
  242. url:'/pages/myCenter/logion'
  243. })
  244. } },
  245. goSearch() {
  246. let lat = this.lat;
  247. let lon = this.lot;
  248. uni.navigateTo({
  249. url: `/pages/index/searchresult?lat=${lat}&lon=${lon}`
  250. })
  251. },
  252. // 滚动到顶部
  253. upper(e) {
  254. },
  255. getop() {
  256.    this.scrollTop = this.old.scrollTop
  257.                 this.$nextTick(function(){
  258.                     this.scrollTop=0;
  259.                 });
  260. this.isTop = false;
  261. },
  262. // 滚到底部
  263. lower(e) {
  264. this.page = this.page + 1;
  265. if(this.ispull) {
  266. this.gethotelist();
  267. }
  268. },
  269. // 滚动时触发
  270. scroll(e) {
  271. if(e.detail.scrollTop > 400) {
  272. this.isTop = true;
  273. }else{ //当距离小于500时显示回到顶部按钮
  274. this.isTop = false;
  275. }
  276. this.old.scrollTop = e.detail.scrollTop
  277. },
  278. isGetLocation(a="scope.userLocation"){ // 检查当前是否已经授权访问scope属性W
  279. uni.getSetting({
  280. success:(res)=> {
  281. if (!res.authSetting[a]) { // 每次进入程序判断当前是否获得授权,如果没有就去获得授权,如果获得授权,就直接获取当前地理位置
  282. this.getAuthorizeInfo()
  283. }else{
  284. this.getRegeo()
  285. }
  286. }
  287. });
  288. },
  289. isUserInfo(b='scope.userInfo') {
  290. uni.getSetting({
  291. success:(res)=> {
  292. if(!res.authSetting[b]) {
  293. this.showDialog(false);
  294. }else {
  295. this.showDialog(true);
  296. let userInfo = uni.getStorageSync('userInfo');
  297. this.login(userInfo);
  298. }
  299. }
  300. })
  301. },
  302. getAuthorizeInfo(a="scope.userLocation"){ //uniapp弹窗弹出获取授权弹窗
  303. uni.authorize({
  304. scope: a,
  305. success:(res)=> { //允许授权
  306. this.getRegeo();
  307. },
  308. fail(){ //拒绝授权
  309. this.allow = true;
  310. this.$msg("你拒绝了授权,无法获得周边信息")
  311. }
  312. })
  313. },
  314. getRegeo(){
  315. let _this=this;
  316. uni.showLoading({
  317. title: '获取位置中'
  318. });
  319. _this.amapPlugin.getRegeo({
  320. success: (data) => {
  321. this.isrefesh = true;
  322. this.location = data[0].name;
  323. this.lat = data[0].latitude; // 经度
  324. this.lot = data[0].longitude; // 纬度
  325. this.allow = false;
  326. this.gethotelist();
  327. uni.hideLoading();
  328. },
  329. fail: (res) => {
  330. this.allow = true;
  331. uni.hideLoading();
  332. }
  333. });
  334. },
  335. // 获取首页轮播
  336. getswiper() {
  337. this.request({
  338.                 url:"/v1/entry/adv",
  339.                 method:'get',
  340. success: (res) => {
  341. this.backgroundlist = res.data.data;
  342. }
  343. })
  344. },
  345. // 获取酒店列表
  346. gethotelist() {
  347. this.request({
  348.                 url:"/v2/entry/storeList",
  349.                 method:'get',
  350. data: {
  351. page: this.page,
  352. page_size: 10,
  353. lat: this.lat,
  354. lon: this.lot
  355. },
  356. success: (res) => {
  357. let { data,code } = res.data;
  358. if(code == 1000) {
  359. if(data.store_list.length<10) {
  360. this.ispull = false;
  361. }
  362. data.store_list.forEach((items,index) => {
  363. items.tages = items.store_summary.split(' ');
  364. items.tageslist = [];
  365. items.tages.forEach((item,index) => {
  366. if(item!='') {
  367. items.tageslist.push(item);
  368. }
  369. })
  370. })
  371. if(this.hotelist.length == 0) {
  372. this.hotelist = data.store_list
  373. }else {
  374. this.hotelist = this.hotelist.concat(data.store_list);
  375. }
  376. }else {
  377. this.$msg("网络错误稍后再试")
  378. }
  379. }
  380. })
  381. },
  382. // 点击扫码
  383. scan(){
  384. uni.scanCode({
  385. success: (res) => {
  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>