2023-08-21 17:25:01 +08:00
|
|
|
|
<template>
|
|
|
|
|
<view>
|
2023-08-22 16:01:58 +08:00
|
|
|
|
<!-- <view v-if='showLoading'>
|
2023-08-21 17:25:01 +08:00
|
|
|
|
<u-loading-page :loading="showLoading"></u-loading-page>
|
2023-08-22 16:01:58 +08:00
|
|
|
|
</view> -->
|
|
|
|
|
<view>
|
2023-08-21 17:25:01 +08:00
|
|
|
|
<view class="content">
|
|
|
|
|
<u-toast ref="uToast"></u-toast>
|
|
|
|
|
<view class="map">
|
|
|
|
|
<map :class="mapClass" id="map" @markertap='mapFun' :enable-zoom="true" :polyline="polyline"
|
2023-08-22 16:01:58 +08:00
|
|
|
|
:markers='markers' :scale="scale" style="width:100%;height: 100%;"
|
2023-08-21 17:25:01 +08:00
|
|
|
|
:latitude="markers[0].latitude" :enable-scroll="true" :longitude="markers[0].longitude">
|
|
|
|
|
</map>
|
|
|
|
|
</view>
|
2023-08-22 16:01:58 +08:00
|
|
|
|
<view class="map_address">
|
|
|
|
|
<view class="li">
|
2023-08-22 17:26:07 +08:00
|
|
|
|
<view style="display: flex;justify-content: left;">
|
2023-08-23 11:35:09 +08:00
|
|
|
|
<view style="flex-shrink: 0;margin-right: 14rpx;">
|
|
|
|
|
<text class="cir" style="background-color: #40BC5E;"></text>
|
|
|
|
|
中转站:
|
|
|
|
|
</view>
|
2023-08-22 17:26:07 +08:00
|
|
|
|
<view v-if="address.terminus">{{address.terminus.address}}</view>
|
2023-08-21 17:25:01 +08:00
|
|
|
|
</view>
|
2023-08-22 17:26:07 +08:00
|
|
|
|
<view :class="{lg_status1:address.terminus.status==2,lg_status2:address.terminus.status==1}">
|
2023-08-22 16:01:58 +08:00
|
|
|
|
<text class="cir" style="background-color: transparent;"></text>
|
2023-08-22 17:26:07 +08:00
|
|
|
|
<text>车辆状态:</text><text v-if="address.terminus.status==2">已完成</text>
|
2023-08-22 16:01:58 +08:00
|
|
|
|
<text v-else style="color: #FF7C32;">进行中</text>
|
2023-08-21 17:25:01 +08:00
|
|
|
|
</view>
|
|
|
|
|
</view>
|
2023-08-22 16:01:58 +08:00
|
|
|
|
<view class="li">
|
2023-08-23 11:35:09 +08:00
|
|
|
|
<view style="display: flex;justify-content: left;">
|
|
|
|
|
<view style="flex-shrink: 0;margin-right: 14rpx;">
|
|
|
|
|
<text class="cir" style="background-color: #40BC5E;"></text>
|
|
|
|
|
终 点:
|
|
|
|
|
</view>
|
|
|
|
|
<view v-if="address.transfer">{{address.transfer.address}}</view>
|
|
|
|
|
</view>
|
2023-08-22 17:26:07 +08:00
|
|
|
|
<view :class="{lg_status1:address.transfer.status==2,lg_status2:address.transfer.status==1}">
|
2023-08-22 16:01:58 +08:00
|
|
|
|
<text class="cir" style="background-color: transparent;"></text>
|
2023-08-22 17:26:07 +08:00
|
|
|
|
<text class="status">车辆状态:</text><text v-if="address.transfer.status==2">已完成</text>
|
2023-08-22 16:01:58 +08:00
|
|
|
|
<text v-else style=" color: #FF7C32;">进行中</text>
|
2023-08-21 17:25:01 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
2023-08-23 11:35:09 +08:00
|
|
|
|
|
2023-08-21 17:25:01 +08:00
|
|
|
|
</view>
|
2023-08-23 11:35:09 +08:00
|
|
|
|
<mybtn v-if="status==1" @click="getFn" text="抵达地点(中转站) 1/2"></mybtn>
|
2023-08-22 17:32:25 +08:00
|
|
|
|
<mybtn v-else-if="status==2" @click="getFn" text="抵达地点(终点) 2/2"></mybtn>
|
|
|
|
|
<mybtn v-else-if="status==3" text="任务已完成" my_btn_disabled></mybtn>
|
2023-08-21 17:25:01 +08:00
|
|
|
|
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2023-08-22 16:01:58 +08:00
|
|
|
|
import mybtn from "@/components/mybtn/mybtn.vue"
|
2023-08-23 11:35:09 +08:00
|
|
|
|
import {
|
|
|
|
|
taskTricycleDetail,
|
|
|
|
|
taskAddTricycleCoordinate
|
|
|
|
|
} from "@/api/task.js"
|
|
|
|
|
import {
|
|
|
|
|
Toast
|
|
|
|
|
} from "../../libs/uniApi";
|
2023-08-21 17:25:01 +08:00
|
|
|
|
export default {
|
2023-08-22 16:01:58 +08:00
|
|
|
|
components: {
|
|
|
|
|
mybtn
|
|
|
|
|
},
|
2023-08-21 17:25:01 +08:00
|
|
|
|
data() {
|
|
|
|
|
return {
|
2023-08-22 16:01:58 +08:00
|
|
|
|
status: 1,
|
2023-08-21 17:25:01 +08:00
|
|
|
|
mapClass: 'custom-map',
|
|
|
|
|
showLoading: true,
|
|
|
|
|
showPop: false,
|
|
|
|
|
goodsDetil: undefined,
|
|
|
|
|
scale: 17,
|
|
|
|
|
nowAddress: "无",
|
|
|
|
|
markers: [
|
|
|
|
|
// 商家
|
|
|
|
|
{
|
|
|
|
|
id: 1,
|
2023-08-22 16:01:58 +08:00
|
|
|
|
latitude: 28.8733,
|
|
|
|
|
longitude: 105.445717,
|
2023-08-21 17:25:01 +08:00
|
|
|
|
iconPath: '../../static/img/logistics/SJ.png', //显示的图标
|
|
|
|
|
},
|
2023-08-22 17:26:07 +08:00
|
|
|
|
// 当前所在位置
|
2023-08-21 17:25:01 +08:00
|
|
|
|
{
|
|
|
|
|
id: 2,
|
|
|
|
|
latitude: undefined,
|
|
|
|
|
longitude: undefined,
|
|
|
|
|
iconPath: '../../static/img/logistics/QS.png', //显示的图标
|
|
|
|
|
}
|
|
|
|
|
],
|
2023-08-22 17:26:07 +08:00
|
|
|
|
polyline: [],
|
2023-08-23 11:35:09 +08:00
|
|
|
|
task_id: -1,
|
|
|
|
|
address: {
|
|
|
|
|
terminus: {
|
|
|
|
|
status: 1
|
|
|
|
|
},
|
|
|
|
|
transfer: {
|
|
|
|
|
status: 1
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-21 17:25:01 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2023-08-23 11:35:09 +08:00
|
|
|
|
onLoad(options) {
|
|
|
|
|
this.task_id = options.task_id;
|
|
|
|
|
this.initPosition();
|
|
|
|
|
this.locationFn();
|
|
|
|
|
},
|
2023-08-21 17:25:01 +08:00
|
|
|
|
methods: {
|
|
|
|
|
// 获取位置
|
2023-08-23 11:35:09 +08:00
|
|
|
|
async initPosition() {
|
|
|
|
|
let res = await taskTricycleDetail({
|
|
|
|
|
id: this.task_id
|
|
|
|
|
});
|
|
|
|
|
this.address = res.data.extend;
|
|
|
|
|
if (res.data.extend?.update?.terminus?.lnglat[0]) { //已抵达中转站,更新目标点为终点
|
|
|
|
|
this.markers[0].latitude = +res.data.extend.transfer.lnglat[1];
|
|
|
|
|
this.markers[0].longitude = +res.data.extend.transfer.lnglat[0];
|
|
|
|
|
this.status = 2;
|
|
|
|
|
this.address.terminus['status'] = 2;
|
|
|
|
|
} else { // 未抵达中转站,设置中转站为目标点
|
|
|
|
|
this.markers[0].latitude = +res.data.extend.terminus.lnglat[1];
|
|
|
|
|
this.markers[0].longitude = +res.data.extend.terminus.lnglat[0];
|
|
|
|
|
this.address.terminus['status'] = 1;
|
|
|
|
|
}
|
|
|
|
|
if (res.data.extend?.update?.transfer?.lnglat[0]) {
|
|
|
|
|
this.address.transfer['status'] = 2;
|
|
|
|
|
this.status = 3;
|
|
|
|
|
} else this.address.transfer['status'] = 1;
|
|
|
|
|
},
|
2023-08-21 17:25:01 +08:00
|
|
|
|
// 位置
|
|
|
|
|
locationFn() {
|
|
|
|
|
let that = this
|
|
|
|
|
//#ifdef APP
|
|
|
|
|
uni.getLocation({
|
|
|
|
|
type: 'gcj02',
|
|
|
|
|
geocode: true,
|
|
|
|
|
isHighAccuracy: true,
|
|
|
|
|
success: function async (res) {
|
|
|
|
|
that.markers[1].latitude = res.latitude
|
|
|
|
|
that.markers[1].longitude = res.longitude
|
|
|
|
|
that.getDriverLine()
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
//#endif
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 唤起高德
|
|
|
|
|
test() {
|
|
|
|
|
if (this.is_captain) return
|
|
|
|
|
var packageName = 'com.autonavi.minimap';
|
|
|
|
|
var main = plus.android.runtimeMainActivity();
|
|
|
|
|
var packageManager = main.getPackageManager();
|
|
|
|
|
var PackageManager = plus.android.importClass(packageManager)
|
|
|
|
|
var packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
|
|
|
|
|
if (packageInfo) {
|
|
|
|
|
var Uri = plus.android.importClass("android.net.Uri");
|
|
|
|
|
var url =
|
|
|
|
|
`amapuri://route/plan?sourceApplication=maxuslife+
|
|
|
|
|
&sid=A&slat=36.702558&slon=116.876678&sname=我的位置&did=B&dlat=${this.markers[0].latitude}&dlon=${this.markers[0].longitude}&dname=${this.goodsDetil.logistics.shop_name}&dev=0&t=0`;
|
|
|
|
|
var Intent = plus.android.importClass('android.content.Intent');
|
|
|
|
|
var intent = new Intent();
|
|
|
|
|
intent.setAction(Intent.ACTION_VIEW);
|
|
|
|
|
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
|
|
|
|
var uri = Uri.parse(url);
|
|
|
|
|
//将功能Scheme以URI的方式传入data
|
|
|
|
|
intent.setData(uri);
|
|
|
|
|
intent.setPackage("com.autonavi.minimap");
|
|
|
|
|
var main = plus.android.runtimeMainActivity();
|
|
|
|
|
main.startActivity(intent);
|
|
|
|
|
} else {
|
|
|
|
|
// alert('未安装' + packageName + '')
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: `只支持高德地图`,
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
console.log("唤醒高德线路规划")
|
|
|
|
|
},
|
|
|
|
|
showToast() {
|
|
|
|
|
this.$refs.uToast.show({
|
|
|
|
|
type: 'success',
|
|
|
|
|
title: '成功主题(带图标)',
|
|
|
|
|
message: "操作成功",
|
|
|
|
|
iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
mapFun() {
|
|
|
|
|
uni.openLocation({
|
|
|
|
|
latitude: Number(this.goodsDetil.logistics.shop_lat),
|
|
|
|
|
longitude: Number(this.goodsDetil.logistics.shop_long),
|
|
|
|
|
address: this.goodsDetil.logistics.shop_address,
|
|
|
|
|
name: this.goodsDetil.logistics.shop_name,
|
|
|
|
|
scale: 15,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
showToast() {
|
|
|
|
|
this.$refs.uToast.show({
|
|
|
|
|
type: 'success',
|
|
|
|
|
title: '成功主题(带图标)',
|
|
|
|
|
message: "操作成功",
|
|
|
|
|
iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
|
|
|
|
|
})
|
|
|
|
|
},
|
2023-08-22 16:01:58 +08:00
|
|
|
|
// 计算距离
|
|
|
|
|
getDistance(point1, point2) {
|
|
|
|
|
const rad = Math.PI / 180.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const lat1 = point1.latitude;
|
|
|
|
|
const lng1 = point1.longitude;
|
|
|
|
|
const lat2 = point2.latitude;
|
|
|
|
|
const lng2 = point2.longitude;
|
|
|
|
|
const dlat = lat2 - lat1;
|
|
|
|
|
const dlng = lng2 - lng1;
|
|
|
|
|
const a =
|
|
|
|
|
Math.sin(dlat / 2 * rad) * Math.sin(dlat / 2 * rad) +
|
|
|
|
|
Math.cos(lat1 * rad) * Math.cos(lat2 * rad) *
|
|
|
|
|
Math.sin(dlng / 2 * rad) * Math.sin(dlng / 2 * rad);
|
|
|
|
|
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
|
|
|
const distance = 6378137 * c;
|
|
|
|
|
return distance;
|
|
|
|
|
},
|
2023-08-23 11:35:09 +08:00
|
|
|
|
// 上报位置
|
2023-08-22 16:01:58 +08:00
|
|
|
|
getFn() {
|
2023-08-23 11:35:09 +08:00
|
|
|
|
uni.showLoading({
|
|
|
|
|
title: '上传中',
|
|
|
|
|
mask: true
|
|
|
|
|
})
|
2023-08-22 16:01:58 +08:00
|
|
|
|
this.locationFn()
|
|
|
|
|
// console.log(this.getDistance(this.markers[0], this.markers[1]))
|
2023-08-22 17:26:07 +08:00
|
|
|
|
if ((this.getDistance(this.markers[0], this.markers[1]) >> 0) > 10000) {
|
|
|
|
|
return Toast('距离目标位置过远');
|
2023-08-23 11:35:09 +08:00
|
|
|
|
} else {
|
|
|
|
|
let data;
|
|
|
|
|
if (this.status == 1) data = {
|
|
|
|
|
id: this.task_id,
|
|
|
|
|
terminus: {
|
|
|
|
|
lnglat: [
|
|
|
|
|
this.markers[1].longitude,
|
|
|
|
|
this.markers[1].latitude
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
else data = {
|
|
|
|
|
id: this.task_id,
|
|
|
|
|
transfer: {
|
|
|
|
|
lnglat: [
|
|
|
|
|
this.markers[1].longitude,
|
|
|
|
|
this.markers[1].latitude
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
taskAddTricycleCoordinate(data).then(() => {
|
|
|
|
|
uni.hideLoading()
|
|
|
|
|
Toast('上传成功!')
|
|
|
|
|
if (this.status == 1) {
|
|
|
|
|
this.initPosition();
|
|
|
|
|
this.locationFn();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
2023-08-22 16:01:58 +08:00
|
|
|
|
},
|
2023-08-21 17:25:01 +08:00
|
|
|
|
getDriverLine() {
|
|
|
|
|
const that = this;
|
|
|
|
|
const key = "997c9a3d88154fa78f4d28bebc1dd84f";
|
|
|
|
|
const origin = `${this.markers[1].longitude},${this.markers[1].latitude}`;
|
|
|
|
|
const destination = `${this.markers[0].longitude},${this.markers[0].latitude}`;
|
|
|
|
|
uni.request({
|
|
|
|
|
// url: `https://restapi.amap.com/v3/direction/walking?key=${key}&origin=105.43639400000002,28.908854&destination=105.439304,28.908447`,
|
|
|
|
|
url: `https:restapi.amap.com/v4/direction/bicycling?key=${key}&origin=${origin}&destination=${destination}`,
|
|
|
|
|
success: (res) => {
|
|
|
|
|
const data = res.data.data;
|
|
|
|
|
var points = [];
|
|
|
|
|
if (data.paths && data.paths[0] && data.paths[0].steps) {
|
|
|
|
|
var steps = data.paths[0].steps;
|
|
|
|
|
for (var i = 0; i < steps.length; i++) {
|
|
|
|
|
//将每一步的数据放到points数组中
|
|
|
|
|
var poLen = steps[i].polyline.split(";");
|
|
|
|
|
for (var j = 0; j < poLen.length; j++) {
|
|
|
|
|
points.push({
|
|
|
|
|
longitude: parseFloat(poLen[j].split(",")[0]),
|
|
|
|
|
latitude: parseFloat(poLen[j].split(",")[1]),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
that.runningRoute = data.paths[0].steps[0].instruction;
|
|
|
|
|
}
|
|
|
|
|
that.polyline = [{
|
|
|
|
|
points: points,
|
|
|
|
|
color: "#0091ff",
|
|
|
|
|
dottedLine: true,
|
|
|
|
|
width: 30,
|
|
|
|
|
}, ];
|
|
|
|
|
},
|
|
|
|
|
fail: function(res) {
|
|
|
|
|
console.log("获取路线失败", res);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2023-08-22 16:01:58 +08:00
|
|
|
|
},
|
|
|
|
|
onPullDownRefresh() {
|
|
|
|
|
// this.getOrderList();
|
|
|
|
|
// this.getIndexList()
|
|
|
|
|
uni.stopPullDownRefresh();
|
2023-08-21 17:25:01 +08:00
|
|
|
|
},
|
2023-08-22 16:01:58 +08:00
|
|
|
|
|
2023-08-21 17:25:01 +08:00
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang='scss' scoped>
|
|
|
|
|
.custom-map /deep/ .polyline {
|
|
|
|
|
stroke-width: 20px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.content {
|
|
|
|
|
padding: 2vh 3vw;
|
2023-08-22 16:01:58 +08:00
|
|
|
|
background-color: #F5F5F5;
|
2023-08-21 17:25:01 +08:00
|
|
|
|
height: 100vh;
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.map {
|
2023-08-22 16:01:58 +08:00
|
|
|
|
height: 60vh;
|
2023-08-21 17:25:01 +08:00
|
|
|
|
border-radius: 2vw;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.map_address {
|
|
|
|
|
background-color: white;
|
|
|
|
|
padding: 20rpx 10rpx;
|
|
|
|
|
|
2023-08-22 16:01:58 +08:00
|
|
|
|
.li {
|
|
|
|
|
margin: 20rpx 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-21 17:25:01 +08:00
|
|
|
|
.cir {
|
|
|
|
|
display: inline-block;
|
|
|
|
|
width: 2vw;
|
2023-08-22 16:01:58 +08:00
|
|
|
|
height: 2vw;
|
2023-08-21 17:25:01 +08:00
|
|
|
|
border-radius: 2vw;
|
|
|
|
|
margin: 0 20rpx;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.map_btn {
|
|
|
|
|
width: 50px;
|
|
|
|
|
height: 50px;
|
|
|
|
|
position: absolute;
|
|
|
|
|
bottom: 0px;
|
|
|
|
|
right: 0;
|
|
|
|
|
z-index: 9999999;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.btn {
|
|
|
|
|
|
|
|
|
|
position: fixed;
|
|
|
|
|
bottom: 20rpx;
|
|
|
|
|
width: 90vw;
|
|
|
|
|
left: 50%;
|
|
|
|
|
transform: translateX(-50%);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
</style>
|