rescue.vue 16 KB

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