index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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. // setTimeout( () => {
  241. // uni.pageScrollTo({
  242. // duration:0, //过渡时间必须为0,uniapp bug,否则运行到手机会报错
  243. // scrollTop: 0,
  244. // })
  245. // },300)
  246.    this.scrollTop = this.old.scrollTop
  247.                 this.$nextTick(function(){
  248.                     this.scrollTop=0;
  249.                 });
  250. this.isTop = false;
  251. },
  252. // 滚到底部
  253. lower(e) {
  254. this.page = this.page + 1;
  255. if(this.ispull) {
  256. this.gethotelist();
  257. }
  258. },
  259. // 滚动时触发
  260. scroll(e) {
  261. if(e.detail.scrollTop > 400) {
  262. this.isTop = true;
  263. }else{ //当距离小于500时显示回到顶部按钮
  264. this.isTop = false;
  265. }
  266. this.old.scrollTop = e.detail.scrollTop
  267. },
  268. isGetLocation(a="scope.userLocation"){ // 检查当前是否已经授权访问scope属性W
  269. let _this=this;
  270. uni.getSetting({
  271. success(res) {
  272. // 用户定位接口
  273. if (!res.authSetting[a]) { // 每次进入程序判断当前是否获得授权,如果没有就去获得授权,如果获得授权,就直接获取当前地理位置
  274. _this.getAuthorizeInfo()
  275. }else{
  276. _this.getRegeo()
  277. }
  278. }
  279. });
  280. },
  281. // 进入判断是否授权
  282. isUserInfo(b='scope.userInfo') {
  283. let _this = this;
  284. uni.getSetting({
  285. success(res) {
  286. if(!res.authSetting[b]) {
  287. _this.showDialog(false);
  288. }else {
  289. _this.showDialog(true);
  290. let userInfo = uni.getStorageSync('userInfo');
  291. _this.login(userInfo);
  292. }
  293. }
  294. })
  295. },
  296. getAuthorizeInfo(a="scope.userLocation"){ //uniapp弹窗弹出获取授权弹窗
  297. let _this=this;
  298. uni.authorize({
  299. scope: a,
  300. success(res) { //允许授权
  301. _this.getRegeo();
  302. },
  303. fail(){ //拒绝授权
  304. _this.allow = true;
  305. _this.$msg("你拒绝了授权,无法获得周边信息")
  306. }
  307. })
  308. },
  309. getRegeo(){ //获取地理位置
  310. let _this=this;
  311. uni.showLoading({
  312. title: '获取位置中'
  313. });
  314. _this.amapPlugin.getRegeo({
  315. success: (data) => {
  316. console.log(data);
  317. console.log(data.formatted_address);
  318. this.isrefesh = true;
  319. this.location = data[0].name;
  320. this.lat = data[0].latitude; // 经度
  321. this.lot = data[0].longitude; // 纬度
  322. this.allow = false;
  323. this.gethotelist();
  324. uni.hideLoading();
  325. },
  326. fail: (res) => {
  327. this.allow = true;
  328. uni.hideLoading();
  329. }
  330. });
  331. },
  332. // 获取首页轮播
  333. getswiper() {
  334. this.request({
  335.                 url:"/v1/entry/adv",
  336.                 method:'get',
  337. success: (res) => {
  338. this.backgroundlist = res.data.data;
  339. }
  340. })
  341. },
  342. // 获取酒店列表
  343. gethotelist() {
  344. this.request({
  345.                 url:"/v2/entry/storeList",
  346.                 method:'get',
  347. data: {
  348. page: this.page,
  349. page_size: 10,
  350. lat: this.lat,
  351. lon: this.lot
  352. },
  353. success: (res) => {
  354. let { data,code } = res.data;
  355. if(code == 1000) {
  356. if(data.store_list.length<10) {
  357. this.ispull = false;
  358. }
  359. // data.store_list.forEach(item => {
  360. // item.tages = item.store_summary.split(' ');
  361. // }) .replace(/(^\s*)|(\s*$)/g, "")
  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. // 跳转到新页面 酒店详情
  390. openinfo(item) {
  391. let id = item.store_id;
  392. uni.navigateTo({
  393. url: `/pages/index/hotel?id=${id}`
  394. });
  395. },
  396. // 跳转到商品详情
  397. shopDetail(item) {
  398. let id = item.adv_target.goods_id;
  399. let store_id = item.adv_target.store_id;
  400. if(item.adv_target.type == 'goods') {
  401. uni.navigateTo({
  402. url: `/pages/index/shop?id=${id}&store_id=${store_id}`
  403. });
  404. }else if(item.adv_target.type == 'store') {
  405. let id = item.adv_target.store_id;
  406. let title = item.adv_target.store_name;
  407. uni.navigateTo({
  408. url: `/pages/index/hotel?id=${id}`
  409. });
  410. }
  411. }
  412. }
  413. }
  414. </script>
  415. <style>
  416. .top .uni-navbar__header-btns {
  417. width: 77%!important;
  418. }
  419. .top .uni-navbar__header-container {
  420. width: 50%!important;
  421. }
  422. .content {
  423. background: #fff;
  424. }
  425. .city {
  426. width: 100%;
  427. height: 100%;
  428. white-space:nowrap;
  429. overflow:hidden;
  430. text-overflow:ellipsis;
  431. }
  432. .logo {
  433. height: 200upx;
  434. width: 200upx;
  435. margin-top: 200upx;
  436. margin-left: auto;
  437. margin-right: auto;
  438. margin-bottom: 50upx;
  439. }
  440. .text-area {
  441. display: flex;
  442. justify-content: center;
  443. }
  444. .title {
  445. font-size: 36upx;
  446. color: #8f8f94;
  447. }
  448. .van-cell--borderless {
  449. background-color: #e7e7e7!important;
  450. }
  451. .searchType .input-view {
  452. width: 85%;
  453. display: flex;
  454. background-color: #e7e7e7;
  455. height: 30px;
  456. border-radius: 15px;
  457. padding: 0 4%;
  458. flex-wrap: nowrap;
  459. margin: 7px 0;
  460. line-height: 30px;
  461. margin: 24upx auto;
  462. }
  463. .searchType .input-view .uni-icon {
  464. line-height: 30px !important;
  465. }
  466. .searchType .input-view .input {
  467. height: 30px;
  468. line-height: 30px;
  469. width: 94%;
  470. padding: 0 3%;
  471. }
  472. .uni-navbar--border::after {
  473. background: #fff!important;
  474. }
  475. .swiper {
  476. height: 300upx;
  477. }
  478. .swiper-item {
  479. display: block;
  480. height: 300upx;
  481. line-height: 300upx;
  482. text-align: center;
  483. }
  484. .scrollswiper {
  485. width: 90%;
  486. margin: 20upx auto;
  487. }
  488. .tips {
  489. /* color: #303133;
  490. font-size: 28upx;
  491. text-align: center;
  492. margin: 24upx 0; */
  493. padding: 20upx 32upx;
  494. display: flex;
  495. justify-content: space-between;
  496. font-size: 30upx;
  497. }
  498. .hotelList {
  499. display: flex;
  500. flex-direction: row;
  501. padding: 24upx 32upx;
  502. }
  503. .hotleLeft {
  504. width: 214upx;
  505. height: 152upx;
  506. }
  507. .hotelright {
  508. padding-left: 16upx;
  509. display: flex;
  510. flex-direction: column;
  511. width: 100%;
  512. }
  513. .undertip {
  514. display: flex;
  515. flex-direction: row;
  516. align-items: center;
  517. }
  518. .tipsTop {
  519. border: 2upx solid #606266;
  520. margin-right: 12upx;
  521. color: #606266;
  522. padding: 4upx;
  523. font-size: 24upx;
  524. border-radius: 4upx;
  525. padding: 0 3upx;
  526. }
  527. </style>