index.vue 12 KB

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