index.vue 14 KB

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