新增员工详情编辑弹窗
This commit is contained in:
+14
@@ -222,6 +222,7 @@ public class NailArtistInfoServiceImpl extends ServiceImpl<NailArtistInfoMapper,
|
||||
* @return result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
saveOrUpdate(entity);
|
||||
syncArtistNickname(dto);
|
||||
/**
|
||||
* Run business method `convertToDTO`.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
@@ -231,6 +232,19 @@ public class NailArtistInfoServiceImpl extends ServiceImpl<NailArtistInfoMapper,
|
||||
return convertToDTO(entity);
|
||||
}
|
||||
|
||||
private void syncArtistNickname(NailArtistInfoDTO dto) {
|
||||
if (dto.getUserId() == null || !StringUtils.hasText(dto.getNickname())) {
|
||||
return;
|
||||
}
|
||||
UserDO user = userMapper.selectById(dto.getUserId());
|
||||
String nickname = dto.getNickname().trim();
|
||||
if (user == null || nickname.equals(user.getNickname())) {
|
||||
return;
|
||||
}
|
||||
user.setNickname(nickname);
|
||||
userMapper.updateById(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Load data by the supplied parameter.
|
||||
|
||||
+41
@@ -2,6 +2,7 @@ package com.xiaowang.jayucloud.core.modules.artist.service.impl;
|
||||
|
||||
import com.xiaowang.jayucloud.core.modules.artist.entity.NailArtistInfoDO;
|
||||
import com.xiaowang.jayucloud.core.modules.artist.entity.ArtistScheduleDO;
|
||||
import com.xiaowang.jayucloud.core.modules.artist.dto.NailArtistInfoDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.order.entity.OrderArtistReviewDO;
|
||||
import com.xiaowang.jayucloud.core.modules.order.entity.OrderDO;
|
||||
import com.xiaowang.jayucloud.core.modules.order.entity.OrderItemDO;
|
||||
@@ -41,6 +42,10 @@ import java.util.Map;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class NailArtistInfoServiceImplTest {
|
||||
@@ -93,6 +98,42 @@ class NailArtistInfoServiceImplTest {
|
||||
.thenAnswer(invocation -> invocation.getArgument(0, ObjectStorageFileVO.class).getFileUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
void saveOrUpdateNailArtistInfoSyncsNicknameToUser() {
|
||||
NailArtistInfoDO existing = new NailArtistInfoDO();
|
||||
existing.setId(11L);
|
||||
existing.setUserId(7L);
|
||||
existing.setStatus(1);
|
||||
existing.setIsDelete(0);
|
||||
when(nailArtistInfoMapper.selectOne(any())).thenReturn(existing);
|
||||
when(nailArtistInfoMapper.updateById(any())).thenReturn(1);
|
||||
|
||||
UserDO user = new UserDO();
|
||||
user.setId(7L);
|
||||
user.setNickname("旧名字");
|
||||
user.setType(3);
|
||||
user.setIsDelete(0);
|
||||
when(userMapper.selectById(7L)).thenReturn(user);
|
||||
|
||||
NailArtistInfoDTO dto = new NailArtistInfoDTO();
|
||||
dto.setUserId(7L);
|
||||
dto.setNickname(" 新名字 ");
|
||||
dto.setIdentity("高级美甲师");
|
||||
dto.setStatus(1);
|
||||
dto.setParticipateProduction(1);
|
||||
dto.setWorkStartTime(LocalTime.of(10, 0));
|
||||
dto.setWorkEndTime(LocalTime.of(18, 0));
|
||||
|
||||
NailArtistInfoServiceImpl serviceSpy = spy(service);
|
||||
doReturn(true).when(serviceSpy).saveOrUpdate(any(NailArtistInfoDO.class));
|
||||
|
||||
NailArtistInfoDTO saved = serviceSpy.saveOrUpdateNailArtistInfo(dto);
|
||||
|
||||
assertThat(saved.getNickname()).isEqualTo("新名字");
|
||||
verify(userMapper).updateById(argThat(updatedUser ->
|
||||
Long.valueOf(7L).equals(updatedUser.getId()) && "新名字".equals(updatedUser.getNickname())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPublicProfileAggregatesArtistBasicsWorksReviewsAndAvailability() {
|
||||
NailArtistInfoDO artistInfo = new NailArtistInfoDO();
|
||||
|
||||
@@ -9,9 +9,13 @@ export interface Artist {
|
||||
color?: string
|
||||
shortName?: string
|
||||
avatar?: string
|
||||
identity?: string
|
||||
level?: string
|
||||
enabled?: number
|
||||
status?: number
|
||||
participateProduction?: number
|
||||
workStartTime?: string | null
|
||||
workEndTime?: string | null
|
||||
description?: string
|
||||
rangeCount?: number
|
||||
shopId?: IdType
|
||||
|
||||
@@ -7,15 +7,22 @@
|
||||
<img v-if="employee.avatar" :src="employee.avatar" alt="" />
|
||||
<span v-else>{{ (employee.name || employee.nickname || '员').slice(0, 1) }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<div class="employee-hero__body">
|
||||
<h2>{{ employee.name || employee.nickname || '未命名员工' }}</h2>
|
||||
<p>{{ employee.phone || '未填写手机号' }}</p>
|
||||
</div>
|
||||
<button class="edit-btn" type="button" @click="openEdit">
|
||||
<Pencil :size="15" aria-hidden="true" />
|
||||
<span>编辑</span>
|
||||
</button>
|
||||
</section>
|
||||
|
||||
<section class="card form-card section">
|
||||
<div class="field"><label>员工编号</label><div class="field-value">{{ employee.userId || employee.id }}</div></div>
|
||||
<div class="field"><label>级别</label><div class="field-value">{{ employee.level || '美甲师' }}</div></div>
|
||||
<div class="field"><label>身份/级别</label><div class="field-value">{{ employee.identity || employee.level || '美甲师' }}</div></div>
|
||||
<div class="field"><label>状态</label><div class="field-value">{{ employee.status === 0 ? '休息中' : '可预约' }}</div></div>
|
||||
<div class="field"><label>参与生产</label><div class="field-value">{{ employee.participateProduction === 0 ? '不参与' : '参与' }}</div></div>
|
||||
<div class="field"><label>上班时间</label><div class="field-value">{{ workTimeText }}</div></div>
|
||||
<div class="field"><label>预约颜色</label><div class="field-value color-line"><span class="color-dot" :style="{ backgroundColor: employee.color || '#b8b0a6' }"></span>{{ employee.color || '未设置' }}</div></div>
|
||||
</section>
|
||||
|
||||
@@ -27,29 +34,210 @@
|
||||
</section>
|
||||
</template>
|
||||
<EmptyState v-else title="员工不存在" />
|
||||
|
||||
<BaseModal
|
||||
:model-value="editModalVisible"
|
||||
title="编辑员工"
|
||||
:close-disabled="saving"
|
||||
:has-unsaved-changes="editFormChanged"
|
||||
@update:model-value="updateEditModalVisible"
|
||||
>
|
||||
<div class="modal-form">
|
||||
<div class="field"><label class="required">姓名</label><input v-model.trim="editForm.nickname" placeholder="请输入姓名" /></div>
|
||||
<div class="field"><label>身份/级别</label><input v-model.trim="editForm.identity" placeholder="例如:高级美甲师" /></div>
|
||||
<div class="field">
|
||||
<label>状态</label>
|
||||
<select v-model.number="editForm.status">
|
||||
<option :value="1">可预约</option>
|
||||
<option :value="0">休息中</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>参与生产</label>
|
||||
<select v-model.number="editForm.participateProduction">
|
||||
<option :value="1">参与</option>
|
||||
<option :value="0">不参与</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field"><label>上班开始</label><input v-model="editForm.workStartTime" type="time" /></div>
|
||||
<div class="field"><label>上班结束</label><input v-model="editForm.workEndTime" type="time" /></div>
|
||||
<button class="primary-btn" type="button" :disabled="saving" @click="saveEdit">{{ saving ? '保存中...' : '保存员工' }}</button>
|
||||
</div>
|
||||
</BaseModal>
|
||||
</MobileShell>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { Pencil } from 'lucide-vue-next'
|
||||
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 { managerEmployeesApi } from '@/api/managerEmployees'
|
||||
import { useSessionStore } from '@/stores/session'
|
||||
import { useToastStore } from '@/stores/toast'
|
||||
import type { Artist } from '@/types/manager'
|
||||
import { readFormModalDraft, removeFormModalDraft, writeFormModalDraft } from '@/utils/form-modal-draft'
|
||||
|
||||
interface EditEmployeeForm {
|
||||
nickname: string
|
||||
identity: string
|
||||
status: number
|
||||
participateProduction: number
|
||||
workStartTime: string
|
||||
workEndTime: string
|
||||
}
|
||||
|
||||
const EDIT_EMPLOYEE_DRAFT_NAME_PREFIX = 'employee-edit'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const session = useSessionStore()
|
||||
const toast = useToastStore()
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const employee = ref<Artist | null>(null)
|
||||
const editModalVisible = ref(false)
|
||||
const employeeId = computed(() => String(route.params.id))
|
||||
const editDraftName = computed(() => `${EDIT_EMPLOYEE_DRAFT_NAME_PREFIX}-${employeeId.value}`)
|
||||
const menus = computed(() => [
|
||||
{ title: '排班设置', path: `/employees/${employeeId.value}/schedule` },
|
||||
{ title: '请假管理', path: `/employees/${employeeId.value}/leave` },
|
||||
{ title: '颜色设置', path: `/employees/${employeeId.value}/color` },
|
||||
{ title: '员工作品/订单', path: `/employees/${employeeId.value}/orders` }
|
||||
])
|
||||
const buildEmptyEditForm = (): EditEmployeeForm => ({
|
||||
nickname: '',
|
||||
identity: '',
|
||||
status: 1,
|
||||
participateProduction: 1,
|
||||
workStartTime: '',
|
||||
workEndTime: ''
|
||||
})
|
||||
const editForm = reactive<EditEmployeeForm>(buildEmptyEditForm())
|
||||
const originalEditForm = ref<EditEmployeeForm>(buildEmptyEditForm())
|
||||
const workTimeText = computed(() => {
|
||||
if (!employee.value?.workStartTime || !employee.value?.workEndTime) {
|
||||
return '未设置'
|
||||
}
|
||||
return `${normalizeTimeText(employee.value.workStartTime)}-${normalizeTimeText(employee.value.workEndTime)}`
|
||||
})
|
||||
const editFormChanged = computed(() => !sameEditForm(editForm, originalEditForm.value))
|
||||
|
||||
function normalizeTimeText(value: string | null | undefined): string {
|
||||
if (!value) {
|
||||
return ''
|
||||
}
|
||||
return value.slice(0, 5)
|
||||
}
|
||||
|
||||
function buildEditFormFromEmployee(value: Artist): EditEmployeeForm {
|
||||
return {
|
||||
nickname: value.nickname || value.name || '',
|
||||
identity: value.identity || value.level || '',
|
||||
status: value.status === 0 ? 0 : 1,
|
||||
participateProduction: value.participateProduction === 0 ? 0 : 1,
|
||||
workStartTime: normalizeTimeText(value.workStartTime),
|
||||
workEndTime: normalizeTimeText(value.workEndTime)
|
||||
}
|
||||
}
|
||||
|
||||
function sameEditForm(left: EditEmployeeForm, right: EditEmployeeForm): boolean {
|
||||
return left.nickname === right.nickname
|
||||
&& left.identity === right.identity
|
||||
&& left.status === right.status
|
||||
&& left.participateProduction === right.participateProduction
|
||||
&& left.workStartTime === right.workStartTime
|
||||
&& left.workEndTime === right.workEndTime
|
||||
}
|
||||
|
||||
function snapshotEditForm(): EditEmployeeForm {
|
||||
return {
|
||||
nickname: editForm.nickname,
|
||||
identity: editForm.identity,
|
||||
status: editForm.status,
|
||||
participateProduction: editForm.participateProduction,
|
||||
workStartTime: editForm.workStartTime,
|
||||
workEndTime: editForm.workEndTime
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeEditForm(form: EditEmployeeForm): EditEmployeeForm {
|
||||
return {
|
||||
nickname: String(form.nickname || ''),
|
||||
identity: String(form.identity || ''),
|
||||
status: Number(form.status) === 0 ? 0 : 1,
|
||||
participateProduction: Number(form.participateProduction) === 0 ? 0 : 1,
|
||||
workStartTime: normalizeTimeText(String(form.workStartTime || '')),
|
||||
workEndTime: normalizeTimeText(String(form.workEndTime || ''))
|
||||
}
|
||||
}
|
||||
|
||||
function applyEditForm(form: EditEmployeeForm): void {
|
||||
const normalizedForm = normalizeEditForm(form)
|
||||
editForm.nickname = normalizedForm.nickname
|
||||
editForm.identity = normalizedForm.identity
|
||||
editForm.status = normalizedForm.status
|
||||
editForm.participateProduction = normalizedForm.participateProduction
|
||||
editForm.workStartTime = normalizedForm.workStartTime
|
||||
editForm.workEndTime = normalizedForm.workEndTime
|
||||
}
|
||||
|
||||
function resetEditForm(): void {
|
||||
const emptyForm = buildEmptyEditForm()
|
||||
applyEditForm(emptyForm)
|
||||
originalEditForm.value = emptyForm
|
||||
}
|
||||
|
||||
function syncEditDraft(): void {
|
||||
if (!editModalVisible.value || !editFormChanged.value) {
|
||||
return
|
||||
}
|
||||
writeFormModalDraft(session.userInfo, editDraftName.value, snapshotEditForm(), editModalVisible.value)
|
||||
}
|
||||
|
||||
function restoreEditDraft(): void {
|
||||
if (!employee.value) {
|
||||
return
|
||||
}
|
||||
const draft = readFormModalDraft<EditEmployeeForm>(session.userInfo, editDraftName.value)
|
||||
if (!draft?.open) {
|
||||
return
|
||||
}
|
||||
const baseForm = buildEditFormFromEmployee(employee.value)
|
||||
originalEditForm.value = baseForm
|
||||
applyEditForm(draft.form)
|
||||
editModalVisible.value = true
|
||||
}
|
||||
|
||||
function clearEditDraft(): void {
|
||||
removeFormModalDraft(session.userInfo, editDraftName.value)
|
||||
}
|
||||
|
||||
function updateEditModalVisible(value: boolean): void {
|
||||
editModalVisible.value = value
|
||||
if (!value) {
|
||||
clearEditDraft()
|
||||
resetEditForm()
|
||||
}
|
||||
}
|
||||
|
||||
function openEdit(): void {
|
||||
if (!employee.value) {
|
||||
return
|
||||
}
|
||||
clearEditDraft()
|
||||
const form = buildEditFormFromEmployee(employee.value)
|
||||
applyEditForm(form)
|
||||
originalEditForm.value = snapshotEditForm()
|
||||
editModalVisible.value = true
|
||||
}
|
||||
|
||||
function errorMessage(error: { message?: string } | null): string {
|
||||
return error?.message ? error.message : '员工信息保存失败,请稍后重试'
|
||||
}
|
||||
|
||||
const loadEmployee = async (): Promise<void> => {
|
||||
loading.value = true
|
||||
@@ -60,9 +248,55 @@ const loadEmployee = async (): Promise<void> => {
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadEmployee()
|
||||
const validateEditForm = (): boolean => {
|
||||
if (!editForm.nickname.trim()) {
|
||||
toast.error('请输入员工姓名')
|
||||
return false
|
||||
}
|
||||
if (Boolean(editForm.workStartTime) !== Boolean(editForm.workEndTime)) {
|
||||
toast.error('请同时填写上班开始和结束时间')
|
||||
return false
|
||||
}
|
||||
if (editForm.workStartTime && editForm.workEndTime && editForm.workStartTime >= editForm.workEndTime) {
|
||||
toast.error('上班结束时间必须晚于开始时间')
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
const saveEdit = async (): Promise<void> => {
|
||||
if (!employee.value || !validateEditForm()) {
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
await managerEmployeesApi.save({
|
||||
...employee.value,
|
||||
userId: employee.value.userId || employeeId.value,
|
||||
nickname: editForm.nickname.trim(),
|
||||
identity: editForm.identity.trim(),
|
||||
status: editForm.status,
|
||||
participateProduction: editForm.participateProduction,
|
||||
workStartTime: editForm.workStartTime || null,
|
||||
workEndTime: editForm.workEndTime || null
|
||||
})
|
||||
toast.success('员工信息已保存')
|
||||
updateEditModalVisible(false)
|
||||
await loadEmployee()
|
||||
} catch (error) {
|
||||
toast.error(errorMessage(error as { message?: string } | null))
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadEmployee()
|
||||
restoreEditDraft()
|
||||
})
|
||||
|
||||
watch(editForm, syncEditDraft, { deep: true })
|
||||
watch(editModalVisible, syncEditDraft)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -85,6 +319,11 @@ onMounted(() => {
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.employee-hero__body {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.employee-avatar img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
@@ -101,6 +340,21 @@ onMounted(() => {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.edit-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
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;
|
||||
}
|
||||
|
||||
.color-line {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -132,4 +386,10 @@ onMounted(() => {
|
||||
.menu-row:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.modal-form {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
padding: 14px;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user