index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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%;" 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 @click="goinfor">
  22. <uni-icon size="22" type="chat"></uni-icon>
  23. </view>
  24. </block>
  25. </uniNavBar>
  26. <view @click="goSearch" 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. import logionDialog from '@/component/loginDialog.vue'
  78. export default {
  79. components: {
  80. uniNavBar,
  81. uniIcon,
  82. logionDialog
  83. },
  84. data() {
  85. return {
  86. showdialog: false, // 点击确定显示弹窗
  87. background: ['color1', 'color2', 'color3'],
  88. indicatorDots: true,
  89. autoplay: true,
  90. interval: 2000,
  91. duration: 500,
  92. title: 'Hello',
  93. location:'测试定位信息',
  94. scrollTop: 0,
  95. old: {
  96. scrollTop: 0
  97. }
  98. }
  99. },
  100. computed:{
  101. ...mapState([
  102. 'hasLogin',
  103. 'userInfo'
  104. ]),
  105. },
  106. onLoad() {
  107. this.isGetLocation(); // 检查是否开启定位权限
  108. this.isUserInfo(); // 检查是否允许获取用户授权
  109. // 用户授全
  110. },
  111. methods: {
  112. ...mapMutations(['login','showDialog']),
  113. goinfor() {
  114. console.log(this.hasLogin);
  115. console.log(this.userInfo);
  116. if(this.hasLogin) {
  117. uni.navigateTo({
  118. url: '../myCenter/information' // 我的收藏
  119. })
  120. }else {
  121. this.showdialog = true;
  122. } },
  123. // 关闭弹窗
  124. cancelDiaolog() {
  125. this.showdialog = false;
  126. },
  127. // 确定
  128. confirmDiaolog() {
  129. this.showdialog = false;
  130. uni.navigateTo({
  131. url: '../myCenter/information' // 我的收藏
  132. })
  133. },
  134. goSearch() {
  135. uni.navigateTo({
  136. url: './searchresult' // 我的搜索
  137. })
  138. },
  139. // 滚动到顶部
  140. upper(e) {
  141. console.log(e)
  142. console.log("顶部")
  143. },
  144. // 滚到底部
  145. lower(e) {
  146. console.log("底部")
  147. },
  148. // 滚动时触发
  149. scroll(e) {
  150. this.old.scrollTop = e.detail.scrollTop
  151. },
  152. isGetLocation(a="scope.userLocation"){ // 检查当前是否已经授权访问scope属性W
  153. let _this=this;
  154. uni.getSetting({
  155. success(res) {
  156. // 用户定位接口
  157. if (!res.authSetting[a]) { // 每次进入程序判断当前是否获得授权,如果没有就去获得授权,如果获得授权,就直接获取当前地理位置
  158. _this.getAuthorizeInfo()
  159. }else{
  160. _this.getLocationInfo()
  161. }
  162. }
  163. });
  164. },
  165. // 进入判断是否授权
  166. isUserInfo(b='scope.userInfo') {
  167. let _this = this;
  168. uni.getSetting({
  169. success(res) {
  170. if(!res.authSetting[b]) {
  171. _this.showDialog(false);
  172. }else {
  173. _this.showDialog(true);
  174. }
  175. }
  176. })
  177. },
  178. getAuthorizeInfo(a="scope.userLocation"){ //uniapp弹窗弹出获取授权弹窗
  179. let _this=this;
  180. uni.authorize({
  181. scope: a,
  182. success() { //允许授权
  183. console.log("调用位置授权")
  184. _this.getLocationInfo();
  185. },
  186. fail(){ //拒绝授权
  187. _this.$msg("你拒绝了授权,无法获得周边信息")
  188. }
  189. })
  190. },
  191. //wgs84togcj02 转火星坐标
  192. wgs84togcj02: function (lng, lat) {
  193. const PI = 3.1415926535897932384626
  194. const a = 6378245.0
  195. const ee = 0.00669342162296594323
  196. // WGS84转GCj02
  197. let dlat = this.transformlat(lng - 105.0, lat - 35.0)
  198. let dlng = this.transformlng(lng - 105.0, lat - 35.0)
  199. let radlat = lat / 180.0 * PI
  200. let magic = Math.sin(radlat)
  201. magic = 1 - ee * magic * magic
  202. let sqrtmagic = Math.sqrt(magic)
  203. dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI)
  204. dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI)
  205. let mglat = lat + dlat
  206. let mglng = lng + dlng
  207. // 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换
  208. return {lng: mglng, lat: mglat}
  209. // return gcj02tobd09(mglng, mglat)
  210. },
  211. transformlat: function (lng, lat) {
  212. const PI = 3.1415926535897932384626
  213. let ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng))
  214. ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0
  215. ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0
  216. ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0
  217. return ret
  218. },
  219. transformlng: function (lng, lat) {
  220. const PI = 3.1415926535897932384626
  221. let ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng))
  222. ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0
  223. ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0
  224. ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0
  225. return ret
  226. },
  227. getLocationInfo(){ //获取地理位置
  228. let _this=this;
  229. uni.getLocation({
  230. type: 'wgs84',
  231. success (res) {
  232. console.log(res)
  233. let latitude,longitude;
  234. latitude = res.latitude.toString();
  235. longitude = res.longitude.toString();
  236. let ws = _this.wgs84togcj02(latitude,longitude) // 转换成gcjo2
  237. let lng = ws.lng
  238. let lat = ws.lat
  239. console.log(lng);console.log(lat)
  240. _this.loaction = '测试定位';
  241. request({
  242. url:'',
  243. methods:'',
  244. success: (res) => {
  245. console.log(res);
  246. cosnole.log("请求成功")
  247. }
  248. })
  249. // uni.request({
  250. // header:{
  251. // "Content-Type": "application/text"
  252. // },
  253. // url:'',
  254. // success(re) {
  255. // console.log("中文位置")
  256. // console.log(re)
  257. // if(re.statusCode===200){
  258. // console.log("获取中文街道地理位置成功")
  259. // }else{
  260. // console.log("获取信息失败,请重试!")
  261. // }
  262. // }
  263. // });
  264. },
  265. fail(res) {
  266. if(res.errMsg == 'getLocation:fail:system permission denied') {
  267. _this.$msg("定位失败开启手机微信定位权限")
  268. }
  269. console.log(res.errMsg)
  270. }
  271. });
  272. },
  273. // 确定登录
  274. wxlogion() {
  275. // let that = this;
  276. //     uni.getUserInfo({
  277. //      success(res) {
  278. // that.login(res.userInfo);
  279. // that.showDialog(true);
  280. //      },
  281. //      fail(res) {
  282. // that.$msg("授权失败")
  283. //      }
  284. //     })
  285. },
  286. // 点击扫码
  287. scan(){
  288. uni.scanCode({
  289. success: (res) => {
  290. console.log(res);
  291. }
  292. });
  293. },
  294. // 跳转到新页面 酒店详情
  295. openinfo() {
  296. uni.navigateTo({
  297. url: './hotel',
  298. });
  299. },
  300. // 跳转到商品详情
  301. shopDetail() {
  302. uni.navigateTo({
  303. url: './shop',
  304. });
  305. }
  306. }
  307. }
  308. </script>
  309. <style>
  310. .top .uni-navbar__header-btns {
  311. width: 80%!important;
  312. }
  313. .top .uni-navbar__header-container {
  314. width: 50%!important;
  315. }
  316. .content {
  317. background: #fff;
  318. }
  319. .city {
  320. width: 100%;
  321. height: 100%;
  322. white-space:nowrap;
  323. overflow:hidden;
  324. text-overflow:ellipsis;
  325. }
  326. .logo {
  327. height: 200upx;
  328. width: 200upx;
  329. margin-top: 200upx;
  330. margin-left: auto;
  331. margin-right: auto;
  332. margin-bottom: 50upx;
  333. }
  334. .text-area {
  335. display: flex;
  336. justify-content: center;
  337. }
  338. .title {
  339. font-size: 36upx;
  340. color: #8f8f94;
  341. }
  342. .van-cell--borderless {
  343. background-color: #e7e7e7!important;
  344. }
  345. .searchType .input-view {
  346. width: 85%;
  347. display: flex;
  348. background-color: #e7e7e7;
  349. height: 30px;
  350. border-radius: 15px;
  351. padding: 0 4%;
  352. flex-wrap: nowrap;
  353. margin: 7px 0;
  354. line-height: 30px;
  355. margin: 24upx auto;
  356. }
  357. .searchType .input-view .uni-icon {
  358. line-height: 30px !important;
  359. }
  360. .searchType .input-view .input {
  361. height: 30px;
  362. line-height: 30px;
  363. width: 94%;
  364. padding: 0 3%;
  365. }
  366. .uni-navbar--border::after {
  367. background: #fff!important;
  368. }
  369. .swiper {
  370. height: 300upx;
  371. }
  372. .swiper-item {
  373. display: block;
  374. height: 300upx;
  375. line-height: 300upx;
  376. text-align: center;
  377. }
  378. .scrollswiper {
  379. width: 90%;
  380. margin: 20upx auto;
  381. }
  382. .tips {
  383. color: #303133;
  384. font-size: 28upx;
  385. text-align: center;
  386. margin: 24upx 0;
  387. }
  388. .hotelList {
  389. display: flex;
  390. flex-direction: row;
  391. padding: 24upx 32upx;
  392. }
  393. .hotleLeft {
  394. width: 214upx;
  395. height: 152upx;
  396. background-color: #007AFF;
  397. }
  398. .hotelright {
  399. padding-left: 16upx;
  400. display: flex;
  401. flex-direction: column;
  402. width: 100%;
  403. }
  404. .undertip {
  405. display: flex;
  406. flex-direction: row;
  407. align-items: center;
  408. }
  409. .tipsTop {
  410. border: 2upx solid #BBBBBB;
  411. margin-right: 14upx;
  412. color: #BBBBBB;
  413. padding: 4upx;
  414. }
  415. </style>