index.vue 23 KB

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