index.vue 14 KB

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