Files
medical-mall/pages/mall/delivery/orders/index.uvue

616 lines
15 KiB
Plaintext

<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>