index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. <template>
  2. <view class="content">
  3. <view style="postion:sticky;top:0;">
  4. <uniNavBar class="top" :shadow="false" :fixed="false" color="#333333" background-color="#FFFFFF">
  5. <block style="width: 70%;padding-left: 32upx;" slot="left">
  6. <view class="city" v-if="!allow">
  7. <view style="font-size: 35upx;">
  8. <image
  9. @click="refeshadress"
  10. v-if="isrefesh"
  11. src="../../static/home_local.png"
  12. style="width: 40rpx;height: 45rpx;vertical-align: middle;padding-right:10upx;"
  13. ></image>
  14. <image
  15. @click="refeshadress"
  16. v-if="!isrefesh"
  17. src="../../static/home_local2.png"
  18. style="width: 40rpx;height: 45rpx;vertical-align: middle;padding-right:10upx;"
  19. ></image>
  20. {{ location }}
  21. </view>
  22. </view>
  23. <button class="btnOPne flex-box flex-v-ce" v-if="allow" @opensetting="handler" plain="true" open-type="openSetting">
  24. <image src="../../static/setting.png" style="width: 40rpx; height: 40rpx;padding-right: 6upx;"></image>
  25. 定位失败,开启权限
  26. </button>
  27. </block>
  28. <view class="input-view" style="float: right;"><uni-icon color="#606266" size="24" @click="scan" type="scan"></uni-icon></view>
  29. <block slot="right">
  30. <view @click="goinfor" style="padding-top: 8upx;">
  31. <van-icon v-if="successlogion && hasLogin && msg_count > 0" name="chat-o" color="#606266" size="24px" dot />
  32. <van-icon v-else name="chat-o" color="#606266" size="24px" />
  33. </view>
  34. </block>
  35. </uniNavBar>
  36. <view @click="goSearch" class="searchType" style="background: #fff;">
  37. <view class="input-view">
  38. <uni-icon type="search" size="22" color="#666666" />
  39. <view style="color: #999;">搜索您入住的酒店</view>
  40. </view>
  41. </view>
  42. </view>
  43. <scroll-view
  44. class="floor-list"
  45. style="height:calc(100vh - 172upx);"
  46. :scroll-top="scrollTop"
  47. scroll-y="true"
  48. @scroll="scroll"
  49. @scrolltoupper="upper"
  50. @scrolltolower="lower"
  51. :refresher-enabled="false"
  52. >
  53. <view class="scrollswiper">
  54. <swiper class="swiper" indicator-dots circular="true" :autoplay="autoplay" :interval="interval" :duration="duration">
  55. <swiper-item v-for="(item, index) in backgroundlist" :key="index">
  56. <view class="swiper-item" @tap="shopDetail(item)">
  57. <image v-if="item.adv_code" style="height: 100%;width: 100%;border-radius: 10upx;" :src="pictureUrl + '/uploads/home/adv/' + item.adv_code" />
  58. </view>
  59. </swiper-item>
  60. </swiper>
  61. </view>
  62. <view class="tips">
  63. <view style="font-weight: bold;font-size: 34rpx;">附近酒店</view>
  64. <view style="color: #909399;">在此找到您入住的酒店</view>
  65. </view>
  66. <view style="border-bottom: 2upx solid #EEEEEE;width: 100%;margin-bottom: 24upx 0;"></view>
  67. <view v-if="!allow">
  68. <view class="hotelList" v-for="(item, index) in hotelist" :key="index" @click="openinfo(item)">
  69. <view class="hotleLeft">
  70. <image
  71. v-if="item.store_banner"
  72. style="width: 214upx;height: 152upx;border-radius: 10upx;"
  73. :src="pictureUrl + '/uploads/home/store/' + item.store_id + '/' + item.store_banner"
  74. />
  75. </view>
  76. <view class="hotelright">
  77. <view style="font-size: 28upx;color: #303133;font-weight: bold;">{{ item.store_name }}</view>
  78. <view style="display: flex;flex-direction: row;justify-content: space-between;align-items: center;padding: 2rpx 0;">
  79. <view style="font-size: 46upx; color: #303133;font-weight: 900;">{{ intToFloat(item.store_servicecredit) }}</view>
  80. <view style="color: #606266;font-size: 24upx;">月访客{{ item.store_visitor }}</view>
  81. <view style="color: #606266;font-size: 24upx;">{{ item.distance }}</view>
  82. </view>
  83. <view class="undertip">
  84. <view v-for="(items, index) in item.tageslist" :key="index" class="tipsTop">{{ items }}</view>
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. <view v-if="allow" style="text-align: center;margin: 100upx 0;">
  90. <image src="../../static/no_lon.png" style="width: 140upx;height: 140upx;" @click="refeshadress"></image>
  91. <view style="color: #999;text-align: center;margin-bottom: 10upx;" @click="refeshadress">
  92. <view>定位失败</view>
  93. <view>请在手机上打开位置信息</view>
  94. <view>或直接搜索当前入住的酒店</view>
  95. </view>
  96. </view>
  97. </scroll-view>
  98. <unipopup :images="images" v-if="enable == 1" :show="ishow" />
  99. <Gobacktop @getop="getop" v-if="isTop" />
  100. </view>
  101. </template>
  102. <script>
  103. import { mapMutations, mapState } from 'vuex';
  104. import unipopup from '@/component/popup.vue';
  105. import uniNavBar from '@/component/uni-nav-bar/uni-nav-bar.vue';
  106. import uniIcon from '@/component/uni-icon/uni-icon.vue';
  107. import logionDialog from '@/component/loginDialog.vue';
  108. import amap from '@/common/amap-wx.js';
  109. import Gobacktop from '@/component/Gobacktop.vue';
  110. export default {
  111. components: {
  112. unipopup,
  113. uniNavBar,
  114. uniIcon,
  115. logionDialog,
  116. Gobacktop
  117. },
  118. data() {
  119. return {
  120. isrefesh: true,
  121. lat: '', // 经度
  122. lot: '', // 维度
  123. ishow: true,
  124. firstpoint: true,
  125. page: 1,
  126. ispull: true,
  127. pagesize: 10,
  128. store_summary: [], // 标签数组
  129. pictureUrl: this.pictureUrl,
  130. amapPlugin: null,
  131. key: '7277de7a5833626b7da8f2496e9d6bf9',
  132. showdialog: false, // 点击确定显示弹窗
  133. backgroundlist: ['color1', 'color2', 'color3'], // 轮播数组
  134. hotelist: [], // 酒店数组
  135. indicatorDots: true,
  136. autoplay: true,
  137. interval: 2000,
  138. duration: 500,
  139. title: 'Hello',
  140. location: '正在定位...',
  141. scrollTop: 0,
  142. isTop: false,
  143. old: {
  144. scrollTop: 0
  145. },
  146. allow: true,
  147. images: '', // 开机图片广告
  148. enable: '', // 是否展示广告
  149. msg_count: 0,
  150. timer: ''
  151. };
  152. },
  153. onShareAppMessage(res) {
  154. uni.showShareMenu({
  155. withShareTicket: true
  156. });
  157. let that = this;
  158. let id = this.goodId; // 酒店id
  159. if (res.from === 'button') {
  160. // 来自页面内分享按钮
  161. }
  162. return {
  163. title: '圈在网',
  164. path: `/pages/index/index`,
  165. imageUrl: that.store_slide[0]
  166. };
  167. },
  168. computed: {
  169. ...mapState(['hasLogin', 'userInfo', 'successlogion', 'beginload'])
  170. },
  171. onShow() {
  172. if (this.successlogion && this.hasLogin) {
  173. this.firstget();
  174. }
  175. this.isGetLocation();
  176. },
  177. onHide() {
  178. clearInterval(this.timer);
  179. this.timer = null;
  180. },
  181. onLoad() {
  182. if (this.beginload) {
  183. this.getpicture(); // 开机广告
  184. this.amapPlugin = new amap.AMapWX({
  185. key: this.key
  186. });
  187. // this.isGetLocation(); // 检查是否开启定位权限
  188. this.isUserInfo(); // 检查是否允许获取用户授权
  189. this.getswiper(); // 获取首页轮播
  190. }
  191. if (this.successlogion && this.hasLogin) {
  192. this.firstget();
  193. }
  194. },
  195. watch: {
  196. beginload: function(val) {
  197. this.getpicture(); // 开机广告
  198. this.amapPlugin = new amap.AMapWX({
  199. key: this.key
  200. });
  201. // this.isGetLocation(); // 检查是否开启定位权限
  202. this.isUserInfo(); // 检查是否允许获取用户授权
  203. this.getswiper(); // 获取首页轮播
  204. },
  205. hasLogin: function(val) {
  206. if (val) {
  207. this.firstget();
  208. // this.getuserinfo();
  209. }
  210. }
  211. },
  212. methods: {
  213. ...mapMutations(['login', 'showDialog']),
  214. firstget() {
  215. this.request({
  216. url: '/v2/member/info',
  217. method: 'GET',
  218. success: res => {
  219. this.msg_count = res.data.data.msg_count;
  220. }
  221. });
  222. },
  223. getuserinfo() {
  224. this.timer = setInterval(() => {
  225. this.request({
  226. url: '/v2/member/info',
  227. method: 'GET',
  228. success: res => {
  229. this.msg_count = res.data.data.msg_count;
  230. }
  231. });
  232. }, 180000);
  233. },
  234. refeshadress() {
  235. this.isrefesh = false;
  236. this.getRegeo();
  237. },
  238. intToFloat(val) {
  239. return new Number(val).toFixed(1);
  240. },
  241. getpicture() {
  242. this.request({
  243. url: '/v1/entry/poster',
  244. method: 'get',
  245. success: res => {
  246. let { data } = res.data;
  247. this.images = data.images;
  248. this.enable = data.enable;
  249. }
  250. });
  251. },
  252. handler() {
  253. this.getAuthorizeInfo();
  254. },
  255. goinfor() {
  256. if (this.successlogion && this.hasLogin) {
  257. uni.navigateTo({
  258. url: '../myCenter/information' // 我的消息通知
  259. });
  260. } else {
  261. uni.navigateTo({
  262. url: '/pages/myCenter/logion'
  263. });
  264. }
  265. },
  266. goSearch() {
  267. let lat = this.lat;
  268. let lon = this.lot;
  269. uni.navigateTo({
  270. url: `/pages/index/searchresult?lat=${lat}&lon=${lon}`
  271. });
  272. },
  273. // 滚动到顶部
  274. upper(e) {},
  275. getop() {
  276. this.scrollTop = this.old.scrollTop;
  277. this.$nextTick(function() {
  278. this.scrollTop = 0;
  279. });
  280. this.isTop = false;
  281. },
  282. // 滚到底部
  283. lower(e) {
  284. this.page = this.page + 1;
  285. if (this.ispull) {
  286. this.gethotelist();
  287. }
  288. },
  289. // 滚动时触发
  290. scroll(e) {
  291. if (e.detail.scrollTop > 250) {
  292. this.isTop = true;
  293. } else {
  294. //当距离小于500时显示回到顶部按钮
  295. this.isTop = false;
  296. }
  297. this.old.scrollTop = e.detail.scrollTop;
  298. },
  299. isGetLocation(a = 'scope.userLocation') {
  300. // 检查当前是否已经授权访问scope属性W
  301. uni.getSetting({
  302. success: res => {
  303. if (!res.authSetting[a]) {
  304. // 每次进入程序判断当前是否获得授权,如果没有就去获得授权,如果获得授权,就直接获取当前地理位置
  305. console.log("未授权")
  306. this.getAuthorizeInfo();
  307. } else {
  308. if(this.allow){
  309. console.log("授权了")
  310. this.getRegeo();
  311. }
  312. }
  313. }
  314. });
  315. },
  316. isUserInfo(b = 'scope.userInfo') {
  317. uni.getSetting({
  318. success: res => {
  319. if (!res.authSetting[b]) {
  320. this.showDialog(false);
  321. } else {
  322. this.showDialog(true);
  323. let userInfo = uni.getStorageSync('userInfo');
  324. this.login(userInfo);
  325. }
  326. }
  327. });
  328. },
  329. getAuthorizeInfo(a = 'scope.userLocation') {
  330. var that=this;
  331. //uniapp弹窗弹出获取授权弹窗
  332. uni.authorize({
  333. scope: a,
  334. success: res => {
  335. //允许授权
  336. that.getRegeo();
  337. },
  338. fail(err) {
  339. console.log(err);
  340. //拒绝授权
  341. that.allow = true;
  342. that.$msg('你拒绝了授权,无法获得周边信息');
  343. }
  344. });
  345. },
  346. getRegeo() {
  347. let _this = this;
  348. uni.showLoading({
  349. title: '获取位置中'
  350. });
  351. _this.amapPlugin.getRegeo({
  352. success: data => {
  353. this.isrefesh = true;
  354. this.location = data[0].name;
  355. this.lat = data[0].latitude; // 经度
  356. this.lot = data[0].longitude; // 纬度
  357. this.allow = false;
  358. this.gethotelist();
  359. uni.hideLoading();
  360. },
  361. fail: res => {
  362. this.allow = true;
  363. uni.hideLoading();
  364. }
  365. });
  366. },
  367. // 获取首页轮播
  368. getswiper() {
  369. this.request({
  370. url: '/v1/entry/adv',
  371. method: 'get',
  372. success: res => {
  373. this.backgroundlist = res.data.data;
  374. }
  375. });
  376. },
  377. // 获取酒店列表
  378. gethotelist() {
  379. this.request({
  380. url: '/v2/entry/storeList',
  381. method: 'get',
  382. data: {
  383. page: this.page,
  384. page_size: 10,
  385. lat: this.lat,
  386. lon: this.lot
  387. },
  388. success: res => {
  389. let { data, code } = res.data;
  390. if (code == 1000) {
  391. if (data.store_list.length < 10) {
  392. this.ispull = false;
  393. }
  394. data.store_list.forEach((items, index) => {
  395. items.tages = items.store_summary.split(' ');
  396. items.tageslist = [];
  397. items.tages.forEach((item, index) => {
  398. if (item != '') {
  399. items.tageslist.push(item);
  400. }
  401. });
  402. });
  403. if (this.hotelist.length == 0) {
  404. this.hotelist = data.store_list;
  405. } else {
  406. this.hotelist = this.hotelist.concat(data.store_list);
  407. }
  408. } else {
  409. this.$msg('网络错误稍后再试');
  410. }
  411. }
  412. });
  413. },
  414. // 点击扫码
  415. scan() {
  416. uni.scanCode({
  417. success: res => {
  418. if (res.scanType != 'QR_CODE') {
  419. this.$msg('二维码错误');
  420. } else {
  421. var obj = this.GetRequest(res.result);
  422. uni.navigateTo({
  423. url: `/pages/index/shop?id=${obj.goods_id}&store_id=${obj.store_id}`
  424. });
  425. }
  426. }
  427. });
  428. },
  429. GetRequest(urlStr) {
  430. if (typeof urlStr == 'undefined') {
  431. var url = decodeURI(location.search); //获取url中"?"符后的字符串
  432. } else {
  433. var url = '?' + urlStr.split('?')[1];
  434. }
  435. var theRequest = new Object();
  436. var strs;
  437. if (url.indexOf('?') != -1) {
  438. var str = url.substr(1);
  439. strs = str.split('&');
  440. for (var i = 0; i < strs.length; i++) {
  441. theRequest[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1]);
  442. }
  443. }
  444. return theRequest;
  445. },
  446. openinfo(item) {
  447. let id = item.store_id;
  448. uni.navigateTo({
  449. url: `/pages/index/hotel?id=${id}`
  450. });
  451. },
  452. // 跳转到商品详情
  453. shopDetail(item) {
  454. let id = item.adv_target.goods_id;
  455. let store_id = item.adv_target.store_id;
  456. if (item.adv_target.type == 'goods') {
  457. uni.navigateTo({
  458. url: `/pages/index/shop?id=${id}&store_id=${store_id}`
  459. });
  460. } else if (item.adv_target.type == 'store') {
  461. let id = item.adv_target.store_id;
  462. let title = item.adv_target.store_name;
  463. uni.navigateTo({
  464. url: `/pages/index/hotel?id=${id}`
  465. });
  466. }
  467. }
  468. }
  469. };
  470. </script>
  471. <style>
  472. .btnOPne{
  473. height: 60upx;
  474. line-height: 60upx;
  475. border:1px solid #fff !important;
  476. background-color: #fff !important;
  477. /* font-size: 28upx; */
  478. text-align: left;
  479. padding: 0 10upx;
  480. }
  481. .top .uni-navbar__header-btns {
  482. width: 77% !important;
  483. }
  484. .top .uni-navbar__header-container {
  485. width: 50% !important;
  486. }
  487. .content {
  488. background: #fff;
  489. }
  490. .city {
  491. width: 100%;
  492. height: 100%;
  493. white-space: nowrap;
  494. overflow: hidden;
  495. text-overflow: ellipsis;
  496. }
  497. .logo {
  498. height: 200upx;
  499. width: 200upx;
  500. margin-top: 200upx;
  501. margin-left: auto;
  502. margin-right: auto;
  503. margin-bottom: 50upx;
  504. }
  505. .text-area {
  506. display: flex;
  507. justify-content: center;
  508. }
  509. .title {
  510. font-size: 36upx;
  511. color: #8f8f94;
  512. }
  513. .van-cell--borderless {
  514. background-color: #e7e7e7 !important;
  515. }
  516. .searchType .input-view {
  517. width: 85%;
  518. display: flex;
  519. background-color: #e7e7e7;
  520. height: 30px;
  521. border-radius: 15px;
  522. padding: 0 4%;
  523. flex-wrap: nowrap;
  524. margin: 7px 0;
  525. line-height: 30px;
  526. margin: 10upx auto;
  527. display: flex;
  528. justify-content: center;
  529. }
  530. .searchType .input-view .uni-icon {
  531. line-height: 30px !important;
  532. }
  533. .searchType .input-view .input {
  534. height: 30px;
  535. line-height: 30px;
  536. width: 94%;
  537. padding: 0 3%;
  538. }
  539. .uni-navbar--border::after {
  540. background: #fff !important;
  541. }
  542. .swiper {
  543. height: 300upx;
  544. border-radius: 10upx;
  545. width: 100%;
  546. }
  547. .swiper-item {
  548. display: block;
  549. height: 300upx;
  550. line-height: 300upx;
  551. text-align: center;
  552. border-radius: 10upx;
  553. }
  554. swiper-item {
  555. border-radius: 15upx;
  556. }
  557. .swiper-item image {
  558. border-radius: 10upx;
  559. }
  560. .scrollswiper {
  561. width: 90%;
  562. margin: 20upx auto;
  563. border-radius: 10upx;
  564. }
  565. .tips {
  566. /* color: #303133;
  567. font-size: 28upx;
  568. text-align: center;
  569. margin: 24upx 0; */
  570. padding: 20upx 32upx 0 32upx;
  571. display: flex;
  572. justify-content: space-between;
  573. font-size: 30upx;
  574. }
  575. .hotelList {
  576. display: flex;
  577. flex-direction: row;
  578. padding: 24upx 32upx;
  579. }
  580. .hotleLeft {
  581. width: 214upx;
  582. height: 152upx;
  583. }
  584. .hotelright {
  585. padding-left: 16upx;
  586. display: flex;
  587. flex-direction: column;
  588. width: 100%;
  589. }
  590. .undertip {
  591. display: flex;
  592. flex-direction: row;
  593. align-items: center;
  594. }
  595. .tipsTop {
  596. border: 1upx solid #606266;
  597. margin-right: 12upx;
  598. color: #606266;
  599. font-size: 22rpx;
  600. border-radius: 5rpx;
  601. padding: 0rpx 5rpx;
  602. }
  603. .placeholdercenter {
  604. text-align: center;
  605. }
  606. </style>