fix:申请换车点

This commit is contained in:
5g0Wp7Zy 2025-07-15 15:48:53 +08:00
parent 15c89d0a81
commit 1f980fe663
3 changed files with 304 additions and 274 deletions

View File

@ -1,35 +1,39 @@
<template> <template>
<div :style="{ width: '100%', height: height }"> <div :style="{ width: '100%', height: height }">
<div class="divBtn" @click="getLoalcationPoint"> <div class="divBtn" @click="getLoalcationPoint">
<uni-icons custom-prefix="iconfont" type="icon-ebikedingwei2" color="#6f7777" size="16" /> <uni-icons
custom-prefix="iconfont"
type="icon-ebikedingwei2"
color="#6f7777"
size="16"
/>
<div>定位</div> <div>定位</div>
</div> </div>
<map id="mapRef" ref="mapRef" show-location :style="{width:'100%',height:height}" :scale="scale" <map
:longitude="longitude" :latitude="latitude" :markers="markers" @tap="ontap" /> id="mapRef"
ref="mapRef"
show-location
:style="{ width: '100%', height: height }"
:scale="scale"
:longitude="longitude"
:latitude="latitude"
:markers="markers"
@tap="ontap"
/>
</div> </div>
</template> </template>
<script setup> <script setup>
import AMapWX from "@/utils/amap-wx.130.js"; import AMapWX from "@/utils/amap-wx.130.js";
import { import { ref, onMounted, getCurrentInstance } from "vue";
ref,
onMounted,
getCurrentInstance
} from "vue";
import * as map from "@/utils/usermap.js"; import * as map from "@/utils/usermap.js";
import { import { findIndex } from "lodash";
findIndex
} from "lodash";
var amapsdk = new AMapWX({ var amapsdk = new AMapWX({
key: map.sdkKey key: map.sdkKey,
}); });
const { const { lng, lat, height } = defineProps(["lng", "lat", "height"]);
lng,
lat,
height
} = defineProps(["lng", "lat", "height"]);
const emit = defineEmits(["change"]); const emit = defineEmits(["change"]);
const mapRef = ref("mapRef"); const mapRef = ref("mapRef");
@ -46,43 +50,39 @@
const ontap = (e) => { const ontap = (e) => {
const { const {
detail: { detail: { latitude: lat, longitude: lng },
latitude: lat,
longitude: lng
}
} = e; } = e;
changPoint(lng, lat); changPoint(lng, lat);
} };
const getLoalcationPoint = () => { const getLoalcationPoint = () => {
map.getLoalcation((res) => { map.getLoalcation((res) => {
const { const { longitude: lng, latitude: lat } = res;
longitude: lng,
latitude: lat
} = res;
latitude.value = lat; latitude.value = lat;
longitude.value = lng; longitude.value = lng;
changPoint(lng, lat); changPoint(lng, lat);
oMap.moveToLocation(); oMap.moveToLocation();
}); });
} };
const changPoint = (lng, lat) => { const changPoint = (lng, lat) => {
const arrPoint = markers.value; const arrPoint = markers.value;
let index = findIndex(arrPoint, { let index = findIndex(arrPoint, {
id: 1 id: 1,
}); });
index = index == -1 ? arrPoint.length : index; index = index == -1 ? arrPoint.length : index;
arrPoint[index] = map.addMarker(1, lng, lat, "point.png"); arrPoint[index] = map.addMarker(1, lng, lat, "point.png");
markers.value = arrPoint; markers.value = arrPoint;
map.reverseGeocoder(amapsdk, lng, lat, (res) => { map.reverseGeocoder(
emit('change', res); amapsdk,
}, (res) => { lng,
lat,
}) (res) => {
} emit("change", res);
},
(res) => {}
);
};
</script> </script>
<style> <style>

View File

