解决登录显示、首页显示bug
This commit is contained in:
182
pages/mall/delivery/orders/checkin.uvue
Normal file
182
pages/mall/delivery/orders/checkin.uvue
Normal file
@@ -0,0 +1,182 @@
|
||||
<template>
|
||||
<ServicePageScaffold title="到达签到" fallback-url="/pages/mall/delivery/orders/route">
|
||||
<ServicePanel title="签到要求" subtitle="定位签到或扫码签到,要求在 50 米范围内并上传现场图片。">
|
||||
<text v-if="order != null" class="info-text">服务地址:{{ order.fullAddress }}</text>
|
||||
<text class="info-text">当前定位:{{ locationText }}</text>
|
||||
<text class="info-text">现场图片:{{ photos.length }} 张</text>
|
||||
</ServicePanel>
|
||||
<ServicePanel title="签到操作" subtitle="定位失败时要给出清晰提示。">
|
||||
<view class="button-stack">
|
||||
<button class="secondary-btn" @click="getCurrentLocation">获取 GPS 定位</button>
|
||||
<button class="secondary-btn" @click="choosePhoto">拍照上传现场图片</button>
|
||||
<input class="note-input" v-model="note" placeholder="补充签到说明,例如入户前核验联系人" />
|
||||
<button class="primary-btn" :disabled="submitting" @click="submitCheckin">{{ submitting ? '签到中...' : '完成签到' }}</button>
|
||||
</view>
|
||||
</ServicePanel>
|
||||
</ServicePageScaffold>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import ServicePageScaffold from '@/components/homeService/ServicePageScaffold.uvue'
|
||||
import ServicePanel from '@/components/homeService/ServicePanel.uvue'
|
||||
import type { DeliveryLocationType, DeliveryOrderType } from '@/types/delivery.uts'
|
||||
import { checkinOrder, getDeliveryOrderDetail } from '@/services/deliveryService.uts'
|
||||
import { requireDeliveryAuth } from '@/utils/deliveryAuth.uts'
|
||||
import { getDeliveryRouteParam } from '@/utils/deliveryRoute.uts'
|
||||
|
||||
const orderId = ref('')
|
||||
const order = ref<DeliveryOrderType | null>(null)
|
||||
const currentLocation = ref<DeliveryLocationType | null>(null)
|
||||
const locationText = ref('未获取')
|
||||
const photos = ref([] as Array<string>)
|
||||
const note = ref('')
|
||||
const submitting = ref(false)
|
||||
|
||||
function toRadians(value: number): number {
|
||||
return value * 3.1415926 / 180
|
||||
}
|
||||
|
||||
function calculateDistance(lat1: number, lng1: number, lat2: number, lng2: number): number {
|
||||
const earthRadius = 6378137
|
||||
const deltaLat = toRadians(lat2 - lat1)
|
||||
const deltaLng = toRadians(lng2 - lng1)
|
||||
const a = Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2) + Math.cos(toRadians(lat1)) * Math.cos(toRadians(lat2)) * Math.sin(deltaLng / 2) * Math.sin(deltaLng / 2)
|
||||
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
|
||||
return earthRadius * c
|
||||
}
|
||||
|
||||
function wrapLocation(): Promise<DeliveryLocationType> {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.getLocation({
|
||||
type: 'gcj02',
|
||||
success: (res) => {
|
||||
resolve({ latitude: res.latitude, longitude: res.longitude, address: '当前位置', time: new Date().toISOString().replace('T', ' ').substring(0, 19) })
|
||||
},
|
||||
fail: () => {
|
||||
reject(new Error('定位失败'))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function wrapChooseImage(): Promise<Array<string>> {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.chooseImage({
|
||||
count: 3,
|
||||
sourceType: ['camera'],
|
||||
success: (res) => {
|
||||
resolve(res.tempFilePaths)
|
||||
},
|
||||
fail: () => {
|
||||
reject(new Error('拍照失败'))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
async function loadData() {
|
||||
const authResult = await requireDeliveryAuth({ redirectOnFail: true, toastOnFail: true })
|
||||
if (!authResult.ok || orderId.value == '') {
|
||||
return
|
||||
}
|
||||
order.value = await getDeliveryOrderDetail(orderId.value)
|
||||
}
|
||||
|
||||
async function getCurrentLocation() {
|
||||
try {
|
||||
currentLocation.value = await wrapLocation()
|
||||
locationText.value = '纬度 ' + String(currentLocation.value.latitude) + ' / 经度 ' + String(currentLocation.value.longitude)
|
||||
} catch (error) {
|
||||
uni.showToast({ title: '签到定位失败,请检查定位权限', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
async function choosePhoto() {
|
||||
try {
|
||||
const selected = await wrapChooseImage()
|
||||
photos.value = selected
|
||||
} catch (error) {
|
||||
uni.showToast({ title: '拍照失败,请重试', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
async function submitCheckin() {
|
||||
if (submitting.value) return
|
||||
if (order.value == null) return
|
||||
if (currentLocation.value == null) {
|
||||
await getCurrentLocation()
|
||||
if (currentLocation.value == null) return
|
||||
}
|
||||
if (photos.value.length == 0) {
|
||||
uni.showToast({ title: '请至少上传一张现场图片', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const distance = calculateDistance(currentLocation.value.latitude, currentLocation.value.longitude, order.value.latitude, order.value.longitude)
|
||||
if (distance > order.value.allowCheckinRadiusMeters) {
|
||||
uni.showToast({ title: '距离服务地址超出允许范围,不能签到', icon: 'none' })
|
||||
return
|
||||
}
|
||||
submitting.value = true
|
||||
try {
|
||||
await checkinOrder(orderId.value, {
|
||||
location: currentLocation.value as DeliveryLocationType,
|
||||
note: note.value,
|
||||
photos: photos.value,
|
||||
checkinMode: 'gps'
|
||||
})
|
||||
uni.showToast({ title: '签到成功', icon: 'success' })
|
||||
uni.navigateTo({ url: '/pages/mall/delivery/orders/execute?id=' + orderId.value })
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onLoad((options) => {
|
||||
if (options != null) {
|
||||
orderId.value = getDeliveryRouteParam(options as UTSJSONObject, 'id')
|
||||
}
|
||||
loadData()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.info-text {
|
||||
display: block;
|
||||
margin-bottom: 14rpx;
|
||||
font-size: 26rpx;
|
||||
line-height: 38rpx;
|
||||
color: #16324f;
|
||||
}
|
||||
|
||||
.button-stack {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.primary-btn,
|
||||
.secondary-btn {
|
||||
margin-bottom: 18rpx;
|
||||
border-radius: 18rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.primary-btn {
|
||||
background: #0f766e;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.secondary-btn {
|
||||
background: #eaf2f0;
|
||||
color: #0f766e;
|
||||
}
|
||||
|
||||
.note-input {
|
||||
height: 84rpx;
|
||||
padding: 0 24rpx;
|
||||
margin-bottom: 18rpx;
|
||||
border-radius: 18rpx;
|
||||
background: #f2f7f6;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
</style>
|
||||
144
pages/mall/delivery/orders/detail.uvue
Normal file
144
pages/mall/delivery/orders/detail.uvue
Normal file
@@ -0,0 +1,144 @@
|
||||
<template>
|
||||
<ServicePageScaffold title="工单详情" fallback-url="/pages/mall/delivery/orders/index">
|
||||
<ServicePanel title="基础信息" subtitle="接单前脱敏,接单后展示完整信息。">
|
||||
<view v-if="order != null">
|
||||
<text class="row-text">工单号:{{ order.orderNo }}</text>
|
||||
<text class="row-text">服务项目:{{ order.serviceName }}</text>
|
||||
<text class="row-text">服务对象:{{ order.status == 'pending_accept' ? order.elderNameMasked : order.fullElderName }}</text>
|
||||
<text class="row-text">联系电话:{{ order.status == 'pending_accept' ? order.elderPhoneMasked : order.fullPhone }}</text>
|
||||
<text class="row-text">服务地址:{{ order.status == 'pending_accept' ? order.addressSummary : order.fullAddress }}</text>
|
||||
<text class="row-text">预约时间:{{ order.appointmentStartTime }} - {{ order.appointmentEndTime }}</text>
|
||||
<text class="row-text">联系人:{{ order.contactName }} / {{ order.contactPhone }}</text>
|
||||
<text class="row-text">注意事项:{{ order.notices.join(';') }}</text>
|
||||
</view>
|
||||
</ServicePanel>
|
||||
|
||||
<ServicePanel title="服务项目" subtitle="未完成项需在执行页填写原因。">
|
||||
<view v-if="order != null" v-for="item in order.serviceItems" :key="item.id" class="item-row">
|
||||
<text class="row-text">{{ item.name }}</text>
|
||||
</view>
|
||||
</ServicePanel>
|
||||
|
||||
<ServicePanel title="状态时间轴" subtitle="所有关键动作都需要留痕。">
|
||||
<ServiceTimeline :items="timelineItems"></ServiceTimeline>
|
||||
</ServicePanel>
|
||||
|
||||
<view class="bottom-space"></view>
|
||||
<view v-if="order != null" class="fixed-bar">
|
||||
<view class="bar-btn secondary-btn" @click="goException"><text class="bar-text secondary-text">异常上报</text></view>
|
||||
<view v-if="order.status == 'pending_accept'" class="bar-btn primary-btn" @click="acceptOrder"><text class="bar-text">接单</text></view>
|
||||
<view v-else-if="order.status == 'accepted' || order.status == 'on_the_way' || order.status == 'arrived'" class="bar-btn primary-btn" @click="goRoute"><text class="bar-text">出发/签到</text></view>
|
||||
<view v-else class="bar-btn primary-btn" @click="goExecute"><text class="bar-text">进入执行</text></view>
|
||||
</view>
|
||||
</ServicePageScaffold>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import ServicePageScaffold from '@/components/homeService/ServicePageScaffold.uvue'
|
||||
import ServicePanel from '@/components/homeService/ServicePanel.uvue'
|
||||
import ServiceTimeline from '@/components/homeService/ServiceTimeline.uvue'
|
||||
import { acceptDeliveryOrder, getDeliveryOrderDetail } from '@/services/deliveryService.uts'
|
||||
import type { DeliveryOrderType } from '@/types/delivery.uts'
|
||||
import { requireDeliveryAuth } from '@/utils/deliveryAuth.uts'
|
||||
import { getDeliveryRouteParam } from '@/utils/deliveryRoute.uts'
|
||||
|
||||
const orderId = ref('')
|
||||
const order = ref<DeliveryOrderType | null>(null)
|
||||
const timelineItems = ref([] as Array<any>)
|
||||
|
||||
async function loadData() {
|
||||
const authResult = await requireDeliveryAuth({ redirectOnFail: true, toastOnFail: true })
|
||||
if (!authResult.ok || orderId.value == '') {
|
||||
return
|
||||
}
|
||||
order.value = await getDeliveryOrderDetail(orderId.value)
|
||||
if (order.value != null) {
|
||||
timelineItems.value = order.value.timeline
|
||||
}
|
||||
}
|
||||
|
||||
async function acceptOrder() {
|
||||
await acceptDeliveryOrder(orderId.value)
|
||||
uni.showToast({ title: '接单成功', icon: 'success' })
|
||||
loadData()
|
||||
}
|
||||
|
||||
function goRoute() {
|
||||
uni.navigateTo({ url: '/pages/mall/delivery/orders/route?id=' + orderId.value })
|
||||
}
|
||||
|
||||
function goExecute() {
|
||||
uni.navigateTo({ url: '/pages/mall/delivery/orders/execute?id=' + orderId.value })
|
||||
}
|
||||
|
||||
function goException() {
|
||||
uni.navigateTo({ url: '/pages/mall/delivery/orders/exception?id=' + orderId.value })
|
||||
}
|
||||
|
||||
onLoad((options) => {
|
||||
if (options != null) {
|
||||
orderId.value = getDeliveryRouteParam(options as UTSJSONObject, 'id')
|
||||
}
|
||||
loadData()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.row-text {
|
||||
display: block;
|
||||
margin-bottom: 14rpx;
|
||||
font-size: 26rpx;
|
||||
line-height: 38rpx;
|
||||
color: #16324f;
|
||||
}
|
||||
|
||||
.item-row {
|
||||
padding: 16rpx 0;
|
||||
border-bottom: 1rpx solid #e6edf1;
|
||||
}
|
||||
|
||||
.bottom-space {
|
||||
height: 140rpx;
|
||||
}
|
||||
|
||||
.fixed-bar {
|
||||
position: fixed;
|
||||
left: 24rpx;
|
||||
right: 24rpx;
|
||||
bottom: 24rpx;
|
||||
padding: 16rpx;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
background: #ffffff;
|
||||
border-radius: 24rpx;
|
||||
box-shadow: 0 12rpx 24rpx rgba(15, 118, 110, 0.08);
|
||||
}
|
||||
|
||||
.bar-btn {
|
||||
width: 48%;
|
||||
padding: 20rpx 0;
|
||||
border-radius: 18rpx;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.primary-btn {
|
||||
background: #0f766e;
|
||||
}
|
||||
|
||||
.secondary-btn {
|
||||
background: #eaf2f0;
|
||||
}
|
||||
|
||||
.bar-text {
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.secondary-text {
|
||||
color: #0f766e;
|
||||
}
|
||||
</style>
|
||||
186
pages/mall/delivery/orders/evidence.uvue
Normal file
186
pages/mall/delivery/orders/evidence.uvue
Normal file
@@ -0,0 +1,186 @@
|
||||
<template>
|
||||
<ServicePageScaffold title="证据上传" fallback-url="/pages/mall/delivery/orders/execute">
|
||||
<ServicePanel title="上传分组" subtitle="服务前、服务中、服务后图片,音频/视频先预留。">
|
||||
<view class="phase-tabs">
|
||||
<view v-for="item in phases" :key="item.value" class="phase-item" :class="currentPhase == item.value ? 'phase-active' : ''" @click="switchPhase(item.value)">
|
||||
<text class="phase-text">{{ item.label }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<button class="secondary-btn" @click="chooseImageUpload">拍照并上传</button>
|
||||
<button class="secondary-btn" @click="simulateFailedUpload">模拟失败上传</button>
|
||||
</ServicePanel>
|
||||
|
||||
<ServicePanel title="材料列表" subtitle="失败材料可重试。">
|
||||
<view v-if="evidenceList.length == 0" class="empty-box"><text class="empty-text">当前阶段暂无材料</text></view>
|
||||
<view v-for="item in evidenceList" :key="item.id" class="evidence-card">
|
||||
<text class="row-text">{{ item.name }}</text>
|
||||
<text class="row-text">状态:{{ item.status }} · 进度:{{ item.progress }}%</text>
|
||||
<text class="row-text">创建时间:{{ item.createdAt }}</text>
|
||||
<view v-if="item.retryable" class="retry-btn" @click="retryUpload(item.id)"><text class="retry-text">重试上传</text></view>
|
||||
</view>
|
||||
</ServicePanel>
|
||||
</ServicePageScaffold>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import ServicePageScaffold from '@/components/homeService/ServicePageScaffold.uvue'
|
||||
import ServicePanel from '@/components/homeService/ServicePanel.uvue'
|
||||
import type { DeliveryEvidenceRecordType, DeliveryOrderType } from '@/types/delivery.uts'
|
||||
import { getDeliveryOrderDetail, retryUploadEvidence, uploadEvidence } from '@/services/deliveryService.uts'
|
||||
import { requireDeliveryAuth } from '@/utils/deliveryAuth.uts'
|
||||
import { getDeliveryRouteParam } from '@/utils/deliveryRoute.uts'
|
||||
|
||||
const orderId = ref('')
|
||||
const order = ref<DeliveryOrderType | null>(null)
|
||||
const currentPhase = ref('before')
|
||||
const evidenceList = ref([] as Array<DeliveryEvidenceRecordType>)
|
||||
const phases = [
|
||||
{ label: '服务前', value: 'before' },
|
||||
{ label: '服务中', value: 'during' },
|
||||
{ label: '服务后', value: 'after' }
|
||||
]
|
||||
|
||||
function wrapChooseImage(): Promise<Array<string>> {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.chooseImage({
|
||||
count: 3,
|
||||
sourceType: ['camera', 'album'],
|
||||
success: (res) => {
|
||||
resolve(res.tempFilePaths)
|
||||
},
|
||||
fail: () => {
|
||||
reject(new Error('选择图片失败'))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function rebuildPhaseList() {
|
||||
const list: Array<DeliveryEvidenceRecordType> = []
|
||||
if (order.value == null) {
|
||||
evidenceList.value = list
|
||||
return
|
||||
}
|
||||
for (let i = 0; i < order.value.evidenceList.length; i++) {
|
||||
const item = order.value.evidenceList[i]
|
||||
if (item.phase == currentPhase.value) {
|
||||
list.push(item)
|
||||
}
|
||||
}
|
||||
evidenceList.value = list
|
||||
}
|
||||
|
||||
async function loadData() {
|
||||
const authResult = await requireDeliveryAuth({ redirectOnFail: true, toastOnFail: true })
|
||||
if (!authResult.ok || orderId.value == '') {
|
||||
return
|
||||
}
|
||||
order.value = await getDeliveryOrderDetail(orderId.value)
|
||||
rebuildPhaseList()
|
||||
}
|
||||
|
||||
function switchPhase(value: string) {
|
||||
currentPhase.value = value
|
||||
rebuildPhaseList()
|
||||
}
|
||||
|
||||
async function chooseImageUpload() {
|
||||
try {
|
||||
const files = await wrapChooseImage()
|
||||
await uploadEvidence(orderId.value, currentPhase.value, files)
|
||||
uni.showToast({ title: '上传请求已提交', icon: 'success' })
|
||||
loadData()
|
||||
} catch (error) {
|
||||
uni.showToast({ title: '上传失败,请重试', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
async function simulateFailedUpload() {
|
||||
await uploadEvidence(orderId.value, 'during', ['mock-failed-image'])
|
||||
loadData()
|
||||
}
|
||||
|
||||
async function retryUpload(evidenceId: string) {
|
||||
await retryUploadEvidence(orderId.value, evidenceId)
|
||||
uni.showToast({ title: '已重试上传', icon: 'success' })
|
||||
loadData()
|
||||
}
|
||||
|
||||
onLoad((options) => {
|
||||
if (options != null) {
|
||||
orderId.value = getDeliveryRouteParam(options as UTSJSONObject, 'id')
|
||||
}
|
||||
loadData()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.phase-tabs {
|
||||
flex-direction: row;
|
||||
margin-bottom: 18rpx;
|
||||
}
|
||||
|
||||
.phase-item {
|
||||
padding: 14rpx 24rpx;
|
||||
margin-right: 14rpx;
|
||||
border-radius: 999rpx;
|
||||
background: #eef2f6;
|
||||
}
|
||||
|
||||
.phase-active {
|
||||
background: #0f766e;
|
||||
}
|
||||
|
||||
.phase-text {
|
||||
font-size: 24rpx;
|
||||
color: #476178;
|
||||
}
|
||||
|
||||
.phase-active .phase-text {
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.secondary-btn {
|
||||
margin-bottom: 18rpx;
|
||||
border-radius: 18rpx;
|
||||
background: #eaf2f0;
|
||||
color: #0f766e;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.evidence-card {
|
||||
padding: 20rpx;
|
||||
margin-bottom: 16rpx;
|
||||
border-radius: 18rpx;
|
||||
background: #f8fbfc;
|
||||
}
|
||||
|
||||
.row-text,
|
||||
.empty-text {
|
||||
display: block;
|
||||
margin-bottom: 12rpx;
|
||||
font-size: 24rpx;
|
||||
line-height: 36rpx;
|
||||
color: #16324f;
|
||||
}
|
||||
|
||||
.retry-btn {
|
||||
padding: 16rpx 0;
|
||||
border-radius: 16rpx;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #fff4e5;
|
||||
}
|
||||
|
||||
.retry-text {
|
||||
font-size: 26rpx;
|
||||
font-weight: 700;
|
||||
color: #b45309;
|
||||
}
|
||||
|
||||
.empty-box {
|
||||
padding: 24rpx;
|
||||
}
|
||||
</style>
|
||||
167
pages/mall/delivery/orders/exception.uvue
Normal file
167
pages/mall/delivery/orders/exception.uvue
Normal file
@@ -0,0 +1,167 @@
|
||||
<template>
|
||||
<ServicePageScaffold title="异常上报" fallback-url="/pages/mall/delivery/orders/detail">
|
||||
<ServicePanel title="异常类型" subtitle="高风险异常需立即提醒联系家属、调度或 120。">
|
||||
<view class="type-grid">
|
||||
<view v-for="item in exceptionTypes" :key="item.value" class="type-item" :class="currentType == item.value ? 'type-active' : ''" @click="currentType = item.value">
|
||||
<text class="type-text">{{ item.label }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</ServicePanel>
|
||||
<ServicePanel title="异常说明" subtitle="说明必填,支持上传图片凭证。">
|
||||
<textarea class="textarea" v-model="description" placeholder="请填写异常发生情况、现场处置动作和需要协同的事项"></textarea>
|
||||
<button class="secondary-btn" @click="chooseImage">上传异常图片</button>
|
||||
<text class="info-text">已选择图片:{{ images.length }} 张</text>
|
||||
<text v-if="isHighRisk" class="risk-text">高风险异常:请同步联系家属/调度/120,并保留处置留痕。</text>
|
||||
</ServicePanel>
|
||||
<button class="primary-btn" :disabled="submitting" @click="submitForm">{{ submitting ? '提交中...' : '提交异常' }}</button>
|
||||
</ServicePageScaffold>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref, computed } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import ServicePageScaffold from '@/components/homeService/ServicePageScaffold.uvue'
|
||||
import ServicePanel from '@/components/homeService/ServicePanel.uvue'
|
||||
import { submitException } from '@/services/deliveryService.uts'
|
||||
import { requireDeliveryAuth } from '@/utils/deliveryAuth.uts'
|
||||
import { getDeliveryRouteParam } from '@/utils/deliveryRoute.uts'
|
||||
|
||||
const orderId = ref('')
|
||||
const currentType = ref('cannot_contact_elder')
|
||||
const description = ref('')
|
||||
const images = ref([] as Array<string>)
|
||||
const submitting = ref(false)
|
||||
const exceptionTypes = [
|
||||
{ label: '无法联系老人', value: 'cannot_contact_elder' },
|
||||
{ label: '无法入户', value: 'cannot_enter_home' },
|
||||
{ label: '地址错误', value: 'wrong_address' },
|
||||
{ label: '老人拒绝服务', value: 'elder_refuse_service' },
|
||||
{ label: '家属要求改期', value: 'family_requests_reschedule' },
|
||||
{ label: '现场存在安全风险', value: 'safety_risk' },
|
||||
{ label: '老人身体异常', value: 'elder_health_abnormal' },
|
||||
{ label: '突发疾病', value: 'emergency_illness' },
|
||||
{ label: '服务项目无法完成', value: 'item_unavailable' },
|
||||
{ label: '其他', value: 'other' }
|
||||
]
|
||||
const isHighRisk = computed(() => currentType.value == 'safety_risk' || currentType.value == 'elder_health_abnormal' || currentType.value == 'emergency_illness')
|
||||
|
||||
function wrapChooseImage(): Promise<Array<string>> {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.chooseImage({
|
||||
count: 3,
|
||||
sourceType: ['camera', 'album'],
|
||||
success: (res) => { resolve(res.tempFilePaths) },
|
||||
fail: () => { reject(new Error('选择图片失败')) }
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
async function chooseImage() {
|
||||
try {
|
||||
images.value = await wrapChooseImage()
|
||||
} catch (error) {
|
||||
uni.showToast({ title: '图片选择失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
async function submitForm() {
|
||||
if (submitting.value) return
|
||||
if (description.value.trim() == '') {
|
||||
uni.showToast({ title: '异常说明不能为空', icon: 'none' })
|
||||
return
|
||||
}
|
||||
submitting.value = true
|
||||
try {
|
||||
await submitException(orderId.value, { exceptionType: currentType.value as any, description: description.value.trim(), images: images.value })
|
||||
uni.showToast({ title: '异常已上报', icon: 'success' })
|
||||
uni.setStorageSync('delivery_orders_tab', 'exception')
|
||||
uni.switchTab({ url: '/pages/mall/delivery/orders/index' })
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onLoad(async (options) => {
|
||||
const authResult = await requireDeliveryAuth({ redirectOnFail: true, toastOnFail: true })
|
||||
if (!authResult.ok) {
|
||||
return
|
||||
}
|
||||
if (options != null) {
|
||||
orderId.value = getDeliveryRouteParam(options as UTSJSONObject, 'id')
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.type-grid {
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.type-item {
|
||||
width: 48%;
|
||||
padding: 18rpx 16rpx;
|
||||
margin-bottom: 16rpx;
|
||||
border-radius: 18rpx;
|
||||
background: #eef2f6;
|
||||
}
|
||||
|
||||
.type-active {
|
||||
background: #0f766e;
|
||||
}
|
||||
|
||||
.type-text {
|
||||
font-size: 24rpx;
|
||||
line-height: 34rpx;
|
||||
color: #476178;
|
||||
}
|
||||
|
||||
.type-active .type-text {
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.textarea {
|
||||
width: 100%;
|
||||
min-height: 220rpx;
|
||||
padding: 24rpx;
|
||||
border-radius: 20rpx;
|
||||
background: #f2f7f6;
|
||||
font-size: 28rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.secondary-btn,
|
||||
.primary-btn {
|
||||
margin-top: 18rpx;
|
||||
border-radius: 18rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.secondary-btn {
|
||||
background: #eaf2f0;
|
||||
color: #0f766e;
|
||||
}
|
||||
|
||||
.primary-btn {
|
||||
background: #0f766e;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.info-text,
|
||||
.risk-text {
|
||||
display: block;
|
||||
margin-top: 12rpx;
|
||||
font-size: 24rpx;
|
||||
line-height: 36rpx;
|
||||
}
|
||||
|
||||
.info-text {
|
||||
color: #5e758c;
|
||||
}
|
||||
|
||||
.risk-text {
|
||||
color: #b45309;
|
||||
font-weight: 700;
|
||||
}
|
||||
</style>
|
||||
258
pages/mall/delivery/orders/execute.uvue
Normal file
258
pages/mall/delivery/orders/execute.uvue
Normal file
@@ -0,0 +1,258 @@
|
||||
<template>
|
||||
<ServicePageScaffold title="服务执行" fallback-url="/pages/mall/delivery/orders/detail">
|
||||
<ServicePanel title="执行计时" subtitle="服务开始后持续计时,提交前可暂存。">
|
||||
<text class="timer-text">已服务时长:{{ elapsedText }}</text>
|
||||
<text class="info-text">备注:{{ progressNote }}</text>
|
||||
</ServicePanel>
|
||||
|
||||
<ServicePanel title="服务项目打卡" subtitle="未完成项必须填写原因。">
|
||||
<view v-for="item in serviceItems" :key="item.id" class="item-card">
|
||||
<view class="item-header">
|
||||
<text class="item-title">{{ item.name }}</text>
|
||||
<switch :checked="item.completed" color="#0f766e" @change="toggleItem(item.id, $event)" />
|
||||
</view>
|
||||
<input class="note-input" v-model="item.remark" placeholder="服务备注,例如监测结果、陪护说明" />
|
||||
<input v-if="item.completed == false" class="note-input" v-model="item.incompleteReason" placeholder="未完成原因,必填" />
|
||||
</view>
|
||||
</ServicePanel>
|
||||
|
||||
<ServicePanel title="过程留痕" subtitle="服务中可补充备注、证据和异常上报。">
|
||||
<input class="note-input" v-model="progressNote" placeholder="请输入服务过程备注" />
|
||||
<input class="note-input" v-model="serviceSummary" placeholder="请输入服务总结,完成提交时会带入" />
|
||||
<view class="action-row">
|
||||
<view class="secondary-btn" @click="goEvidence"><text class="btn-text secondary-text">证据上传</text></view>
|
||||
<view class="secondary-btn" @click="goException"><text class="btn-text secondary-text">异常上报</text></view>
|
||||
</view>
|
||||
</ServicePanel>
|
||||
|
||||
<view class="bottom-space"></view>
|
||||
<view class="fixed-bar">
|
||||
<view class="bar-btn secondary-btn" @click="saveDraft"><text class="btn-text secondary-text">暂存</text></view>
|
||||
<view class="bar-btn primary-btn" @click="goFinish"><text class="btn-text">完成服务</text></view>
|
||||
</view>
|
||||
</ServicePageScaffold>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref } from 'vue'
|
||||
import { onLoad, onUnload } from '@dcloudio/uni-app'
|
||||
import ServicePageScaffold from '@/components/homeService/ServicePageScaffold.uvue'
|
||||
import ServicePanel from '@/components/homeService/ServicePanel.uvue'
|
||||
import { getDeliveryOrderDetail, saveServiceProgress, startService } from '@/services/deliveryService.uts'
|
||||
import type { DeliveryOrderType, DeliveryServiceItemType } from '@/types/delivery.uts'
|
||||
import { requireDeliveryAuth } from '@/utils/deliveryAuth.uts'
|
||||
import { getDeliveryRouteParam } from '@/utils/deliveryRoute.uts'
|
||||
|
||||
const orderId = ref('')
|
||||
const order = ref<DeliveryOrderType | null>(null)
|
||||
const serviceItems = ref([] as Array<DeliveryServiceItemType>)
|
||||
const progressNote = ref('')
|
||||
const serviceSummary = ref('')
|
||||
const elapsedText = ref('00:00')
|
||||
let timerId: number | null = null
|
||||
|
||||
function formatElapsed() {
|
||||
if (order.value == null || order.value.actualStartTime == '') {
|
||||
elapsedText.value = '00:00'
|
||||
return
|
||||
}
|
||||
const start = new Date(order.value.actualStartTime.replace(' ', 'T')).getTime()
|
||||
const diffMinutes = Math.floor((Date.now() - start) / 60000)
|
||||
const hours = Math.floor(diffMinutes / 60)
|
||||
const minutes = diffMinutes % 60
|
||||
const hourText = hours < 10 ? '0' + String(hours) : String(hours)
|
||||
const minuteText = minutes < 10 ? '0' + String(minutes) : String(minutes)
|
||||
elapsedText.value = hourText + ':' + minuteText
|
||||
}
|
||||
|
||||
function startTimer() {
|
||||
formatElapsed()
|
||||
if (timerId != null) {
|
||||
clearInterval(timerId)
|
||||
}
|
||||
timerId = setInterval(() => {
|
||||
formatElapsed()
|
||||
}, 60000)
|
||||
}
|
||||
|
||||
function toggleItem(itemId: string, event: any) {
|
||||
for (let i = 0; i < serviceItems.value.length; i++) {
|
||||
if (serviceItems.value[i].id == itemId) {
|
||||
const checked = event.detail.value === true
|
||||
serviceItems.value[i].completed = checked
|
||||
serviceItems.value[i].updatedAt = new Date().toISOString().replace('T', ' ').substring(0, 19)
|
||||
if (checked) {
|
||||
serviceItems.value[i].incompleteReason = ''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function ensureStarted(orderData: DeliveryOrderType) {
|
||||
if (orderData.status == 'checked_in' || orderData.status == 'arrived') {
|
||||
order.value = await startService(orderId.value)
|
||||
} else {
|
||||
order.value = orderData
|
||||
}
|
||||
if (order.value != null) {
|
||||
serviceItems.value = order.value.serviceItems
|
||||
progressNote.value = order.value.progressNote
|
||||
serviceSummary.value = order.value.serviceSummary
|
||||
startTimer()
|
||||
}
|
||||
}
|
||||
|
||||
async function loadData() {
|
||||
const authResult = await requireDeliveryAuth({ redirectOnFail: true, toastOnFail: true })
|
||||
if (!authResult.ok || orderId.value == '') {
|
||||
return
|
||||
}
|
||||
const detail = await getDeliveryOrderDetail(orderId.value)
|
||||
if (detail != null) {
|
||||
await ensureStarted(detail)
|
||||
}
|
||||
}
|
||||
|
||||
function validateItems(): boolean {
|
||||
for (let i = 0; i < serviceItems.value.length; i++) {
|
||||
const item = serviceItems.value[i]
|
||||
if (item.completed == false && item.incompleteReason == '') {
|
||||
uni.showToast({ title: '未完成项目必须填写原因', icon: 'none' })
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
async function saveDraft() {
|
||||
if (!validateItems()) {
|
||||
return
|
||||
}
|
||||
await saveServiceProgress(orderId.value, { items: serviceItems.value, progressNote: progressNote.value, serviceSummary: serviceSummary.value })
|
||||
uni.showToast({ title: '已暂存服务记录', icon: 'success' })
|
||||
loadData()
|
||||
}
|
||||
|
||||
async function goFinish() {
|
||||
if (!validateItems()) {
|
||||
return
|
||||
}
|
||||
await saveServiceProgress(orderId.value, { items: serviceItems.value, progressNote: progressNote.value, serviceSummary: serviceSummary.value })
|
||||
uni.navigateTo({ url: '/pages/mall/delivery/orders/finish?id=' + orderId.value })
|
||||
}
|
||||
|
||||
function goEvidence() {
|
||||
uni.navigateTo({ url: '/pages/mall/delivery/orders/evidence?id=' + orderId.value })
|
||||
}
|
||||
|
||||
function goException() {
|
||||
uni.navigateTo({ url: '/pages/mall/delivery/orders/exception?id=' + orderId.value })
|
||||
}
|
||||
|
||||
onLoad((options) => {
|
||||
if (options != null) {
|
||||
orderId.value = getDeliveryRouteParam(options as UTSJSONObject, 'id')
|
||||
}
|
||||
loadData()
|
||||
})
|
||||
|
||||
onUnload(() => {
|
||||
if (timerId != null) {
|
||||
clearInterval(timerId)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.timer-text {
|
||||
font-size: 38rpx;
|
||||
font-weight: 700;
|
||||
color: #0f766e;
|
||||
}
|
||||
|
||||
.info-text {
|
||||
margin-top: 12rpx;
|
||||
font-size: 24rpx;
|
||||
line-height: 36rpx;
|
||||
color: #5e758c;
|
||||
}
|
||||
|
||||
.item-card {
|
||||
padding: 20rpx;
|
||||
margin-bottom: 16rpx;
|
||||
border-radius: 18rpx;
|
||||
background: #f8fbfc;
|
||||
}
|
||||
|
||||
.item-header,
|
||||
.action-row {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.item-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
color: #16324f;
|
||||
}
|
||||
|
||||
.note-input {
|
||||
height: 84rpx;
|
||||
padding: 0 24rpx;
|
||||
margin-top: 14rpx;
|
||||
border-radius: 18rpx;
|
||||
background: #f2f7f6;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.action-row {
|
||||
margin-top: 18rpx;
|
||||
}
|
||||
|
||||
.secondary-btn,
|
||||
.primary-btn,
|
||||
.bar-btn {
|
||||
flex: 1;
|
||||
padding: 20rpx 0;
|
||||
border-radius: 18rpx;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.secondary-btn {
|
||||
background: #eaf2f0;
|
||||
margin-right: 12rpx;
|
||||
}
|
||||
|
||||
.primary-btn {
|
||||
background: #0f766e;
|
||||
margin-left: 12rpx;
|
||||
}
|
||||
|
||||
.btn-text {
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.secondary-text {
|
||||
color: #0f766e;
|
||||
}
|
||||
|
||||
.bottom-space {
|
||||
height: 140rpx;
|
||||
}
|
||||
|
||||
.fixed-bar {
|
||||
position: fixed;
|
||||
left: 24rpx;
|
||||
right: 24rpx;
|
||||
bottom: 24rpx;
|
||||
padding: 16rpx;
|
||||
flex-direction: row;
|
||||
background: #ffffff;
|
||||
border-radius: 24rpx;
|
||||
box-shadow: 0 12rpx 24rpx rgba(15, 118, 110, 0.08);
|
||||
}
|
||||
</style>
|
||||
176
pages/mall/delivery/orders/finish.uvue
Normal file
176
pages/mall/delivery/orders/finish.uvue
Normal file
@@ -0,0 +1,176 @@
|
||||
<template>
|
||||
<ServicePageScaffold title="完成确认" fallback-url="/pages/mall/delivery/orders/execute">
|
||||
<ServicePanel title="完成摘要" subtitle="结算由机构端或后台处理,这里只做执行完成提交。">
|
||||
<text v-if="order != null" class="row-text">开始时间:{{ order.actualStartTime }}</text>
|
||||
<text v-if="order != null" class="row-text">结束时间:{{ order.actualEndTime == '' ? '提交后生成' : order.actualEndTime }}</text>
|
||||
<text v-if="order != null" class="row-text">完成项目:{{ completedCount }}</text>
|
||||
<text v-if="order != null" class="row-text">未完成项目:{{ incompleteCount }}</text>
|
||||
<text v-if="order != null" class="row-text">有效证据:{{ evidenceCount }}</text>
|
||||
</ServicePanel>
|
||||
<ServicePanel title="确认信息" subtitle="至少要有服务记录和必要证据,签名先采用文本签名 mock。">
|
||||
<textarea class="textarea" v-model="serviceSummary" placeholder="请填写服务总结"></textarea>
|
||||
<input class="note-input" v-model="signatureName" placeholder="请输入老人或家属签名姓名" />
|
||||
<label class="confirm-row">
|
||||
<switch :checked="confirmByFamily" color="#0f766e" @change="toggleConfirm" />
|
||||
<text class="confirm-text">已由老人/家属确认本次服务结果</text>
|
||||
</label>
|
||||
</ServicePanel>
|
||||
<button class="primary-btn" :disabled="submitting" @click="submitFinish">{{ submitting ? '提交中...' : '提交完成确认' }}</button>
|
||||
</ServicePageScaffold>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import ServicePageScaffold from '@/components/homeService/ServicePageScaffold.uvue'
|
||||
import ServicePanel from '@/components/homeService/ServicePanel.uvue'
|
||||
import type { DeliveryOrderType } from '@/types/delivery.uts'
|
||||
import { finishService, getDeliveryOrderDetail } from '@/services/deliveryService.uts'
|
||||
import { requireDeliveryAuth } from '@/utils/deliveryAuth.uts'
|
||||
import { getDeliveryRouteParam } from '@/utils/deliveryRoute.uts'
|
||||
|
||||
const orderId = ref('')
|
||||
const order = ref<DeliveryOrderType | null>(null)
|
||||
const serviceSummary = ref('')
|
||||
const signatureName = ref('')
|
||||
const confirmByFamily = ref(false)
|
||||
const submitting = ref(false)
|
||||
const completedCount = ref(0)
|
||||
const incompleteCount = ref(0)
|
||||
const evidenceCount = ref(0)
|
||||
|
||||
function rebuildCounters() {
|
||||
if (order.value == null) {
|
||||
completedCount.value = 0
|
||||
incompleteCount.value = 0
|
||||
evidenceCount.value = 0
|
||||
return
|
||||
}
|
||||
let completed = 0
|
||||
let incomplete = 0
|
||||
for (let i = 0; i < order.value.serviceItems.length; i++) {
|
||||
if (order.value.serviceItems[i].completed) {
|
||||
completed++
|
||||
} else {
|
||||
incomplete++
|
||||
}
|
||||
}
|
||||
let evidence = 0
|
||||
for (let i = 0; i < order.value.evidenceList.length; i++) {
|
||||
if (order.value.evidenceList[i].status == 'success') {
|
||||
evidence++
|
||||
}
|
||||
}
|
||||
completedCount.value = completed
|
||||
incompleteCount.value = incomplete
|
||||
evidenceCount.value = evidence
|
||||
}
|
||||
|
||||
async function loadData() {
|
||||
const authResult = await requireDeliveryAuth({ redirectOnFail: true, toastOnFail: true })
|
||||
if (!authResult.ok || orderId.value == '') {
|
||||
return
|
||||
}
|
||||
order.value = await getDeliveryOrderDetail(orderId.value)
|
||||
if (order.value != null) {
|
||||
serviceSummary.value = order.value.serviceSummary
|
||||
signatureName.value = order.value.signatureName
|
||||
}
|
||||
rebuildCounters()
|
||||
}
|
||||
|
||||
function toggleConfirm(event: any) {
|
||||
confirmByFamily.value = event.detail.value === true
|
||||
}
|
||||
|
||||
async function submitFinish() {
|
||||
if (submitting.value) return
|
||||
if (serviceSummary.value.trim() == '') {
|
||||
uni.showToast({ title: '请填写服务总结', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (signatureName.value.trim() == '') {
|
||||
uni.showToast({ title: '请填写签名姓名', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!confirmByFamily.value) {
|
||||
uni.showToast({ title: '请确认已取得老人/家属确认', icon: 'none' })
|
||||
return
|
||||
}
|
||||
submitting.value = true
|
||||
try {
|
||||
await finishService(orderId.value, { serviceSummary: serviceSummary.value.trim(), signatureName: signatureName.value.trim(), confirmByFamily: confirmByFamily.value })
|
||||
uni.showToast({ title: '已提交待验收', icon: 'success' })
|
||||
uni.setStorageSync('delivery_orders_tab', 'completed')
|
||||
uni.switchTab({ url: '/pages/mall/delivery/orders/index' })
|
||||
} catch (error) {
|
||||
let message = '提交失败'
|
||||
try {
|
||||
const err = error as Error
|
||||
if (err.message != null && err.message != '') {
|
||||
message = err.message
|
||||
}
|
||||
} catch (e) {}
|
||||
uni.showToast({ title: message, icon: 'none' })
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onLoad((options) => {
|
||||
if (options != null) {
|
||||
orderId.value = getDeliveryRouteParam(options as UTSJSONObject, 'id')
|
||||
}
|
||||
loadData()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.row-text,
|
||||
.confirm-text {
|
||||
display: block;
|
||||
margin-bottom: 14rpx;
|
||||
font-size: 26rpx;
|
||||
line-height: 38rpx;
|
||||
color: #16324f;
|
||||
}
|
||||
|
||||
.textarea {
|
||||
width: 100%;
|
||||
min-height: 220rpx;
|
||||
padding: 24rpx;
|
||||
border-radius: 20rpx;
|
||||
background: #f2f7f6;
|
||||
font-size: 28rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.note-input {
|
||||
height: 84rpx;
|
||||
padding: 0 24rpx;
|
||||
margin-top: 18rpx;
|
||||
border-radius: 18rpx;
|
||||
background: #f2f7f6;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.confirm-row {
|
||||
margin-top: 18rpx;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.confirm-text {
|
||||
margin-left: 16rpx;
|
||||
margin-bottom: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.primary-btn {
|
||||
margin-top: 24rpx;
|
||||
border-radius: 18rpx;
|
||||
background: #0f766e;
|
||||
color: #ffffff;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
</style>
|
||||
616
pages/mall/delivery/orders/index.uvue
Normal file
616
pages/mall/delivery/orders/index.uvue
Normal file
@@ -0,0 +1,616 @@
|
||||
<template>
|
||||
<ServicePageScaffold title="工单列表" fallback-url="/pages/mall/delivery/home/index" :hide-header="true">
|
||||
<view class="delivery-orders-page">
|
||||
<view class="delivery-orders-hero">
|
||||
<view class="delivery-orders-hero-top">
|
||||
<view class="delivery-orders-hero-main">
|
||||
<text class="delivery-orders-hero-title">服务工单</text>
|
||||
<text class="delivery-orders-hero-subtitle">{{ getCurrentTabLabel() }} · {{ getCurrentTabSubtitle() }}</text>
|
||||
</view>
|
||||
<view class="delivery-orders-hero-badge">
|
||||
<text class="delivery-orders-hero-badge-text">{{ orders.length }} 单</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="delivery-orders-hero-tip-box">
|
||||
<text class="delivery-orders-hero-tip">接单前仅显示脱敏信息,接单后查看详情可见完整信息。</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="delivery-orders-card delivery-orders-filter-card">
|
||||
<view class="delivery-orders-card-header">
|
||||
<view>
|
||||
<text class="delivery-orders-card-title">状态筛选</text>
|
||||
<text class="delivery-orders-card-subtitle">横向切换工单状态,列表会同步刷新对应内容</text>
|
||||
</view>
|
||||
</view>
|
||||
<scroll-view
|
||||
class="status-scroll"
|
||||
direction="horizontal"
|
||||
:show-scrollbar="false"
|
||||
:scroll-into-view="activeTabViewId"
|
||||
scroll-with-animation="true"
|
||||
>
|
||||
<view class="status-tabs-row">
|
||||
<view
|
||||
v-for="item in tabs"
|
||||
:key="item.value"
|
||||
:id="'status-tab-' + item.value"
|
||||
class="status-tab-item"
|
||||
:class="currentTab == item.value ? 'status-tab-active' : ''"
|
||||
@click="switchTab(item.value)"
|
||||
>
|
||||
<text class="status-tab-text" :class="currentTab == item.value ? 'status-tab-text-active' : ''">{{ item.label }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<view class="delivery-orders-card delivery-orders-list-card">
|
||||
<view class="delivery-orders-card-header">
|
||||
<view>
|
||||
<text class="delivery-orders-card-title">工单列表</text>
|
||||
<text class="delivery-orders-card-subtitle">突出状态、地址、风险与下一步处理动作</text>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="orders.length == 0" class="empty-box"><text class="empty-text">{{ getEmptyText() }}</text></view>
|
||||
<view v-for="item in orders" :key="item.id" class="order-card" :class="getStatusSurfaceClass(item.status)">
|
||||
<view class="card-top">
|
||||
<view class="order-main" @click="goDetail(item.id)">
|
||||
<text class="order-title">{{ item.serviceType }} · {{ item.serviceName }}</text>
|
||||
<text class="order-meta">服务对象:{{ item.elderNameMasked }}</text>
|
||||
</view>
|
||||
<ServiceStatusTag :text="item.statusText" :tone="item.statusTone"></ServiceStatusTag>
|
||||
</view>
|
||||
<view class="order-info-box" @click="goDetail(item.id)">
|
||||
<text class="order-meta">预约时间:{{ item.appointmentStartTime }}</text>
|
||||
<text class="order-meta">服务地址:{{ item.addressSummary }}</text>
|
||||
<text class="order-meta">距离:{{ item.distanceKm }} · 风险:{{ formatRiskTags(item.riskTags) }}</text>
|
||||
</view>
|
||||
<view class="order-footer">
|
||||
<text class="order-next-text">下一步:{{ getPrimaryActionText(item.status) }}</text>
|
||||
<view class="order-action-btn order-action-btn-secondary" @click="goDetail(item.id)">
|
||||
<text class="order-action-btn-text order-action-btn-text-secondary">查看详情</text>
|
||||
</view>
|
||||
<view v-if="item.status == 'pending_accept'" class="order-action-btn" :class="getPrimaryActionClass(item.status)" @click="acceptOrder(item.id)"><text class="order-action-btn-text">接单</text></view>
|
||||
<view v-else-if="item.status == 'accepted'" class="order-action-btn" :class="getPrimaryActionClass(item.status)" @click="goRoute(item.id)"><text class="order-action-btn-text">去出发</text></view>
|
||||
<view v-else-if="item.status == 'on_the_way' || item.status == 'arrived'" class="order-action-btn" :class="getPrimaryActionClass(item.status)" @click="goCheckin(item.id)"><text class="order-action-btn-text">去签到</text></view>
|
||||
<view v-else-if="item.status == 'checked_in' || item.status == 'serving' || item.status == 'pending_submit' || item.status == 'pending_acceptance'" class="order-action-btn" :class="getPrimaryActionClass(item.status)" @click="goExecute(item.id)"><text class="order-action-btn-text">继续服务</text></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="delivery-orders-safe"></view>
|
||||
</view>
|
||||
</ServicePageScaffold>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref } from 'vue'
|
||||
import { onLoad, onShow } from '@dcloudio/uni-app'
|
||||
import ServicePageScaffold from '@/components/homeService/ServicePageScaffold.uvue'
|
||||
import ServiceStatusTag from '@/components/homeService/ServiceStatusTag.uvue'
|
||||
import { acceptDeliveryOrder, getDeliveryOrders } from '@/services/deliveryService.uts'
|
||||
import type { DeliveryOrderType } from '@/types/delivery.uts'
|
||||
import { requireDeliveryAuth } from '@/utils/deliveryAuth.uts'
|
||||
import { getDeliveryRouteParam } from '@/utils/deliveryRoute.uts'
|
||||
|
||||
const tabs = [
|
||||
{ label: '全部', value: 'all' },
|
||||
{ label: '待接单', value: 'pending_accept' },
|
||||
{ label: '待出发', value: 'accepted' },
|
||||
{ label: '服务中', value: 'serving' },
|
||||
{ label: '待提交', value: 'pending_submit' },
|
||||
{ label: '已完成', value: 'completed' },
|
||||
{ label: '异常', value: 'exception' }
|
||||
]
|
||||
|
||||
const currentTab = ref('all')
|
||||
const activeTabViewId = ref('status-tab-all')
|
||||
const orders = ref<Array<DeliveryOrderType>>([])
|
||||
|
||||
function getCurrentTabLabel(): string {
|
||||
for (let i = 0; i < tabs.length; i++) {
|
||||
if (tabs[i].value == currentTab.value) {
|
||||
return tabs[i].label
|
||||
}
|
||||
}
|
||||
return '全部'
|
||||
}
|
||||
|
||||
function getCurrentTabSubtitle(): string {
|
||||
if (currentTab.value == 'pending_accept') {
|
||||
return '优先响应新派单,避免错过服务时效'
|
||||
}
|
||||
if (currentTab.value == 'accepted') {
|
||||
return '确认出发路线,尽快进入上门流程'
|
||||
}
|
||||
if (currentTab.value == 'serving') {
|
||||
return '关注执行进度、签到与服务记录'
|
||||
}
|
||||
if (currentTab.value == 'pending_submit') {
|
||||
return '尽快补齐记录,完成本次服务提交'
|
||||
}
|
||||
if (currentTab.value == 'completed') {
|
||||
return '回顾已完成服务,跟进结算与评价反馈'
|
||||
}
|
||||
if (currentTab.value == 'exception') {
|
||||
return '优先处理异常事项,保障服务连续性'
|
||||
}
|
||||
return '集中查看全部服务工单与处理进展'
|
||||
}
|
||||
|
||||
function isValidTab(tab: string): boolean {
|
||||
for (let i = 0; i < tabs.length; i++) {
|
||||
if (tabs[i].value == tab) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function syncActiveTabViewId(): void {
|
||||
activeTabViewId.value = 'status-tab-' + currentTab.value
|
||||
}
|
||||
|
||||
function applyTab(tab: string): void {
|
||||
if (tab == '' || !isValidTab(tab)) {
|
||||
currentTab.value = 'all'
|
||||
} else {
|
||||
currentTab.value = tab
|
||||
}
|
||||
syncActiveTabViewId()
|
||||
}
|
||||
|
||||
function consumeStoredTab(): void {
|
||||
const storedTab = uni.getStorageSync('delivery_orders_tab') as string | null
|
||||
if (storedTab != null && storedTab != '') {
|
||||
uni.removeStorageSync('delivery_orders_tab')
|
||||
applyTab(storedTab)
|
||||
}
|
||||
}
|
||||
|
||||
function getEmptyText(): string {
|
||||
if (currentTab.value == 'pending_accept') {
|
||||
return '暂无待接单工单'
|
||||
}
|
||||
if (currentTab.value == 'accepted') {
|
||||
return '暂无待出发工单'
|
||||
}
|
||||
if (currentTab.value == 'serving') {
|
||||
return '暂无服务中工单'
|
||||
}
|
||||
if (currentTab.value == 'pending_submit') {
|
||||
return '暂无待提交工单'
|
||||
}
|
||||
if (currentTab.value == 'completed') {
|
||||
return '暂无已完成工单'
|
||||
}
|
||||
if (currentTab.value == 'exception') {
|
||||
return '暂无异常工单'
|
||||
}
|
||||
return '暂无工单'
|
||||
}
|
||||
|
||||
function formatRiskTags(tags: Array<string>): string {
|
||||
if (tags.length == 0) {
|
||||
return '常规服务'
|
||||
}
|
||||
return tags.join(' / ')
|
||||
}
|
||||
|
||||
function getPrimaryActionText(status: string): string {
|
||||
if (status == 'pending_accept') {
|
||||
return '立即接单'
|
||||
}
|
||||
if (status == 'accepted') {
|
||||
return '准备出发'
|
||||
}
|
||||
if (status == 'on_the_way' || status == 'arrived') {
|
||||
return '去签到'
|
||||
}
|
||||
if (status == 'checked_in' || status == 'serving' || status == 'pending_submit' || status == 'pending_acceptance') {
|
||||
return '继续服务'
|
||||
}
|
||||
if (status == 'exception_pending') {
|
||||
return '处理异常'
|
||||
}
|
||||
if (status == 'completed' || status == 'settled' || status == 'archived') {
|
||||
return '查看结果'
|
||||
}
|
||||
return '查看详情'
|
||||
}
|
||||
|
||||
function getPrimaryActionClass(status: string): string {
|
||||
if (status == 'pending_accept') {
|
||||
return 'action-warning'
|
||||
}
|
||||
if (status == 'accepted' || status == 'on_the_way' || status == 'arrived') {
|
||||
return 'action-primary'
|
||||
}
|
||||
if (status == 'checked_in' || status == 'serving' || status == 'pending_submit' || status == 'pending_acceptance') {
|
||||
return 'action-teal'
|
||||
}
|
||||
if (status == 'exception_pending') {
|
||||
return 'action-danger'
|
||||
}
|
||||
if (status == 'completed' || status == 'settled' || status == 'archived') {
|
||||
return 'action-success'
|
||||
}
|
||||
return 'action-default'
|
||||
}
|
||||
|
||||
function getStatusSurfaceClass(status: string): string {
|
||||
if (status == 'pending_accept') {
|
||||
return 'status-surface-warning'
|
||||
}
|
||||
if (status == 'accepted' || status == 'on_the_way' || status == 'arrived') {
|
||||
return 'status-surface-primary'
|
||||
}
|
||||
if (status == 'checked_in' || status == 'serving' || status == 'pending_submit' || status == 'pending_acceptance') {
|
||||
return 'status-surface-teal'
|
||||
}
|
||||
if (status == 'exception_pending') {
|
||||
return 'status-surface-danger'
|
||||
}
|
||||
if (status == 'completed' || status == 'settled' || status == 'archived') {
|
||||
return 'status-surface-success'
|
||||
}
|
||||
return 'status-surface-default'
|
||||
}
|
||||
|
||||
async function loadData() {
|
||||
const authResult = await requireDeliveryAuth({ redirectOnFail: true, toastOnFail: true })
|
||||
if (!authResult.ok) {
|
||||
return
|
||||
}
|
||||
orders.value = await getDeliveryOrders({ tab: currentTab.value, keyword: '' })
|
||||
}
|
||||
|
||||
function switchTab(tab: string) {
|
||||
if (currentTab.value == tab) {
|
||||
return
|
||||
}
|
||||
applyTab(tab)
|
||||
loadData()
|
||||
}
|
||||
|
||||
function goDetail(id: string) {
|
||||
uni.navigateTo({ url: '/pages/mall/delivery/orders/detail?id=' + id })
|
||||
}
|
||||
|
||||
function goRoute(id: string) {
|
||||
uni.navigateTo({ url: '/pages/mall/delivery/orders/route?id=' + id })
|
||||
}
|
||||
|
||||
function goCheckin(id: string) {
|
||||
uni.navigateTo({ url: '/pages/mall/delivery/orders/checkin?id=' + id })
|
||||
}
|
||||
|
||||
function goExecute(id: string) {
|
||||
uni.navigateTo({ url: '/pages/mall/delivery/orders/execute?id=' + id })
|
||||
}
|
||||
|
||||
function acceptOrder(id: string) {
|
||||
uni.showModal({
|
||||
title: '确认接单',
|
||||
content: '接单后将展示完整服务对象信息,并进入待出发状态。',
|
||||
success: async (result) => {
|
||||
if (result.confirm) {
|
||||
await acceptDeliveryOrder(id)
|
||||
uni.showToast({ title: '接单成功', icon: 'success' })
|
||||
loadData()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
onLoad((options) => {
|
||||
let routeTab = ''
|
||||
if (options != null) {
|
||||
const tab = getDeliveryRouteParam(options as UTSJSONObject, 'tab')
|
||||
if (tab != null && tab != '') {
|
||||
routeTab = tab
|
||||
}
|
||||
}
|
||||
if (routeTab != '') {
|
||||
uni.removeStorageSync('delivery_orders_tab')
|
||||
applyTab(routeTab)
|
||||
} else {
|
||||
consumeStoredTab()
|
||||
}
|
||||
loadData()
|
||||
})
|
||||
|
||||
onShow(() => {
|
||||
consumeStoredTab()
|
||||
loadData()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.delivery-orders-page {
|
||||
min-height: 100%;
|
||||
margin-left: -24rpx;
|
||||
margin-right: -24rpx;
|
||||
margin-top: -24rpx;
|
||||
padding-bottom: 32rpx;
|
||||
background-color: #f4f8fb;
|
||||
}
|
||||
|
||||
.delivery-orders-hero {
|
||||
padding: 72rpx 28rpx 34rpx;
|
||||
border-bottom-left-radius: 36rpx;
|
||||
border-bottom-right-radius: 36rpx;
|
||||
background-color: #0f766e;
|
||||
}
|
||||
|
||||
.delivery-orders-hero-top,
|
||||
.delivery-orders-card-header,
|
||||
.card-top,
|
||||
.order-footer {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.delivery-orders-hero-top {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.delivery-orders-hero-main {
|
||||
flex: 1;
|
||||
padding-right: 16rpx;
|
||||
}
|
||||
|
||||
.delivery-orders-hero-title {
|
||||
font-size: 38rpx;
|
||||
font-weight: 700;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.delivery-orders-hero-subtitle {
|
||||
margin-top: 10rpx;
|
||||
font-size: 24rpx;
|
||||
line-height: 34rpx;
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
}
|
||||
|
||||
.delivery-orders-hero-badge {
|
||||
padding: 10rpx 18rpx;
|
||||
border-radius: 999rpx;
|
||||
background-color: rgba(255, 255, 255, 0.18);
|
||||
}
|
||||
|
||||
.delivery-orders-hero-badge-text {
|
||||
font-size: 24rpx;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.delivery-orders-hero-tip-box {
|
||||
margin-top: 28rpx;
|
||||
padding: 20rpx 22rpx;
|
||||
border-radius: 22rpx;
|
||||
background-color: rgba(255, 255, 255, 0.16);
|
||||
}
|
||||
|
||||
.delivery-orders-hero-tip {
|
||||
font-size: 23rpx;
|
||||
line-height: 34rpx;
|
||||
color: rgba(255, 255, 255, 0.88);
|
||||
}
|
||||
|
||||
.delivery-orders-card {
|
||||
margin-left: 24rpx;
|
||||
margin-right: 24rpx;
|
||||
margin-top: 22rpx;
|
||||
padding: 26rpx;
|
||||
border-radius: 28rpx;
|
||||
background-color: #ffffff;
|
||||
box-shadow: 0 10rpx 28rpx rgba(15, 35, 55, 0.06);
|
||||
}
|
||||
|
||||
.delivery-orders-filter-card {
|
||||
margin-top: -18rpx;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.delivery-orders-card-title {
|
||||
font-size: 30rpx;
|
||||
font-weight: 700;
|
||||
color: #16324f;
|
||||
}
|
||||
|
||||
.delivery-orders-card-subtitle {
|
||||
display: block;
|
||||
margin-top: 8rpx;
|
||||
font-size: 22rpx;
|
||||
line-height: 34rpx;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.status-scroll {
|
||||
margin-top: 22rpx;
|
||||
width: 100%;
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.status-tabs-row {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
padding-left: 4rpx;
|
||||
padding-right: 20rpx;
|
||||
padding-top: 4rpx;
|
||||
padding-bottom: 4rpx;
|
||||
}
|
||||
|
||||
.status-tab-item {
|
||||
flex-shrink: 0;
|
||||
height: 64rpx;
|
||||
padding-left: 28rpx;
|
||||
padding-right: 28rpx;
|
||||
margin-right: 16rpx;
|
||||
border-radius: 999rpx;
|
||||
background-color: #f1f5f9;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.status-tab-active {
|
||||
background-color: #0f766e;
|
||||
box-shadow: 0 8rpx 18rpx rgba(15, 118, 110, 0.18);
|
||||
}
|
||||
|
||||
.status-tab-text {
|
||||
font-size: 26rpx;
|
||||
font-weight: 500;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
|
||||
.status-tab-text-active {
|
||||
color: #ffffff;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.order-card {
|
||||
margin-top: 22rpx;
|
||||
padding: 24rpx;
|
||||
border-radius: 24rpx;
|
||||
background: #f8fbfc;
|
||||
border-width: 1rpx;
|
||||
border-style: solid;
|
||||
border-color: #e5edf5;
|
||||
border-top-width: 8rpx;
|
||||
}
|
||||
|
||||
.status-surface-warning {
|
||||
border-top-color: #b45309;
|
||||
background: linear-gradient(180deg, #fffaf5, #f8fbfc);
|
||||
}
|
||||
|
||||
.status-surface-primary {
|
||||
border-top-color: #2563eb;
|
||||
background: linear-gradient(180deg, #f5f9ff, #f8fbfc);
|
||||
}
|
||||
|
||||
.status-surface-teal {
|
||||
border-top-color: #0f766e;
|
||||
background: linear-gradient(180deg, #f3fbfa, #f8fbfc);
|
||||
}
|
||||
|
||||
.status-surface-success {
|
||||
border-top-color: #15803d;
|
||||
background: linear-gradient(180deg, #f4fbf6, #f8fbfc);
|
||||
}
|
||||
|
||||
.status-surface-danger {
|
||||
border-top-color: #dc2626;
|
||||
background: linear-gradient(180deg, #fff6f6, #f8fbfc);
|
||||
}
|
||||
|
||||
.status-surface-default {
|
||||
border-top-color: #94a3b8;
|
||||
}
|
||||
|
||||
.card-top,
|
||||
.order-footer {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.order-main {
|
||||
flex: 1;
|
||||
padding-right: 16rpx;
|
||||
}
|
||||
|
||||
.order-title {
|
||||
font-size: 30rpx;
|
||||
font-weight: 700;
|
||||
color: #16324f;
|
||||
}
|
||||
|
||||
.order-info-box {
|
||||
margin-top: 18rpx;
|
||||
padding: 20rpx;
|
||||
border-radius: 20rpx;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.order-meta,
|
||||
.empty-text,
|
||||
.order-next-text {
|
||||
margin-top: 10rpx;
|
||||
font-size: 24rpx;
|
||||
line-height: 36rpx;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.order-footer {
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
|
||||
.order-action-btn {
|
||||
min-width: 132rpx;
|
||||
margin-left: 14rpx;
|
||||
padding-top: 14rpx;
|
||||
padding-bottom: 14rpx;
|
||||
padding-left: 22rpx;
|
||||
padding-right: 22rpx;
|
||||
border-radius: 18rpx;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.order-action-btn-secondary {
|
||||
background: #eaf2f0;
|
||||
}
|
||||
|
||||
.order-action-btn-text {
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.order-action-btn-text-secondary {
|
||||
color: #0f766e;
|
||||
}
|
||||
|
||||
.action-warning {
|
||||
background: #b45309;
|
||||
}
|
||||
|
||||
.action-primary {
|
||||
background: #2563eb;
|
||||
}
|
||||
|
||||
.action-teal {
|
||||
background: #0f766e;
|
||||
}
|
||||
|
||||
.action-success {
|
||||
background: #15803d;
|
||||
}
|
||||
|
||||
.action-danger {
|
||||
background: #dc2626;
|
||||
}
|
||||
|
||||
.action-default {
|
||||
background: #64748b;
|
||||
}
|
||||
|
||||
.empty-box {
|
||||
padding: 24rpx;
|
||||
margin-top: 22rpx;
|
||||
border-radius: 22rpx;
|
||||
background: #f8fbfc;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.delivery-orders-safe {
|
||||
height: 40rpx;
|
||||
}
|
||||
</style>
|
||||
151
pages/mall/delivery/orders/route.uvue
Normal file
151
pages/mall/delivery/orders/route.uvue
Normal file
@@ -0,0 +1,151 @@
|
||||
<template>
|
||||
<ServicePageScaffold title="出发与导航" fallback-url="/pages/mall/delivery/orders/detail">
|
||||
<ServicePanel title="路线信息" subtitle="支持出发状态回写、地图导航和位置上报。">
|
||||
<text v-if="order != null" class="info-text">服务地址:{{ order.fullAddress }}</text>
|
||||
<text v-if="order != null" class="info-text">预约时间:{{ order.appointmentStartTime }}</text>
|
||||
<text class="info-text">当前位置:{{ currentLocationText }}</text>
|
||||
</ServicePanel>
|
||||
<ServicePanel title="执行动作" subtitle="先获取位置,再执行出发或到达。">
|
||||
<view class="button-stack">
|
||||
<button class="secondary-btn" @click="getCurrentLocation">获取当前位置</button>
|
||||
<button class="primary-btn" :disabled="submitting" @click="startDepartAction">{{ submitting ? '处理中...' : '点击出发' }}</button>
|
||||
<button class="secondary-btn" @click="openMap">打开地图导航</button>
|
||||
<button class="primary-btn" :disabled="submitting" @click="arriveAction">标记到达</button>
|
||||
</view>
|
||||
</ServicePanel>
|
||||
</ServicePageScaffold>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import ServicePageScaffold from '@/components/homeService/ServicePageScaffold.uvue'
|
||||
import ServicePanel from '@/components/homeService/ServicePanel.uvue'
|
||||
import type { DeliveryLocationType, DeliveryOrderType } from '@/types/delivery.uts'
|
||||
import { arriveOrder, getDeliveryOrderDetail, startDepart } from '@/services/deliveryService.uts'
|
||||
import { requireDeliveryAuth } from '@/utils/deliveryAuth.uts'
|
||||
import { getDeliveryRouteParam } from '@/utils/deliveryRoute.uts'
|
||||
|
||||
const orderId = ref('')
|
||||
const order = ref<DeliveryOrderType | null>(null)
|
||||
const currentLocation = ref<DeliveryLocationType | null>(null)
|
||||
const currentLocationText = ref('未获取')
|
||||
const submitting = ref(false)
|
||||
|
||||
function wrapLocation(): Promise<DeliveryLocationType> {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.getLocation({
|
||||
type: 'gcj02',
|
||||
success: (res) => {
|
||||
resolve({
|
||||
latitude: res.latitude,
|
||||
longitude: res.longitude,
|
||||
address: '当前位置',
|
||||
time: new Date().toISOString().replace('T', ' ').substring(0, 19)
|
||||
})
|
||||
},
|
||||
fail: () => {
|
||||
reject(new Error('定位失败,请检查定位权限后重试'))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
async function loadData() {
|
||||
const authResult = await requireDeliveryAuth({ redirectOnFail: true, toastOnFail: true })
|
||||
if (!authResult.ok || orderId.value == '') {
|
||||
return
|
||||
}
|
||||
order.value = await getDeliveryOrderDetail(orderId.value)
|
||||
}
|
||||
|
||||
async function getCurrentLocation() {
|
||||
try {
|
||||
currentLocation.value = await wrapLocation()
|
||||
currentLocationText.value = '纬度 ' + String(currentLocation.value.latitude) + ' / 经度 ' + String(currentLocation.value.longitude)
|
||||
} catch (error) {
|
||||
uni.showToast({ title: '定位失败,请检查定位权限', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
async function startDepartAction() {
|
||||
if (submitting.value) return
|
||||
if (currentLocation.value == null) {
|
||||
await getCurrentLocation()
|
||||
if (currentLocation.value == null) {
|
||||
return
|
||||
}
|
||||
}
|
||||
submitting.value = true
|
||||
try {
|
||||
await startDepart(orderId.value, currentLocation.value as DeliveryLocationType)
|
||||
uni.showToast({ title: '已更新为出发中', icon: 'success' })
|
||||
loadData()
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function arriveAction() {
|
||||
if (submitting.value) return
|
||||
if (currentLocation.value == null) {
|
||||
await getCurrentLocation()
|
||||
if (currentLocation.value == null) {
|
||||
return
|
||||
}
|
||||
}
|
||||
submitting.value = true
|
||||
try {
|
||||
await arriveOrder(orderId.value, currentLocation.value as DeliveryLocationType)
|
||||
uni.showToast({ title: '已标记到达', icon: 'success' })
|
||||
uni.navigateTo({ url: '/pages/mall/delivery/orders/checkin?id=' + orderId.value })
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function openMap() {
|
||||
if (order.value == null) {
|
||||
return
|
||||
}
|
||||
uni.openLocation({ latitude: order.value.latitude, longitude: order.value.longitude, address: order.value.fullAddress })
|
||||
}
|
||||
|
||||
onLoad((options) => {
|
||||
if (options != null) {
|
||||
orderId.value = getDeliveryRouteParam(options as UTSJSONObject, 'id')
|
||||
}
|
||||
loadData()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.info-text {
|
||||
display: block;
|
||||
margin-bottom: 14rpx;
|
||||
font-size: 26rpx;
|
||||
line-height: 38rpx;
|
||||
color: #16324f;
|
||||
}
|
||||
|
||||
.button-stack {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.primary-btn,
|
||||
.secondary-btn {
|
||||
margin-bottom: 18rpx;
|
||||
border-radius: 18rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.primary-btn {
|
||||
background: #0f766e;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.secondary-btn {
|
||||
background: #eaf2f0;
|
||||
color: #0f766e;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user