index.vue 13 KB

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