Files
JayuCloud/JY-Salon-Front/src/views/CustomersView.vue
T

113 lines
3.6 KiB
Vue
Raw Normal View History

2026-06-29 20:58:39 +08:00
<template>
<MobileShell>
<div class="toolbar-card card">
<input v-model.trim="keyword" class="search-input" placeholder="搜索客户姓名或手机号" @keyup.enter="loadCustomers" />
<button class="secondary-btn" type="button" @click="loadCustomers">搜索</button>
</div>
<LoadingState v-if="loading" text="正在加载客户" />
<EmptyState v-else-if="customers.length === 0" title="暂无客户" description="新增客户后会显示在这里" />
<section v-else class="list section">
<article v-for="customer in customers" :key="String(customer.id)" class="card list-card" @click="router.push(`/customers/${customer.id}`)">
<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>
<span class="tag">{{ customer.createTime ? '已建档' : '客户' }}</span>
</div>
</article>
</section>
<button class="fab" type="button" @click="openCreate">+</button>
<BaseModal v-model="createModalVisible" title="新增客户">
<div class="modal-form">
<div class="field">
<label class="required">客户姓名</label>
<input v-model.trim="createForm.nickname" placeholder="请输入客户姓名" />
</div>
<div class="field">
<label class="required">手机号</label>
<input v-model.trim="createForm.phone" inputmode="numeric" placeholder="请输入手机号" />
</div>
<button class="primary-btn" type="button" :disabled="creating" @click="createCustomer">
{{ creating ? '新增中...' : '保存客户' }}
</button>
</div>
</BaseModal>
</MobileShell>
</template>
<script setup lang="ts">
import { onMounted, reactive, ref } from 'vue'
import { 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'
import { managerCustomersApi } from '@/api/managerCustomers'
import type { UserInfo } from '@/types/common'
import { useToastStore } from '@/stores/toast'
const router = useRouter()
const toast = useToastStore()
const keyword = ref('')
const loading = ref(false)
const customers = ref<UserInfo[]>([])
const createModalVisible = ref(false)
const creating = ref(false)
const createForm = reactive({ nickname: '', phone: '' })
const loadCustomers = async (): Promise<void> => {
loading.value = true
try {
const data = await managerCustomersApi.list({ page: 1, size: 50, keyword: keyword.value })
customers.value = data.list || []
} finally {
loading.value = false
}
}
const openCreate = (): void => {
createForm.nickname = ''
createForm.phone = ''
createModalVisible.value = true
}
const createCustomer = async (): Promise<void> => {
if (!createForm.nickname || !createForm.phone) {
toast.error('请填写客户姓名和手机号')
return
}
creating.value = true
try {
await managerCustomersApi.create({ nickname: createForm.nickname, phone: createForm.phone })
toast.success('客户已新增')
createModalVisible.value = false
await loadCustomers()
} finally {
creating.value = false
}
}
onMounted(() => {
void loadCustomers()
})
</script>
<style scoped>
.toolbar-card {
display: grid;
grid-template-columns: 1fr 84px;
gap: 8px;
padding: 12px;
}
.modal-form {
display: grid;
gap: 12px;
padding: 14px;
}
</style>