index.vue 14 KB

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