|
@@ -63,7 +63,7 @@
|
|
|
<script setup>
|
|
|
import { ref } from 'vue'
|
|
|
import { onLoad, onUnload } from '@dcloudio/uni-app'
|
|
|
-import { getVolunteerOrderInfo, getTimesByDate } from '@/api/volunteer.js'
|
|
|
+import { getVolunteerOrderInfo, getTimesByDate, getVolunteerFinishSecondOrder } from '@/api/volunteer.js'
|
|
|
import PositioningMap from '@/pages_classify/components/PositioningMap/index.vue'
|
|
|
import Slide from '@/pages_classify/components/Slide/index.vue'
|
|
|
import { useDict } from '@/utils/dict.js'
|
|
@@ -85,6 +85,90 @@ const onPhone = (phone) => {
|
|
|
const dateData = ref('00:00:00')
|
|
|
let timer = null
|
|
|
|
|
|
+// 获取当前位置信息
|
|
|
+const getCurrentLocation = () => {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ // 先检查用户是否授权了位置权限
|
|
|
+ uni.getSetting({
|
|
|
+ success: (res) => {
|
|
|
+ if (!res.authSetting['scope.userLocation']) {
|
|
|
+ // 如果用户未授权,先请求授权
|
|
|
+ uni.authorize({
|
|
|
+ scope: 'scope.userLocation',
|
|
|
+ success: () => {
|
|
|
+ // 授权成功后获取位置
|
|
|
+ getLocation(resolve, reject);
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.error('位置授权失败:', err);
|
|
|
+ uni.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: '需要获取您的位置信息,请在设置中打开位置权限',
|
|
|
+ confirmText: '去设置',
|
|
|
+ success: (res) => {
|
|
|
+ if (res.confirm) {
|
|
|
+ uni.openSetting();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ reject(err);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ // 已授权,直接获取位置
|
|
|
+ getLocation(resolve, reject);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.error('获取设置失败:', err);
|
|
|
+ reject(err);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+// 获取位置的具体实现
|
|
|
+const getLocation = (resolve, reject) => {
|
|
|
+ // 开发环境中使用模拟位置,避免权限问题
|
|
|
+ if (process.env.NODE_ENV === 'development') {
|
|
|
+ console.log('开发环境,使用模拟位置');
|
|
|
+ // 模拟重庆的位置
|
|
|
+ const mockLocation = {
|
|
|
+ longitude: 106.504962,
|
|
|
+ latitude: 29.533155
|
|
|
+ };
|
|
|
+ setTimeout(() => {
|
|
|
+ resolve(mockLocation);
|
|
|
+ }, 500);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ uni.getLocation({
|
|
|
+ type: 'gcj02',
|
|
|
+ isHighAccuracy: true, // 高精度
|
|
|
+ highAccuracyExpireTime: 3000, // 高精度过期时间
|
|
|
+ success: (res) => {
|
|
|
+ const { longitude, latitude } = res;
|
|
|
+ console.log('当前位置 - 经度:', longitude);
|
|
|
+ console.log('当前位置 - 纬度:', latitude);
|
|
|
+ resolve({
|
|
|
+ longitude,
|
|
|
+ latitude
|
|
|
+ });
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.error('获取位置失败:', err);
|
|
|
+ // 如果获取失败,使用默认位置(重庆)
|
|
|
+ const defaultLocation = {
|
|
|
+ longitude: 106.504962,
|
|
|
+ latitude: 29.533155
|
|
|
+ };
|
|
|
+ console.log('使用默认位置:', defaultLocation);
|
|
|
+ resolve(defaultLocation);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
const slideData = computed(() => {
|
|
|
//服务已开始,待上传图片
|
|
|
if (orderStatus.value) {
|
|
@@ -145,9 +229,22 @@ const getOrderDetail = async () => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const change = (e) => {
|
|
|
+const change = async (e) => {
|
|
|
if (e.state && !orderStatus.value) {
|
|
|
- getTimesByDate(secondOrderId.value).then((res) => {
|
|
|
+ try {
|
|
|
+ uni.showLoading({
|
|
|
+ title: '获取位置信息...'
|
|
|
+ })
|
|
|
+
|
|
|
+ // 获取开始服务时的位置
|
|
|
+ const locationData = await getCurrentLocation()
|
|
|
+
|
|
|
+ // 构建参数字符串
|
|
|
+ const params = `secondOrderId=${secondOrderId.value}&serviceStartLongitude=${locationData.longitude.toString()}&serviceStartLatitude=${locationData.latitude.toString()}`
|
|
|
+
|
|
|
+ // 调用开始服务接口,通过URL查询参数传递位置信息
|
|
|
+ const res = await getTimesByDate(params)
|
|
|
+
|
|
|
if (res.code === 200) {
|
|
|
uni.showToast({
|
|
|
title: '已开始服务',
|
|
@@ -159,26 +256,65 @@ const change = (e) => {
|
|
|
},
|
|
|
})
|
|
|
}
|
|
|
- })
|
|
|
+ } catch (error) {
|
|
|
+ console.error('开始服务失败', error)
|
|
|
+ uni.showToast({
|
|
|
+ title: '开始服务失败',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ } finally {
|
|
|
+ uni.hideLoading()
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
if (e.state && orderStatus.value) {
|
|
|
- uni.showToast({
|
|
|
- title: '操作成功',
|
|
|
- icon: 'success',
|
|
|
- success: () => {
|
|
|
- setTimeout(() => {
|
|
|
- uni.redirectTo({
|
|
|
- url: `/pages_classify/pages/order/index?secondOrderId=${secondOrderId.value}`,
|
|
|
- })
|
|
|
- }, 800)
|
|
|
- },
|
|
|
- })
|
|
|
+ try {
|
|
|
+ uni.showLoading({
|
|
|
+ title: '获取位置信息...'
|
|
|
+ })
|
|
|
+
|
|
|
+ // 获取结束服务时的位置
|
|
|
+ const locationData = await getCurrentLocation()
|
|
|
+
|
|
|
+ // 构建参数字符串
|
|
|
+ const params = `secondOrderId=${secondOrderId.value}&serviceFinishLongitude=${locationData.longitude.toString()}&serviceFinishLatitude=${locationData.latitude.toString()}`
|
|
|
+
|
|
|
+ // 调用结束服务接口,通过URL查询参数传递位置信息
|
|
|
+ await getVolunteerFinishSecondOrder(params)
|
|
|
+
|
|
|
+ uni.showToast({
|
|
|
+ title: '操作成功',
|
|
|
+ icon: 'success',
|
|
|
+ success: () => {
|
|
|
+ setTimeout(() => {
|
|
|
+ uni.redirectTo({
|
|
|
+ url: `/pages_classify/pages/order/index?secondOrderId=${secondOrderId.value}`,
|
|
|
+ })
|
|
|
+ }, 800)
|
|
|
+ },
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ console.error('结束服务失败', error)
|
|
|
+ uni.showToast({
|
|
|
+ title: '结束服务失败',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ } finally {
|
|
|
+ uni.hideLoading()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
onLoad((options) => {
|
|
|
secondOrderId.value = options.secondOrderId
|
|
|
getOrderDetail()
|
|
|
+
|
|
|
+ // 可选地获取当前位置
|
|
|
+ getCurrentLocation().then(location => {
|
|
|
+ console.log('页面加载时的位置:', location);
|
|
|
+ }).catch(err => {
|
|
|
+ console.log('位置获取失败,将在需要时使用默认位置');
|
|
|
+ });
|
|
|
})
|
|
|
onUnload(() => {
|
|
|
clearInterval(timer)
|