支持店务修改客户联系方式和备注
This commit is contained in:
@@ -9,6 +9,11 @@ export interface CustomerListParams {
|
||||
hasOrder?: boolean
|
||||
}
|
||||
|
||||
export interface CustomerUpdateRequest {
|
||||
contactPhone: string
|
||||
remark: string
|
||||
}
|
||||
|
||||
export const managerCustomersApi = {
|
||||
list(params: CustomerListParams): Promise<CustomerPage> {
|
||||
return adminApi.get('/manager/customers', { params })
|
||||
@@ -18,5 +23,8 @@ export const managerCustomersApi = {
|
||||
},
|
||||
create(data: CustomerCreateRequest): Promise<IdType> {
|
||||
return adminApi.post('/manager/customers', data)
|
||||
},
|
||||
update(id: IdType, data: CustomerUpdateRequest): Promise<boolean> {
|
||||
return adminApi.put(`/manager/customers/${id}`, data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,29 +4,54 @@
|
||||
<template v-else-if="customer">
|
||||
<section class="card customer-card">
|
||||
<div class="avatar">{{ firstName }}</div>
|
||||
<div>
|
||||
<div class="customer-card__body">
|
||||
<h2>{{ customer.nickname || customer.account || '未命名客户' }}</h2>
|
||||
<p>{{ customer.phone || customer.contactPhone || '未填写手机号' }}</p>
|
||||
<p>{{ customer.contactPhone || customer.phone || '未填写手机号' }}</p>
|
||||
</div>
|
||||
<button class="edit-btn" type="button" @click="openEdit">编辑</button>
|
||||
</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.signature || '未填写' }}</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>
|
||||
|
||||
<BaseModal
|
||||
:model-value="editModalVisible"
|
||||
title="编辑客户"
|
||||
:close-disabled="saving"
|
||||
:has-unsaved-changes="editFormChanged"
|
||||
@update:model-value="updateEditModalVisible"
|
||||
>
|
||||
<div class="modal-form">
|
||||
<div class="field">
|
||||
<label>联系电话</label>
|
||||
<input v-model.trim="editForm.contactPhone" inputmode="tel" placeholder="请输入联系电话" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>备注</label>
|
||||
<textarea v-model.trim="editForm.remark" rows="4" maxlength="200" placeholder="请输入客户备注" />
|
||||
</div>
|
||||
<button class="primary-btn" type="button" :disabled="saving" @click="saveEdit">
|
||||
{{ saving ? '保存中...' : '保存客户' }}
|
||||
</button>
|
||||
</div>
|
||||
</BaseModal>
|
||||
</template>
|
||||
<EmptyState v-else title="客户不存在" />
|
||||
</MobileShell>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import BaseModal from '@/components/BaseModal.vue'
|
||||
import EmptyState from '@/components/EmptyState.vue'
|
||||
import LoadingState from '@/components/LoadingState.vue'
|
||||
import MobileShell from '@/components/MobileShell.vue'
|
||||
@@ -42,25 +67,81 @@ const router = useRouter()
|
||||
const toast = useToastStore()
|
||||
const session = useSessionStore()
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const customer = ref<UserInfo | null>(null)
|
||||
const editModalVisible = ref(false)
|
||||
const editForm = reactive({
|
||||
contactPhone: '',
|
||||
remark: ''
|
||||
})
|
||||
const editBaseline = reactive({
|
||||
contactPhone: '',
|
||||
remark: ''
|
||||
})
|
||||
const firstName = computed(() => String(customer.value?.nickname || customer.value?.account || '客').slice(0, 1))
|
||||
const editFormChanged = computed(() => editForm.contactPhone !== editBaseline.contactPhone || editForm.remark !== editBaseline.remark)
|
||||
|
||||
const applyEditForm = (value: UserInfo): void => {
|
||||
editForm.contactPhone = value.contactPhone || value.phone || ''
|
||||
editForm.remark = value.signature || ''
|
||||
editBaseline.contactPhone = editForm.contactPhone
|
||||
editBaseline.remark = editForm.remark
|
||||
}
|
||||
|
||||
const loadCustomer = async (): Promise<void> => {
|
||||
loading.value = true
|
||||
try {
|
||||
customer.value = await managerCustomersApi.detail(String(route.params.id))
|
||||
if (customer.value) {
|
||||
applyEditForm(customer.value)
|
||||
}
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const openEdit = (): void => {
|
||||
if (!customer.value) {
|
||||
return
|
||||
}
|
||||
applyEditForm(customer.value)
|
||||
editModalVisible.value = true
|
||||
}
|
||||
|
||||
const updateEditModalVisible = (value: boolean): void => {
|
||||
editModalVisible.value = value
|
||||
if (!value && customer.value) {
|
||||
applyEditForm(customer.value)
|
||||
}
|
||||
}
|
||||
|
||||
const saveEdit = async (): Promise<void> => {
|
||||
if (!customer.value) {
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
await managerCustomersApi.update(customer.value.id, {
|
||||
contactPhone: editForm.contactPhone.trim(),
|
||||
remark: editForm.remark.trim()
|
||||
})
|
||||
toast.success('客户信息已保存')
|
||||
editModalVisible.value = false
|
||||
await loadCustomer()
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : '客户信息保存失败')
|
||||
} finally {
|
||||
saving.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 || '')
|
||||
const phone = encodeURIComponent(customer.value?.contactPhone || customer.value?.phone || '')
|
||||
void router.push(`/appointments/new?customerName=${name}&phone=${phone}`)
|
||||
}
|
||||
|
||||
@@ -89,6 +170,11 @@ onMounted(() => {
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.customer-card__body {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.customer-card h2,
|
||||
.customer-card p {
|
||||
margin: 0;
|
||||
@@ -98,4 +184,22 @@ onMounted(() => {
|
||||
margin-top: 4px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.edit-btn {
|
||||
min-height: 34px;
|
||||
padding: 0 12px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 999px;
|
||||
background: var(--card-bg);
|
||||
color: var(--accent);
|
||||
font-size: 13px;
|
||||
font-weight: 800;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.modal-form {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
padding: 14px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<div class="row-between">
|
||||
<div>
|
||||
<h2 class="list-card__title">{{ customer.nickname || customer.account || '未命名客户' }}</h2>
|
||||
<div class="list-card__subtitle">{{ customer.phone || customer.contactPhone || '未填写手机号' }}</div>
|
||||
<div class="list-card__subtitle">{{ customer.contactPhone || customer.phone || '未填写手机号' }}</div>
|
||||
</div>
|
||||
<span class="tag">{{ customer.createTime ? '已建档' : '客户' }}</span>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user