对于采购件的内容进行修改,使其填写更加便利加上库位自动加载上一次的逻辑
This commit is contained in:
@ -98,6 +98,13 @@
|
||||
</el-tag>
|
||||
</template>
|
||||
|
||||
<template #default="scope" v-else-if="col.prop === 'qty_stock'">
|
||||
<span class="stock-num">{{ scope.row.qty_stock }}</span>
|
||||
</template>
|
||||
<template #default="scope" v-else-if="col.prop === 'qty_available'">
|
||||
<span class="avail-num">{{ scope.row.qty_available }}</span>
|
||||
</template>
|
||||
|
||||
<template #default="scope" v-else-if="['arrival_photo', 'inspection_report'].includes(col.prop)">
|
||||
<div v-if="getImagesOnly(scope.row[col.prop]).length > 0" style="display: flex; align-items: center; justify-content: center;">
|
||||
<el-image
|
||||
@ -245,7 +252,18 @@
|
||||
<el-form-item label="条码" prop="barcode"><el-input v-model="form.barcode" placeholder="扫描条码"/></el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="库位" prop="warehouse_location"><el-input v-model="form.warehouse_location" placeholder="例如: A-01-02"/></el-form-item>
|
||||
<el-form-item label="库位" prop="warehouse_location">
|
||||
<el-autocomplete
|
||||
v-model="form.warehouse_location"
|
||||
:fetch-suggestions="querySearchLocation"
|
||||
placeholder="例如: A-01-02"
|
||||
style="width: 100%"
|
||||
clearable
|
||||
:trigger-on-focus="true"
|
||||
>
|
||||
<template #default="{ item }"><div style="font-weight: 500">{{ item.value }}</div></template>
|
||||
</el-autocomplete>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
@ -487,7 +505,8 @@ import {
|
||||
deleteFile,
|
||||
getSupplierSuggestions,
|
||||
getUserSuggestions,
|
||||
getLinkSuggestions
|
||||
getLinkSuggestions,
|
||||
getLocationSuggestions
|
||||
} from '@/api/inbound/buy'
|
||||
import {getLabelPreview, executePrint} from '@/api/common/print'
|
||||
import WebRtcCamera from '@/components/Camera/WebRtcCamera.vue'
|
||||
@ -617,7 +636,6 @@ const fetchUserSuggestions = async (query: string, cb: any) => {
|
||||
try {
|
||||
const res: any = await getUserSuggestions({ keyword: query })
|
||||
if (res.code === 200) {
|
||||
// res.data = [{value: '张三', email: 'xx@xx.com'}]
|
||||
cb(res.data)
|
||||
} else {
|
||||
cb([])
|
||||
@ -629,7 +647,6 @@ const fetchUserSuggestions = async (query: string, cb: any) => {
|
||||
const querySearchPurchaser = (qs: string, cb: any) => fetchUserSuggestions(qs, cb)
|
||||
const handlePurchaserSelect = (item: any) => {
|
||||
form.purchaser = item.value
|
||||
// 自动填充邮箱
|
||||
if (item.email) {
|
||||
form.purchaser_email = item.email
|
||||
}
|
||||
@ -649,7 +666,22 @@ const fetchLinkSuggestions = async (query: string, cb: any, type: 'original' | '
|
||||
}
|
||||
const querySearchLinks = (qs: string, cb: any, type: 'original' | 'detail') => fetchLinkSuggestions(qs, cb, type)
|
||||
|
||||
// 4. 币种
|
||||
// 4. [新增] 库位建议 (基于 base_id)
|
||||
const fetchLocationSuggestions = async (query: string, cb: any) => {
|
||||
if (!form.base_id) { cb([]); return }
|
||||
try {
|
||||
const res: any = await getLocationSuggestions({ base_id: form.base_id })
|
||||
if (res.code === 200) {
|
||||
const locs = res.data.map((loc: string) => ({ value: loc }))
|
||||
const filtered = query ? locs.filter((item:any) => item.value.toLowerCase().includes(query.toLowerCase())) : locs
|
||||
cb(filtered)
|
||||
} else { cb([]) }
|
||||
} catch(e) { cb([]) }
|
||||
}
|
||||
const querySearchLocation = (qs: string, cb: any) => fetchLocationSuggestions(qs, cb)
|
||||
|
||||
|
||||
// 5. 币种
|
||||
const currencyOptions = [{value: 'CNY', desc: '人民币'}, {value: 'USD', desc: '美元'}, {value: 'EUR', desc: '欧元'}]
|
||||
const querySearchCurrency = (queryString: string, cb: any) => {
|
||||
const filtered = queryString ? currencyOptions.filter(item => item.value.toLowerCase().includes(queryString.toLowerCase()) || item.desc.toLowerCase().includes(queryString.toLowerCase())) : currencyOptions
|
||||
@ -787,7 +819,7 @@ const handleUpdate = (row: any) => {
|
||||
source_link: row.source_link, detail_link: row.detail_link,
|
||||
arrival_photo: row.arrival_photo || [], inspection_report: row.inspection_report || []
|
||||
})
|
||||
// 回显图片,补全路径
|
||||
// 回显图片
|
||||
arrivalFileList.value = form.arrival_photo.map(url => ({ name: url.split('/').pop(), url: getImageUrl(url) }))
|
||||
const reports = form.inspection_report || []
|
||||
const reportImgs = reports.filter(r => !isExternalLink(r))
|
||||
@ -834,18 +866,15 @@ const submitForm = async () => {
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// 图片/文件处理 (核心修复)
|
||||
// 图片/文件处理
|
||||
// ------------------------------------
|
||||
|
||||
// 1. 路径补全
|
||||
const getImageUrl = (url: string) => {
|
||||
if (!url) return ''
|
||||
if (url.startsWith('http') || url.startsWith('https') || url.startsWith('blob:')) {
|
||||
return url
|
||||
}
|
||||
// 获取 VITE_APP_BASE_API,如果未设置则默认为空
|
||||
const apiBase = import.meta.env.VITE_APP_BASE_API || ''
|
||||
// 去除末尾斜杠
|
||||
const baseUrl = apiBase.endsWith('/') ? apiBase.slice(0, -1) : apiBase
|
||||
const path = url.startsWith('/') ? url : '/' + url
|
||||
return baseUrl + path
|
||||
@ -861,7 +890,6 @@ const beforeAvatarUpload = (rawFile: any) => {
|
||||
return true
|
||||
}
|
||||
|
||||
// 2. 自定义上传 (修复回显)
|
||||
const customUpload = async (options: any, targetField: 'arrival_photo' | 'inspection_report') => {
|
||||
const { file, onSuccess, onError } = options
|
||||
const formData = new FormData()
|
||||
@ -869,12 +897,9 @@ const customUpload = async (options: any, targetField: 'arrival_photo' | 'inspec
|
||||
try {
|
||||
const res: any = await uploadFile(formData)
|
||||
if (res.code === 200) {
|
||||
const newUrl = res.data.url // 后端返回的相对路径
|
||||
|
||||
// 1. 存入表单数据 (相对路径)
|
||||
const newUrl = res.data.url
|
||||
form[targetField].push(newUrl)
|
||||
|
||||
// 2. 显式更新 fileList (完整路径,用于显示)
|
||||
const fullUrl = getImageUrl(newUrl)
|
||||
const fileObj = { name: file.name, url: fullUrl, status: 'success', uid: file.uid }
|
||||
|
||||
@ -887,7 +912,6 @@ const customUpload = async (options: any, targetField: 'arrival_photo' | 'inspec
|
||||
if (idx > -1) reportFileList.value[idx] = fileObj
|
||||
else reportFileList.value.push(fileObj)
|
||||
}
|
||||
|
||||
ElMessage.success('上传成功')
|
||||
onSuccess(res)
|
||||
} else {
|
||||
@ -903,7 +927,6 @@ const customUpload = async (options: any, targetField: 'arrival_photo' | 'inspec
|
||||
const handleRemoveImage = async (uploadFile: any, targetField: 'arrival_photo' | 'inspection_report') => {
|
||||
try {
|
||||
const filename = uploadFile.url.split('/').pop()
|
||||
// 尝试匹配完整路径或文件名
|
||||
const urlToRemove = form[targetField].find(u => u.endsWith(filename)) || uploadFile.url
|
||||
|
||||
form[targetField] = form[targetField].filter(u => u !== urlToRemove)
|
||||
@ -938,18 +961,13 @@ const handleCameraConfirm = async (file: File) => {
|
||||
if (res.code === 200) {
|
||||
const newUrl = res.data.url
|
||||
const field = currentCameraField.value
|
||||
|
||||
// 更新表单
|
||||
form[field].push(newUrl)
|
||||
|
||||
// 更新文件列表 (完整路径)
|
||||
const fileObj = { name: file.name, url: getImageUrl(newUrl) }
|
||||
if (field === 'arrival_photo') {
|
||||
arrivalFileList.value.push(fileObj)
|
||||
} else if (field === 'inspection_report') {
|
||||
reportFileList.value.push(fileObj)
|
||||
}
|
||||
|
||||
ElMessage.success('拍照上传成功')
|
||||
cameraDialogVisible.value = false
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user