index.vue 11 KB

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