index.vue 12 KB

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