实现点击确认收货后直接入库
This commit is contained in:
parent
aa40502f82
commit
11ca3ae4a6
|
@ -100,9 +100,12 @@ export const equipmentProcurementApi = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 确认收货
|
* 确认收货(扩展版,支持完整设备数据)
|
||||||
*/
|
*/
|
||||||
receiveGoods: (equipmentId: string, data: ReceiptRequest) => {
|
receiveGoods: (equipmentId: string, data: ReceiptRequest) => {
|
||||||
|
console.log('📦 收货API被调用,设备ID:', equipmentId)
|
||||||
|
console.log('📦 收货数据:', data)
|
||||||
|
|
||||||
return http.post<ApiRes<null>>(`/equipment/procurement/receipt/${equipmentId}`, data)
|
return http.post<ApiRes<null>>(`/equipment/procurement/receipt/${equipmentId}`, data)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -410,33 +410,63 @@ export interface EquipmentApprovalResp {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 收货请求参数
|
* 收货请求参数(扩展版,包含完整设备信息)
|
||||||
*/
|
*/
|
||||||
export interface ReceiptRequest {
|
export interface ReceiptRequest {
|
||||||
/** 收货时间 */
|
// 收货特有信息
|
||||||
receiptTime: string
|
receiptTime: string
|
||||||
/** 收货人 */
|
|
||||||
receiptPerson: string
|
receiptPerson: string
|
||||||
/** 收货数量 */
|
|
||||||
receiptQuantity: number
|
receiptQuantity: number
|
||||||
/** 收货备注 */
|
|
||||||
receiptRemark?: string
|
receiptRemark?: string
|
||||||
/** 外观检查结果 */
|
|
||||||
appearanceCheck: string
|
appearanceCheck: string
|
||||||
/** 功能测试结果 */
|
|
||||||
functionTest: string
|
functionTest: string
|
||||||
/** 包装完整性 */
|
|
||||||
packageIntegrity: string
|
packageIntegrity: string
|
||||||
/** 配件完整性 */
|
|
||||||
accessoryIntegrity: string
|
accessoryIntegrity: string
|
||||||
/** 检查结果 */
|
|
||||||
checkResult: 'PASS' | 'FAIL' | 'CONDITIONAL'
|
checkResult: 'PASS' | 'FAIL' | 'CONDITIONAL'
|
||||||
/** 检查备注 */
|
|
||||||
checkRemark?: string
|
checkRemark?: string
|
||||||
/** 入库位置 */
|
|
||||||
storageLocation: string
|
storageLocation: string
|
||||||
/** 库管员 */
|
|
||||||
storageManager: string
|
storageManager: string
|
||||||
|
|
||||||
|
// 设备基本信息(从采购数据继承)
|
||||||
|
equipmentName?: string
|
||||||
|
equipmentModel?: string
|
||||||
|
equipmentType?: string
|
||||||
|
equipmentSn?: string
|
||||||
|
brand?: string
|
||||||
|
specification?: string
|
||||||
|
assetCode?: string
|
||||||
|
|
||||||
|
// 采购信息(从采购数据继承)
|
||||||
|
purchaseOrder?: string
|
||||||
|
supplierName?: string
|
||||||
|
purchasePrice?: number
|
||||||
|
purchaseTime?: string
|
||||||
|
quantity?: number
|
||||||
|
unitPrice?: number
|
||||||
|
totalPrice?: number
|
||||||
|
|
||||||
|
// 入库信息
|
||||||
|
inStockTime?: string
|
||||||
|
physicalLocation?: string
|
||||||
|
locationStatus?: string
|
||||||
|
responsiblePerson?: string
|
||||||
|
inventoryBarcode?: string
|
||||||
|
|
||||||
|
// 状态信息
|
||||||
|
equipmentStatus?: string
|
||||||
|
useStatus?: string
|
||||||
|
healthStatus?: string
|
||||||
|
receiptStatus?: string
|
||||||
|
|
||||||
|
// 其他管理信息
|
||||||
|
depreciationMethod?: string
|
||||||
|
depreciationYears?: number
|
||||||
|
salvageValue?: number
|
||||||
|
currentNetValue?: number
|
||||||
|
|
||||||
|
// 系统字段
|
||||||
|
createTime?: string
|
||||||
|
updateTime?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
v-model="formData.receiptTime"
|
v-model="formData.receiptTime"
|
||||||
show-time
|
show-time
|
||||||
format="YYYY-MM-DD HH:mm:ss"
|
format="YYYY-MM-DD HH:mm:ss"
|
||||||
|
value-format="YYYY-MM-DD HH:mm:ss"
|
||||||
placeholder="请选择收货时间"
|
placeholder="请选择收货时间"
|
||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
/>
|
/>
|
||||||
|
@ -233,8 +234,9 @@ const emit = defineEmits<{
|
||||||
const formRef = ref<FormInstance>()
|
const formRef = ref<FormInstance>()
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|
||||||
// 表单数据
|
// 表单数据 - 使用正确的字段映射
|
||||||
const formData = reactive<ReceiptRequest>({
|
const formData = reactive<ReceiptRequest>({
|
||||||
|
// 收货特有信息
|
||||||
receiptTime: '',
|
receiptTime: '',
|
||||||
receiptPerson: '',
|
receiptPerson: '',
|
||||||
receiptQuantity: 1,
|
receiptQuantity: 1,
|
||||||
|
@ -247,6 +249,47 @@ const formData = reactive<ReceiptRequest>({
|
||||||
checkRemark: '',
|
checkRemark: '',
|
||||||
storageLocation: '',
|
storageLocation: '',
|
||||||
storageManager: '',
|
storageManager: '',
|
||||||
|
|
||||||
|
// 设备基本信息(从采购数据继承)
|
||||||
|
equipmentName: '',
|
||||||
|
equipmentModel: '',
|
||||||
|
equipmentType: '',
|
||||||
|
equipmentSn: '',
|
||||||
|
brand: '',
|
||||||
|
specification: '',
|
||||||
|
assetCode: '',
|
||||||
|
|
||||||
|
// 采购信息(从采购数据继承)
|
||||||
|
purchaseOrder: '',
|
||||||
|
supplierName: '',
|
||||||
|
purchasePrice: 0,
|
||||||
|
purchaseTime: '',
|
||||||
|
quantity: 1,
|
||||||
|
unitPrice: 0,
|
||||||
|
totalPrice: 0,
|
||||||
|
|
||||||
|
// 入库信息
|
||||||
|
inStockTime: '',
|
||||||
|
physicalLocation: '',
|
||||||
|
locationStatus: '',
|
||||||
|
responsiblePerson: '',
|
||||||
|
inventoryBarcode: '',
|
||||||
|
|
||||||
|
// 状态信息
|
||||||
|
equipmentStatus: '',
|
||||||
|
useStatus: '',
|
||||||
|
healthStatus: '',
|
||||||
|
receiptStatus: '',
|
||||||
|
|
||||||
|
// 其他管理信息
|
||||||
|
depreciationMethod: '',
|
||||||
|
depreciationYears: 5,
|
||||||
|
salvageValue: 0,
|
||||||
|
currentNetValue: 0,
|
||||||
|
|
||||||
|
// 系统字段
|
||||||
|
createTime: '',
|
||||||
|
updateTime: ''
|
||||||
})
|
})
|
||||||
|
|
||||||
// 表单验证规则
|
// 表单验证规则
|
||||||
|
@ -287,28 +330,46 @@ const rules = {
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 初始化表单数据
|
||||||
|
const initFormData = () => {
|
||||||
|
if (props.equipmentData) {
|
||||||
|
// 从设备数据中复制相关字段
|
||||||
|
Object.keys(formData).forEach((key) => {
|
||||||
|
const formKey = key as keyof ReceiptRequest
|
||||||
|
const equipmentKey = key as keyof EquipmentResp
|
||||||
|
if (formKey in formData && equipmentKey in props.equipmentData!) {
|
||||||
|
const value = props.equipmentData![equipmentKey]
|
||||||
|
if (value !== undefined) {
|
||||||
|
(formData[formKey] as any) = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 设置默认值
|
||||||
|
formData.receiptQuantity = props.equipmentData.quantity || 1
|
||||||
|
formData.storageLocation = props.equipmentData.physicalLocation || ''
|
||||||
|
formData.storageManager = props.equipmentData.responsiblePerson || ''
|
||||||
|
|
||||||
|
// 设置收货时间默认为当前时间
|
||||||
|
formData.receiptTime = formatDateTime(new Date())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 监听弹窗显示状态
|
// 监听弹窗显示状态
|
||||||
watch(() => props.visible, (visible) => {
|
watch(() => props.visible, (visible) => {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
// 重置表单
|
initFormData()
|
||||||
Object.assign(formData, {
|
|
||||||
receiptTime: '',
|
|
||||||
receiptPerson: '',
|
|
||||||
receiptQuantity: props.equipmentData?.quantity || 1,
|
|
||||||
receiptRemark: '',
|
|
||||||
appearanceCheck: '',
|
|
||||||
functionTest: '',
|
|
||||||
packageIntegrity: '',
|
|
||||||
accessoryIntegrity: '',
|
|
||||||
checkResult: 'PASS',
|
|
||||||
checkRemark: '',
|
|
||||||
storageLocation: '',
|
|
||||||
storageManager: '',
|
|
||||||
})
|
|
||||||
formRef.value?.clearValidate()
|
formRef.value?.clearValidate()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 监听设备数据变化
|
||||||
|
watch(() => props.equipmentData, () => {
|
||||||
|
if (props.visible && props.equipmentData) {
|
||||||
|
initFormData()
|
||||||
|
}
|
||||||
|
}, { deep: true })
|
||||||
|
|
||||||
// 提交表单
|
// 提交表单
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
try {
|
try {
|
||||||
|
@ -319,17 +380,77 @@ const handleSubmit = async () => {
|
||||||
throw new Error('设备ID不能为空')
|
throw new Error('设备ID不能为空')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 格式化时间
|
console.log('📦 开始提交收货数据...')
|
||||||
const receiptTime = formData.receiptTime ? new Date(formData.receiptTime).toISOString() : new Date().toISOString()
|
console.log('📦 设备数据:', props.equipmentData)
|
||||||
|
console.log('📦 表单数据:', formData)
|
||||||
const requestData: ReceiptRequest = {
|
|
||||||
...formData,
|
// 构建收货请求数据
|
||||||
receiptTime,
|
const receiptData: ReceiptRequest = {
|
||||||
|
// 收货特有信息
|
||||||
|
receiptTime: formData.receiptTime ? formatDateTime(formData.receiptTime) : formatDateTime(new Date()),
|
||||||
|
receiptPerson: formData.receiptPerson,
|
||||||
|
receiptQuantity: formData.receiptQuantity,
|
||||||
|
receiptRemark: formData.receiptRemark,
|
||||||
|
appearanceCheck: formData.appearanceCheck,
|
||||||
|
functionTest: formData.functionTest,
|
||||||
|
packageIntegrity: formData.packageIntegrity,
|
||||||
|
accessoryIntegrity: formData.accessoryIntegrity,
|
||||||
|
checkResult: formData.checkResult,
|
||||||
|
checkRemark: formData.checkRemark,
|
||||||
|
storageLocation: formData.storageLocation,
|
||||||
|
storageManager: formData.storageManager,
|
||||||
|
|
||||||
|
// 设备基本信息(从采购数据继承)
|
||||||
|
equipmentName: props.equipmentData.equipmentName,
|
||||||
|
equipmentModel: props.equipmentData.equipmentModel,
|
||||||
|
equipmentType: props.equipmentData.equipmentType,
|
||||||
|
equipmentSn: props.equipmentData.equipmentSn,
|
||||||
|
brand: props.equipmentData.brand,
|
||||||
|
specification: props.equipmentData.specification,
|
||||||
|
assetCode: props.equipmentData.assetCode,
|
||||||
|
|
||||||
|
// 采购信息(从采购数据继承)
|
||||||
|
purchaseOrder: props.equipmentData.purchaseOrder,
|
||||||
|
supplierName: props.equipmentData.supplierName,
|
||||||
|
purchasePrice: props.equipmentData.purchasePrice,
|
||||||
|
purchaseTime: props.equipmentData.purchaseTime,
|
||||||
|
quantity: props.equipmentData.quantity,
|
||||||
|
unitPrice: props.equipmentData.unitPrice,
|
||||||
|
totalPrice: props.equipmentData.totalPrice,
|
||||||
|
|
||||||
|
// 入库信息
|
||||||
|
inStockTime: formData.receiptTime ? formatDateTime(formData.receiptTime) : formatDateTime(new Date()),
|
||||||
|
physicalLocation: formData.storageLocation,
|
||||||
|
locationStatus: 'in_stock',
|
||||||
|
responsiblePerson: formData.storageManager,
|
||||||
|
inventoryBarcode: props.equipmentData.inventoryBarcode || generateInventoryBarcode(),
|
||||||
|
|
||||||
|
// 状态信息
|
||||||
|
equipmentStatus: 'normal',
|
||||||
|
useStatus: '0',
|
||||||
|
healthStatus: 'good',
|
||||||
|
receiptStatus: 'RECEIVED',
|
||||||
|
|
||||||
|
// 其他管理信息
|
||||||
|
depreciationMethod: props.equipmentData.depreciationMethod || 'straight_line',
|
||||||
|
depreciationYears: props.equipmentData.depreciationYears || 5,
|
||||||
|
salvageValue: props.equipmentData.salvageValue || 0,
|
||||||
|
currentNetValue: props.equipmentData.purchasePrice || 0,
|
||||||
|
|
||||||
|
// 系统字段
|
||||||
|
createTime: formatDateTime(new Date()),
|
||||||
|
updateTime: formatDateTime(new Date())
|
||||||
}
|
}
|
||||||
|
|
||||||
await equipmentProcurementApi.receiveGoods(props.equipmentData.equipmentId, requestData)
|
console.log('📦 构建的收货数据:', receiptData)
|
||||||
|
|
||||||
|
// 调用收货API
|
||||||
|
await equipmentProcurementApi.receiveGoods(
|
||||||
|
props.equipmentData.equipmentId,
|
||||||
|
receiptData
|
||||||
|
)
|
||||||
|
|
||||||
Message.success('收货成功')
|
Message.success('收货成功,设备已自动入库')
|
||||||
emit('success')
|
emit('success')
|
||||||
emit('update:visible', false)
|
emit('update:visible', false)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
@ -340,6 +461,26 @@ const handleSubmit = async () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 生成库存条码的辅助函数
|
||||||
|
const generateInventoryBarcode = () => {
|
||||||
|
const timestamp = Date.now().toString(36)
|
||||||
|
const random = Math.random().toString(36).substr(2, 5)
|
||||||
|
return `INV-${timestamp}-${random}`.toUpperCase()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化日期时间
|
||||||
|
const formatDateTime = (date: string | Date) => {
|
||||||
|
const d = new Date(date);
|
||||||
|
let month = '' + (d.getMonth() + 1);
|
||||||
|
let day = '' + d.getDate();
|
||||||
|
const year = d.getFullYear();
|
||||||
|
if (month.length < 2)
|
||||||
|
month = '0' + month;
|
||||||
|
if (day.length < 2)
|
||||||
|
day = '0' + day;
|
||||||
|
return [year, month, day].join('-') + ' ' + [d.getHours(), d.getMinutes(), d.getSeconds()].join(':');
|
||||||
|
}
|
||||||
|
|
||||||
// 取消
|
// 取消
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
emit('update:visible', false)
|
emit('update:visible', false)
|
||||||
|
|
Loading…
Reference in New Issue