index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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. <uniNavBar class="top" :shadow="false" :fixed="false" color="#333333" background-color="#FFFFFF">
  9. <block style="width: 70%;" slot="left">
  10. <view class="city">
  11. <view style="font-size: 35upx;">{{ location }}</view>
  12. </view>
  13. </block>
  14. <view class="input-view" style="float: right;">
  15. <uni-icon size="22" @click="scan" type="scan"></uni-icon>
  16. </view>
  17. <block slot="right">
  18. <view>
  19. <uni-icon size="22" type="chat"></uni-icon>
  20. </view>
  21. </block>
  22. </uniNavBar>
  23. <view class="searchType" style="background: #fff;">
  24. <view class="input-view">
  25. <uni-icon type="search" size="22" color="#666666" />
  26. <input confirm-type="search" class="input" type="text" placeholder="输入搜索关键词" @confirm="confirm" />
  27. </view>
  28. </view>
  29. <view class="scrollswiper">
  30. <swiper class="swiper" :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval" :duration="duration">
  31. <swiper-item>
  32. <view class="swiper-item uni-bg-red">A</view>
  33. </swiper-item>
  34. <swiper-item>
  35. <view class="swiper-item uni-bg-green">B</view>
  36. </swiper-item>
  37. <swiper-item>
  38. <view class="swiper-item uni-bg-blue">C</view>
  39. </swiper-item>
  40. </swiper>
  41. </view>
  42. <view class="tips">
  43. 在附近酒店找到您入住的酒店
  44. </view>
  45. <view style="border-bottom: 2upx solid #EEEEEE;width: 100%;margin-bottom: 24upx 0;"></view>
  46. <scroll-view style="height: 100vh;" class="floor-list"
  47. :scroll-top="scrollTop" scroll-y="true" @scroll="scroll" @scrolltoupper="upper" @scrolltolower="lower"
  48. refresher-enabled="true">
  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. }
  228. </script>
  229. <style>
  230. .top .uni-navbar__header-btns {
  231. width: 80%!important;
  232. }
  233. .top .uni-navbar__header-container {
  234. width: 50%!important;
  235. }
  236. .content {
  237. background: #fff;
  238. }
  239. .city {
  240. width: 100%;
  241. height: 100%;
  242. white-space:nowrap;
  243. overflow:hidden;
  244. text-overflow:ellipsis;
  245. }
  246. .logo {
  247. height: 200upx;
  248. width: 200upx;
  249. margin-top: 200upx;
  250. margin-left: auto;
  251. margin-right: auto;
  252. margin-bottom: 50upx;
  253. }
  254. .text-area {
  255. display: flex;
  256. justify-content: center;
  257. }
  258. .title {
  259. font-size: 36upx;
  260. color: #8f8f94;
  261. }
  262. .van-cell--borderless {
  263. background-color: #e7e7e7!important;
  264. }
  265. .searchType .input-view {
  266. width: 85%;
  267. display: flex;
  268. background-color: #e7e7e7;
  269. height: 30px;
  270. border-radius: 15px;
  271. padding: 0 4%;
  272. flex-wrap: nowrap;
  273. margin: 7px 0;
  274. line-height: 30px;
  275. margin: 24upx auto;
  276. }
  277. .searchType .input-view .uni-icon {
  278. line-height: 30px !important;
  279. }
  280. .searchType .input-view .input {
  281. height: 30px;
  282. line-height: 30px;
  283. width: 94%;
  284. padding: 0 3%;
  285. }
  286. .uni-navbar--border::after {
  287. background: #fff!important;
  288. }
  289. .swiper {
  290. height: 300upx;
  291. }
  292. .swiper-item {
  293. display: block;
  294. height: 300upx;
  295. line-height: 300upx;
  296. text-align: center;
  297. }
  298. .scrollswiper {
  299. width: 90%;
  300. margin: 20upx auto;
  301. }
  302. .tips {
  303. color: #303133;
  304. font-size: 28upx;
  305. text-align: center;
  306. margin: 24upx 0;
  307. }
  308. .hotelList {
  309. display: flex;
  310. flex-direction: row;
  311. padding: 24upx 32upx;
  312. }
  313. .hotleLeft {
  314. width: 214upx;
  315. height: 152upx;
  316. background-color: #007AFF;
  317. }
  318. .hotelright {
  319. padding-left: 16upx;
  320. display: flex;
  321. flex-direction: column;
  322. width: 100%;
  323. }
  324. .undertip {
  325. display: flex;
  326. flex-direction: row;
  327. align-items: center;
  328. }
  329. .tipsTop {
  330. border: 2upx solid #BBBBBB;
  331. margin-right: 14upx;
  332. color: #BBBBBB;
  333. padding: 4upx;
  334. }
  335. </style>