index.vue 14 KB

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