feat(mes): 迁移生产报工 antd/ele 并补齐任务选择器
parent
5a1100aed4
commit
d1e2202e59
|
|
@ -36,6 +36,7 @@ const formType = ref<FormType>('create');
|
||||||
const formData = ref<MesProFeedbackApi.Feedback>();
|
const formData = ref<MesProFeedbackApi.Feedback>();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const subTabsName = ref('itemConsume');
|
const subTabsName = ref('itemConsume');
|
||||||
|
const originalSnapshot = ref(''); // 表单原始数据快照,用于 submit 时跳过未变更的保存请求
|
||||||
|
|
||||||
const isEditable = computed(() =>
|
const isEditable = computed(() =>
|
||||||
['create', 'submit', 'update'].includes(formType.value),
|
['create', 'submit', 'update'].includes(formType.value),
|
||||||
|
|
@ -100,6 +101,13 @@ function alignQuantity(data: MesProFeedbackApi.Feedback) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 读取并按提交规则对齐后的表单数据,用于快照和保存 */
|
||||||
|
async function getAlignedData(): Promise<MesProFeedbackApi.Feedback> {
|
||||||
|
const data = (await formApi.getValues()) as MesProFeedbackApi.Feedback;
|
||||||
|
alignQuantity(data);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
/** 保存:create 后切换为 update 模式 */
|
/** 保存:create 后切换为 update 模式 */
|
||||||
async function handleSave() {
|
async function handleSave() {
|
||||||
const { valid } = await formApi.validate();
|
const { valid } = await formApi.validate();
|
||||||
|
|
@ -108,13 +116,12 @@ async function handleSave() {
|
||||||
}
|
}
|
||||||
modalApi.lock();
|
modalApi.lock();
|
||||||
try {
|
try {
|
||||||
const data = (await formApi.getValues()) as MesProFeedbackApi.Feedback;
|
const data = await getAlignedData();
|
||||||
alignQuantity(data);
|
|
||||||
if (formType.value === 'create') {
|
if (formType.value === 'create') {
|
||||||
const id = await createFeedback(data);
|
const id = await createFeedback(data);
|
||||||
|
data.id = id;
|
||||||
formData.value = {
|
formData.value = {
|
||||||
...data,
|
...data,
|
||||||
id,
|
|
||||||
status: MesProFeedbackStatusEnum.PREPARE,
|
status: MesProFeedbackStatusEnum.PREPARE,
|
||||||
};
|
};
|
||||||
formType.value = 'update';
|
formType.value = 'update';
|
||||||
|
|
@ -126,13 +133,15 @@ async function handleSave() {
|
||||||
formData.value = { ...formData.value, ...data };
|
formData.value = { ...formData.value, ...data };
|
||||||
message.success($t('common.updateSuccess'));
|
message.success($t('common.updateSuccess'));
|
||||||
}
|
}
|
||||||
|
// 刷新快照(已对齐数量并补 id),后续 submit 用于判断是否需要再保存
|
||||||
|
originalSnapshot.value = JSON.stringify(data);
|
||||||
emit('success');
|
emit('success');
|
||||||
} finally {
|
} finally {
|
||||||
modalApi.unlock();
|
modalApi.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 提交:保存最新内容后调用提交接口 */
|
/** 提交:仅当表单较快照有变更时才先保存,再调用提交接口 */
|
||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
const { valid } = await formApi.validate();
|
const { valid } = await formApi.validate();
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
|
|
@ -140,15 +149,13 @@ async function handleSubmit() {
|
||||||
}
|
}
|
||||||
modalApi.lock();
|
modalApi.lock();
|
||||||
try {
|
try {
|
||||||
const data = (await formApi.getValues()) as MesProFeedbackApi.Feedback;
|
const data = await getAlignedData();
|
||||||
alignQuantity(data);
|
// 表单有修改时,先保存
|
||||||
let id = formData.value?.id;
|
if (JSON.stringify(data) !== originalSnapshot.value) {
|
||||||
if (formType.value === 'create' || !id) {
|
|
||||||
id = await createFeedback(data);
|
|
||||||
} else {
|
|
||||||
await updateFeedback(data);
|
await updateFeedback(data);
|
||||||
|
originalSnapshot.value = JSON.stringify(data);
|
||||||
}
|
}
|
||||||
await submitFeedback(id!);
|
await submitFeedback(formData.value!.id!);
|
||||||
await modalApi.close();
|
await modalApi.close();
|
||||||
emit('success');
|
emit('success');
|
||||||
message.success('报工单已提交');
|
message.success('报工单已提交');
|
||||||
|
|
@ -217,6 +224,7 @@ const [Modal, modalApi] = useVbenModal({
|
||||||
if (!isOpen) {
|
if (!isOpen) {
|
||||||
formData.value = undefined;
|
formData.value = undefined;
|
||||||
subTabsName.value = 'itemConsume';
|
subTabsName.value = 'itemConsume';
|
||||||
|
originalSnapshot.value = '';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 加载数据
|
// 加载数据
|
||||||
|
|
@ -242,6 +250,8 @@ const [Modal, modalApi] = useVbenModal({
|
||||||
feedbackTime: Date.now(),
|
feedbackTime: Date.now(),
|
||||||
feedbackUserId: userStore.userInfo?.id,
|
feedbackUserId: userStore.userInfo?.id,
|
||||||
});
|
});
|
||||||
|
// 记录初始快照(含数量对齐结果),submit 时用于跳过无变更的保存请求
|
||||||
|
originalSnapshot.value = JSON.stringify(await getAlignedData());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
modalApi.lock();
|
modalApi.lock();
|
||||||
|
|
@ -253,6 +263,8 @@ const [Modal, modalApi] = useVbenModal({
|
||||||
);
|
);
|
||||||
// 设置到 values
|
// 设置到 values
|
||||||
await formApi.setValues({ ...formData.value, checkFlag });
|
await formApi.setValues({ ...formData.value, checkFlag });
|
||||||
|
// 记录初始快照(含数量对齐结果),submit 时用于跳过无变更的保存请求
|
||||||
|
originalSnapshot.value = JSON.stringify(await getAlignedData());
|
||||||
} finally {
|
} finally {
|
||||||
modalApi.unlock();
|
modalApi.unlock();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,12 +43,11 @@ const hovering = ref(false); // 是否悬停
|
||||||
const selectedItem = ref<MesProTaskApi.Task>(); // 选中的任务
|
const selectedItem = ref<MesProTaskApi.Task>(); // 选中的任务
|
||||||
|
|
||||||
const displayLabel = computed(() => selectedItem.value?.code ?? ''); // 选择器展示编号
|
const displayLabel = computed(() => selectedItem.value?.code ?? ''); // 选择器展示编号
|
||||||
const showClear = computed( // 是否显示清空图标
|
const showClear = computed(() => // 是否显示清空图标
|
||||||
() =>
|
props.allowClear &&
|
||||||
props.allowClear &&
|
!props.disabled &&
|
||||||
!props.disabled &&
|
hovering.value &&
|
||||||
hovering.value &&
|
props.modelValue !== undefined,
|
||||||
props.modelValue !== undefined,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/** 根据任务编号回显选择器 */
|
/** 根据任务编号回显选择器 */
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ const formType = ref<FormType>('create');
|
||||||
const formData = ref<MesProFeedbackApi.Feedback>();
|
const formData = ref<MesProFeedbackApi.Feedback>();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const subTabsName = ref('itemConsume');
|
const subTabsName = ref('itemConsume');
|
||||||
|
const originalSnapshot = ref(''); // 表单原始数据快照,用于 submit 时跳过未变更的保存请求
|
||||||
|
|
||||||
const isEditable = computed(() =>
|
const isEditable = computed(() =>
|
||||||
['create', 'submit', 'update'].includes(formType.value),
|
['create', 'submit', 'update'].includes(formType.value),
|
||||||
|
|
@ -106,6 +107,13 @@ function alignQuantity(data: MesProFeedbackApi.Feedback) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 读取并按提交规则对齐后的表单数据,用于快照和保存 */
|
||||||
|
async function getAlignedData(): Promise<MesProFeedbackApi.Feedback> {
|
||||||
|
const data = (await formApi.getValues()) as MesProFeedbackApi.Feedback;
|
||||||
|
alignQuantity(data);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
/** 保存:create 后切换为 update 模式 */
|
/** 保存:create 后切换为 update 模式 */
|
||||||
async function handleSave() {
|
async function handleSave() {
|
||||||
const { valid } = await formApi.validate();
|
const { valid } = await formApi.validate();
|
||||||
|
|
@ -114,13 +122,12 @@ async function handleSave() {
|
||||||
}
|
}
|
||||||
modalApi.lock();
|
modalApi.lock();
|
||||||
try {
|
try {
|
||||||
const data = (await formApi.getValues()) as MesProFeedbackApi.Feedback;
|
const data = await getAlignedData();
|
||||||
alignQuantity(data);
|
|
||||||
if (formType.value === 'create') {
|
if (formType.value === 'create') {
|
||||||
const id = await createFeedback(data);
|
const id = await createFeedback(data);
|
||||||
|
data.id = id;
|
||||||
formData.value = {
|
formData.value = {
|
||||||
...data,
|
...data,
|
||||||
id,
|
|
||||||
status: MesProFeedbackStatusEnum.PREPARE,
|
status: MesProFeedbackStatusEnum.PREPARE,
|
||||||
};
|
};
|
||||||
formType.value = 'update';
|
formType.value = 'update';
|
||||||
|
|
@ -132,13 +139,15 @@ async function handleSave() {
|
||||||
formData.value = { ...formData.value, ...data };
|
formData.value = { ...formData.value, ...data };
|
||||||
ElMessage.success($t('common.updateSuccess'));
|
ElMessage.success($t('common.updateSuccess'));
|
||||||
}
|
}
|
||||||
|
// 刷新快照(已对齐数量并补 id),后续 submit 用于判断是否需要再保存
|
||||||
|
originalSnapshot.value = JSON.stringify(data);
|
||||||
emit('success');
|
emit('success');
|
||||||
} finally {
|
} finally {
|
||||||
modalApi.unlock();
|
modalApi.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 提交:保存最新内容后调用提交接口 */
|
/** 提交:仅当表单较快照有变更时才先保存,再调用提交接口 */
|
||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
const { valid } = await formApi.validate();
|
const { valid } = await formApi.validate();
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
|
|
@ -146,15 +155,13 @@ async function handleSubmit() {
|
||||||
}
|
}
|
||||||
modalApi.lock();
|
modalApi.lock();
|
||||||
try {
|
try {
|
||||||
const data = (await formApi.getValues()) as MesProFeedbackApi.Feedback;
|
const data = await getAlignedData();
|
||||||
alignQuantity(data);
|
// 表单有修改时,先保存
|
||||||
let id = formData.value?.id;
|
if (JSON.stringify(data) !== originalSnapshot.value) {
|
||||||
if (formType.value === 'create' || !id) {
|
|
||||||
id = await createFeedback(data);
|
|
||||||
} else {
|
|
||||||
await updateFeedback(data);
|
await updateFeedback(data);
|
||||||
|
originalSnapshot.value = JSON.stringify(data);
|
||||||
}
|
}
|
||||||
await submitFeedback(id!);
|
await submitFeedback(formData.value!.id!);
|
||||||
await modalApi.close();
|
await modalApi.close();
|
||||||
emit('success');
|
emit('success');
|
||||||
ElMessage.success('报工单已提交');
|
ElMessage.success('报工单已提交');
|
||||||
|
|
@ -225,6 +232,7 @@ const [Modal, modalApi] = useVbenModal({
|
||||||
if (!isOpen) {
|
if (!isOpen) {
|
||||||
formData.value = undefined;
|
formData.value = undefined;
|
||||||
subTabsName.value = 'itemConsume';
|
subTabsName.value = 'itemConsume';
|
||||||
|
originalSnapshot.value = '';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 加载数据
|
// 加载数据
|
||||||
|
|
@ -250,6 +258,8 @@ const [Modal, modalApi] = useVbenModal({
|
||||||
feedbackTime: Date.now(),
|
feedbackTime: Date.now(),
|
||||||
feedbackUserId: userStore.userInfo?.id,
|
feedbackUserId: userStore.userInfo?.id,
|
||||||
});
|
});
|
||||||
|
// 记录初始快照(含数量对齐结果),submit 时用于跳过无变更的保存请求
|
||||||
|
originalSnapshot.value = JSON.stringify(await getAlignedData());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
modalApi.lock();
|
modalApi.lock();
|
||||||
|
|
@ -261,6 +271,8 @@ const [Modal, modalApi] = useVbenModal({
|
||||||
);
|
);
|
||||||
// 设置到 values
|
// 设置到 values
|
||||||
await formApi.setValues({ ...formData.value, checkFlag });
|
await formApi.setValues({ ...formData.value, checkFlag });
|
||||||
|
// 记录初始快照(含数量对齐结果),submit 时用于跳过无变更的保存请求
|
||||||
|
originalSnapshot.value = JSON.stringify(await getAlignedData());
|
||||||
} finally {
|
} finally {
|
||||||
modalApi.unlock();
|
modalApi.unlock();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,12 +43,11 @@ const hovering = ref(false); // 是否悬停
|
||||||
const selectedItem = ref<MesProTaskApi.Task>(); // 选中的任务
|
const selectedItem = ref<MesProTaskApi.Task>(); // 选中的任务
|
||||||
|
|
||||||
const displayLabel = computed(() => selectedItem.value?.code ?? ''); // 选择器展示编号
|
const displayLabel = computed(() => selectedItem.value?.code ?? ''); // 选择器展示编号
|
||||||
const showClear = computed( // 是否显示清空图标
|
const showClear = computed(() => // 是否显示清空图标
|
||||||
() =>
|
props.clearable &&
|
||||||
props.clearable &&
|
!props.disabled &&
|
||||||
!props.disabled &&
|
hovering.value &&
|
||||||
hovering.value &&
|
props.modelValue !== undefined,
|
||||||
props.modelValue !== undefined,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/** 根据任务编号回显选择器 */
|
/** 根据任务编号回显选择器 */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue