index.vue 14 KB

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