rescue.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. <template>
  2. <view class="box">
  3. <map :latitude="latitude"
  4. :longitude="longitude" :markers="covers"
  5. @poitap="tapfn" class="mapbox"
  6. :include-points="points" ></map><!-- @regionchange="regionchangefn" :style="{height:mapHeight + 'px'}" -->
  7. <view class="contBox" >
  8. <view class="tab">
  9. <view class="tabLine" :class="{tabActive:tabIndex==0}" @click="tabClick(0)">现在</view>
  10. <view class="tabLine" :class="{tabActive:tabIndex==1}" @click="tabClick(1)">预约</view>
  11. </view>
  12. <view class="timeBox" v-if="tabIndex==1" @click="openDatetimePicker">
  13. <view class="time">{{yytime?yytime:'预约救援时间'}}</view>
  14. <image src="../../static/img/little_rightArrow.png" mode="" style="width: 30rpx;height: 30rpx;"></image>
  15. </view>
  16. <view class="typeBox">
  17. <view class="box2" @click="typeClick(1)" :class="{typeActive:typeIndex==1}">
  18. <image src="../../static/img/icon_dadian_N.png" mode="" class="typeImg"></image>
  19. <view class="title">搭电</view>
  20. </view>
  21. <view class="box2" @click="typeClick(2)" :class="{typeActive:typeIndex==2}">
  22. <image src="../../static/img/icon_tuoche_N.png" mode="" class="typeImg"></image>
  23. <view class="title">拖车</view>
  24. </view>
  25. <view class="box2" @click="typeClick(3)" :class="{typeActive:typeIndex==3}">
  26. <image src="../../static/img/icon_luntai_N.png" mode="" class="typeImg"></image>
  27. <view class="title">换胎</view>
  28. </view>
  29. </view>
  30. <view class="price">服务费用 199元/次</view>
  31. <view class="shopBox">
  32. <view class="left">
  33. <view class="graypoint"></view>
  34. <view class="leftTitle">门店</view>
  35. <view class="content">{{shopInfo.shopName}}</view>
  36. </view>
  37. <image src="../../static/img/little_rightArrow.png" mode="" style="width: 30rpx;height: 30rpx;"></image>
  38. </view>
  39. <view class="shopBox" @click="startBtn">
  40. <view class="left">
  41. <view class="graypoint"></view>
  42. <view class="leftTitle">位置</view>
  43. <view class="content">{{currentAddress}}</view>
  44. </view>
  45. <image src="../../static/img/little_rightArrow.png" mode="" style="width: 30rpx;height: 30rpx;"></image>
  46. </view>
  47. <view class="shopBox" @click="endBtn" v-if="typeIndex==2">
  48. <view class="left">
  49. <view class="graypoint"></view>
  50. <view class="leftTitle">终点</view>
  51. <view class="content">{{endAddress}}</view>
  52. </view>
  53. <image src="../../static/img/little_rightArrow.png" mode="" style="width: 30rpx;height: 30rpx;"></image>
  54. </view>
  55. </view>
  56. <view class="bottomView">
  57. <view class="sure" @click="sure">确定</view>
  58. </view>
  59. <w-picker
  60. :visible.sync="visible"
  61. mode="date"
  62. startYear="2022"
  63. endYear="2029"
  64. value="2020-04-08 13:18"
  65. :current="true"
  66. fields="minute"
  67. @confirm="onConfirm($event,'date')"
  68. @cancel="onCancel"
  69. :disabled-after="false"
  70. ref="picker"
  71. ></w-picker>
  72. </view>
  73. </template>
  74. <script>
  75. import wPicker from "@/components/w-picker/w-picker.vue";
  76. import QQMapWX from '@/utils/qqmap-wx-jssdk.js'
  77. export default {
  78. components: {
  79. wPicker
  80. },
  81. data() {
  82. return {
  83. latitude: '',
  84. longitude: '',
  85. covers: [
  86. // {
  87. // latitude: 39.909,
  88. // longitude: 116.39742,
  89. // iconPath: '../../static/img/icon_qidian.png'
  90. // }, {
  91. // latitude: 39.90,
  92. // longitude: 116.39,
  93. // iconPath: '../../static/img/icon_zhongdian.png'
  94. // },
  95. ],
  96. tabIndex: 0,
  97. tMap:'',
  98. mapHeight:200,
  99. currentAddress:'',
  100. endAddress:'',
  101. points: [],
  102. endLat:'',
  103. endLng:'',
  104. distance:'',
  105. time:'',
  106. typeIndex:1,
  107. shopInfo:{
  108. lat: "36.671541",
  109. lng: "117.138777",
  110. shopName: "连锁一号测试店铺",
  111. id: "1B43BADD-B670-4B27-B6C1-604523287EAF"
  112. },
  113. shopList:'',
  114. visible:false,
  115. yytime:'',
  116. }
  117. },
  118. onLoad() {
  119. var that = this;
  120. //this.queryRescue()
  121. //return false;
  122. const tMap = new QQMapWX({
  123. key: 'L2GBZ-CIS6J-HRFFV-K5LO6-QROT7-BQFXZ' //开发者密钥 //这里要换成自己的key
  124. });
  125. this.tMap=tMap
  126. // uni.getSystemInfo({
  127. // success: (res) => {
  128. // this.mapHeight = res.windowHeight *2 - 664 - 120
  129. // }
  130. // })
  131. uni.getLocation({
  132. type: 'gcj02',
  133. success: function (res) {
  134. console.log('当前位置的经度:' + res.longitude);
  135. console.log('当前位置的纬度:' + res.latitude);
  136. that.latitude=res.latitude;
  137. that.longitude=res.longitude;
  138. var obj={
  139. latitude: that.latitude,
  140. longitude: that.longitude,
  141. iconPath: '../../static/img/icon_qidian.png',
  142. width:25,
  143. height:39
  144. }
  145. that.covers.push(obj);
  146. that.points.push({
  147. longitude: that.longitude,
  148. latitude:that.latitude
  149. })
  150. that.calculateDistance()
  151. //that.queryhelpshopList()
  152. that.tMap.reverseGeocoder({
  153. location: {
  154. latitude: that.latitude,
  155. longitude: that.longitude
  156. },
  157. success: function(res) {
  158. console.log(res)
  159. that.currentAddress=res.result.formatted_addresses.recommend
  160. },
  161. fail: function(res) {
  162. console.log(res);
  163. },
  164. })
  165. }
  166. });
  167. },
  168. methods: {
  169. onConfirm(e){
  170. console.log(e)
  171. this.yytime=e.result
  172. },
  173. openDatetimePicker() {
  174. this.$refs.picker.show()
  175. },
  176. // 关闭picker
  177. onCancel() {
  178. this.$refs.picker.hide()
  179. },
  180. queryRescue(){
  181. uni.showLoading({
  182. title: '加载中'
  183. })
  184. this.$http('openEmergencyRescue/queryRescue', {}, 'GET').then(res => {
  185. uni.hideLoading();
  186. //this.shopList = res.data
  187. })
  188. },
  189. queryhelpshopList(){
  190. uni.showLoading({
  191. title: '加载中'
  192. })
  193. this.$http('openEmergencyRescue/queryhelpshopList', {}, 'GET').then(res => {
  194. uni.hideLoading();
  195. this.shopList = res.data
  196. })
  197. },
  198. sure(){
  199. if(this.tabIndex==0){
  200. const yy = new Date().getFullYear()
  201. const MM = (new Date().getMonth() + 1) < 10 ? '0' + (new Date().getMonth() + 1) : (new Date().getMonth() + 1)
  202. const dd = new Date().getDate() < 10 ? '0' + new Date().getDate() : new Date().getDate()
  203. const HH = new Date().getHours() < 10 ? '0' + new Date().getHours() : new Date().getHours()
  204. const mm = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes()
  205. //const ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds()
  206. var time= yy + '-' + MM + '-' + dd + ' ' + HH + ':' + mm //+ ':' + ss
  207. console.log(time)
  208. //return false;
  209. }else{
  210. if(this.yytime==''){
  211. uni.showToast({
  212. title: '请选择预约时间',
  213. icon:'none',
  214. duration: 3000
  215. });
  216. return false;
  217. }
  218. var time=this.yytime
  219. }
  220. uni.navigateTo({
  221. url:'confirmRescue?lat='+this.latitude+"&lng="+this.longitude+"&shopId="+this.shopInfo.id+'&shopName='+this.shopInfo.shopName+'&type='+this.typeIndex+'&time='+time+'&currentAddress='+this.currentAddress+'&endAddress='+this.endAddress+'&endLat='+this.endLat+'&endLng='+this.endLng
  222. })
  223. },
  224. startBtn(){
  225. var that=this;
  226. uni.chooseLocation({
  227. success: function (res) {
  228. console.log(res);
  229. that.currentAddress=res.name
  230. // console.log('位置名称:' + res.name);
  231. // console.log('详细地址:' + res.address);
  232. // console.log('纬度:' + res.latitude);
  233. // console.log('经度:' + res.longitude);
  234. that.longitude=res.longitude
  235. that.latitude=res.latitude
  236. var obj={
  237. latitude: that.latitude,
  238. longitude: that.longitude,
  239. iconPath: '../../static/img/icon_qidian.png',
  240. width:25,
  241. height:39
  242. }
  243. var obj2 = {
  244. longitude: that.longitude,
  245. latitude:that.latitude
  246. }
  247. that.covers[0]=obj;
  248. that.points[0]=obj2;
  249. that.calculateDistance()
  250. console.log(that.covers)
  251. },
  252. fail(err){
  253. console.log(err)
  254. }
  255. })
  256. },
  257. endBtn(){
  258. var that=this;
  259. uni.getSetting({
  260. success(res) {
  261. if (!res.authSetting['scope.userLocation']) {
  262. uni.authorize({
  263. scope: 'scope.userLocation',
  264. success() {
  265. that.chooseLocation()
  266. return;
  267. }
  268. })
  269. }else{
  270. that.chooseLocation()
  271. return;
  272. }
  273. }
  274. })
  275. },
  276. chooseLocation(){
  277. var that=this;
  278. uni.chooseLocation({
  279. success: function (res) {
  280. console.log(res);
  281. that.endAddress=res.name
  282. // console.log('位置名称:' + res.name);
  283. // console.log('详细地址:' + res.address);
  284. // console.log('纬度:' + res.latitude);
  285. // console.log('经度:' + res.longitude);
  286. var longitude=res.longitude
  287. var latitude=res.latitude
  288. var obj={
  289. latitude: latitude,
  290. longitude: longitude,
  291. iconPath: '../../static/img/icon_zhongdian.png',
  292. width:25,
  293. height:39,
  294. // label:{
  295. // content:'文本'
  296. // },
  297. callout: { //自定义标记点上方的气泡窗口 点击有效
  298. content: '拖到这里', //文本
  299. color: '#ffffff', //文字颜色
  300. fontSize: 15, //文本大小
  301. borderRadius: 15, //边框圆角
  302. padding: '10',
  303. bgColor: '#FF0000', //背景颜色
  304. display: 'ALWAYS', //常显
  305. }
  306. }
  307. var obj2={
  308. longitude: longitude,
  309. latitude:latitude
  310. }
  311. that.endLat=latitude;
  312. that.endLng=longitude
  313. if(that.covers.length>1){
  314. that.covers[1]=obj;
  315. that.points[1]=obj2;
  316. }else{
  317. that.covers.push(obj);
  318. that.points.push(obj2)
  319. }
  320. //console.log(that.covers)
  321. that.calculateDistance()
  322. },
  323. fail(err){
  324. console.log(err)
  325. }
  326. })
  327. },
  328. //计算距离
  329. calculateDistance(){
  330. //调用距离计算接口
  331. var that=this;
  332. this.tMap.calculateDistance({
  333. mode: 'driving',//可选值:'driving'(驾车)、'walking'(步行),不填默认:'walking',可不填
  334. //from参数不填默认当前地址
  335. //获取表单提交的经纬度并设置from和to参数(示例为string格式)
  336. from: {
  337. latitude: that.shopInfo.lat,
  338. longitude: that.shopInfo.lng,
  339. }, //若起点有数据则采用起点坐标,若为空默认当前地址
  340. to:[
  341. {
  342. latitude: that.latitude,
  343. longitude: that.longitude
  344. }
  345. ] , //终点坐标
  346. success: function(res) {//成功后的回调
  347. console.log(res);
  348. that.distance=res.result.elements[0].distance;
  349. that.time = res.result.elements[0].duration/60;
  350. that.time=Math.ceil(that.time)
  351. that.setTime()
  352. },
  353. fail: function(error) {
  354. console.error(error);
  355. },
  356. complete: function(res) {
  357. console.log(res);
  358. }
  359. });
  360. },
  361. setTime(){
  362. var obj={
  363. latitude: this.latitude,
  364. longitude: this.longitude,
  365. iconPath: '../../static/img/icon_qidian.png',
  366. width:25,
  367. height:39,
  368. callout: { //自定义标记点上方的气泡窗口 点击有效
  369. content: '约'+this.time+'分钟到达', //文本
  370. color: '#ffffff', //文字颜色
  371. fontSize: 15, //文本大小
  372. borderRadius: 15, //边框圆角
  373. padding: '10',
  374. bgColor: '#3F90F7', //背景颜色
  375. display: 'ALWAYS', //常显
  376. }
  377. }
  378. this.covers[0]=obj;
  379. },
  380. regionchangefn(e){
  381. console.log(e)
  382. var that=this;
  383. if(e.detail.centerLocation){
  384. var latitude=e.detail.centerLocation.latitude;
  385. var longitude=e.detail.centerLocation.longitude;
  386. var obj={
  387. latitude: latitude,
  388. longitude: longitude,
  389. iconPath: '../../static/img/icon_qidian.png',
  390. width:25,
  391. height:39
  392. }
  393. this.covers=[];
  394. this.covers.push(obj)
  395. }
  396. },
  397. tapfn(e){
  398. //点击获取位置
  399. return false;
  400. console.log(e);
  401. var that=this;
  402. var latitude=e.detail.latitude;
  403. var longitude=e.detail.longitude;
  404. var obj={
  405. latitude: latitude,
  406. longitude: longitude,
  407. iconPath: '../../static/img/icon_qidian.png',
  408. width:25,
  409. height:39
  410. }
  411. this.covers=[];
  412. this.covers.push(obj)
  413. this.tMap.reverseGeocoder({
  414. location: {
  415. latitude: latitude,
  416. longitude: longitude
  417. },
  418. success: function(res) {
  419. //console.log(res)
  420. that.currentAddress=res.result.formatted_addresses.recommend;
  421. //console.log(this.currentAddress)
  422. //this.$set(this, 'currentAddress', this.currentAddress)
  423. },
  424. fail: function(res) {
  425. console.log(res);
  426. },
  427. })
  428. },
  429. tabClick(num) {
  430. this.tabIndex = num;
  431. },
  432. typeClick(num){
  433. this.typeIndex=num;
  434. if(num!=2){
  435. this.endLat='';
  436. this.endLng='';
  437. this.endAddress='';
  438. this.covers.splice(1,1);
  439. }
  440. }
  441. }
  442. }
  443. </script>
  444. <style>
  445. .box {
  446. width: 100vw;
  447. min-height: 100vh;
  448. background-color: #FFFFFF;
  449. }
  450. map {
  451. width: 750rpx;
  452. height: calc(100vh - 664rpx - 120rpx);
  453. }
  454. .contBox {
  455. width: 100%;
  456. height: 664rpx;
  457. }
  458. .tab {
  459. background: #FFFFFF;
  460. display: flex;
  461. justify-content: space-between;
  462. align-items: center;
  463. padding-left: 230rpx;
  464. padding-right: 230rpx;
  465. height: 92rpx;
  466. line-height: 60rpx;
  467. }
  468. .tabLine {
  469. font-size: 30rpx;
  470. color: #333333;
  471. text-align: center;
  472. padding: 0 10rpx;
  473. }
  474. .tabActive {
  475. color: #FF0000;
  476. font-weight: bold;
  477. border-bottom: 4rpx solid #FF0000;
  478. }
  479. .timeBox {
  480. padding-top: 20rpx;
  481. display: flex;
  482. justify-content: center;
  483. align-items: center;
  484. }
  485. .time {
  486. color: #959595;
  487. font-size: 24rpx;
  488. }
  489. .typeBox {
  490. padding: 30rpx 115rpx;
  491. display: flex;
  492. justify-content: space-between;
  493. }
  494. .box2 {
  495. display: flex;
  496. align-items: center;
  497. padding: 20rpx;
  498. background: #FFFFFF;
  499. height: 32rpx;
  500. border-radius: 10rpx;
  501. border: 2rpx solid #CCCCCC;
  502. }
  503. .typeImg {
  504. width: 34rpx;
  505. height: 34rpx;
  506. margin-right: 10rpx;
  507. }
  508. .title {
  509. height: 40rpx;
  510. font-size: 28rpx;
  511. font-weight: 400;
  512. color: #666666;
  513. line-height: 40rpx;
  514. }
  515. .price {
  516. padding-bottom: 30rpx;
  517. font-size: 24rpx;
  518. font-weight: 400;
  519. color: #D53533;
  520. text-align: center;
  521. }
  522. .shopBox {
  523. padding: 30rpx 24rpx;
  524. border-top: 1rpx solid #EEEEEE;
  525. display: flex;
  526. justify-content: space-between;
  527. align-items: center;
  528. }
  529. .left {
  530. display: flex;
  531. align-items: center;
  532. }
  533. .leftTitle{
  534. width: 56rpx;
  535. font-size: 28rpx;
  536. font-weight: 400;
  537. color: #666666;
  538. line-height: 40rpx;
  539. margin-left: 16rpx;
  540. margin-right: 30rpx;
  541. }
  542. .graypoint {
  543. width: 14rpx;
  544. height: 14rpx;
  545. background: #DDDDDD;
  546. border-radius: 7rpx;
  547. }
  548. .bluepoint {
  549. width: 14rpx;
  550. height: 14rpx;
  551. background: #3F90F7;
  552. border-radius: 7rpx;
  553. }
  554. .redpoint {
  555. width: 14rpx;
  556. height: 14rpx;
  557. background: #FF0000;
  558. border-radius: 7rpx;
  559. }
  560. .typeActive{
  561. background: #FF0000;
  562. }
  563. .typeActive .title{
  564. color: #FFFFFF !important;
  565. }
  566. .bottomView {
  567. border-top: 1rpx solid #EEEEEE;
  568. background-color: #FFFFFF;
  569. width: 100%;
  570. height: 120rpx;
  571. position: fixed;
  572. bottom: 0rpx;
  573. /* padding-bottom: constant(safe-area-inset-bottom);
  574. padding-bottom: env(safe-area-inset-bottom); */
  575. }
  576. .content{
  577. width: 540rpx;
  578. word-wrap: break-word; /*强制换行*/
  579. overflow: hidden; /*超出隐藏*/
  580. text-overflow: ellipsis;/*隐藏后添加省略号*/
  581. white-space: nowrap;/*强制不换行*/
  582. }
  583. .sure {
  584. background-color: #D53533;
  585. margin: 23rpx 30rpx;
  586. height: 74rpx;
  587. border-radius: 37rpx;
  588. color: #FFFFFF;
  589. font-size: 30rpx;
  590. font-weight: bold;
  591. text-align: center;
  592. line-height: 74rpx;
  593. }
  594. </style>