index.vue 14 KB

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