This commit is contained in:
@@ -446,7 +446,9 @@
|
||||
import { normalizeApiError } from '@/utils/business/apiError'
|
||||
import {
|
||||
getExchangePhoneConflictMessage,
|
||||
getExchangeBusinessErrorMessage
|
||||
getExchangeBusinessErrorMessage,
|
||||
getExchangePhoneAssociationQuery,
|
||||
type ExchangeNewAssetContext
|
||||
} from '@/utils/business/exchangeError'
|
||||
|
||||
defineOptions({ name: 'ExchangeManagement' })
|
||||
@@ -455,7 +457,11 @@
|
||||
const userStore = useUserStore()
|
||||
const router = useRouter()
|
||||
|
||||
const handleExchangeFailure = async (failure: unknown, fallback: string) => {
|
||||
const handleExchangeFailure = async (
|
||||
failure: unknown,
|
||||
fallback: string,
|
||||
newAsset: ExchangeNewAssetContext = {}
|
||||
) => {
|
||||
const conflictMessage = getExchangePhoneConflictMessage(failure)
|
||||
if (!conflictMessage) {
|
||||
const normalized = normalizeApiError(failure)
|
||||
@@ -467,6 +473,7 @@
|
||||
return
|
||||
}
|
||||
const canManageAssociations = hasAuth(AUGUST_PERMISSIONS.phoneAssetAssociation.list)
|
||||
const associationQuery = getExchangePhoneAssociationQuery(failure, newAsset)
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
canManageAssociations
|
||||
@@ -481,7 +488,8 @@
|
||||
dangerouslyUseHTMLString: false
|
||||
}
|
||||
)
|
||||
if (canManageAssociations) await router.push(RoutesAlias.PhoneAssetAssociation)
|
||||
if (canManageAssociations)
|
||||
await router.push({ path: RoutesAlias.PhoneAssetAssociation, query: associationQuery })
|
||||
} catch {
|
||||
// 用户关闭提示,不执行解绑或改写换货状态。
|
||||
}
|
||||
@@ -735,6 +743,7 @@
|
||||
type ShopSelectableOption = {
|
||||
shop_id?: number | null
|
||||
shop_name?: string | null
|
||||
associated_phones?: string[]
|
||||
}
|
||||
|
||||
const getShopDisplayName = (option?: ShopSelectableOption | null) => {
|
||||
@@ -1552,6 +1561,11 @@
|
||||
createFormRef.value?.validate(async (valid) => {
|
||||
if (!valid || createLoading.value) return
|
||||
|
||||
// 提交时冻结新资产上下文;请求或提示期间改动表单也不能跳到其他资产。
|
||||
const newAsset: ExchangeNewAssetContext = {
|
||||
asset_identifier: createForm.new_identifier,
|
||||
associated_phones: [...(createSelectedNewAsset.value?.associated_phones || [])]
|
||||
}
|
||||
createLoading.value = true
|
||||
try {
|
||||
const exchangeReason =
|
||||
@@ -1583,9 +1597,9 @@
|
||||
return
|
||||
}
|
||||
|
||||
await handleExchangeFailure(res, '换货单创建失败')
|
||||
await handleExchangeFailure(res, '换货单创建失败', newAsset)
|
||||
} catch (error) {
|
||||
await handleExchangeFailure(error, '换货单创建失败')
|
||||
await handleExchangeFailure(error, '换货单创建失败', newAsset)
|
||||
} finally {
|
||||
createLoading.value = false
|
||||
}
|
||||
@@ -1810,6 +1824,9 @@
|
||||
const handleCompleteExchange = async (row: ExchangeResponse) => {
|
||||
if (completeLoadingId.value === row.id) return
|
||||
|
||||
const newAsset: ExchangeNewAssetContext = {
|
||||
asset_identifier: row.new_asset_identifier || undefined
|
||||
}
|
||||
completeLoadingId.value = row.id
|
||||
|
||||
try {
|
||||
@@ -1829,11 +1846,11 @@
|
||||
// 刷新失败也不能吞掉原操作的 1202 业务响应。
|
||||
await Promise.allSettled([refreshExchangeDetail(row.id), loadExchangeList()])
|
||||
if (res.code === 0) ElMessage.success('操作成功')
|
||||
else await handleExchangeFailure(res, '确认完成失败')
|
||||
else await handleExchangeFailure(res, '确认完成失败', newAsset)
|
||||
} catch (error) {
|
||||
// 仅重新读取原单状态,不乐观标记完成,错误对象可能包含完整手机号,不输出日志。
|
||||
await Promise.allSettled([refreshExchangeDetail(row.id), loadExchangeList()])
|
||||
await handleExchangeFailure(error, '确认完成失败')
|
||||
await handleExchangeFailure(error, '确认完成失败', newAsset)
|
||||
} finally {
|
||||
completeLoadingId.value = null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user