完善收货状态随着流程变化,确保在采购审批后通过后才出现收货状态,添加支付状态和收获状态字段
This commit is contained in:
parent
f3fa274e18
commit
2feea5fd8f
|
@ -457,6 +457,7 @@ export interface ReceiptRequest {
|
|||
useStatus?: string
|
||||
healthStatus?: string
|
||||
receiptStatus?: string
|
||||
paymentStatus?: string
|
||||
|
||||
// 其他管理信息
|
||||
depreciationMethod?: string
|
||||
|
|
|
@ -87,11 +87,15 @@
|
|||
<a-form-item label="序列号" field="equipmentSn">
|
||||
<a-input
|
||||
v-model="formData.equipmentSn"
|
||||
placeholder="请输入序列号"
|
||||
:disabled="isView"
|
||||
placeholder="选择设备类型后自动生成"
|
||||
:disabled="true"
|
||||
show-word-limit
|
||||
:max-length="100"
|
||||
/>
|
||||
<div class="field-tip">
|
||||
<IconInfoCircle style="color: #1890ff; margin-right: 4px;" />
|
||||
选择设备类型后自动生成,格式:设备类型+顺序号+日期
|
||||
</div>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
</a-row>
|
||||
|
@ -528,6 +532,7 @@ import { Message } from '@arco-design/web-vue'
|
|||
import type { FormInstance } from '@arco-design/web-vue'
|
||||
import { equipmentProcurementApi } from '@/apis/equipment/procurement'
|
||||
import type { EquipmentResp, EquipmentReq } from '@/apis/equipment/type'
|
||||
import { IconInfoCircle } from '@arco-design/web-vue/es/icon'
|
||||
|
||||
interface Props {
|
||||
visible: boolean
|
||||
|
@ -692,6 +697,40 @@ watch([() => formData.unitPrice, () => formData.quantity], ([newUnitPrice, newQu
|
|||
}
|
||||
})
|
||||
|
||||
// 生成设备序列号
|
||||
const generateEquipmentSn = (equipmentType: string) => {
|
||||
// 获取当前时间戳作为顺序号
|
||||
const timestamp = Date.now()
|
||||
const orderNumber = timestamp.toString().slice(-6) // 取后6位作为顺序号
|
||||
|
||||
// 获取设备类型简称
|
||||
const typeMap: Record<string, string> = {
|
||||
'detection': 'DET',
|
||||
'security': 'SEC',
|
||||
'office': 'OFF',
|
||||
'car': 'CAR',
|
||||
'other': 'OTH'
|
||||
}
|
||||
const typeCode = typeMap[equipmentType] || 'OTH'
|
||||
|
||||
// 格式化当前时间(年月日)
|
||||
const now = new Date()
|
||||
const dateStr = now.getFullYear().toString().slice(-2) +
|
||||
(now.getMonth() + 1).toString().padStart(2, '0') +
|
||||
now.getDate().toString().padStart(2, '0')
|
||||
|
||||
// 生成序列号:设备类型+顺序号+当前时间
|
||||
return `${typeCode}${orderNumber}${dateStr}`
|
||||
}
|
||||
|
||||
// 监听设备类型变化,自动生成序列号
|
||||
watch(() => formData.equipmentType, (newType) => {
|
||||
if (newType && !formData.equipmentSn) {
|
||||
// 只有在序列号为空时才自动生成
|
||||
formData.equipmentSn = generateEquipmentSn(newType)
|
||||
}
|
||||
})
|
||||
|
||||
// 初始化表单数据
|
||||
const initFormData = () => {
|
||||
if (props.procurementData) {
|
||||
|
@ -841,7 +880,7 @@ const fillTestData = () => {
|
|||
const nextMaintenanceTime = nextMaintenanceDate.toISOString().slice(0, 19).replace('T', ' ')
|
||||
|
||||
// 生成随机序列号
|
||||
const randomSn = 'SN' + Math.random().toString(36).substr(2, 8).toUpperCase()
|
||||
const randomSn = generateEquipmentSn('detection')
|
||||
|
||||
// 生成随机资产编号
|
||||
const randomAssetCode = 'ZC' + Math.random().toString(36).substr(2, 6).toUpperCase()
|
||||
|
@ -949,6 +988,15 @@ const handleCancel = () => {
|
|||
color: var(--color-text-1);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.field-tip {
|
||||
margin-top: 4px;
|
||||
font-size: 12px;
|
||||
color: var(--color-text-3);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
|
||||
.arco-input,
|
||||
|
|
|
@ -27,9 +27,15 @@
|
|||
<a-descriptions-item label="设备型号">
|
||||
{{ equipmentData?.equipmentModel || '-' }}
|
||||
</a-descriptions-item>
|
||||
<a-descriptions-item label="设备序列号">
|
||||
{{ equipmentData?.equipmentSn || '-' }}
|
||||
</a-descriptions-item>
|
||||
<a-descriptions-item label="品牌">
|
||||
{{ equipmentData?.brand || '-' }}
|
||||
</a-descriptions-item>
|
||||
<a-descriptions-item label="配置规格">
|
||||
{{ equipmentData?.specification || '-' }}
|
||||
</a-descriptions-item>
|
||||
<a-descriptions-item label="供应商">
|
||||
{{ equipmentData?.supplierName || '-' }}
|
||||
</a-descriptions-item>
|
||||
|
@ -370,6 +376,32 @@ watch(() => props.equipmentData, () => {
|
|||
}
|
||||
}, { deep: true })
|
||||
|
||||
// 生成设备序列号
|
||||
const generateEquipmentSn = (equipmentType: string, inStockTime: string) => {
|
||||
// 获取当前时间戳作为顺序号
|
||||
const timestamp = Date.now()
|
||||
const orderNumber = timestamp.toString().slice(-6) // 取后6位作为顺序号
|
||||
|
||||
// 获取设备类型简称
|
||||
const typeMap: Record<string, string> = {
|
||||
'detection': 'DET',
|
||||
'security': 'SEC',
|
||||
'office': 'OFF',
|
||||
'car': 'CAR',
|
||||
'other': 'OTH'
|
||||
}
|
||||
const typeCode = typeMap[equipmentType] || 'OTH'
|
||||
|
||||
// 格式化入库时间(年月日)
|
||||
const date = new Date(inStockTime)
|
||||
const dateStr = date.getFullYear().toString().slice(-2) +
|
||||
(date.getMonth() + 1).toString().padStart(2, '0') +
|
||||
date.getDate().toString().padStart(2, '0')
|
||||
|
||||
// 生成序列号:设备类型+顺序号+入库时间
|
||||
return `${typeCode}${orderNumber}${dateStr}`
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
|
@ -380,13 +412,37 @@ const handleSubmit = async () => {
|
|||
throw new Error('设备ID不能为空')
|
||||
}
|
||||
|
||||
console.log('📦 开始提交收货数据...')
|
||||
console.log('📦 设备数据:', props.equipmentData)
|
||||
console.log('📦 表单数据:', formData)
|
||||
// 1. 获取采购阶段的设备信息
|
||||
const procurementData = props.equipmentData
|
||||
|
||||
// 构建收货请求数据
|
||||
const receiptData: ReceiptRequest = {
|
||||
// 收货特有信息
|
||||
// 2. 生成设备序列号
|
||||
const equipmentSn = generateEquipmentSn(
|
||||
procurementData.equipmentType || 'other',
|
||||
formData.receiptTime || new Date().toISOString()
|
||||
)
|
||||
|
||||
// 3. 合并收货信息和设备信息
|
||||
const equipmentData = {
|
||||
// 采购阶段的数据(已有)
|
||||
equipmentId: procurementData.equipmentId,
|
||||
equipmentName: procurementData.equipmentName,
|
||||
equipmentModel: procurementData.equipmentModel,
|
||||
equipmentType: procurementData.equipmentType,
|
||||
equipmentSn: equipmentSn, // 使用生成的序列号
|
||||
brand: procurementData.brand,
|
||||
specification: procurementData.specification,
|
||||
assetCode: procurementData.assetCode,
|
||||
|
||||
// 采购信息(已有)
|
||||
purchaseOrder: procurementData.purchaseOrder,
|
||||
supplierName: procurementData.supplierName,
|
||||
purchasePrice: procurementData.purchasePrice,
|
||||
purchaseTime: procurementData.purchaseTime,
|
||||
quantity: procurementData.quantity,
|
||||
unitPrice: procurementData.unitPrice,
|
||||
totalPrice: procurementData.totalPrice,
|
||||
|
||||
// 收货相关信息
|
||||
receiptTime: formData.receiptTime ? formatDateTime(formData.receiptTime) : formatDateTime(new Date()),
|
||||
receiptPerson: formData.receiptPerson,
|
||||
receiptQuantity: formData.receiptQuantity,
|
||||
|
@ -400,62 +456,31 @@ const handleSubmit = async () => {
|
|||
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())
|
||||
useStatus: '0', // 空闲中
|
||||
locationStatus: 'in_stock', // 库存中
|
||||
healthStatus: 'excellent',
|
||||
responsiblePerson: formData.storageManager,
|
||||
physicalLocation: formData.storageLocation,
|
||||
inStockTime: formData.receiptTime ? formatDateTime(formData.receiptTime) : formatDateTime(new Date()),
|
||||
inventoryBarcode: `BC${Date.now()}${Math.random().toString(36).substr(2, 4).toUpperCase()}`,
|
||||
depreciationMethod: 'straight_line',
|
||||
warrantyExpireDate: procurementData.warrantyExpireDate,
|
||||
assetRemark: `设备已收货入库,收货人:${formData.receiptPerson},入库时间:${formData.receiptTime}`
|
||||
}
|
||||
|
||||
console.log('📦 构建的收货数据:', receiptData)
|
||||
console.log('📦 准备提交收货数据:', equipmentData)
|
||||
|
||||
// 调用收货API
|
||||
await equipmentProcurementApi.receiveGoods(
|
||||
props.equipmentData.equipmentId,
|
||||
receiptData
|
||||
)
|
||||
// 4. 调用收货API
|
||||
await equipmentProcurementApi.receiveGoods(procurementData.equipmentId, equipmentData)
|
||||
|
||||
Message.success('收货成功,设备已自动入库')
|
||||
Message.success('收货成功!设备已自动入库')
|
||||
emit('success')
|
||||
emit('update:visible', false)
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('收货失败:', error)
|
||||
Message.error(error?.message || '收货失败,请检查表单信息')
|
||||
Message.error(error?.message || '收货失败,请重试')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
|
|
|
@ -244,6 +244,18 @@
|
|||
>
|
||||
查看支付详情
|
||||
</a-button>
|
||||
<!-- 手动刷新按钮 - 用于调试状态更新 -->
|
||||
<a-button
|
||||
type="text"
|
||||
size="small"
|
||||
@click="handleRefreshRecord(record)"
|
||||
title="刷新此条记录状态"
|
||||
>
|
||||
<template #icon>
|
||||
<IconRefresh />
|
||||
</template>
|
||||
刷新
|
||||
</a-button>
|
||||
<!-- 显示采购状态 - 优先显示采购状态 -->
|
||||
<a-tag
|
||||
v-if="record.procurementStatus && record.procurementStatus !== 'NOT_STARTED'"
|
||||
|
@ -936,13 +948,42 @@ const handleModalSuccess = () => {
|
|||
// 采购申请成功回调
|
||||
const handleApplicationSuccess = async () => {
|
||||
applicationModalVisible.value = false
|
||||
console.log('采购申请成功,准备刷新数据...')
|
||||
// 延迟刷新数据,确保后端状态更新完成
|
||||
setTimeout(async () => {
|
||||
console.log('开始刷新数据...')
|
||||
await loadData(currentSearchParams.value)
|
||||
console.log('✅ 采购申请成功,准备更新本地数据...')
|
||||
|
||||
// 立即更新本地数据,让申请采购按钮消失
|
||||
if (currentApplicationData.value) {
|
||||
const equipmentId = currentApplicationData.value.equipmentId
|
||||
|
||||
// 找到对应的记录并更新采购状态
|
||||
const recordIndex = tableData.value.findIndex(item => item.equipmentId === equipmentId)
|
||||
if (recordIndex !== -1) {
|
||||
// 立即更新本地状态为待审批
|
||||
tableData.value[recordIndex] = {
|
||||
...tableData.value[recordIndex],
|
||||
procurementStatus: 'PENDING_APPROVAL'
|
||||
}
|
||||
|
||||
console.log('✅ 本地数据已更新,申请采购按钮应该消失')
|
||||
console.log('🔍 更新后的记录:', tableData.value[recordIndex])
|
||||
|
||||
message.success('采购申请已提交,请等待审批')
|
||||
}, 1000)
|
||||
} else {
|
||||
console.warn('⚠️ 未找到对应的记录,无法更新本地状态')
|
||||
message.warning('状态更新失败,请手动刷新页面')
|
||||
}
|
||||
}
|
||||
|
||||
// 可选:延迟刷新数据以确保后端状态同步
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
console.log('🔄 延迟刷新数据,确保后端状态同步...')
|
||||
await loadData(currentSearchParams.value)
|
||||
console.log('✅ 后端数据同步完成')
|
||||
} catch (error) {
|
||||
console.error('❌ 后端数据同步失败:', error)
|
||||
// 不显示错误提示,因为本地状态已经更新
|
||||
}
|
||||
}, 1000) // 1秒后刷新
|
||||
}
|
||||
|
||||
// 刷新数据
|
||||
|
@ -993,17 +1034,37 @@ const getTotalAmount = () => {
|
|||
// 检查是否可以申请采购
|
||||
const canApplyProcurement = (record: EquipmentResp) => {
|
||||
// 根据采购状态判断是否可以申请采购
|
||||
// 只有未开始、已拒绝、已完成的设备可以重新申请采购
|
||||
const allowedStatuses = ['NOT_STARTED', 'REJECTED', 'COMPLETED', null, undefined]
|
||||
// 只有未开始、已拒绝的设备可以申请采购
|
||||
// 待审批、已通过、已完成等状态不能重复申请
|
||||
const allowedStatuses = ['NOT_STARTED', 'REJECTED', null, undefined]
|
||||
const canApply = allowedStatuses.includes(record.procurementStatus)
|
||||
console.log(`设备 ${record.equipmentName} 采购状态: ${record.procurementStatus}, 可申请: ${canApply}`)
|
||||
|
||||
// 添加详细的调试日志
|
||||
console.log(`🔍 申请采购按钮显示检查 - 设备: ${record.equipmentName}`)
|
||||
console.log(`🔍 当前采购状态: ${record.procurementStatus}`)
|
||||
console.log(`🔍 允许申请的状态: ${allowedStatuses.join(', ')}`)
|
||||
console.log(`🔍 是否显示按钮: ${canApply}`)
|
||||
console.log(`🔍 完整记录:`, record)
|
||||
|
||||
return canApply
|
||||
}
|
||||
|
||||
// 检查是否可以收货
|
||||
const canReceiveGoods = (record: EquipmentResp) => {
|
||||
const receiptStatus = (record as any).receiptStatus
|
||||
return receiptStatus === 'NOT_RECEIVED' || receiptStatus === 'PARTIALLY_RECEIVED'
|
||||
// 只有在采购状态为已通过且收货状态为未收货时才显示确认收货按钮
|
||||
const procurementStatus = record.procurementStatus
|
||||
const receiptStatus = record.receiptStatus
|
||||
|
||||
console.log('🔍 canReceiveGoods 检查:', {
|
||||
equipmentName: record.equipmentName,
|
||||
procurementStatus,
|
||||
receiptStatus,
|
||||
canReceive: procurementStatus === 'APPROVED' &&
|
||||
(receiptStatus === 'NOT_RECEIVED' || receiptStatus === 'PARTIALLY_RECEIVED')
|
||||
})
|
||||
|
||||
return procurementStatus === 'APPROVED' &&
|
||||
(receiptStatus === 'NOT_RECEIVED' || receiptStatus === 'PARTIALLY_RECEIVED')
|
||||
}
|
||||
|
||||
// 收货操作
|
||||
|
@ -1021,7 +1082,10 @@ const handleViewReceipt = (record: EquipmentResp) => {
|
|||
// 收货成功回调
|
||||
const handleReceiptSuccess = () => {
|
||||
receiptModalVisible.value = false
|
||||
// 收货成功后,采购状态应该更新为已收货
|
||||
// 重新加载数据以显示最新状态
|
||||
loadData(currentSearchParams.value)
|
||||
message.success('收货成功!设备已自动入库')
|
||||
}
|
||||
|
||||
// 检查是否可以付款
|
||||
|
@ -1072,6 +1136,30 @@ const getApprovalStatusText = (status: string) => {
|
|||
return textMap[status] || '未知'
|
||||
}
|
||||
|
||||
// 手动刷新单条记录
|
||||
const handleRefreshRecord = async (record: EquipmentResp) => {
|
||||
console.log('🔄 手动刷新记录:', record.equipmentId)
|
||||
try {
|
||||
// 显示加载提示
|
||||
const loadingMessage = message.loading('正在刷新数据...')
|
||||
|
||||
// 重新加载整个表格数据,确保获取最新状态
|
||||
await loadData(currentSearchParams.value)
|
||||
|
||||
// 清除加载提示
|
||||
if (loadingMessage && typeof loadingMessage.close === 'function') {
|
||||
loadingMessage.close()
|
||||
}
|
||||
message.success('记录状态已刷新')
|
||||
|
||||
console.log('✅ 表格数据刷新完成')
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('❌ 刷新失败:', error)
|
||||
message.error(error?.message || '刷新失败')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadData()
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue