index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <view class="content">
  3. <!-- <userInfo /> -->
  4. <!-- <view>
  5. <view>点击授权{{showModal}}</view>
  6. <button v-if="showModal" open-type="getUserInfo" @click="wxlogion">请点击授权</button>
  7. </view> -->
  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%;" slot="left">
  13. <view class="city">
  14. <view style="font-size: 35upx;">{{ location }}</view>
  15. </view>
  16. </block>
  17. <view class="input-view" style="float: right;">
  18. <uni-icon size="22" @click="scan" type="scan"></uni-icon>
  19. </view>
  20. <block slot="right">
  21. <view>
  22. <uni-icon size="22" type="chat"></uni-icon>
  23. </view>
  24. </block>
  25. </uniNavBar>
  26. <view class="searchType" style="background: #fff;">
  27. <view class="input-view">
  28. <uni-icon type="search" size="22" color="#666666" />
  29. <input confirm-type="search" class="input" type="text" placeholder="输入搜索关键词" @confirm="confirm" />
  30. </view>
  31. </view>
  32. <view @tap="shopDetail" class="scrollswiper">
  33. <swiper class="swiper" :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval" :duration="duration">
  34. <swiper-item>
  35. <view class="swiper-item uni-bg-red">A</view>
  36. </swiper-item>
  37. <swiper-item>
  38. <view class="swiper-item uni-bg-green">B</view>
  39. </swiper-item>
  40. <swiper-item>
  41. <view class="swiper-item uni-bg-blue">C</view>
  42. </swiper-item>
  43. </swiper>
  44. </view>
  45. <view class="tips">
  46. 在附近酒店找到您入住的酒店
  47. </view>
  48. <view style="border-bottom: 2upx solid #EEEEEE;width: 100%;margin-bottom: 24upx 0;"></view>
  49. <view @tap="openinfo">
  50. <view class="hotelList">
  51. <view class="hotleLeft">
  52. <image style="width: 214upx;height: 152upx;" src=""/>
  53. </view>
  54. <view class="hotelright">
  55. <view style="font-size: 36upx;color: #303133;">华南城市酒店</view>
  56. <view style="display: flex;flex-direction: row;justify-content: space-between;align-items: center;">
  57. <view style="font-size: 40upx; color: #303133;"> 0.0</view>
  58. <view>月访客990</view>
  59. <view>8km</view>
  60. </view>
  61. <view class="undertip">
  62. <view class="tipsTop">有停车为</view>
  63. <view class="tipsTop">内置酒店</view>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </scroll-view>
  69. </view>
  70. </template>
  71. <script>
  72. import {
  73. mapMutations,mapState
  74. } from 'vuex'
  75. import uniNavBar from '@/component/uni-nav-bar/uni-nav-bar.vue'
  76. import uniIcon from '@/component/uni-icon/uni-icon.vue'
  77. export default {
  78. components: {
  79. uniNavBar,
  80. uniIcon
  81. },
  82. data() {
  83. return {
  84. background: ['color1', 'color2', 'color3'],
  85. indicatorDots: true,
  86. autoplay: true,
  87. interval: 2000,
  88. duration: 500,
  89. title: 'Hello',
  90. location:'测试定位信息',
  91. scrollTop: 0,
  92. old: {
  93. scrollTop: 0
  94. }
  95. }
  96. },
  97. computed:{
  98. ...mapState([
  99. 'showModal',
  100. 'userInfo'
  101. ]),
  102. },
  103. onLoad() {
  104. this.isGetLocation(); // 检查是否开启定位权限
  105. this.isUserInfo(); // 检查是否允许获取用户授权
  106. // 用户授全
  107. },
  108. methods: {
  109. ...mapMutations(['login','showDialog']),
  110. // 滚动到顶部
  111. upper(e) {
  112. console.log(e)
  113. console.log("顶部")
  114. },
  115. // 滚到底部
  116. lower(e) {
  117. console.log("底部")
  118. },
  119. // 滚动时触发
  120. scroll(e) {
  121. this.old.scrollTop = e.detail.scrollTop
  122. },
  123. isGetLocation(a="scope.userLocation"){ // 检查当前是否已经授权访问scope属性WEW
  124. let _this=this;
  125. uni.getSetting({
  126. success(res) {
  127. // 用户定位接口
  128. if (!res.authSetting[a]) { // 每次进入程序判断当前是否获得授权,如果没有就去获得授权,如果获得授权,就直接获取当前地理位置
  129. _this.getAuthorizeInfo()
  130. }else{
  131. _this.getLocationInfo()
  132. }
  133. }
  134. });
  135. },
  136. isUserInfo(b='scope.userInfo') {
  137. let _this = this;
  138. uni.getSetting({
  139. success(res) {
  140. // 未授权
  141. if(!res.authSetting[b]) {
  142. // 打开授权按钮 用户点击授权
  143. _this.showDialog(true);
  144. }else {
  145. _this.showDialog(false);
  146. }
  147. }
  148. })
  149. },
  150. getAuthorizeInfo(a="scope.userLocation"){ //uniapp弹窗弹出获取授权弹窗
  151. let _this=this;
  152. uni.authorize({
  153. scope: a,
  154. success() { //允许授权
  155. console.log("调用位置授权")
  156. _this.getLocationInfo();
  157. },
  158. fail(){ //拒绝授权
  159. _this.$msg("你拒绝了授权,无法获得周边信息")
  160. }
  161. })
  162. },
  163. getLocationInfo(){ //获取地理位置
  164. let _this=this;
  165. uni.getLocation({
  166. type: 'wgs84',
  167. success (res) {
  168. console.log(res)
  169. let latitude,longitude;
  170. latitude = res.latitude.toString();
  171. longitude = res.longitude.toString();
  172. _this.loaction = '测试定位';
  173. uni.request({
  174. header:{
  175. "Content-Type": "application/text"
  176. },
  177. url:'',
  178. success(re) {
  179. console.log("中文位置")
  180. console.log(re)
  181. if(re.statusCode===200){
  182. console.log("获取中文街道地理位置成功")
  183. }else{
  184. console.log("获取信息失败,请重试!")
  185. }
  186. }
  187. });
  188. },
  189. fail(res) {
  190. if(res.errMsg == 'getLocation:fail:system permission denied') {
  191. _this.$msg("定位失败开启手机微信定位权限")
  192. }
  193. console.log(res.errMsg)
  194. }
  195. });
  196. },
  197. wxlogion() {
  198. let that = this;
  199.     uni.getUserInfo({
  200.      success(res) {
  201. that.login(res.userInfo);
  202. that.showDialog(false);
  203.      },
  204.      fail(res) {
  205. that.$msg("授权失败")
  206. //      uni.showModal({
  207. // title: 'shouquanshibai',
  208. // })
  209.      }
  210.     })
  211. },
  212. // 点击扫码
  213. scan(){
  214. uni.scanCode({
  215. success: (res) => {
  216. console.log(res);
  217. }
  218. });
  219. },
  220. // 跳转到新页面 酒店详情
  221. openinfo() {
  222. uni.navigateTo({
  223. url: './hotel',
  224. });
  225. },
  226. // 跳转到商品详情
  227. shopDetail() {
  228. uni.navigateTo({
  229. url: './shop',
  230. });
  231. }
  232. }
  233. }
  234. </script>
  235. <style>
  236. .top .uni-navbar__header-btns {
  237. width: 80%!important;
  238. }
  239. .top .uni-navbar__header-container {
  240. width: 50%!important;
  241. }
  242. .content {
  243. background: #fff;
  244. }
  245. .city {
  246. width: 100%;
  247. height: 100%;
  248. white-space:nowrap;
  249. overflow:hidden;
  250. text-overflow:ellipsis;
  251. }
  252. .logo {
  253. height: 200upx;
  254. width: 200upx;
  255. margin-top: 200upx;
  256. margin-left: auto;
  257. margin-right: auto;
  258. margin-bottom: 50upx;
  259. }
  260. .text-area {
  261. display: flex;
  262. justify-content: center;
  263. }
  264. .title {
  265. font-size: 36upx;
  266. color: #8f8f94;
  267. }
  268. .van-cell--borderless {
  269. background-color: #e7e7e7!important;
  270. }
  271. .searchType .input-view {
  272. width: 85%;
  273. display: flex;
  274. background-color: #e7e7e7;
  275. height: 30px;
  276. border-radius: 15px;
  277. padding: 0 4%;
  278. flex-wrap: nowrap;
  279. margin: 7px 0;
  280. line-height: 30px;
  281. margin: 24upx auto;
  282. }
  283. .searchType .input-view .uni-icon {
  284. line-height: 30px !important;
  285. }
  286. .searchType .input-view .input {
  287. height: 30px;
  288. line-height: 30px;
  289. width: 94%;
  290. padding: 0 3%;
  291. }
  292. .uni-navbar--border::after {
  293. background: #fff!important;
  294. }
  295. .swiper {
  296. height: 300upx;
  297. }
  298. .swiper-item {
  299. display: block;
  300. height: 300upx;
  301. line-height: 300upx;
  302. text-align: center;
  303. }
  304. .scrollswiper {
  305. width: 90%;
  306. margin: 20upx auto;
  307. }
  308. .tips {
  309. color: #303133;
  310. font-size: 28upx;
  311. text-align: center;
  312. margin: 24upx 0;
  313. }
  314. .hotelList {
  315. display: flex;
  316. flex-direction: row;
  317. padding: 24upx 32upx;
  318. }
  319. .hotleLeft {
  320. width: 214upx;
  321. height: 152upx;
  322. background-color: #007AFF;
  323. }
  324. .hotelright {
  325. padding-left: 16upx;
  326. display: flex;
  327. flex-direction: column;
  328. width: 100%;
  329. }
  330. .undertip {
  331. display: flex;
  332. flex-direction: row;
  333. align-items: center;
  334. }
  335. .tipsTop {
  336. border: 2upx solid #BBBBBB;
  337. margin-right: 14upx;
  338. color: #BBBBBB;
  339. padding: 4upx;
  340. }
  341. </style>