index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. <template>
  2. <view class="content">
  3. <!-- 背景图 -->
  4. <view class="index_bg">
  5. <view class="welcome"><image class="welcome_img" src="../../static/index/welcome.png"></image></view>
  6. </view>
  7. <!-- 第一层公寓名称卡片 -->
  8. <view class="uni-ka" style="margin-top: -40px;margin-bottom:0px;">
  9. <text class="uni-title">墨轩湖姬子公寓(南昌交通学院)</text>
  10. <text class="uni-sub-title">2021年装修 | 智能门锁 | 房间wifi | 免费停车</text>
  11. <text class="uni-extra" @click="navigateToXiangqing">设施/详情></text>
  12. <text class="uni-body">宜春市靖安县北高速路口什么路899号</text>
  13. <image class="uni-phone" @click="telphone(phone)" src="../../static/index/index_phone.svg"></image>
  14. <a href="https://uri.amap.com/marker?position=115.387261,28.788671&name=南昌交通学院智慧公寓">
  15. <image class="uni-map" @click="mapDaohang('115.387261','28.788671')" src="../../static/index/index_map.svg"></image>
  16. </a>
  17. <br><text class="uni-body2">距离我{{distance}}km</text>
  18. </view>
  19. <!-- 第二层工具 -->
  20. <view class="item-list">
  21. <view class="item-list-one" @click="navigateToXuzhi">
  22. <image src="../../static/index/xuzhi.png" class="img-btn" height="100%" width="100%"></image>
  23. <text class="list-txt">入住须知</text>
  24. </view>
  25. <view class="item-list-one" @click="navigateToDairuzhu">
  26. <image src="../../static/index/ruzhu.png" class="img-btn"></image>
  27. <text class="list-txt">办理入住</text>
  28. </view>
  29. <!-- <view class="item-list-one" @click="navigateToXuzhu">
  30. <image src="../../static/index/index_xuzhu.svg" class="img-btn"></image>
  31. <text class="list-txt">办理续住</text>
  32. </view> -->
  33. <view class="item-list-one" @click="navigateToTuifang">
  34. <image src="../../static/index/tuifang.png" class="img-btn"></image>
  35. <text class="list-txt">办理退房</text>
  36. </view>
  37. </view>
  38. <!-- 退房失败时弹框 -->
  39. <uni-popup ref="popup_tui" type="center" width="300rpx" height="300rpx" background-color="#fff">
  40. <view class="kuang_txt">
  41. <text>请先订房</text>
  42. </view>
  43. </uni-popup>
  44. <!-- 第三层订房 -->
  45. <view class="room-list">
  46. <!-- 选择住房日期 -->
  47. <view class="select-time" @click="openCalendar">
  48. <view class="select-time-one">
  49. <text class="select-list">{{startWeek}}入住</text>
  50. <text class="select-list-time">{{startTime}}</text>
  51. </view>
  52. <view class="select-center">
  53. <view class="select-line1"></view>
  54. <view class="select-circle">{{ruzhu_num}}晚</view>
  55. <view class="select-line2"></view>
  56. </view>
  57. <view class="select-time-one">
  58. <text class="select-list">{{endWeek}}离店</text>
  59. <text class="select-list-time">{{endTime}}</text>
  60. </view>
  61. </view>
  62. <uni-popup ref="popup_picker" :mask-click="true">
  63. <view class=popup_bg_picker>
  64. <!-- <text class="popup_title">取消</text>
  65. <text class="popup_error" style="margin-left: 272px;" @click="popup_pickerClose">确定</text> -->
  66. <uni-calendar :selected="info.selected" class="uni-calendar--hook" :clear-date="true" :date="info.date" :insert="info.insert" :lunar="info.lunar" :startDate="info.startDate"
  67. :endDate="info.endDate" :range="info.range" @change="change"/>
  68. </view>
  69. </uni-popup>
  70. <!-- 房型列表 -->
  71. <view class="room-kuang">
  72. <view class="room-xinxi" v-for="(item,index) in roomType" :key="index">
  73. <image class="room-image" :src="item.masterImage" @click="inputDialogToggle(item.id)"></image>
  74. <view class="room-name">{{item.typeName}}</view>
  75. <view class="room-mark">{{item.typeShortDesc}}</view>
  76. <view class="room-icon">
  77. <image src="../../static/index/index_wifi.svg" style="width: 30rpx;height: 30rpx;"></image>
  78. <image src="../../static/index/index_kongtiao.svg" style="width: 26rpx;height: 26rpx;margin-left: 10rpx;"></image>
  79. <image src="../../static/index/index_nosmoking.svg" style="width: 30rpx;height: 30rpx;margin-left: 10rpx;"></image>
  80. <image src="../../static/index/index_lock.svg" style="width: 30rpx;height: 30rpx;margin-left: 10rpx;"></image>
  81. </view>
  82. <view class="before-price"><strike>¥{{item.usualPrice}}</strike></view>
  83. <view class="room-price">¥{{item.discountPrice}}</view>
  84. <view class="room-button" :class="{'room-button2': item.enableNum == 0}">
  85. <text v-if="item.enableNum==0">已满</text>
  86. <text v-else @click="navigateToOrderRoom(item.enableNum,item.id,item.typeName)">订</text>
  87. </view>
  88. <view class="room-line" v-if="index<(roomType.length-1)"></view>
  89. </view>
  90. </view>
  91. </view>
  92. <!-- 房间样式弹窗页面 -->
  93. <uni-popup ref="popup" type="dialog" :mask-click="false">
  94. <view class="popup_bg">
  95. <text class="popup_title">户型详情</text>
  96. <text class="popup_error" @click="popupClose"></text>
  97. <!-- 轮播图 -->
  98. <swiper class="swiper" circular :indicator-dots="indicatorDots">
  99. <swiper-item v-for="(item, index) in img" :key="index">
  100. <view class="swiper-item">
  101. <image :src="item" class="swiper-img"></image>
  102. </view>
  103. </swiper-item>
  104. </swiper>
  105. <text class="popup_title2">便利设施</text>
  106. <view class="popup_txt">{{typeText}}</view>
  107. </view>
  108. </uni-popup>
  109. <!-- 有一个可续住订单时办理续住弹窗页面 -->
  110. <uni-popup ref="popup_xuzhu" type="dialog" :mask-click="false">
  111. <view class="popup_bg_xu">
  112. <text class="popup_title">办理续住</text>
  113. <text class="popup_error" @click="popupXuzhuClose"></text>
  114. <text class="popup_xu_line"></text>
  115. <!-- 时间选择 -->
  116. <view class="select-time-xu" @click="openXuCalendar">
  117. <view class="select-time-one-xu">
  118. <text class="select-list">周四入住</text>
  119. <text class="select-list-time">07月21日</text>
  120. </view>
  121. <view class="select-center">
  122. <view class="select-line1"></view>
  123. <view class="select-circle">1晚</view>
  124. <view class="select-line2"></view>
  125. </view>
  126. <view class="select-time-one-xu">
  127. <text class="select-list">周五离店</text>
  128. <text class="select-list-time">07月22日</text>
  129. </view>
  130. </view>
  131. <text class="popup_xu_txt">注:办理续住最多7天,如超过7天需要重新预定</text>
  132. <!-- 支付框 -->
  133. <view class="fukuan">
  134. <view class="fu-price"><text style="font-size: 28rpx;">总计:</text>¥20.00</view>
  135. <view class="fu-zhifu">立即支付</view>
  136. </view>
  137. </view>
  138. </uni-popup>
  139. <uni-popup ref="popup_xu" :mask-click="true">
  140. <uni-calendar :selected="infoXu.selected" class="uni-calendar--hook" :clear-date="true" :date="infoXu.date" :insert="infoXu.insert" :lunar="infoXu.lunar" :startDate="infoXu.startDate"
  141. :endDate="infoXu.endDate" :range="infoXu.range" @change="changeXu"/>
  142. </uni-popup>
  143. <!-- 无可续住订单时办理续住弹窗页面 -->
  144. <uni-popup ref="popup_xuzhu_no" type="dialog">
  145. <uni-popup-dialog cancelText="关闭" confirmText="确定" content="请先订房"
  146. @close="dialogClose"></uni-popup-dialog>
  147. </uni-popup>
  148. </view>
  149. </template>
  150. <script>
  151. /**
  152. * 获取任意时间
  153. */
  154. function getDate(date, AddDayCount = 0) {
  155. if (!date) {
  156. date = new Date()
  157. }
  158. if (typeof date !== 'object') {
  159. date = date.replace(/-/g, '/')
  160. }
  161. const dd = new Date(date)
  162. dd.setDate(dd.getDate() + AddDayCount) // 获取AddDayCount天后的日期
  163. var a = new Array("日", "一", "二", "三", "四", "五", "六");
  164. var week = new Date().getDay();
  165. var week2 = new Date().getDay()+1;
  166. const y = dd.getFullYear()
  167. const m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1 // 获取当前月份的日期,不足10补0
  168. const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate() // 获取当前几号,不足10补0
  169. const h = dd.getHours() < 10 ? '0' + dd.getHours() : dd.getHours()
  170. const f = dd.getMinutes() < 10 ? '0' + dd.getMinutes() : dd.getMinutes()
  171. const s = dd.getSeconds() < 10 ? '0' + dd.getSeconds() : dd.getSeconds()
  172. return {
  173. fullDate: y + '-' + m + '-' + d,
  174. fullDate2: y + '-' + m + '-' + d+' '+h+':'+f+':'+s,
  175. fullTime: m + '月' + d + '日',
  176. year: y,
  177. month: m,
  178. date: d,
  179. day: dd.getDay(),
  180. sWeek:"周"+ a[week],
  181. eWeek:"周"+ a[week2]
  182. }
  183. }
  184. // 导入图片
  185. import AMap from "../../lib/qqmap-wx-jssdk.js"
  186. export default {
  187. data() {
  188. return {
  189. showCalendar: false,
  190. info: {
  191. lunar: true,
  192. range: true,
  193. insert: true,
  194. selected: [],
  195. startDate:'',
  196. date:'',
  197. endDate:''
  198. },
  199. distance: 0, //"距离"
  200. startTime:'',//默认到店日期
  201. endTime:'',//默认离店日期
  202. startDate:'',//默认到店日期接口数据
  203. endDate:'',//默认离店日期接口数据
  204. startWeek:'',// 默认入店日
  205. endWeek:'',// 默认离店
  206. payMount:0,//房间价格
  207. freeRoom:0,//房间剩余
  208. ruzhu_num:1,//入住夜晚数
  209. //续住里选择器
  210. infoXu: {
  211. lunar: true,
  212. range: true,
  213. insert: true,
  214. selected: [],
  215. startDate:'',
  216. date:'',
  217. endDate:''
  218. },
  219. roomType:[],
  220. typeText:'',//房型详细描述
  221. indicatorDots: true,//滚动图片提示条默认出现
  222. img:[],//轮播图里图片
  223. phone:'0791-82293574',//电话
  224. latitude: '', // 默认当前纬度
  225. longitude:'',
  226. scale: 12, // 默认16
  227. markers: [],
  228. markerHeight: 30,
  229. xuzhu_type:[],// 办理续住判断条件
  230. xuzhu_panduan:[]// 办理续住判断条件赋值
  231. }
  232. },
  233. onLoad() {
  234. this.startDate = getDate(new Date()).fullDate2
  235. this.endDate = getDate(new Date(),1).fullDate2
  236. this.getRoomType()
  237. },
  238. mounted() {
  239. },
  240. onReady() {
  241. this.$nextTick(() => {
  242. this.showCalendar = true
  243. })
  244. // TODO 模拟请求异步同步数据
  245. setTimeout(() => {
  246. // console.log('date:'+getDate(new Date()).fullDate)
  247. // console.log('startDate:'+getDate(new Date()).fullDate)
  248. // console.log('startWeek:'+getDate(new Date()).eWeek)
  249. this.info.date = getDate(new Date()).fullDate
  250. this.info.startDate = getDate(new Date()).fullDate
  251. this.info.endDate = getDate(new Date(),6).fullDate
  252. this.infoXu.date = getDate(new Date()).fullDate
  253. this.infoXu.startDate = getDate(new Date()).fullDate
  254. this.infoXu.endDate = getDate(new Date(),6).fullDate
  255. this.startTime = getDate(new Date()).fullTime
  256. this.endTime = getDate(new Date(),1).fullTime
  257. this.startWeek = getDate(new Date()).sWeek
  258. this.endWeek = getDate(new Date(),1).eWeek
  259. }, 1)
  260. // wx请求获取位置权限
  261. this.getAuthorize()
  262. .then(() => {
  263. // 同意后获取
  264. this.getLocationInfo();
  265. })
  266. .catch(() => {
  267. const that = this;
  268. uni.getLocation({
  269. type: "gcj02",
  270. success: function(res) {
  271. // 暂时
  272. that.longitude = res.longitude;
  273. that.latitude = res.latitude;
  274. var long = 0;
  275. var lat = 0;
  276. //小数点保留六位 经度
  277. if (that.longitude.toString().indexOf('.') > 0) {
  278. const longlatsplit = that.longitude.toString().split('.');
  279. if (longlatsplit.length >= 2) {
  280. long = parseFloat(longlatsplit[0] === "" ? 0 : longlatsplit[0]) + parseFloat("." + longlatsplit[1].slice(0,6));
  281. }
  282. }
  283. if (that.latitude.toString().indexOf('.') > 0) {
  284. const longlatsplit1 = that.latitude.toString().split('.');
  285. if (longlatsplit1.length >= 2) {
  286. lat = parseFloat(longlatsplit1[0] === "" ? 0 : longlatsplit1[0]) + parseFloat("." + longlatsplit1[1].slice(0,6));
  287. }
  288. }
  289. that.distance = that.getMapDistance(lat,long,'28.788671','115.387261');
  290. that.markers = [{
  291. id: "",
  292. latitude: res.latitude,
  293. longitude: res.longitude,
  294. iconPath: "../../static/img/phone.png",
  295. width: that.markerHeight, //宽
  296. height: that.markerHeight, //高
  297. }, ];
  298. },
  299. });
  300. // 不同意给出弹框,再次确认
  301. // this.openConfirm()
  302. // .then(() => {
  303. // this.getLocationInfo();
  304. // })
  305. // .catch(() => {
  306. // this.rejectGetLocation();
  307. // });
  308. });
  309. },
  310. methods: {
  311. // 房型接口
  312. getRoomType() {
  313. let _self = this
  314. _self.roomType = []
  315. this.$axios.get("/ihotel/roomType/list?startDate="+this.startDate.substring(0,10)+"&endDate="+this.endDate.substring(0,10)).then(res => {
  316. res = res.data
  317. if (res.success) {
  318. // console.log(res)
  319. res.data.forEach(data => {
  320. if (data.flag !== '-1') {
  321. _self.roomType.push(data)
  322. }
  323. })
  324. } else {
  325. console.log('获取房型失败')
  326. }
  327. });
  328. },
  329. // 房型详情接口
  330. getRoomTypeInfo(id) {
  331. let _self = this
  332. _self.typeText=''
  333. _self.img=[]
  334. this.$axios.get(`/ihotel/roomType/info/${id}`).then(res => {
  335. res = res.data
  336. if (res.success) {
  337. // console.log(res)
  338. _self.typeText=res.data.typeDesc
  339. _self.img=res.data.typeImage.split(',')
  340. // console.log(_self.img)
  341. } else {
  342. console.log('获取房型详情失败')
  343. }
  344. });
  345. },
  346. // 订单列表
  347. getOrderPage() {
  348. let _self = this
  349. _self.xuzhu_type=[]
  350. this.$axios.get("/ihotel/hotelOrder/user/order/page?curPage=1&pageSize=100",
  351. {
  352. headers:{
  353. 'user_token':localStorage.getItem('token')
  354. }
  355. }).then(res => {
  356. res = res.data
  357. if (res.success) {
  358. res.data.list.forEach(data => {
  359. if (data.flag !== '-1') {
  360. _self.xuzhu_type.push(data.orderStatu)
  361. // console.log(_self.xuzhu_type)
  362. }
  363. })
  364. } else {
  365. console.log('获取订单列表失败')
  366. }
  367. });
  368. },
  369. // 跳转到入住须知
  370. navigateToXuzhi(){
  371. uni.navigateTo({
  372. url: "../ruzhuxuzhi/ruzhuxuzhi",
  373. });
  374. },
  375. // 跳转到公寓详情
  376. navigateToXiangqing(){
  377. uni.navigateTo({
  378. url: "../gongyuxiangqing/gongyuxiangqing",
  379. });
  380. },
  381. // 订房间
  382. navigateToOrderRoom(enableNum,id,typeName) {
  383. let _self = this
  384. _self.roomType = []
  385. this.$axios.get("/ihotel/hotelOrder/user/order/confirm?startTime="+this.startDate.substring(0,10)+"&endTime="+this.endDate.substring(0,10)+'&roomTypeId='+id).then(res => {
  386. res = res.data
  387. if (res.success) {
  388. // console.log(res)
  389. this.payMount=res.data.totalAmount
  390. this.freeRoom=res.data.freeNum
  391. this.ruzhu_num=res.data.nums
  392. if (enableNum>=1){
  393. uni.navigateTo({
  394. url: "../order_room/order_room?roomTypeId="+id +"&enableStartTime="+this.startDate+"&enableEndTime="+this.endDate+"&startTime="+this.startTime+"&endTime="+this.endTime+"&typeName="+typeName+"&payMount="+this.payMount+"&freeRoom="+this.freeRoom+'&ruzhu_num='+this.ruzhu_num,
  395. });
  396. }
  397. this.getRoomType()
  398. } else {
  399. alert(res.message)
  400. }
  401. });
  402. },
  403. //办理入住跳转
  404. navigateToDairuzhu(){
  405. uni.navigateTo({
  406. url: "../my_orderlist/my_orderlist?Inv=2",
  407. })
  408. },
  409. //办理退房
  410. navigateToTuifang(){
  411. this.xuzhu_panduan=[]
  412. setTimeout(() => {
  413. this.getOrderPage()
  414. },1)
  415. setTimeout(() => {
  416. for (let i=0;i<this.xuzhu_type.length;i++){
  417. this.xuzhu_type.forEach(val => {
  418. if(val[i]==3) {
  419. this.xuzhu_panduan.push(val)
  420. }
  421. })
  422. }
  423. if(this.xuzhu_panduan.length>1) {
  424. uni.navigateTo({
  425. url:"../my_orderlist/my_orderlist?Inv=3"
  426. })
  427. }else if(this.xuzhu_panduan.length<1) {
  428. this.$refs.popup_tui.open()
  429. }
  430. },150)
  431. },
  432. //户型详情弹窗
  433. inputDialogToggle(id) {
  434. this.$refs.popup.open()
  435. this.getRoomTypeInfo(id)
  436. },
  437. popupClose() {
  438. this.$refs.popup.close()
  439. },
  440. //办理续住弹窗
  441. navigateToXuzhu(){
  442. this.xuzhu_panduan=[]
  443. setTimeout(() => {
  444. this.getOrderPage()
  445. },1)
  446. setTimeout(() => {
  447. for (let i=0;i<this.xuzhu_type.length;i++){
  448. this.xuzhu_type.forEach(val => {
  449. if(val[i]==3) {
  450. this.xuzhu_panduan.push(val)
  451. }
  452. })
  453. }
  454. console.log(this.xuzhu_panduan)
  455. if(this.xuzhu_panduan.length>1) {
  456. uni.navigateTo({
  457. url:"../my_orderlist/my_orderlist?Inv=3"
  458. })
  459. }else if(this.xuzhu_panduan.length==1) {
  460. this.$refs.popup_xuzhu.open()
  461. }else if(this.xuzhu_panduan.length==0) {
  462. this.$refs.popup_xuzhu_no.open()
  463. }
  464. },150)
  465. },
  466. popupXuzhuClose() {
  467. this.$refs.popup_xuzhu.close()
  468. },
  469. // 不可续住关闭弹窗
  470. dialogClose(){
  471. this.$refs.popup_xuzhu_no.close()
  472. },
  473. // 日期选择器弹窗开启
  474. openCalendar() {
  475. this.$refs.popup_picker.open()
  476. },
  477. change(e) {
  478. this.info.selected=[
  479. {
  480. date: e.range.before,
  481. info: '到店'
  482. },
  483. {
  484. date: e.range.after,
  485. info: '离店'
  486. }
  487. ]
  488. if(e.range.before!=''&&e.range.after=='') {
  489. this.startWeek='周'+e.lunar.ncWeek.substring(2,3)
  490. } else if(e.range.before!=''&&e.range.after!=''){
  491. this.endWeek='周'+e.lunar.ncWeek.substring(2,3)
  492. }
  493. this.startTime=e.range.before.substring(5,7)+'月'+e.range.before.substring(8,10)+'日'
  494. this.endTime=e.range.after.substring(5,7)+'月'+e.range.after.substring(8,10)+'日'
  495. this.startDate = e.range.before +' 14:00:00'
  496. this.endDate = e.range.after +' 12:00:00'
  497. this.ruzhu_num=parseInt(((new Date(e.range.after).getTime())-(new Date(e.range.before).getTime()))/1000/60/60/24)
  498. if(this.endDate !=' 12:00:00') {
  499. this.getRoomType()
  500. }
  501. },
  502. // 续住里日期选择器弹窗
  503. openXuCalendar() {
  504. this.$refs.popup_xu.open()
  505. },
  506. changeXu(e) {
  507. console.log('1change 返回:', e)
  508. // 模拟动态打卡
  509. if (this.infoXu.selected.length > 5) return
  510. this.infoXu.selected.push({
  511. date: e.range.before,
  512. info: '到店'
  513. })
  514. this.infoXu.selected.push({
  515. date: e.range.after,
  516. info: '离店'
  517. })
  518. },
  519. //拨打电话
  520. telphone(phone){
  521. uni.makePhoneCall({
  522. phoneNumber: phone ,
  523. }) // 传参带入号码即可
  524. },
  525. // 初次位置授权
  526. getAuthorize() {
  527. return new Promise((resolve, reject) => {
  528. uni.authorize({
  529. scope: "scope.userLocation",
  530. success: () => {
  531. resolve(); // 允许授权
  532. },
  533. fail: () => {
  534. reject(); // 拒绝授权
  535. },
  536. });
  537. });
  538. },
  539. // 确认授权后,获取用户位置
  540. getLocationInfo() {
  541. const that = this;
  542. uni.getLocation({
  543. type: "gcj02",
  544. success: function(res) {
  545. // 暂时
  546. that.longitude = res.longitude; //118.787575;
  547. that.latitude = res.latitude; //32.05024;
  548. console.log("获取当前的用户经度", that.longitude);
  549. console.log("获取当前的用户纬度", that.latitude);
  550. var long = 0;
  551. var lat = 0;
  552. //小数点保留六位 经度
  553. if (that.longitude.toString().indexOf('.') > 0) {
  554. const longlatsplit = that.longitude.toString().split('.');
  555. if (longlatsplit.length >= 2) {
  556. long = parseFloat(longlatsplit[0] === "" ? 0 : longlatsplit[0]) + parseFloat("." + longlatsplit[1].slice(0,6));
  557. }
  558. }
  559. if (that.latitude.toString().indexOf('.') > 0) {
  560. const longlatsplit1 = that.latitude.toString().split('.');
  561. if (longlatsplit1.length >= 2) {
  562. lat = parseFloat(longlatsplit1[0] === "" ? 0 : longlatsplit1[0]) + parseFloat("." + longlatsplit1[1].slice(0,6));
  563. }
  564. }
  565. console.log("纬度", lat);
  566. that.distance = that.getMapDistance(lat,long,'28.788671','115.387261');
  567. console.log(that.distance)
  568. that.markers = [{
  569. id: "",
  570. latitude: res.latitude,
  571. longitude: res.longitude,
  572. iconPath: "../../static/img/phone.png",
  573. width: that.markerHeight, //宽
  574. height: that.markerHeight, //高
  575. }, ];
  576. },
  577. });
  578. },
  579. // 拒绝授权后,弹框提示是否手动打开位置授权
  580. openConfirm() {
  581. return new Promise((resolve, reject) => {
  582. uni.showModal({
  583. title: "请求授权当前位置",
  584. content: "我们需要获取地理位置信息,为您推荐路线",
  585. success: (res) => {
  586. // if (res.confirm) {
  587. // uni.openSetting().then((res) => {
  588. // if (res[1].authSetting["scope.userLocation"] === true) {
  589. // resolve(); // 打开地图权限设置
  590. // } else {
  591. // reject();
  592. // console.log('reject')
  593. // }
  594. // });
  595. // } else if (res.cancel) {
  596. // reject();
  597. // }
  598. },
  599. });
  600. });
  601. },
  602. // 彻底拒绝位置获取
  603. rejectGetLocation() {
  604. uni.showToast({
  605. title: "你拒绝了授权,无法获得周边信息",
  606. icon: "none",
  607. duration: 2000,
  608. });
  609. },
  610. //打开地图导航
  611. mapDaohang(lon,lat){
  612. },
  613. //进行经纬度转换为距离的计算
  614. Rad(d) {
  615. return d * Math.PI / 180.0; //经纬度转换成三角函数中度分表形式。
  616. },
  617. /*
  618. 计算距离,参数分别为第一点的纬度,经度;第二点的纬度,经度
  619. 默认单位km
  620. */
  621. getMapDistance(lat1, lng1, lat2, lng2) {
  622. // console.log(this.Rad(lat1))
  623. // console.log(this.Rad(lng1))
  624. // console.log(this.Rad(lat2))
  625. // console.log(this.Rad(lng2))
  626. // console.log(this.Rad(28.678651))
  627. var radLat1 = this.Rad(lat1);
  628. var radLat2 = this.Rad(lat2);
  629. var a = radLat1 - radLat2;
  630. var b = this.Rad(lng1) - this.Rad(lng2);
  631. var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
  632. Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
  633. s = s * 6378.137; // EARTH_RADIUS;
  634. s = Math.round(s * 10000) / 10000; //输出为公里
  635. s=s.toFixed(2);
  636. return s;
  637. },
  638. }
  639. }
  640. </script>
  641. <style>
  642. @import url("./css/index.css");
  643. </style>