index.vue 15 KB

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