Files
JayuCloud/FM-Front/src/views/CustomerDetailView.vue
T

102 lines
3.2 KiB
Vue

<template>
<MobileShell title="客户详情">
<LoadingState v-if="loading" text="正在加载客户" />
<template v-else-if="customer">
<section class="card customer-card">
<div class="avatar">{{ firstName }}</div>
<div>
<h2>{{ customer.nickname || customer.account || '未命名客户' }}</h2>
<p>{{ customer.phone || customer.contactPhone || '未填写手机号' }}</p>
</div>
</section>
<PageSection title="客户信息">
<section class="card form-card">
<div class="field"><label>登录账号</label><div class="field-value">{{ customer.account || '未设置' }}</div></div>
<div class="field"><label>联系电话</label><div class="field-value">{{ customer.contactPhone || customer.phone || '未设置' }}</div></div>
<div class="field"><label>注册时间</label><div class="field-value">{{ customer.createTime || '暂无' }}</div></div>
</section>
</PageSection>
<button class="primary-btn section" type="button" @click="createAppointment">为客户预约</button>
</template>
<EmptyState v-else title="客户不存在" />
</MobileShell>
</template>
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import EmptyState from '@/components/EmptyState.vue'
import LoadingState from '@/components/LoadingState.vue'
import MobileShell from '@/components/MobileShell.vue'
import PageSection from '@/components/PageSection.vue'
import { managerCustomersApi } from '@/api/managerCustomers'
import type { UserInfo } from '@/types/common'
import { useToastStore } from '@/stores/toast'
import { useSessionStore } from '@/stores/session'
import { canCreateAppointment } from '@/utils/permissions'
const route = useRoute()
const router = useRouter()
const toast = useToastStore()
const session = useSessionStore()
const loading = ref(false)
const customer = ref<UserInfo | null>(null)
const firstName = computed(() => String(customer.value?.nickname || customer.value?.account || '客').slice(0, 1))
const loadCustomer = async (): Promise<void> => {
loading.value = true
try {
customer.value = await managerCustomersApi.detail(String(route.params.id))
} finally {
loading.value = false
}
}
const createAppointment = (): void => {
if (!canCreateAppointment(session.userInfo)) {
toast.error('美甲师账号只能查看预约')
return
}
const name = encodeURIComponent(customer.value?.nickname || customer.value?.account || '')
const phone = encodeURIComponent(customer.value?.phone || customer.value?.contactPhone || '')
void router.push(`/appointments/new?customerName=${name}&phone=${phone}`)
}
onMounted(() => {
void loadCustomer()
})
</script>
<style scoped>
.customer-card {
display: flex;
align-items: center;
gap: 14px;
padding: 18px;
}
.avatar {
display: grid;
place-items: center;
width: 58px;
height: 58px;
border-radius: 20px;
background: var(--accent-soft);
color: var(--accent);
font-size: 24px;
font-weight: 900;
}
.customer-card h2,
.customer-card p {
margin: 0;
}
.customer-card p {
margin-top: 4px;
color: var(--muted);
}
</style>