功能:完善订单流程和加固

This commit is contained in:
xiaowang
2026-05-23 15:16:40 +08:00
parent 9227ec6175
commit 3e6e1cc4e8
90 changed files with 6859 additions and 368 deletions
@@ -75,6 +75,13 @@
<div class="title">{{ item.productTitle }}</div>
<div class="line">¥{{ item.price.toFixed(2) }} x {{ item.quantity }}</div>
<div v-if="item.appointmentTime" class="line appointment">预约时间:{{ item.appointmentTime }}</div>
<div v-if="pendingArtistChangeForItem(order, item)" class="change-status">
改派申请处理中:{{ pendingArtistChangeForItem(order, item)?.requestedArtistName || '新美甲师' }}
</div>
<div v-else-if="canRequestArtistChange(order, item)" class="change-action">
<span>需要更换服务美甲师</span>
<a-button size="small" @click="openArtistChangeModal(order, item)">申请改派</a-button>
</div>
</div>
</div>
@@ -86,6 +93,38 @@
</div>
</a-card>
</main>
<a-modal
v-model:open="artistChangeModalOpen"
title="申请改派"
:confirm-loading="artistChangeSubmitting"
@ok="submitArtistChangeRequest"
@cancel="closeArtistChangeModal"
>
<a-form layout="vertical">
<a-form-item label="当前美甲师">
<span>{{ artistChangeOptions?.currentArtistName || activeArtistChangeItem?.artistName || '未分配' }}</span>
</a-form-item>
<a-form-item label="新美甲师" required>
<a-select
v-model:value="artistChangeForm.requestedArtistId"
:loading="artistChangeOptionsLoading"
placeholder="请选择新的美甲师"
>
<a-select-option
v-for="artist in selectableArtistOptions"
:key="String(artist.artistId)"
:value="artist.artistId"
>
{{ artist.artistName }}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="改派原因" required>
<a-textarea v-model:value="artistChangeForm.reason" :rows="4" :maxlength="300" placeholder="请说明申请改派的原因" />
</a-form-item>
</a-form>
</a-modal>
</div>
</template>
@@ -101,6 +140,7 @@ import { message, Modal } from 'ant-design-vue'
import { userApi } from '@/api/user'
import { fileApi } from '../api/index'
import { orderApi } from '../api/order'
import type { OrderArtistChangeOptionsVO, OrderArtistChangeRequestVO } from '../api/order'
import type { IdType } from '@/utils/id'
import { runWithGlobalLoading } from '@/utils/action-loading'
@@ -110,6 +150,13 @@ const orders = ref<any[]>([])
const imageIdCache = ref<Record<string, string>>({})
const orderRefs = ref<Record<string, any>>({})
const showCalendarEntry = ref(false)
const currentUserId = ref<IdType>()
const artistChangeModalOpen = ref(false)
const artistChangeSubmitting = ref(false)
const artistChangeOptionsLoading = ref(false)
const artistChangeOptions = ref<OrderArtistChangeOptionsVO | null>(null)
const activeArtistChangeOrder = ref<any | null>(null)
const activeArtistChangeItem = ref<any | null>(null)
const filters = reactive({
keyword: '',
source: 'all',
@@ -118,6 +165,10 @@ const filters = reactive({
minAmount: undefined as number | undefined,
maxAmount: undefined as number | undefined
})
const artistChangeForm = reactive({
requestedArtistId: undefined as IdType | undefined,
reason: ''
})
/** filteredOrders is a reactive state variable used by the template and event handlers. */
const filteredOrders = computed(() => {
@@ -182,11 +233,33 @@ const sourceClass = (source?: string) => {
return 'source-service'
}
const sameId = (left: unknown, right: unknown) => {
return left !== undefined && left !== null && right !== undefined && right !== null && String(left) === String(right)
}
const pendingArtistChangeForItem = (order: any, item: any): OrderArtistChangeRequestVO | undefined => {
const itemValue = item?.pendingArtistChangeRequest as OrderArtistChangeRequestVO | undefined
if (itemValue) return itemValue
const orderValue = order?.pendingArtistChangeRequest as OrderArtistChangeRequestVO | undefined
if (!orderValue) return undefined
return sameId(orderValue.orderItemId, item.id) || (order.items || []).length === 1 ? orderValue : undefined
}
/** canComplete is a local helper used by this page script. */
const canComplete = (order: any) => {
return order.status === 1 && order.artistOrderSource !== 'SELF'
}
const canRequestArtistChange = (order: any, item: any) => {
const assignedToCurrentUser = !currentUserId.value || !item.artistId || sameId(item.artistId, currentUserId.value)
return order.status === 1 && item.id && assignedToCurrentUser && !pendingArtistChangeForItem(order, item)
}
const selectableArtistOptions = computed(() => {
const options = artistChangeOptions.value?.artists || []
return options.filter(artist => !sameId(artist.artistId, artistChangeOptions.value?.currentArtistId))
})
/** resetFilters is a local helper used by this page script. */
const resetFilters = () => {
filters.keyword = ''
@@ -225,6 +298,7 @@ const loadCalendarAccess = async () => {
showCalendarEntry.value = false
try {
const currentUser = await userApi.getUserInfo()
currentUserId.value = currentUser.id
if (currentUser.type === 3) {
showCalendarEntry.value = true
return
@@ -234,6 +308,7 @@ const loadCalendarAccess = async () => {
showCalendarEntry.value = Number(artistInfo?.participateProduction) === 1
}
} catch {
currentUserId.value = undefined
showCalendarEntry.value = false
}
}
@@ -243,6 +318,70 @@ const handleRefreshClick = async () => {
await runWithGlobalLoading(() => loadOrders())
}
const openArtistChangeModal = async (order: any, item: any) => {
if (!canRequestArtistChange(order, item)) return
activeArtistChangeOrder.value = order
activeArtistChangeItem.value = item
artistChangeOptions.value = null
artistChangeForm.requestedArtistId = undefined
artistChangeForm.reason = ''
artistChangeModalOpen.value = true
artistChangeOptionsLoading.value = true
try {
artistChangeOptions.value = await orderApi.getArtistChangeOptions(order.id, item.id)
if (!selectableArtistOptions.value.length) {
message.warning('暂无可改派的美甲师')
}
} catch {
message.error('获取可改派美甲师失败')
closeArtistChangeModal()
} finally {
artistChangeOptionsLoading.value = false
}
}
const closeArtistChangeModal = () => {
artistChangeModalOpen.value = false
activeArtistChangeOrder.value = null
activeArtistChangeItem.value = null
artistChangeOptions.value = null
artistChangeForm.requestedArtistId = undefined
artistChangeForm.reason = ''
}
const submitArtistChangeRequest = async () => {
if (!activeArtistChangeOrder.value || !activeArtistChangeItem.value) return
if (!artistChangeForm.requestedArtistId) {
message.warning('请选择新的美甲师')
return
}
const reason = artistChangeForm.reason.trim()
if (!reason) {
message.warning('请填写改派原因')
return
}
if (sameId(artistChangeForm.requestedArtistId, artistChangeOptions.value?.currentArtistId)) {
message.warning('新美甲师不能与当前美甲师相同')
return
}
artistChangeSubmitting.value = true
try {
await orderApi.requestArtistChange({
orderId: activeArtistChangeOrder.value.id,
orderItemId: activeArtistChangeItem.value.id,
requestedArtistId: artistChangeForm.requestedArtistId,
reason
})
message.success('改派申请已提交')
closeArtistChangeModal()
await loadOrders()
} catch {
message.error('提交改派申请失败')
} finally {
artistChangeSubmitting.value = false
}
}
/** completeOrder is a local helper used by this page script. */
const completeOrder = (orderId: IdType) => {
Modal.confirm({
@@ -298,6 +437,8 @@ onMounted(async () => {
.title { font-weight: 600; color: var(--text-primary); }
.line { margin-top: 4px; color: var(--text-secondary); font-size: 13px; }
.appointment { color: var(--theme-primary); }
.change-status { margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: var(--theme-primary-soft); color: var(--theme-primary); font-size: 13px; }
.change-action { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: var(--theme-primary-soft); color: var(--theme-primary); font-size: 13px; }
:deep(.ant-btn-primary) { background: var(--theme-primary); border-color: var(--theme-primary); }
:deep(.ant-btn-link) { color: var(--theme-primary); }