feat(mes): 优化退货单操作逻辑,简化提交与完成流程

pull/871/MERGE
YunaiV 2026-03-29 21:43:46 +08:00
parent 1f2a0904f4
commit 5856838c73
2 changed files with 90 additions and 62 deletions

View File

@ -6,6 +6,7 @@
:rules="formRules"
label-width="110px"
v-loading="formLoading"
:disabled="isDetail"
>
<el-row>
<el-col :span="8">
@ -16,9 +17,7 @@
:disabled="isHeaderReadonly"
>
<template #append>
<el-button @click="generateCode" :disabled="isHeaderReadonly">
生成
</el-button>
<el-button @click="generateCode" :disabled="isHeaderReadonly"> 生成 </el-button>
</template>
</el-input>
</el-form-item>
@ -104,13 +103,24 @@
<ReturnVendorLineList :return-id="formData.id" :form-type="formType" />
</template>
<template #footer>
<el-button v-if="isUpdate" @click="submitForm" type="primary" :disabled="formLoading">
<el-button v-if="isEditable" @click="submitForm" type="primary" :disabled="formLoading">
</el-button>
<el-button
v-if="(isEditable && formData.status === MesWmReturnVendorStatusEnum.PREPARE) || isSubmit"
@click="handleSubmit"
type="warning"
:disabled="formLoading"
>
</el-button>
<el-button v-if="isStock" @click="handleStock" type="primary" :disabled="formLoading">
执行拣货
</el-button>
<el-button @click="dialogVisible = false"> </el-button>
<el-button v-if="isFinish" @click="handleFinish" type="success" :disabled="formLoading">
完成退货
</el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</template>
@ -120,22 +130,38 @@ import { WmReturnVendorApi, WmReturnVendorVO } from '@/api/mes/wm/returnvendor'
import { AutoCodeRecordApi } from '@/api/mes/md/autocode/record'
import MdVendorSelect from '@/views/mes/md/vendor/components/MdVendorSelect.vue'
import ReturnVendorLineList from './ReturnVendorLineList.vue'
import { MesAutoCodeRuleCode } from '@/views/mes/utils/constants'
import { MesAutoCodeRuleCode, MesWmReturnVendorStatusEnum } from '@/views/mes/utils/constants'
defineOptions({ name: 'ReturnVendorForm' })
const emit = defineEmits(['success'])
const message = useMessage() //
const dialogVisible = ref(false) //
const formLoading = ref(false) //
const formType = ref<string>('create') // 表单的类型create / update / stock / detail
const formType = ref<string>('create') // 表单的类型create / update / stock / finish / detail
const isEditable = computed(() => ['create', 'update'].includes(formType.value)) //
const isStock = computed(() => formType.value === 'stock') //
const isFinish = computed(() => formType.value === 'finish') // 退
const isDetail = computed(() => ['detail', 'finish'].includes(formType.value)) //
const isHeaderReadonly = computed(() => ['stock', 'detail', 'finish'].includes(formType.value)) //
const dialogTitle = computed(() => {
const titles = {
create: '新增供应商退货单',
update: '编辑供应商退货单',
stock: '执行拣货',
finish: '完成退货',
detail: '供应商退货单详情'
}
return titles[formType.value] || formType.value
})
const formData = ref({
id: undefined as number | undefined,
status: undefined as number | undefined,
code: undefined,
name: undefined,
purchaseOrderCode: undefined,
vendorId: undefined,
returnDate: undefined,
returnReason: undefined,
transportCode: undefined,
@ -149,19 +175,7 @@ const formRules = reactive({
returnDate: [{ required: true, message: '退货日期不能为空', trigger: 'change' }]
})
const formRef = ref() // Ref
const isUpdate = computed(() => ['create', 'update'].includes(formType.value)) //
const isStock = computed(() => formType.value === 'stock') //
const isHeaderReadonly = computed(() => ['stock', 'detail'].includes(formType.value)) //
const dialogTitle = computed(() => {
const titles = {
create: '新增供应商退货单',
update: '编辑供应商退货单',
stock: '执行拣货',
detail: '供应商退货单详情'
}
return titles[formType.value] || formType.value
})
const originalFormData = ref<string>('') //
/** 生成退货单编号 */
const generateCode = async () => {
@ -175,7 +189,7 @@ const open = async (type: string, id?: number) => {
dialogVisible.value = true
formType.value = type
resetForm()
// //
// ////
if (id) {
formLoading.value = true
try {
@ -184,11 +198,11 @@ const open = async (type: string, id?: number) => {
formLoading.value = false
}
}
//
originalFormData.value = JSON.stringify(formData.value)
}
defineExpose({ open })
/** 提交表单create/update 模式) */
const emit = defineEmits(['success'])
/** 保存表单create/update 模式) */
const submitForm = async () => {
//
await formRef.value.validate()
@ -199,12 +213,16 @@ const submitForm = async () => {
if (formType.value === 'create') {
const res = await WmReturnVendorApi.createReturnVendor(data)
message.success('新增成功')
//
formData.value.id = res
formData.value.status = MesWmReturnVendorStatusEnum.PREPARE
formType.value = 'update'
} else {
await WmReturnVendorApi.updateReturnVendor(data)
message.success('修改成功')
}
//
originalFormData.value = JSON.stringify(formData.value)
//
emit('success')
} finally {
@ -212,6 +230,29 @@ const submitForm = async () => {
}
}
/** 提交操作:表单修改过则先保存,再提交 */
const handleSubmit = async () => {
//
await formRef.value.validate()
try {
await message.confirm('确认提交该退货单?【提交后将不能修改】')
formLoading.value = true
// 1.
if (JSON.stringify(formData.value) !== originalFormData.value) {
const data = formData.value as unknown as WmReturnVendorVO
await WmReturnVendorApi.updateReturnVendor(data)
}
// 2. 退
await WmReturnVendorApi.submitReturnVendor(formData.value.id!)
message.success('提交成功')
dialogVisible.value = false
emit('success')
} catch {
} finally {
formLoading.value = false
}
}
/** 执行拣货 */
const handleStock = async () => {
try {
@ -231,15 +272,30 @@ const handleStock = async () => {
}
}
/** 完成退货 */
const handleFinish = async () => {
try {
await message.confirm('确认完成该退货单并执行退货?')
formLoading.value = true
await WmReturnVendorApi.finishReturnVendor(formData.value.id!)
message.success('完成成功')
dialogVisible.value = false
emit('success')
} catch {
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined,
status: undefined,
code: undefined,
name: undefined,
purchaseOrderCode: undefined,
vendorId: undefined,
returnDate: undefined,
returnReason: undefined,
transportCode: undefined,
@ -248,4 +304,6 @@ const resetForm = () => {
}
formRef.value?.resetFields()
}
defineExpose({ open })
</script>

View File

@ -88,7 +88,7 @@
</el-table-column>
<el-table-column label="操作" align="center" width="240" fixed="right">
<template #default="scope">
<!-- 草稿编辑提交删除 -->
<!-- 草稿编辑删除 -->
<el-button
link
type="primary"
@ -98,15 +98,6 @@
>
编辑
</el-button>
<el-button
link
type="warning"
@click="handleSubmit(scope.row.id)"
v-hasPermi="['mes:wm-return-vendor:update']"
v-if="scope.row.status === MesWmReturnVendorStatusEnum.PREPARE"
>
提交
</el-button>
<el-button
link
type="danger"
@ -116,7 +107,7 @@
>
删除
</el-button>
<!-- 待拣货执行拣货 -->
<!-- 待拣货执行拣货取消 -->
<el-button
link
type="success"
@ -126,17 +117,16 @@
>
执行拣货
</el-button>
<!-- 待执行退货完成 -->
<!-- 待执行退货完成退货取消 -->
<el-button
link
type="success"
@click="handleFinish(scope.row.id)"
@click="openForm('finish', scope.row.id)"
v-hasPermi="['mes:wm-return-vendor:update-status']"
v-if="scope.row.status === MesWmReturnVendorStatusEnum.APPROVED"
>
完成
完成退货
</el-button>
<!-- 待拣货待执行退货取消 -->
<el-button
link
type="danger"
@ -223,16 +213,6 @@ const openForm = (type: string, id?: number) => {
formRef.value.open(type, id)
}
/** 提交按钮操作 */
const handleSubmit = async (id: number) => {
try {
await message.confirm('确认提交该退货单?')
await WmReturnVendorApi.submitReturnVendor(id)
message.success('提交成功')
await getList()
} catch {}
}
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
try {
@ -253,16 +233,6 @@ const handleCancel = async (id: number) => {
} catch {}
}
/** 完成按钮操作 */
const handleFinish = async (id: number) => {
try {
await message.confirm('确认完成该退货单并执行退货?')
await WmReturnVendorApi.finishReturnVendor(id)
message.success('完成成功')
await getList()
} catch {}
}
/** 导出按钮操作 */
const handleExport = async () => {
try {