297 lines
15 KiB
Vue
297 lines
15 KiB
Vue
<template>
|
|
<div class="artist-calendar-page">
|
|
<header class="calendar-header">
|
|
<a-button type="text" class="back-btn" @click="router.back()">
|
|
<LeftOutlined />
|
|
</a-button>
|
|
<div class="header-copy">
|
|
<span>预约日历</span>
|
|
<h1>未来 7 天</h1>
|
|
</div>
|
|
<a-button type="link" @click="openArtistOrders">订单</a-button>
|
|
</header>
|
|
|
|
<main class="calendar-content">
|
|
<section class="summary-strip">
|
|
<div>
|
|
<span>今日预约</span>
|
|
<strong>{{ todayCount }}</strong>
|
|
</div>
|
|
<div>
|
|
<span>下一单</span>
|
|
<strong>{{ nextAppointmentText }}</strong>
|
|
</div>
|
|
<div>
|
|
<span>7 天合计</span>
|
|
<strong>{{ appointments.length }}</strong>
|
|
</div>
|
|
</section>
|
|
|
|
<section class="toolbar">
|
|
<a-button type="primary" :loading="loading" @click="loadAppointments">刷新</a-button>
|
|
<a-button @click="openArtistOrders">查看我的相关订单</a-button>
|
|
</section>
|
|
|
|
<a-spin :spinning="loading">
|
|
<section v-if="groupedDays.length" class="timeline">
|
|
<article v-for="day in groupedDays" :key="day.dateKey" class="day-row">
|
|
<aside class="day-label">
|
|
<strong>{{ day.dayText }}</strong>
|
|
<span>{{ day.weekText }}</span>
|
|
<em>{{ day.items.length }} 单</em>
|
|
</aside>
|
|
<div class="day-line">
|
|
<button
|
|
v-for="item in day.items"
|
|
:key="String(item.orderItemId)"
|
|
type="button"
|
|
class="appointment-block"
|
|
:class="statusClass(item.orderStatus)"
|
|
@click="openDetail(item)"
|
|
>
|
|
<span class="time">{{ timeRange(item) }}</span>
|
|
<strong>{{ item.customerNickname || '用户' }} · {{ item.productTitle }}</strong>
|
|
<small>{{ item.orderStatusText }} · {{ item.shopName || '门店' }}</small>
|
|
</button>
|
|
</div>
|
|
</article>
|
|
</section>
|
|
<a-empty v-else description="未来 7 天暂无预约" />
|
|
</a-spin>
|
|
</main>
|
|
|
|
<a-drawer v-model:open="detailOpen" title="预约详情" placement="right" :width="420">
|
|
<div v-if="selected" class="detail-body">
|
|
<div class="detail-title">
|
|
<strong>{{ selected.productTitle }}</strong>
|
|
<a-tag :color="selected.orderStatus === 2 ? 'green' : 'orange'">{{ selected.orderStatusText }}</a-tag>
|
|
</div>
|
|
<dl>
|
|
<dt>预约时间</dt>
|
|
<dd>{{ formatDateTime(selected.appointmentStartTime) }} - {{ formatClock(selected.appointmentEndTime) }}</dd>
|
|
<dt>客户</dt>
|
|
<dd>{{ selected.customerNickname || '用户' }} {{ selected.customerPhoneMasked || '' }}</dd>
|
|
<dt>订单号</dt>
|
|
<dd>{{ selected.orderNo }}</dd>
|
|
<dt>订单金额</dt>
|
|
<dd>{{ formatMoney(selected.totalAmount) }} / 实付 {{ formatMoney(selected.actualAmount) }}</dd>
|
|
<dt>门店</dt>
|
|
<dd>{{ selected.shopName || '--' }}</dd>
|
|
<dt>数量 / 时长</dt>
|
|
<dd>{{ selected.quantity }} 件 · {{ selected.durationMinutes }} 分钟</dd>
|
|
</dl>
|
|
<a-space direction="vertical" style="width: 100%">
|
|
<a-button block @click="openSelectedProduct">查看客户选择的作品</a-button>
|
|
<a-button block @click="openSelectedOrder">查看对应订单</a-button>
|
|
<a-button
|
|
v-if="selected.orderStatus === 1"
|
|
type="primary"
|
|
block
|
|
:loading="completing"
|
|
@click="completeSelectedOrder"
|
|
>
|
|
完成服务
|
|
</a-button>
|
|
<a-button block @click="openArtistOrders">打开我的相关订单</a-button>
|
|
</a-space>
|
|
</div>
|
|
</a-drawer>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
/**
|
|
* ArtistCalendarView page script.
|
|
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
|
|
*/
|
|
import { computed, onMounted, ref } from 'vue'
|
|
import { useRouter } from 'vue-router'
|
|
import { LeftOutlined } from '@ant-design/icons-vue'
|
|
import { message } from 'ant-design-vue'
|
|
/**
|
|
* Purpose: ArtistCalendarAppointment supports ArtistCalendarView.vue by holding or executing the artist calendar appointment page or API role.
|
|
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
import { orderApi, type ArtistCalendarAppointment } from '@/api/order'
|
|
import { runWithGlobalLoading } from '@/utils/action-loading'
|
|
|
|
/**
|
|
* Purpose: router supports ArtistCalendarView.vue by holding or executing the router page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const router = useRouter()
|
|
/** loading is a reactive state variable used by the template and event handlers. */
|
|
const loading = ref(false)
|
|
/** completing is a reactive state variable used by the template and event handlers. */
|
|
const completing = ref(false)
|
|
/**
|
|
* Purpose: appointments supports ArtistCalendarView.vue by holding or executing the appointments page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const appointments = ref<ArtistCalendarAppointment[]>([])
|
|
/**
|
|
* Purpose: selected supports ArtistCalendarView.vue by holding or executing the selected page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const selected = ref<ArtistCalendarAppointment | null>(null)
|
|
/** detailOpen is a reactive state variable used by the template and event handlers. */
|
|
const detailOpen = ref(false)
|
|
|
|
/**
|
|
* Purpose: todayKey supports ArtistCalendarView.vue by holding or executing the today key page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const todayKey = localDateKey(new Date())
|
|
/** todayCount is a reactive state variable used by the template and event handlers. */
|
|
const todayCount = computed(() => appointments.value.filter(item => dateKey(item.appointmentStartTime) === todayKey).length)
|
|
/** nextAppointmentText is a reactive state variable used by the template and event handlers. */
|
|
const nextAppointmentText = computed(() => {
|
|
const now = Date.now()
|
|
const next = appointments.value.find(item => new Date(item.appointmentStartTime).getTime() >= now)
|
|
return next ? formatClock(next.appointmentStartTime) : '--'
|
|
})
|
|
/** groupedDays is a reactive state variable used by the template and event handlers. */
|
|
const groupedDays = computed(() => {
|
|
const map = new Map<string, ArtistCalendarAppointment[]>()
|
|
appointments.value.forEach(item => {
|
|
const key = dateKey(item.appointmentStartTime)
|
|
map.set(key, [...(map.get(key) || []), item])
|
|
})
|
|
return Array.from(map.entries()).map(([key, items]) => ({
|
|
dateKey: key,
|
|
dayText: key.slice(5),
|
|
weekText: weekText(key),
|
|
items: items.sort((a, b) => a.appointmentStartTime.localeCompare(b.appointmentStartTime))
|
|
}))
|
|
})
|
|
|
|
/** loadAppointments is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
|
const loadAppointments = async () => {
|
|
loading.value = true
|
|
try {
|
|
appointments.value = await orderApi.getArtistCalendarRecent(7)
|
|
} catch (error: any) {
|
|
message.error(error?.message || '获取预约日历失败')
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
/** openDetail is a local helper used by this page script. */
|
|
const openDetail = (item: ArtistCalendarAppointment) => {
|
|
selected.value = item
|
|
detailOpen.value = true
|
|
}
|
|
|
|
/** completeSelectedOrder is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
|
const completeSelectedOrder = async () => {
|
|
if (!selected.value) return
|
|
completing.value = true
|
|
try {
|
|
await runWithGlobalLoading(() => orderApi.completeArtistOrder(selected.value!.orderId))
|
|
message.success('服务已完成')
|
|
detailOpen.value = false
|
|
await loadAppointments()
|
|
} catch (error: any) {
|
|
message.error(error?.message || '完成服务失败')
|
|
} finally {
|
|
completing.value = false
|
|
}
|
|
}
|
|
|
|
/** openSelectedProduct is a local helper used by this page script. */
|
|
const openSelectedProduct = () => {
|
|
if (!selected.value?.productId) return
|
|
const productId = selected.value.productId
|
|
detailOpen.value = false
|
|
router.push(`/product/${productId}`)
|
|
}
|
|
|
|
/** openArtistOrders is a local helper used by this page script. */
|
|
const openArtistOrders = () => {
|
|
detailOpen.value = false
|
|
router.push({ path: '/artist-orders' })
|
|
}
|
|
|
|
/** openSelectedOrder is a local helper used by this page script. */
|
|
const openSelectedOrder = () => {
|
|
if (!selected.value?.orderId) return
|
|
const orderId = selected.value.orderId
|
|
detailOpen.value = false
|
|
router.push({ path: '/artist-orders', query: { orderId: String(orderId) } })
|
|
}
|
|
|
|
/** dateKey is a local helper used by this page script. */
|
|
const dateKey = (value: string) => value ? value.slice(0, 10) : ''
|
|
/**
|
|
* Purpose: localDateKey supports ArtistCalendarView.vue by holding or executing the local date key page or API role.
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
function localDateKey(value: Date) {
|
|
const month = String(value.getMonth() + 1).padStart(2, '0')
|
|
const day = String(value.getDate()).padStart(2, '0')
|
|
return `${value.getFullYear()}-${month}-${day}`
|
|
}
|
|
/** formatDateTime is a local helper used by this page script. */
|
|
const formatDateTime = (value: string) => value ? value.replace('T', ' ').slice(0, 16) : '--'
|
|
/** formatClock is a local helper used by this page script. */
|
|
const formatClock = (value: string) => value ? value.replace('T', ' ').slice(11, 16) : '--'
|
|
/** formatMoney is a local helper used by this page script. */
|
|
const formatMoney = (value?: number) => value === undefined || value === null ? '--' : `¥${Number(value).toFixed(2)}`
|
|
/** timeRange is a local helper used by this page script. */
|
|
const timeRange = (item: ArtistCalendarAppointment) => `${formatClock(item.appointmentStartTime)} - ${formatClock(item.appointmentEndTime)}`
|
|
/** weekText is a local helper used by this page script. */
|
|
const weekText = (key: string) => ['周日', '周一', '周二', '周三', '周四', '周五', '周六'][new Date(`${key}T00:00:00`).getDay()] || ''
|
|
/** statusClass is a local helper used by this page script. */
|
|
const statusClass = (status: number) => {
|
|
if (status === 2) return 'is-completed'
|
|
if (status === 3) return 'is-cancelled'
|
|
return 'is-pending'
|
|
}
|
|
|
|
onMounted(loadAppointments)
|
|
</script>
|
|
|
|
<style scoped>
|
|
.artist-calendar-page { min-height: 100vh; background: var(--theme-page-bg); color: var(--text-primary); }
|
|
.calendar-header { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; background: color-mix(in srgb, var(--theme-card-bg) 94%, transparent); border-bottom: 1px solid var(--theme-border); backdrop-filter: blur(12px); }
|
|
.back-btn { width: 40px; height: 40px; }
|
|
.header-copy { flex: 1; min-width: 0; }
|
|
.header-copy span { display: block; font-size: 12px; color: var(--text-secondary); }
|
|
.header-copy h1 { margin: 2px 0 0; font-size: 20px; }
|
|
.calendar-content { max-width: 1040px; margin: 0 auto; padding: 18px 16px 96px; }
|
|
.summary-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; overflow: hidden; border-radius: 8px; background: var(--theme-border); }
|
|
.summary-strip div { padding: 16px; background: var(--theme-card-bg); }
|
|
.summary-strip span { display: block; color: var(--text-secondary); font-size: 12px; }
|
|
.summary-strip strong { display: block; margin-top: 8px; font-size: 22px; }
|
|
.toolbar { display: flex; justify-content: space-between; gap: 12px; margin: 16px 0; }
|
|
.timeline { display: grid; gap: 14px; }
|
|
.day-row { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 14px; }
|
|
.day-label { display: grid; align-content: start; gap: 4px; padding-top: 4px; }
|
|
.day-label strong { font-size: 20px; }
|
|
.day-label span, .day-label em { color: var(--text-secondary); font-style: normal; font-size: 12px; }
|
|
.day-line { position: relative; display: grid; gap: 10px; padding-left: 18px; border-left: 2px solid var(--theme-border); }
|
|
.appointment-block { position: relative; width: 100%; display: grid; gap: 5px; overflow: hidden; padding: 14px 16px; border: 1px solid var(--theme-border); border-radius: 8px; background: var(--theme-card-bg); text-align: left; color: var(--text-primary); box-shadow: 0 10px 22px color-mix(in srgb, var(--theme-primary) 8%, transparent); cursor: pointer; transition: transform .18s ease, border-color .18s ease; }
|
|
.appointment-block:hover { transform: translateY(-2px); border-color: var(--theme-primary); }
|
|
.appointment-block.is-completed { background: #f5fff7; border-color: #c8ead1; }
|
|
.appointment-block.is-cancelled { background: #fff5f6; border-color: #e8c7cc; }
|
|
.appointment-block.is-completed::after, .appointment-block.is-cancelled::after { content: ""; position: absolute; inset: 0; background-repeat: no-repeat; background-size: 100% 100%; pointer-events: none; }
|
|
.appointment-block.is-completed::after { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio='none' viewBox='0 0 100 100'%3E%3Cline x1='0' y1='0' x2='100' y2='100' stroke='%2345825b' stroke-opacity='.78' stroke-width='3' stroke-linecap='square' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E"); }
|
|
.appointment-block.is-cancelled::after { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio='none' viewBox='0 0 100 100'%3E%3Cline x1='0' y1='0' x2='100' y2='100' stroke='%23c64e5b' stroke-opacity='.8' stroke-width='3' stroke-linecap='square' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E"); }
|
|
.appointment-block .time { color: var(--theme-primary); font-weight: 700; }
|
|
.appointment-block small { color: var(--text-secondary); }
|
|
.detail-body { display: grid; gap: 18px; }
|
|
.detail-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
|
.detail-title strong { font-size: 20px; }
|
|
dl { display: grid; gap: 10px; margin: 0; }
|
|
dt { color: var(--text-secondary); font-size: 12px; }
|
|
dd { margin: -6px 0 4px; color: var(--text-primary); font-weight: 600; }
|
|
@media (max-width: 720px) {
|
|
.summary-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
|
.summary-strip div { min-width: 0; padding: 12px 10px; }
|
|
.summary-strip strong { font-size: 18px; }
|
|
.day-row { grid-template-columns: 1fr; gap: 8px; }
|
|
.day-label { grid-template-columns: auto auto 1fr; align-items: baseline; }
|
|
}
|
|
</style>
|