index.vue 14 KB

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