@ -1,132 +1,121 @@
<template> <template>
<map :style="{width: '100vw',height: scrollHeight+'px'}" :scale="scale" :longitude="mapcenter.longitude" <map
:latitude="mapcenter.latitude" :markers="markers" @tap="mapTap" @poitap="mapTap" show-location /> id="mapRef"
<div class="divInfo"> ref="mapRef"
<div class="divTitle">申请位置</div> :style="{ width: '100%', height: scrollHeight + 'rpx' }"
<div> :scale="scale"
<uni-easyinput v-model="data.site" placeholder="所在定位 点击地图修改地址" disabled="true" /> :longitude="longitude"
</div> :latitude="latitude"
<div class="divTitle">原因</div> :markers="markers"
<div> @tap="mapTap"
<uni-easyinput v-model="data.reason" placeholder="输入原因" maxlength="100" type="textarea" /> @poitap="mapTap"
</div> />
<div class="divBtn" @click="submit"> <view
提交 class="info_box"
</div> :style="{
</div> height: scrollHeight - 50 + 'rpx',
}"
>
<view class="divTitle">申请位置</view>
<view>
<uni-easyinput
v-model="data.site"
placeholder="所在定位 点击地图修改地址"
disabled="true"
/>
</view>
<view class="divTitle">原因</view>
<view>
<uni-easyinput
v-model="data.reason"
placeholder="输入原因"
maxlength="100"
type="textarea"
/>
</view>
<view class="divBtn" @click="submit">提交</view>
</view>
</template> </template>
<script setup> <script setup>
import {
ref
} from 'vue';
import AMapWX from "@/utils/amap-wx.130.js"; import AMapWX from "@/utils/amap-wx.130.js";
import { import { ref, onMounted, getCurrentInstance } from "vue";
onShow
} from "@dcloudio/uni-app";
import * as map from "@/utils/usermap.js"; import * as map from "@/utils/usermap.js";
import { import { showModelMessage, jkcBaseDecode } from "@/utils/tools.js";
callOrdereApi import { callOrdereApi } from "@/utils/api.js";
} from '@/utils/api.js'; import { onShow } from "@dcloudio/uni-app";
import {
showModelMessage,
jkcBaseDecode
} from "@/utils/tools.js";
var amapsdk = new AMapWX({ var amapsdk = new AMapWX({
key: map.sdkKey key: map.sdkKey,
}); });
//
const mapRef = ref();
let oMap = null;
const scale = 15; const scale = 15;
const mapcenter = ref({ const scrollHeight = ref(330);
longitude: null,
latitude: null
});
const markers = ref([]); const markers = ref([]);
const latitude = ref(null);
const longitude = ref(null);
const data = ref({ const data = ref({
site: "", site: "",
reason: "", reason: "",
zoneName: "" zoneName: "",
}); });
let oUser = null; let oUser = null;
// const getLoalcationPoint = () => {
const systemInfo = uni.getSystemInfoSync();
//
const screenHeight = systemInfo.screenHeight;
let scrollHeight = screenHeight - 330;
onShow(() => {
oUser = JSON.parse(jkcBaseDecode(uni.getStorageSync("wechat_user")));
map.getLoalcation((res) => { map.getLoalcation((res) => {
const { console.log(res);
latitude, const { longitude: lng, latitude: lat } = res;
longitude latitude.value = lat;
} = res; longitude.value = lng;
mapcenter.value = { changPoint(lng, lat);
latitude, oMap.moveToLocation();
longitude });
} };
getPoint(longitude, latitude);
})
})
function getPoint(longitude, latitude) { const changPoint = (lng, lat) => {
map.reverseGeocoder(amapsdk, longitude, latitude, (res) => { map.reverseGeocoder(
const { amapsdk,
formatted_address, lng,
district lat,
} = res; (res) => {
// const { const { formatted_address, district } = res;
// address, console.log(res);
// location: {
// lat,
// lng
// },
// ad_info:{
// district
// }
// } = res;
data.value = { data.value = {
...data.value, ...data.value,
site: formatted_address, site: formatted_address,
zoneName: district, zoneName: district,
lat: longitude, lat,
lng: latitude lng,
}; };
markers.value = [map.addMarker(0, longitude, latitude, "point.png")]; console.log(map);
}) markers.value = [map.addMarker(0, lng, lat, "point.png")];
console.log(markers.value);
},
(res) => {
console.error("逆解析失败");
} }
);
};
function mapTap(e) { function mapTap(e) {
const { const {
detail: { detail: { latitude, longitude },
latitude,
longitude
}
} = e; } = e;
getPoint(longitude, latitude); changPoint(longitude, latitude);
} }
function submit() { const submit = () => {
const { const { site, reason, lat, lng, zoneName } = data.value;
site,
reason,
lat,
lng,
zoneName
} = data.value;
if (!reason) { if (!reason) {
showModelMessage("请填写原因!"); showModelMessage("请填写原因!");
return; return;
} }
showModelMessage("确认提交?", "", true).then( showModelMessage("确认提交?", "", true).then(() => {
() => { const { nickname, mobile } = oUser;
const {
nickname,
mobile
} = oUser;
const params = { const params = {
applySource: "微信小程序", applySource: "微信小程序",
@ -136,19 +125,15 @@
applyNickname: nickname, applyNickname: nickname,
applyPhone: mobile, applyPhone: mobile,
applyReason: reason, applyReason: reason,
dealState: '0', dealState: "0",
zoneName zoneName,
} };
uni.showLoading({ uni.showLoading({
title: "提交中" title: "提交中",
}) });
callOrdereApi("ebikeUserBacksite/save", params, "post").then(res => { callOrdereApi("ebikeUserBacksite/save", params, "post").then((res) => {
uni.hideLoading(); uni.hideLoading();
const { const { code, data, message } = res;
code,
data,
message
} = res;
if (code == 200) { if (code == 200) {
showModelMessage("提交成功!"); showModelMessage("提交成功!");
setTimeout(() => { setTimeout(() => {
@ -162,33 +147,49 @@
} }
}); });
}); });
};
} onMounted(() => {
//
oMap = map.getMap("mapRef", getCurrentInstance());
//
const systemInfo = uni.getSystemInfoSync();
//
const screenHeight = systemInfo.screenHeight;
scrollHeight.value = screenHeight - 100;
getLoalcationPoint();
});
onShow(() => {
oUser = JSON.parse(jkcBaseDecode(uni.getStorageSync("wechat_user")));
});
</script> </script>
<style scoped> <style scoped>
.divInfo { .info_box {
position: absolute; position: fixed;
bottom: 0; bottom: 0;
left: 0;
width: 100%;
padding: 20rpx;
background: white; background: white;
padding: 15px;
height: 330px;
} }
.divTitle { .divTitle {
font-size: 16px; font-size: 30rpx;
font-weight: bold; font-weight: bold;
color: #000; color: #000;
line-height: 35px; line-height: 35px;
} }
.divBtn { .divBtn {
background-color: #61D145; background-color: #61d145;
color: white; color: white;
line-height: 40px; line-height: 40px;
text-align: center; text-align: center;
border-radius: 5px; border-radius: 5px;
margin-top: 40px; margin-top: 40px;
width: 100vw; width: calc(100vw - 30rpx);
} }
</style> </style>

View File

@ -39,19 +39,48 @@ export function getLoalcation(success, fail) {
} }
//逆解析地址 //逆解析地址
export function reverseGeocoder(qqmapsdk, longitude, latitude, success, fail) { export function reverseGeocoder(mapsdk, longitude, latitude, success, fail) {
qqmapsdk.reverseGeocoder({ mapsdk.getRegeo({
location: { location: `${longitude},${latitude}`,
latitude: latitude, success: function (res) {
longitude: longitude const {
name,
regeocodeData
} = res[0];
const {
addressComponent: {
adcode,
province,
city,
district
}, },
success: (res) => { formatted_address
if (success) success(res.result); } = regeocodeData
if (success) success({
name,
formatted_address,
adcode,
province,
city,
district
});
}, },
fail: (res) => { fail: function (info) {
if (fail) success(fail); if (fail) fail(res);
} }
}) })
// qqmapsdk.reverseGeocoder({
// location: {
// latitude: latitude,
// longitude: longitude
// },
// success: (res) => {
// if (success) success(res.result);
// },
// fail: (res) => {
// if (fail) success(fail);
// }
// })
} }
//添加点 //添加点