feat(stocking): useStockingForm 支持车辆明细附件上传
ItemRow 增加 attachment_files,mappedItems 映射 attachment, 新增车辆附件上传/删除方法并暴露。 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -67,6 +67,7 @@ export interface ItemRow {
|
|||||||
fob_transport_fee: number | undefined
|
fob_transport_fee: number | undefined
|
||||||
port_misc_fee: string
|
port_misc_fee: string
|
||||||
remark: string
|
remark: string
|
||||||
|
attachment_files?: { name: string; url: string; file_name: string }[]
|
||||||
ocean_freight: string
|
ocean_freight: string
|
||||||
ocean_freight_currency: string
|
ocean_freight_currency: string
|
||||||
ocean_freight_currency_snapshot: string
|
ocean_freight_currency_snapshot: string
|
||||||
@@ -235,6 +236,7 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
|
|||||||
fob_transport_fee: undefined,
|
fob_transport_fee: undefined,
|
||||||
port_misc_fee: '',
|
port_misc_fee: '',
|
||||||
remark: '',
|
remark: '',
|
||||||
|
attachment_files: [],
|
||||||
ocean_freight: '',
|
ocean_freight: '',
|
||||||
ocean_freight_currency: 'CNY',
|
ocean_freight_currency: 'CNY',
|
||||||
ocean_freight_currency_snapshot: '人民币',
|
ocean_freight_currency_snapshot: '人民币',
|
||||||
@@ -705,6 +707,48 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 车辆明细附件上传
|
||||||
|
const itemUploadAction = `${import.meta.env.VITE_API_URL}/ticket/upload?scene=stock_orders`
|
||||||
|
|
||||||
|
const beforeItemAttachmentUpload = (file: File) => {
|
||||||
|
const isValidType = /\.(jpg|jpeg|png|gif|pdf|doc|docx|xls|xlsx|txt)$/i.test(file.name)
|
||||||
|
if (!isValidType) {
|
||||||
|
ElMessage.error('只能上传图片或文档文件!')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
const isLt10M = file.size / 1024 / 1024 < 10
|
||||||
|
if (!isLt10M) {
|
||||||
|
ElMessage.error('文件大小不能超过 10MB!')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleItemAttachmentUpload = (response: any, idx: number) => {
|
||||||
|
if (response.code === 200) {
|
||||||
|
const fileInfo = {
|
||||||
|
name: response.data.original_name || '附件',
|
||||||
|
url: response.data.file_url,
|
||||||
|
file_name: response.data.file_name
|
||||||
|
}
|
||||||
|
if (!items.value[idx].attachment_files) {
|
||||||
|
items.value[idx].attachment_files = []
|
||||||
|
}
|
||||||
|
items.value[idx].attachment_files!.push(fileInfo)
|
||||||
|
ElMessage.success('附件上传成功!')
|
||||||
|
} else {
|
||||||
|
ElMessage.error(response.message || '附件上传失败!')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const removeItemAttachment = (idx: number, fileIdx: number) => {
|
||||||
|
const list = items.value[idx].attachment_files
|
||||||
|
if (list) {
|
||||||
|
list.splice(fileIdx, 1)
|
||||||
|
ElMessage.success('附件已删除')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const removeContractFile = (index: number) => {
|
const removeContractFile = (index: number) => {
|
||||||
contractFiles.value.splice(index, 1)
|
contractFiles.value.splice(index, 1)
|
||||||
// 更新合同字段为文件名数组
|
// 更新合同字段为文件名数组
|
||||||
@@ -977,6 +1021,11 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
|
|||||||
_echo_vin: Boolean(it.vin),
|
_echo_vin: Boolean(it.vin),
|
||||||
mileage: it.mileage ?? 0,
|
mileage: it.mileage ?? 0,
|
||||||
model_snapshot: it.model_snapshot || '',
|
model_snapshot: it.model_snapshot || '',
|
||||||
|
attachment_files: (it.attachment || []).map((f: any) => ({
|
||||||
|
name: f.original_name || f.name || '附件',
|
||||||
|
url: f.url || f.file_url || '',
|
||||||
|
file_name: f.file_name || f.url || ''
|
||||||
|
})),
|
||||||
listing_price: it.listing_price?.amount ? Number(it.listing_price.amount) : undefined,
|
listing_price: it.listing_price?.amount ? Number(it.listing_price.amount) : undefined,
|
||||||
listing_price_currency: it.listing_price?.currency || 'CNY',
|
listing_price_currency: it.listing_price?.currency || 'CNY',
|
||||||
listing_price_currency_snapshot: '',
|
listing_price_currency_snapshot: '',
|
||||||
@@ -1231,7 +1280,11 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
|
|||||||
),
|
),
|
||||||
retention_price: wrapMoney(it.retention_price, (it as any).retention_price_currency, '挂账'),
|
retention_price: wrapMoney(it.retention_price, (it as any).retention_price_currency, '挂账'),
|
||||||
car_price: wrapMoney(it.car_price, (it as any).car_price_currency, '车价'),
|
car_price: wrapMoney(it.car_price, (it as any).car_price_currency, '车价'),
|
||||||
increase_price: wrapMoney(it.increase_price, (it as any).increase_price_currency, '加价')
|
increase_price: wrapMoney(it.increase_price, (it as any).increase_price_currency, '加价'),
|
||||||
|
attachment: (it.attachment_files || []).map((f) => ({
|
||||||
|
url: f.url,
|
||||||
|
original_name: f.name
|
||||||
|
}))
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// 从提交参数中移除 settlement_currency
|
// 从提交参数中移除 settlement_currency
|
||||||
@@ -1540,6 +1593,10 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
|
|||||||
// 上传相关
|
// 上传相关
|
||||||
actionImageUplode,
|
actionImageUplode,
|
||||||
uploadHeaders,
|
uploadHeaders,
|
||||||
|
itemUploadAction,
|
||||||
|
beforeItemAttachmentUpload,
|
||||||
|
handleItemAttachmentUpload,
|
||||||
|
removeItemAttachment,
|
||||||
|
|
||||||
// 方法
|
// 方法
|
||||||
initializeForm,
|
initializeForm,
|
||||||
|
|||||||
Reference in New Issue
Block a user