完善店务端员工新增和删除
This commit is contained in:
@@ -25,6 +25,9 @@ export const managerEmployeesApi = {
|
||||
createUser(data: EmployeeCreateRequest): Promise<IdType> {
|
||||
return adminApi.post('/manager/employees/users', data)
|
||||
},
|
||||
deleteUser(userId: IdType): Promise<boolean> {
|
||||
return adminApi.delete(`/manager/employees/${userId}`)
|
||||
},
|
||||
schedules(params: { artistId?: IdType; startDate?: string; endDate?: string }): Promise<ArtistSchedule[]> {
|
||||
return adminApi.get('/manager/employees/schedules', { params })
|
||||
},
|
||||
|
||||
@@ -33,6 +33,25 @@
|
||||
<span>›</span>
|
||||
</button>
|
||||
</section>
|
||||
|
||||
<section class="card delete-panel section">
|
||||
<div>
|
||||
<strong>删除员工</strong>
|
||||
<p>删除后该员工会从当前店铺员工列表移除,登录账号仍会保留。</p>
|
||||
</div>
|
||||
<button class="danger-btn" type="button" :disabled="deletingEmployee" @click="requestDeleteEmployee">
|
||||
{{ deletingEmployee ? '删除中...' : '删除员工' }}
|
||||
</button>
|
||||
</section>
|
||||
<div v-if="deleteConfirmVisible" class="reset-confirm delete-confirm">
|
||||
<p>确定要删除该员工吗?该操作只移除当前店铺员工关系,不会删除登录账号。</p>
|
||||
<div class="reset-confirm__actions">
|
||||
<button class="secondary-btn" type="button" :disabled="deletingEmployee" @click="deleteConfirmVisible = false">取消</button>
|
||||
<button class="danger-btn" type="button" :disabled="deletingEmployee" @click="confirmDeleteEmployee">
|
||||
{{ deletingEmployee ? '删除中...' : '确认删除' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<EmptyState v-else title="员工不存在" />
|
||||
|
||||
@@ -139,7 +158,9 @@ const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const avatarUploading = ref(false)
|
||||
const resettingPassword = ref(false)
|
||||
const deletingEmployee = ref(false)
|
||||
const resetConfirmVisible = ref(false)
|
||||
const deleteConfirmVisible = ref(false)
|
||||
const employee = ref<Artist | null>(null)
|
||||
const editModalVisible = ref(false)
|
||||
const employeeId = computed(() => String(route.params.id))
|
||||
@@ -162,7 +183,7 @@ const buildEmptyEditForm = (): EditEmployeeForm => ({
|
||||
const editForm = reactive<EditEmployeeForm>(buildEmptyEditForm())
|
||||
const originalEditForm = ref<EditEmployeeForm>(buildEmptyEditForm())
|
||||
const editFormChanged = computed(() => !sameEditForm(editForm, originalEditForm.value))
|
||||
const closeDisabled = computed(() => saving.value || avatarUploading.value || resettingPassword.value)
|
||||
const closeDisabled = computed(() => saving.value || avatarUploading.value || resettingPassword.value || deletingEmployee.value)
|
||||
|
||||
function buildEditFormFromEmployee(value: Artist): EditEmployeeForm {
|
||||
return {
|
||||
@@ -374,6 +395,30 @@ const confirmResetPassword = async (): Promise<void> => {
|
||||
}
|
||||
}
|
||||
|
||||
const requestDeleteEmployee = (): void => {
|
||||
deleteConfirmVisible.value = true
|
||||
}
|
||||
|
||||
const confirmDeleteEmployee = async (): Promise<void> => {
|
||||
if (!employee.value) {
|
||||
return
|
||||
}
|
||||
deletingEmployee.value = true
|
||||
try {
|
||||
const success = await managerEmployeesApi.deleteUser(employee.value.userId || employeeId.value)
|
||||
if (!success) {
|
||||
throw new Error('员工不存在或已被删除')
|
||||
}
|
||||
deleteConfirmVisible.value = false
|
||||
toast.success('员工已删除')
|
||||
await router.replace('/employees')
|
||||
} catch (error) {
|
||||
toast.error(errorMessage(error as { message?: string } | null, '员工删除失败,请稍后重试'))
|
||||
} finally {
|
||||
deletingEmployee.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadEmployee()
|
||||
restoreEditDraft()
|
||||
@@ -486,6 +531,37 @@ watch(editModalVisible, syncEditDraft)
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.delete-panel {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
padding: 14px;
|
||||
}
|
||||
|
||||
.delete-panel strong,
|
||||
.delete-panel p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.delete-panel strong {
|
||||
display: block;
|
||||
color: var(--ink);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.delete-panel p {
|
||||
margin-top: 4px;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.delete-confirm {
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.modal-form {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
|
||||
@@ -145,19 +145,24 @@ const openCreate = (): void => {
|
||||
}
|
||||
|
||||
const createEmployee = async (): Promise<void> => {
|
||||
if (!createForm.nickname || !createForm.phone || !createForm.account || !createForm.password || !createForm.wechatId) {
|
||||
const nickname = createForm.nickname.trim()
|
||||
const phone = createForm.phone.trim()
|
||||
const account = createForm.account.trim()
|
||||
const password = createForm.password
|
||||
const wechatId = createForm.wechatId.trim() || phone
|
||||
if (!nickname || !phone || !account || !password) {
|
||||
toast.error('请补全美甲师信息')
|
||||
return
|
||||
}
|
||||
creating.value = true
|
||||
try {
|
||||
await managerEmployeesApi.createUser({
|
||||
nickname: createForm.nickname,
|
||||
phone: createForm.phone,
|
||||
account: createForm.account,
|
||||
password: createForm.password,
|
||||
contactPhone: createForm.phone,
|
||||
wechatId: createForm.wechatId
|
||||
nickname,
|
||||
phone,
|
||||
account,
|
||||
password,
|
||||
contactPhone: phone,
|
||||
wechatId
|
||||
})
|
||||
toast.success('美甲师已新增')
|
||||
updateCreateModalVisible(false)
|
||||
|
||||
Reference in New Issue
Block a user