585 lines
13 KiB
Vue
Raw Normal View History

2025-04-14 10:57:27 +08:00
<template>
<map id="mapRef" ref="mapRef" style="width: 100%;height: 100vh;" show-location :longitude="location.longitude"
:latitude="location.latitude" :markers="markers" :scale="scale" :polygons="polygons" :polyline="polylines"
2025-04-15 10:56:35 +08:00
:circles="circles" @markertap="openBikeInfo" />
2025-04-15 14:56:05 +08:00
<div v-if="showTools" class="divMapTools" style="left: 10px;">
2025-04-14 10:57:27 +08:00
<div>
2025-04-15 10:19:23 +08:00
<image class="divImg" :src='imgPath+"static/userui/home/localtion.png"' @click="refresh" />
2025-04-14 10:57:27 +08:00
</div>
<div>
2025-04-15 10:19:23 +08:00
<image class="divImg" :src='imgPath+"static/userui/home/fault.png"' @click="reportFault" />
2025-04-14 10:57:27 +08:00
</div>
</div>
2025-04-15 14:56:05 +08:00
<div v-if="showTools" class="divMapTools" style="right: 10px;">
2025-04-14 10:57:27 +08:00
<div>
2025-04-15 19:03:32 +08:00
<image class="divImg" :src='imgPath+"static/userui/home/packing.png"' @click="applySite" />
2025-04-14 10:57:27 +08:00
</div>
<div>
2025-04-15 10:19:23 +08:00
<image class="divImg" :src='imgPath+"static/userui/home/mine.png"' @click="getMine" />
2025-04-14 10:57:27 +08:00
</div>
</div>
2025-04-15 14:56:05 +08:00
<div v-if="hasOrder" class="divMapOrder" @click="openOrderPay">
2025-04-14 10:57:27 +08:00
<div>
<image style="width: 15px;height: 15px;margin-left: 15px;margin-right: 10px;"
2025-04-15 10:19:23 +08:00
:src='imgPath+"static/userui/home/speaker.png"' />
2025-04-14 10:57:27 +08:00
<label>有骑行订单未支付请查看</label>
</div>
<div style="margin-right: 15px;">
<label>查看 <label>></label></label>
</div>
</div>
<div class="divMapBottom">
<div :class="(hasOrder?'divScanBtnDis ':'')+'divScanBtn'" @click="scanBike">
<uni-icons type="scan" color="white" :size="25"></uni-icons>
<label style="margin-left: 5px;">扫码用车</label>
</div>
</div>
<div v-if="showOrder" class="divOrder">
<div class="divOrderRow">
<div class="divOrderCell">
2025-04-15 10:19:23 +08:00
<image class="divOrderImg" :src='imgPath+"static/userui/home/money.png"' />
2025-04-14 10:57:27 +08:00
<label>费用</label>
<label>{{order.money}}</label>
</div>
<div class="divOrderCell2">
<label>{{order.bikecode}}</label>
</div>
</div>
<div class="divOrderRow" style="font-size: 12px;">
<div class="divOrderCell">
2025-04-15 10:19:23 +08:00
<image class="divOrderImg" :src='imgPath+"static/userui/home/timer.png"' />
2025-04-14 10:57:27 +08:00
<label>计时</label>
<label style="color: #61D246;">{{order.time}}</label>
</div>
<div class="divOrderCell2">
2025-04-15 10:19:23 +08:00
<image class="divOrderImg" :src='imgPath+"static/userui/home/bike.png"' />
2025-04-14 10:57:27 +08:00
<label>骑行</label>
<label style="color: #61D246;">{{order.mileage}}</label>
</div>
</div>
<div class="divOderBtn">
2025-04-15 10:19:23 +08:00
<image v-if="orderState==0" style="width: 120px;height: 40px;" :src='imgPath+"static/userui/home/lock.png"'
2025-04-14 10:57:27 +08:00
@click="lockRiding" />
2025-04-15 10:19:23 +08:00
<image v-if="orderState==1" style="width: 120px;height: 40px;" :src=' imgPath+"static/userui/home/run.png"'
2025-04-14 10:57:27 +08:00
@click="continueRiding" />
2025-04-24 13:54:30 +08:00
<image style="width: 160px;height: 40px;" :src='imgPath+"static/userui/home/endride.png"'
@click="endRiding" />
2025-04-14 10:57:27 +08:00
</div>
</div>
<div v-if="showMess!=1" class="divMess">
<uni-card>
<uni-list border>
2025-04-15 10:56:35 +08:00
<uni-list-item :thumb='imgPath+"static/userui/home/map1.png"' thumb-size="lg">
2025-04-14 10:57:27 +08:00
<template v-slot:body>
<div class="divMessTitle1">服务区域</div>
<div class="divMessTitle2">请在服务区域内骑行</div>
</template>
</uni-list-item>
2025-04-15 10:56:35 +08:00
<uni-list-item :thumb='imgPath+"static/userui/home/map2.png"' thumb-size="lg">
2025-04-14 10:57:27 +08:00
<template v-slot:body>
<div class="divMessTitle1">换车区域</div>
<div class="divMessTitle2">还车时确保车辆已经到达还车区域或者距你最近的停车网点</div>
</template>
</uni-list-item>
2025-04-15 10:56:35 +08:00
<uni-list-item :thumb='imgPath+"static/userui/home/map3.png"' thumb-size="lg">
2025-04-14 10:57:27 +08:00
<template v-slot:body>
<div class="divMessTitle1">停车网点</div>
<div class="divMessTitle2">还车至停车网点时长费最多可半价优惠</div>
</template>
</uni-list-item>
</uni-list>
<div class="divMessWorn">
<div class="divMessWornTitle">
·注意事项
</div>
<div class="divMessWornContent">禁止私自加锁或破坏车辆</div>
<div class="divMessWornContent">未满12岁禁止骑行</div>
<div class="divMessWornContent">如车辆故障及时通过app保修</div>
</div>
<div class="divMessBtn">
<label
style="color: #61D145;border: 1px solid #0000000f;padding: 5px 15px;border-radius: 5px;box-shadow: 2px 2px #0000000a;"
@click="clickMess">已知晓</label>
</div>
</uni-card>
</div>
2025-04-14 18:51:04 +08:00
<div v-if="showBikeInfo" style="position: absolute;z-index: 2000;bottom: 0;width: 100vw;">
2025-04-24 13:54:30 +08:00
<bike-info bikecode="123456" @close="closeBikeInfo" />
2025-04-14 18:51:04 +08:00
</div>
2025-04-15 14:56:05 +08:00
<div v-if="showOrderPay" style="position: absolute;z-index: 2000;bottom: 0;width: 100vw;">
2025-04-24 13:54:30 +08:00
<bike-pay :orderid="orderData.orderId" />
2025-04-15 14:56:05 +08:00
</div>
2025-04-14 10:57:27 +08:00
</template>
<script setup>
import {
ref,
onMounted,
getCurrentInstance
} from 'vue';
import {
showModelMessage,
getUrlParams
} from "@/utils/tools.js";
import {
callOrdereApi,
callOperateApi
} from "@/utils/api.js";
2025-04-15 10:19:23 +08:00
import {
findIndex
} from 'lodash';
import config from '@/utils/config';
2025-04-24 13:54:30 +08:00
import {
onShow,
onUnload
} from "@dcloudio/uni-app";
2025-04-15 19:03:32 +08:00
import * as map from "@/utils/usermap.js";
2025-04-15 10:19:23 +08:00
const imgPath = config.imgPath;
2025-04-14 10:57:27 +08:00
const location = ref({
longitude: "",
latitude: ""
});
const scale = ref(15);
const markers = ref([]);
const polygons = ref([]); //面
const polylines = ref([]); //线
const circles = ref([]); //圆
2025-04-24 13:54:30 +08:00
const pointStart=100000000000;
const pointEnd=100000000001;
2025-04-14 10:57:27 +08:00
let oMap = null;
2025-04-24 13:54:30 +08:00
const showTools = ref(true);
2025-04-15 19:03:32 +08:00
let oUser = null;
2025-04-14 10:57:27 +08:00
const showMess = ref(uni.getStorageSync("kbike-mess"));
const hasOrder = ref(false); //是否有订单
const showOrder = ref(false);
const order = ref({
bikecode: "123456",
money: "2.5",
time: "22.58min",
mileage: "5.6km"
});
//订单信息
let orderData = {
bikeCode: null,
status: null,
createdAt: null,
orderId: null
};
let orderTimer = null;
const orderState = ref(0);
2025-04-24 13:54:30 +08:00
const showOrderPay = ref(false);
2025-04-14 10:57:27 +08:00
//车辆
let arrBikeData = [];
2025-04-15 10:19:23 +08:00
const showBikeInfo = ref(false);
2025-04-14 10:57:27 +08:00
//加载数据
2025-04-15 10:19:23 +08:00
function getLoalcationData() {
2025-04-24 13:54:30 +08:00
map.getLoalcation(res=>{
const {
latitude,
longitude
} = res;
location.value = {
latitude,
longitude
};
oMap.moveToLocation({})
const params = {
latitude,
longitude,
radius: 20
};
callOrdereApi("userOrders/bikeList", params, "post").then(res => {
console.log("11111111111111111", "userOrders/bikeList", res);
2025-04-14 10:57:27 +08:00
const {
2025-04-24 13:54:30 +08:00
code,
data,
message
2025-04-14 10:57:27 +08:00
} = res;
2025-04-24 13:54:30 +08:00
if (code != 200) {
showModelMessage(message);
return;
}
arrBikeData = data || [];
const arrData = markers.value || [];
arrBikeData.map((item) => {
2025-04-15 10:19:23 +08:00
const {
2025-04-24 13:54:30 +08:00
longitude,
latitude
} = item;
let index = findIndex(arrData, {
longitude,
latitude
});
index = index == -1 ? arrData.length : index;
arrData[index] = map.addMarker(index, longitude, latitude, "mapbike.png",
true);
2025-04-14 10:57:27 +08:00
})
2025-04-24 13:54:30 +08:00
markers.value = arrData;
});
})
// uni.getLocation({
// type: 'gcj02',
// geocode: true,
// success(res) {
// location.value = {
// latitude,
// longitude
// };
// },
// fail(res) {
// }
// });
2025-04-14 10:57:27 +08:00
}
2025-04-15 10:19:23 +08:00
function clickMess() {
2025-04-14 10:57:27 +08:00
uni.setStorageSync("kbike-mess", 1);
showMess.value = 1;
}
//刷新
2025-04-15 10:19:23 +08:00
function refresh() {
2025-04-14 10:57:27 +08:00
getLoalcationData();
}
//故障上报
2025-04-15 10:19:23 +08:00
function reportFault() {
2025-04-14 10:57:27 +08:00
if (!oUser) {
tologin();
return;
}
2025-04-15 10:19:23 +08:00
uni.navigateTo({
url: "/pages/user/login/TroubleReportUser"
})
2025-04-14 10:57:27 +08:00
}
2025-04-15 19:03:32 +08:00
//申请站点
function applySite() {
if (!oUser) {
tologin();
return;
}
uni.navigateTo({
2025-04-24 13:54:30 +08:00
url: "/pages/user/scan/applysite"
2025-04-15 19:03:32 +08:00
})
2025-04-14 10:57:27 +08:00
}
//个人中心
2025-04-15 10:19:23 +08:00
function getMine() {
2025-04-14 10:57:27 +08:00
if (!oUser) {
tologin();
return;
}
2025-04-23 16:03:22 +08:00
uni.navigateTo({
2025-04-15 10:19:23 +08:00
url: "/pages/user/mine/MePage"
})
2025-04-14 10:57:27 +08:00
}
//扫描
2025-04-15 10:19:23 +08:00
function scanBike() {
2025-04-14 10:57:27 +08:00
if (!oUser) {
tologin();
return;
}
const {
userId
} = oUser;
uni.navigateTo({
2025-04-15 10:19:23 +08:00
url: "/pages/user/scan/scancode?type=ride"
2025-04-14 10:57:27 +08:00
})
2025-04-15 10:19:23 +08:00
2025-04-14 10:57:27 +08:00
}
2025-04-15 10:19:23 +08:00
2025-04-14 10:57:27 +08:00
2025-04-24 13:54:30 +08:00
2025-04-14 10:57:27 +08:00
//显示订单
2025-04-15 14:56:05 +08:00
function openOrderPay() {
2025-04-24 13:54:30 +08:00
showTools.value = false;
showOrderPay.value = true;
2025-04-14 10:57:27 +08:00
}
//获取订单
function getOrder() {
const {
userId
} = oUser;
callOrdereApi("userOrders/checkHistoryOrder", {
userId
}, "get").then(res => {
2025-04-23 16:03:22 +08:00
console.log("111111111111111", "userOrders/checkHistoryOrder", res);
2025-04-14 10:57:27 +08:00
const {
code,
data,
message
} = res;
if (code != 200) {
showModelMessage(message);
return;
}
if (!data) { //订单完成
completeRiding();
return;
}
const {
bikeCode,
status,
createdAt,
orderId,
tempLock,
ridePoint,
2025-04-15 19:03:32 +08:00
returnPoint,
endTime
2025-04-14 10:57:27 +08:00
} = data;
//0-进行中 1-已取消 2-待支付 3-已支付 4-退款中 5-已退款
orderState.value = tempLock ? 1 : 0;
orderData = data;
2025-04-15 10:19:23 +08:00
if (status == 2) {
2025-04-14 10:57:27 +08:00
completeRiding();
2025-04-15 10:19:23 +08:00
hasOrder.value = true;
2025-04-15 14:56:05 +08:00
getTracking();
2025-04-14 10:57:27 +08:00
return;
2025-04-15 10:19:23 +08:00
} else if (status != 0) {
2025-04-14 10:57:27 +08:00
completeRiding();
return;
}
showOrder.value = true;
2025-04-24 13:54:30 +08:00
if(tempLock==1){
getTracking();
return;
2025-04-14 10:57:27 +08:00
}
2025-04-24 13:54:30 +08:00
getTracking();
// if (!orderTimer) {
// orderTimer = setInterval(getTracking, 100000);
// }
2025-04-14 10:57:27 +08:00
})
}
2025-04-15 10:19:23 +08:00
2025-04-14 10:57:27 +08:00
//轨迹
function getTracking() {
const {
bikeCode,
2025-04-15 10:19:23 +08:00
createdAt,
ridePoint,
2025-04-15 19:03:32 +08:00
returnPoint,
endTime
2025-04-14 10:57:27 +08:00
} = orderData;
2025-04-15 19:03:32 +08:00
let params = {
2025-04-14 10:57:27 +08:00
ebikeCode: bikeCode,
2025-04-15 14:56:05 +08:00
startTime: createdAt
2025-04-14 10:57:27 +08:00
}
2025-04-24 13:54:30 +08:00
if (endTime) params = {
...params,
endTime
}
console.log("7777777777777", params);
2025-04-14 10:57:27 +08:00
callOperateApi("ebikeTracking/query", params, "post").then(res => {
2025-04-24 13:54:30 +08:00
console.log("7777777777777", "ebikeTracking/query", res);
2025-04-14 10:57:27 +08:00
const {
code,
data,
message
} = res;
if (code != 200) {
return;
2025-04-15 10:19:23 +08:00
}
2025-04-24 13:54:30 +08:00
const arrPoints = (!data || data.length == 0) ? [] : data.map(item => {
2025-04-14 10:57:27 +08:00
const {
lngGCJ02,
latGCJ02
} = item;
return {
longitude: lngGCJ02,
latitude: latGCJ02
}
2025-04-24 13:54:30 +08:00
});
const startPoint = ridePoint.split(",");
2025-04-15 10:19:23 +08:00
const lng = startPoint[0];
const lat = startPoint[1];
const start = {
longitude: lng,
latitude: lat
}
const arrMakers = markers.value || [];
2025-04-24 13:54:30 +08:00
arrPoints.splice(0, 0, start);
let indexStart = findIndex(arrMakers, {pointStart});
indexStart = indexStart == -1 ? arrMakers.length : indexStart;
arrMakers[indexStart] = map.addMarker(pointStart, lng, lat, "start.png");
if (data && data.length > 0) {
let {
lngGCJ02: endlng,
latGCJ02: endlat
} = data[data.length - 1];
arrMakers[indexStart + 1] = map.addMarker(pointEnd, endlng, endlat, "end.png");
}
markers.value = arrMakers;
if (arrPoints.length > 1) {
2025-04-21 18:48:15 +08:00
polylines.value = [map.addLine("#168DED", arrPoints)];
}
2025-04-14 10:57:27 +08:00
})
}
2025-04-15 10:19:23 +08:00
2025-04-14 10:57:27 +08:00
//完成骑行
2025-04-15 10:19:23 +08:00
function completeRiding() {
if (!orderTimer) return;
2025-04-14 10:57:27 +08:00
clearInterval(orderTimer);
2025-04-15 10:19:23 +08:00
orderTimer = null;
2025-04-14 10:57:27 +08:00
showOrder.value = false;
hasOrder.value = false;
2025-04-15 10:19:23 +08:00
orderState.value = 0;
2025-04-14 10:57:27 +08:00
}
function tologin() {
uni.navigateTo({
url: "/pages/user/login/wx_login"
})
}
//临时锁车
function lockRiding() {
2025-04-23 16:03:22 +08:00
const {
userId
} = oUser;
2025-04-24 13:54:30 +08:00
const {
bikeCode
} = orderData;
const params = {
2025-04-23 16:03:22 +08:00
userId,
bikeCode
}
2025-04-24 13:54:30 +08:00
callOrdereApi("userOrders/tempLock", params, "post").then(res => {
const {
code,
message,
data
} = res;
showModelMessage(message)
if(code==200){
if(orderTimer) {
clearInterval(orderTimer);
orderTimer=null;
}
orderState.value = 1;
}
2025-04-23 16:03:22 +08:00
});
2025-04-14 10:57:27 +08:00
}
//结束用车
function endRiding() {
2025-04-15 10:19:23 +08:00
const {
userId
} = oUser;
2025-04-14 10:57:27 +08:00
const {
bikeCode
} = orderData;
2025-04-15 10:19:23 +08:00
const params = {
userId,
bikeCode
}
callOrdereApi("userOrders/doneRide", params, "post").then(res => {
const {
code,
data,
message
} = res;
if (code != 200) {
2025-04-14 10:57:27 +08:00
showModelMessage(message);
return;
}
completeRiding();
2025-04-24 13:54:30 +08:00
openOrderPay();
2025-04-14 10:57:27 +08:00
})
2025-04-15 10:19:23 +08:00
2025-04-14 10:57:27 +08:00
}
//继续骑行 需要开锁
function continueRiding() {
2025-04-24 13:54:30 +08:00
const {
userId
} = oUser;
const {
bikeCode
} = orderData;
const params = {
userId,
bikeCode
}
callOrdereApi("userOrders/continueCycling", params, "post").then(res => {
const {
code,
message,
data
} = res;
showModelMessage(message)
if(code==200){
if(orderTimer) {
clearInterval(orderTimer);
orderTimer=null;
}
orderState.value = 0;
}
});
2025-04-14 10:57:27 +08:00
//getOrder();
}
2025-04-15 10:19:23 +08:00
//查看车辆信息
2025-04-15 14:56:05 +08:00
function openBikeInfo(e) {
2025-04-15 10:19:23 +08:00
showModelMessage("该功能暂未实现!");
2025-04-24 13:54:30 +08:00
if (!oUser) {
2025-04-15 14:56:05 +08:00
tologin();
2025-04-23 16:03:22 +08:00
return;
2025-04-15 14:56:05 +08:00
}
2025-04-24 13:54:30 +08:00
console.log("33333333333333333", e);
2025-04-15 10:19:23 +08:00
showBikeInfo.value = true;
2025-04-24 13:54:30 +08:00
showTools.value = false;
2025-04-15 10:19:23 +08:00
}
2025-04-15 10:56:35 +08:00
//关闭车辆信息
2025-04-24 13:54:30 +08:00
function closeBikeInfo() {
showBikeInfo.value = false;
showTools.value = true;
2025-04-15 10:56:35 +08:00
}
2025-04-15 10:19:23 +08:00
2025-04-24 13:54:30 +08:00
onMounted(()=>{
2025-04-14 10:57:27 +08:00
const instance = getCurrentInstance();
oMap = uni.createMapContext("mapRef", {
this: instance.proxy
});
2025-04-24 13:54:30 +08:00
})
onShow(() => {
oUser = uni.getStorageSync("wechat_user");
console.log("7777777777777777777777","oUser", oUser)
getLoalcationData();
2025-04-14 10:57:27 +08:00
const {
userId
} = oUser;
if (userId) {
getOrder();
}
});
2025-04-24 13:54:30 +08:00
onUnload(() => {
console.log("9999999999999999999", "onUnload",orderTimer);
})
2025-04-14 10:57:27 +08:00
</script>
<style scoped>
@import url("home.css");
</style>