index.vue 13 KB

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