Files
syops/frontend/src/features/chat/components/shipping-review/ReviewActionConfirmDialog.vue
T
hugo 1b6483a4ea feat(shipping-notice,receipt-report): 新增收料报表功能并优化发货通知流程
清理废弃的shipping xfa ocr automark相关代码和job配置
新增收料报表管理的前端页面、路由和侧边栏入口
新增后端收料报表配置接口、数据库模型和RPA脚本
优化发货通知流程的重试策略,将shipping相关job默认不自动重试
移除废弃的库存源确认相关逻辑,更新流程门禁规则
重构订单模板的值适配器模块,新增坐标OCR值适配器
清理前端shipping菜单和action的废弃选项
更新相关文档和测试用例,调整.gitignore忽略规则
2026-08-20 20:23:10 +08:00

220 lines
7.0 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!--
features/chat/components/shipping-review/ReviewActionConfirmDialog.vue
用途:复核页破坏性/不可逆操作的二次确认弹窗(确认建单、重识别、非订单、质量异常)。
依赖:vue-i18n、dialog-overlay / dialog-panel 设计系统样式。
逻辑:ShippingOrderReviewView 以 v-model 控制显隐;质量异常须选原因码,other 时备注必填;
非订单/重识别将说明写入 comment,并附带稳定 reasonCode。
-->
<script setup lang="ts">
import { computed, onBeforeUnmount, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
export type ReviewConfirmAction = 'confirm' | 'reparse' | 'non_order' | 'quality_issue';
/** 确认弹窗提交载荷:稳定原因码 + 自由说明,供后端审计复盘。 */
export type ReviewConfirmPayload = {
reasonCode: string;
comment: string;
};
const QUALITY_REASON_CODES = [
'blurred',
'incomplete_pages',
'password_protected',
'corrupted',
'wrong_orientation',
'unsupported_layout',
'missing_order_table',
'other',
] as const;
interface Props {
modelValue: boolean;
action: ReviewConfirmAction;
confirmLoading?: boolean;
}
const props = withDefaults(defineProps<Props>(), {
confirmLoading: false,
});
const emit = defineEmits<{
(e: 'update:modelValue', value: boolean): void;
(e: 'confirm', payload: ReviewConfirmPayload): void;
(e: 'cancel'): void;
}>();
const { t } = useI18n();
const reasonCode = ref('other');
const comment = ref('');
const reasonMissing = ref(false);
const commentMissing = ref(false);
/** 非订单 / 重识别 / 质量异常需要说明或原因选择。 */
const needsDispositionInput = computed(
() => props.action === 'non_order' || props.action === 'reparse' || props.action === 'quality_issue',
);
const title = computed(() => t(`chat.shippingOrderReview.confirmDialog.${props.action}.title`));
const impact = computed(() => t(`chat.shippingOrderReview.confirmDialog.${props.action}.impact`));
const confirmText = computed(() => t(`chat.shippingOrderReview.confirmDialog.${props.action}.confirm`));
const confirmTone = computed(() => (props.action === 'confirm' ? 'primary' : 'danger'));
const confirmButtonClass = computed(() =>
confirmTone.value === 'primary' ? 'btn-primary btn-sm' : 'btn-danger btn-sm',
);
/**
* 质量异常原因码的展示文案。
* @param code - 后端允许的 quality reason 码
*/
const qualityReasonLabel = (code: string) =>
t(`chat.shippingOrderReview.confirmDialog.qualityReasons.${code}`);
/** 关闭弹窗并同步 v-model。 */
const closeDialog = () => {
emit('update:modelValue', false);
};
const handleCancel = () => {
emit('cancel');
closeDialog();
};
/**
* 按 action 组装原因码与备注后触发确认。
* 核心逻辑:质量异常 `other` 强制备注;非订单/重识别使用稳定 reasonCode + 自由 comment。
*/
const handleConfirm = () => {
reasonMissing.value = false;
commentMissing.value = false;
const trimmedComment = comment.value.trim();
if (props.action === 'quality_issue') {
if (!reasonCode.value) {
reasonMissing.value = true;
return;
}
if (reasonCode.value === 'other' && !trimmedComment) {
commentMissing.value = true;
return;
}
emit('confirm', { reasonCode: reasonCode.value, comment: trimmedComment });
closeDialog();
return;
}
if (props.action === 'non_order' || props.action === 'reparse') {
if (!trimmedComment) {
commentMissing.value = true;
return;
}
const code = props.action === 'non_order' ? 'non_order' : 'document_quality';
emit('confirm', { reasonCode: code, comment: trimmedComment });
closeDialog();
return;
}
emit('confirm', { reasonCode: '', comment: '' });
closeDialog();
};
watch(
() => props.modelValue,
(open) => {
if (!open) {
reasonCode.value = 'other';
comment.value = '';
reasonMissing.value = false;
commentMissing.value = false;
}
},
);
const onKeydown = (event: KeyboardEvent) => {
if (event.key === 'Escape' && props.modelValue) handleCancel();
};
watch(
() => props.modelValue,
(open) => {
if (typeof document === 'undefined') return;
if (open) document.addEventListener('keydown', onKeydown);
else document.removeEventListener('keydown', onKeydown);
},
);
onBeforeUnmount(() => {
if (typeof document !== 'undefined') document.removeEventListener('keydown', onKeydown);
});
</script>
<template>
<Teleport to="body">
<div
v-if="modelValue"
class="dialog-overlay z-50 flex items-center justify-center p-4"
role="dialog"
aria-modal="true"
:aria-label="title"
data-testid="review-action-confirm-dialog"
@click.self="handleCancel"
>
<div class="dialog-panel w-full max-w-md space-y-4 p-5">
<header>
<h2 class="text-base font-semibold text-primary">{{ title }}</h2>
<p class="mt-2 text-sm text-secondary">{{ impact }}</p>
</header>
<template v-if="needsDispositionInput">
<label v-if="action === 'quality_issue'" class="block space-y-1 text-sm">
<span class="text-secondary">{{ t('chat.shippingOrderReview.confirmDialog.reasonCodeLabel') }}</span>
<select
v-model="reasonCode"
class="select-field w-full text-sm"
data-testid="review-action-reason-code"
@change="reasonMissing = false"
>
<option v-for="code in QUALITY_REASON_CODES" :key="code" :value="code">
{{ qualityReasonLabel(code) }}
</option>
</select>
<p v-if="reasonMissing" class="text-xs text-rose-600 dark:text-rose-400">
{{ t('chat.shippingOrderReview.confirmDialog.reasonCodeRequired') }}
</p>
</label>
<label class="block space-y-1 text-sm">
<span class="text-secondary">{{ t('chat.shippingOrderReview.confirmDialog.reasonLabel') }}</span>
<textarea
v-model="comment"
rows="3"
class="input-field w-full resize-y text-sm"
:placeholder="t('chat.shippingOrderReview.confirmDialog.reasonPlaceholder')"
data-testid="review-action-reason"
@input="commentMissing = false"
/>
<p v-if="commentMissing" class="text-xs text-rose-600 dark:text-rose-400">
{{ t('chat.shippingOrderReview.confirmDialog.reasonRequired') }}
</p>
</label>
</template>
<footer class="flex justify-end gap-2 pt-1">
<button type="button" class="btn-secondary btn-sm" :disabled="confirmLoading" @click="handleCancel">
{{ t('common.deleteDialog.cancel') }}
</button>
<button
type="button"
:class="confirmButtonClass"
:disabled="confirmLoading"
data-testid="review-action-confirm-submit"
@click="handleConfirm"
>
{{ confirmLoading ? t('chat.shippingOrderReview.saving') : confirmText }}
</button>
</footer>
</div>
</div>
</Teleport>
</template>