index.vue 13 KB

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