index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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="搜索您入住的酒店" @confirm="confirm" />
  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;" :src="pictureUrl+'/uploads/home/store/'+item.store_id+'/'+item.store_banner" />
  57. </view>
  58. <view class="hotelright">
  59. <view style="font-size: 32upx;color: #303133;font-weight: 550;">{{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: 32upx; color: #303133;font-weight: 550;">{{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 v-if="item.tages.length!=1" class="undertip">
  67. <view v-for="(items,index) in item.tages" :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. </view>
  77. </template>
  78. <script>
  79. import {
  80. mapMutations,mapState
  81. } from 'vuex'
  82. import uniNavBar from '@/component/uni-nav-bar/uni-nav-bar.vue'
  83. import uniIcon from '@/component/uni-icon/uni-icon.vue'
  84. import logionDialog from '@/component/loginDialog.vue'
  85. import amap from '@/common/amap-wx.js'
  86. export default {
  87. components: {
  88. uniNavBar,
  89. uniIcon,
  90. logionDialog
  91. },
  92. data() {
  93. return {
  94. page: 1,
  95. ispull: true,
  96. pagesize: 10,
  97. store_summary:[], // 标签数组
  98. pictureUrl: this.pictureUrl,
  99. amapPlugin: null,
  100. key: '7277de7a5833626b7da8f2496e9d6bf9',
  101. showdialog: false, // 点击确定显示弹窗
  102. backgroundlist: ['color1', 'color2', 'color3'], // 轮播数组
  103. hotelist:[], // 酒店数组
  104. indicatorDots: true,
  105. autoplay: true,
  106. interval: 2000,
  107. duration: 500,
  108. title: 'Hello',
  109. location:'正在定位...',
  110. scrollTop: 0,
  111. old: {
  112. scrollTop: 0
  113. },
  114. allow: false
  115. }
  116. },
  117. computed:{
  118. ...mapState([
  119. 'hasLogin',
  120. 'userInfo',
  121. 'successlogion'
  122. ]),
  123. },
  124. onLoad() {
  125. this.getswiper(); // 获取首页轮播
  126. this.gethotelist(); // 酒店列表
  127. if(this.allow) {
  128. }else {
  129. this.gethotelist(); // 酒店列表
  130. }
  131. this.isGetLocation(); // 检查是否开启定位权限
  132. this.isUserInfo(); // 检查是否允许获取用户授权
  133. // 用户授全
  134. this.amapPlugin = new amap.AMapWX({
  135. key: this.key
  136. });
  137. },
  138. methods: {
  139. ...mapMutations(['login','showDialog']),
  140. handler() {
  141. console.log("kkkkk")
  142. this.getAuthorizeInfo();
  143. },
  144. goinfor() {
  145. if(this.successlogion && this.hasLogin) {
  146. uni.navigateTo({
  147. url: '../myCenter/information' // 我的消息通知
  148. })
  149. }else {
  150. uni.navigateTo({
  151. url:'/pages/myCenter/logion'
  152. })
  153. // this.showdialog = true;
  154. } },
  155. // // 关闭弹窗
  156. // cancelDiaolog() {
  157. // this.showdialog = false;
  158. // },
  159. // // 确定
  160. // confirmDiaolog() {
  161. // this.showdialog = false;
  162. // uni.navigateTo({
  163. // url: '../myCenter/information' // 我的收藏
  164. // })
  165. // },
  166. goSearch() {
  167. uni.navigateTo({
  168. url: './searchresult' // 我的搜索
  169. })
  170. },
  171. // 滚动到顶部
  172. upper(e) {
  173. console.log("顶部")
  174. },
  175. // 滚到底部
  176. lower(e) {
  177. this.page = this.page + 1;
  178. if(this.ispull) {
  179. this.gethotelist();
  180. }
  181. },
  182. // 滚动时触发
  183. scroll(e) {
  184. this.old.scrollTop = e.detail.scrollTop
  185. },
  186. isGetLocation(a="scope.userLocation"){ // 检查当前是否已经授权访问scope属性W
  187. let _this=this;
  188. uni.getSetting({
  189. success(res) {
  190. // 用户定位接口
  191. if (!res.authSetting[a]) { // 每次进入程序判断当前是否获得授权,如果没有就去获得授权,如果获得授权,就直接获取当前地理位置
  192. _this.getAuthorizeInfo()
  193. }else{
  194. _this.getRegeo()
  195. }
  196. }
  197. });
  198. },
  199. // 进入判断是否授权
  200. isUserInfo(b='scope.userInfo') {
  201. let _this = this;
  202. uni.getSetting({
  203. success(res) {
  204. if(!res.authSetting[b]) {
  205. _this.showDialog(false);
  206. }else {
  207. _this.showDialog(true);
  208. let userInfo = uni.getStorageSync('userInfo');
  209. _this.login(userInfo);
  210. }
  211. }
  212. })
  213. },
  214. getAuthorizeInfo(a="scope.userLocation"){ //uniapp弹窗弹出获取授权弹窗
  215. let _this=this;
  216. uni.authorize({
  217. scope: a,
  218. success(res) { //允许授权
  219. console.log("调用位置授权")
  220. _this.getRegeo();
  221. },
  222. fail(){ //拒绝授权
  223. _this.allow = true;
  224. _this.$msg("你拒绝了授权,无法获得周边信息")
  225. }
  226. })
  227. },
  228. getRegeo(){ //获取地理位置
  229. let _this=this;
  230. uni.showLoading({
  231. title: '获取信息中'
  232. });
  233. _this.amapPlugin.getRegeo({
  234. success: (data) => {
  235. this.location = data[0].name;
  236. this.allow = false;
  237. uni.hideLoading();
  238. },
  239. fail: (res) => {
  240. console.log(res);
  241. uni.hideLoading();
  242. }
  243. });
  244. },
  245. // 获取首页轮播
  246. getswiper() {
  247. this.request({
  248.                 url:"/v1/entry/adv",
  249.                 method:'get',
  250. success: (res) => {
  251. this.backgroundlist = res.data.data;
  252. }
  253. })
  254. },
  255. // 获取酒店列表
  256. gethotelist() {
  257. this.request({
  258.                 url:"/v2/entry/storeList",
  259.                 method:'get',
  260. data: {
  261. page: this.page,
  262. page_size: 10
  263. },
  264. success: (res) => {
  265. let { data,code } = res.data;
  266. if(code == 1000) {
  267. if(data.store_list.length<10) {
  268. this.ispull = false;
  269. }
  270. if(this.hotelist.length == 0) {
  271. this.hotelist = data.store_list
  272. }else {
  273. this.hotelist = this.hotelist.concat(data.store_list);
  274. }
  275. this.hotelist.forEach(item => {
  276. item.tages = item.store_summary.split(' ');
  277. })
  278. }else {
  279. this.$msg("网络错误稍后再试")
  280. }
  281. }
  282. })
  283. },
  284. // 点击扫码
  285. scan(){
  286. uni.scanCode({
  287. success: (res) => {
  288. console.log(res);
  289. }
  290. });
  291. },
  292. // 跳转到新页面 酒店详情
  293. openinfo(item) {
  294. let id = item.store_id;
  295. uni.navigateTo({
  296. url: `/pages/index/hotel?id=${id}`
  297. });
  298. },
  299. // 跳转到商品详情
  300. shopDetail(item) {
  301. let id = item.adv_target.goods_id;
  302. let store_id = item.adv_target.store_id;
  303. if(item.adv_target.type == 'goods') {
  304. uni.navigateTo({
  305. url: `/pages/index/shop?id=${id}&store_id=${store_id}`
  306. });
  307. }else if(item.adv_target.type == 'store') {
  308. let id = item.adv_target.store_id;
  309. let title = item.adv_target.store_name;
  310. uni.navigateTo({
  311. url: `/pages/index/hotel?id=${id}`
  312. });
  313. }
  314. }
  315. }
  316. }
  317. </script>
  318. <style>
  319. .top .uni-navbar__header-btns {
  320. width: 77%!important;
  321. }
  322. .top .uni-navbar__header-container {
  323. width: 50%!important;
  324. }
  325. .content {
  326. background: #fff;
  327. }
  328. .city {
  329. width: 100%;
  330. height: 100%;
  331. white-space:nowrap;
  332. overflow:hidden;
  333. text-overflow:ellipsis;
  334. }
  335. .logo {
  336. height: 200upx;
  337. width: 200upx;
  338. margin-top: 200upx;
  339. margin-left: auto;
  340. margin-right: auto;
  341. margin-bottom: 50upx;
  342. }
  343. .text-area {
  344. display: flex;
  345. justify-content: center;
  346. }
  347. .title {
  348. font-size: 36upx;
  349. color: #8f8f94;
  350. }
  351. .van-cell--borderless {
  352. background-color: #e7e7e7!important;
  353. }
  354. .searchType .input-view {
  355. width: 85%;
  356. display: flex;
  357. background-color: #e7e7e7;
  358. height: 30px;
  359. border-radius: 15px;
  360. padding: 0 4%;
  361. flex-wrap: nowrap;
  362. margin: 7px 0;
  363. line-height: 30px;
  364. margin: 24upx auto;
  365. }
  366. .searchType .input-view .uni-icon {
  367. line-height: 30px !important;
  368. }
  369. .searchType .input-view .input {
  370. height: 30px;
  371. line-height: 30px;
  372. width: 94%;
  373. padding: 0 3%;
  374. }
  375. .uni-navbar--border::after {
  376. background: #fff!important;
  377. }
  378. .swiper {
  379. height: 300upx;
  380. }
  381. .swiper-item {
  382. display: block;
  383. height: 300upx;
  384. line-height: 300upx;
  385. text-align: center;
  386. }
  387. .scrollswiper {
  388. width: 90%;
  389. margin: 20upx auto;
  390. }
  391. .tips {
  392. color: #303133;
  393. font-size: 28upx;
  394. text-align: center;
  395. margin: 24upx 0;
  396. }
  397. .hotelList {
  398. display: flex;
  399. flex-direction: row;
  400. padding: 24upx 32upx;
  401. }
  402. .hotleLeft {
  403. width: 214upx;
  404. height: 152upx;
  405. }
  406. .hotelright {
  407. padding-left: 16upx;
  408. display: flex;
  409. flex-direction: column;
  410. width: 100%;
  411. }
  412. .undertip {
  413. display: flex;
  414. flex-direction: row;
  415. align-items: center;
  416. }
  417. .tipsTop {
  418. border: 2upx solid #606266;
  419. margin-right: 12upx;
  420. color: #606266;
  421. padding: 4upx;
  422. font-size: 24upx;
  423. border-radius: 4rpx;
  424. padding: 0 10rpx;
  425. }
  426. </style>