Commit 5df48561 by linjinhong

fix:【工厂端】【仓库-入库单】:保存入库单生成三个一样的数据,作废重复数据提示报错#1001087

parent 2c407920
......@@ -308,7 +308,11 @@
</div>
</template>
<template #bottom>
<el-tabs v-loading="showDetailLoading" v-model="tabsValue" @tab-click="tabsClick">
<el-tabs
v-loading="showDetailLoading"
v-model="tabsValue"
@tab-click="tabsClick"
>
<el-tab-pane name="0" label="入库商品">
<div class="table-wrap">
<ElTable size="small" :data="detailList" height="100%" border>
......@@ -341,7 +345,6 @@
width="180"
prop="warehouseSku"
>
</ElTableColumn>
<ElTableColumn
......@@ -467,8 +470,13 @@
<div class="import-dialog">
<div class="label" style="margin-bottom: 10px">
<span style="margin-right: 10px">所属客户:</span>
<el-select v-model="importUserMark" size="small" style="width: 100px;">
<el-option v-for="user in userMarkList" :key="user.userId" :label="user.userMark" :value="user.userId"></el-option>
<el-select v-model="importUserMark" size="small" style="width: 100px">
<el-option
v-for="user in userMarkList"
:key="user.userId"
:label="user.userMark"
:value="user.userId"
></el-option>
</el-select>
</div>
<div class="import-content">
......@@ -651,10 +659,17 @@
</div>
<template #footer>
<div class="product-dialog-footer">
<div style="display: flex;align-items: center">
<span style="margin-right: 10px;font-style:13px;color: gray">搜索:</span>
<el-select v-model="userMark" size="small" style="width: 100px;">
<el-option v-for="user in userMarkList" :key="user.userId" :label="user.userMark" :value="user.userId"></el-option>
<div style="display: flex; align-items: center">
<span style="margin-right: 10px; font-style: 13px; color: gray"
>搜索:</span
>
<el-select v-model="userMark" size="small" style="width: 100px">
<el-option
v-for="user in userMarkList"
:key="user.userId"
:label="user.userMark"
:value="user.userId"
></el-option>
</el-select>
<el-input
v-model.trim="selectSku"
......@@ -873,8 +888,13 @@
>
<div class="label" style="margin-bottom: 10px">
<span style="margin-right: 10px">所属客户:</span>
<el-select v-model="batchUserMark" size="small" style="width: 100px;">
<el-option v-for="user in userMarkList" :key="user.userId" :label="user.userMark" :value="user.userId"></el-option>
<el-select v-model="batchUserMark" size="small" style="width: 100px">
<el-option
v-for="user in userMarkList"
:key="user.userId"
:label="user.userMark"
:value="user.userId"
></el-option>
</el-select>
</div>
<div>
......@@ -922,7 +942,9 @@ import {
warehouseInfo,
InRecordBatchCheckPrintApi,
factoryWarehouseInventoryPrint,
warehouseInRecordExport, getLocalFactoryList, getBySkuAndUserMarkApi,
warehouseInRecordExport,
getLocalFactoryList,
getBySkuAndUserMarkApi,
} from '@/api/warehouse'
import { filePath } from '@/api/axios.ts'
import BigNumber from 'bignumber.js'
......@@ -940,7 +962,7 @@ import {
import ImageView from '@/components/ImageView.vue'
import UploadExcel from '@/components/UploadExcel.vue'
import { useEnterKeyTrigger } from '@/utils/hooks/useEnterKeyTrigger.ts'
interface UserMark{
interface UserMark {
userId: number
userMark: string
userName: string
......@@ -1192,23 +1214,30 @@ async function handlePrintProductTag() {
window.open(filePath + res.message, '_blank')
}
const batchAddCommodity = async (sku: string,type:string): Promise<InterskuList[]> => {
const batchAddCommodity = async (
sku: string,
type: string,
): Promise<InterskuList[]> => {
if (!editForm.value.warehouseId) {
ElMessage.error('请选择仓库')
return []
}
try {
let userValue: string | number = ''
if(type==='1'){
if (type === '1') {
userValue = userMark.value
}else if(type==='2'){
} else if (type === '2') {
userValue = batchUserMark.value
}else if(type==='3'){
} else if (type === '3') {
userValue = importUserMark.value
}
const item = userMarkList.value.find(e=>e.userId===userValue)
const user = userValue===0 ? null : item?.userMark
const res = await getBySkuAndUserMarkApi(editForm.value.warehouseId, sku,user)
const item = userMarkList.value.find((e) => e.userId === userValue)
const user = userValue === 0 ? null : item?.userMark
const res = await getBySkuAndUserMarkApi(
editForm.value.warehouseId,
sku,
user,
)
const arr: InterskuList[] = res.data || []
const ids: Record<string, boolean> = {}
// 过滤掉商品列表已经加了的
......@@ -1297,7 +1326,7 @@ const handleLocalImport = async ({
// 2. 提取导入的 SKU 列表
const importedSkus = importedData.map((item) => item.warehouseSku).join(',')
// 3. 调用 batchAddCommodity 获取商品的完整信息并过滤掉已有的 SKU
const filteredSkusList = await batchAddCommodity(importedSkus,'3') // 使用 await 等待结果
const filteredSkusList = await batchAddCommodity(importedSkus, '3') // 使用 await 等待结果
if (filteredSkusList.length === 0) {
ElMessage.warning('导入的商品SKU已存在或无效')
importedFileUrl.value = path
......@@ -1307,15 +1336,17 @@ const handleLocalImport = async ({
// 4. 将备注信息合并到获取到的商品列表中
const mergedProductList = filteredSkusList.map((skuItem) => {
// 在导入数据中找到匹配的备注信息
const importedItem = importedData.find(
(item) => skuItem.warehouseSku?.includes(item.warehouseSku),
const importedItem = importedData.find((item) =>
skuItem.warehouseSku?.includes(item.warehouseSku),
)
const target = locationList.value.find((item: InterProductList) => {
return item.locationCode == importedItem?.locationCode
})
const item = userMarkList.value.find(e=>e.userId===importUserMark.value)
const item = userMarkList.value.find(
(e) => e.userId === importUserMark.value,
)
return {
customerId:importUserMark.value !== 0 ?importUserMark.value : null,
customerId: importUserMark.value !== 0 ? importUserMark.value : null,
customerName: importUserMark.value !== 0 ? item?.userName || '' : null,
userMark: importUserMark.value !== 0 ? item?.userMark : null,
skuImage: skuItem.skuImage,
......@@ -1409,9 +1440,13 @@ const skuData = ref<InterskuList[]>([])
const selectbySku = async () => {
if (!editForm.value.warehouseId) return ElMessage.error('请选择仓库')
try {
const item = userMarkList.value.find(e=>e.userId===userMark.value)
const user = userMark.value===0 ? null : item?.userMark
const res = await getBySkuAndUserMarkApi(editForm.value.warehouseId, selectSku.value,user)
const item = userMarkList.value.find((e) => e.userId === userMark.value)
const user = userMark.value === 0 ? null : item?.userMark
const res = await getBySkuAndUserMarkApi(
editForm.value.warehouseId,
selectSku.value,
user,
)
skuData.value = res.data || []
} catch (e) {
console.error(e)
......@@ -1440,16 +1475,16 @@ const skudblclick = (val: InterskuList) => {
return
}
}
const item = userMarkList.value.find(e=>e.userId===userMark.value)
const item = userMarkList.value.find((e) => e.userId === userMark.value)
otherPurchaseData.value = [
...JSON.parse(JSON.stringify(otherPurchaseData.value)),
{
skuImage,
warehouseSku,
customerId:userMark.value !== 0 ?userMark.value : null,
customerId: userMark.value !== 0 ? userMark.value : null,
customerName: userMark.value !== 0 ? item?.userName || '' : null,
userMark: userMark.value !== 0 ? item?.userMark : null,
skuName:productName,
skuName: productName,
productNo,
locationCode: locationCode ?? '', // 确保空值处理
locationId: locationId ?? null, // 确保空值处理
......@@ -1498,10 +1533,10 @@ const formId = ref<number | undefined>(undefined)
const otherPurchaseData = ref<InterProductList[]>([])
const getUserMark = async () => {
const {data} = await getLocalFactoryList()
const { data } = await getLocalFactoryList()
userMarkList.value = [
...[{userMark:'九猫商品', userId: 0,userName:''}],
...data
...[{ userMark: '九猫商品', userId: 0, userName: '' }],
...data,
]
}
......@@ -1664,50 +1699,65 @@ watch(
},
)
const addOtherCurrency = async () => {
try {
await editFormRef.value?.validate()
} catch {
return
}
const arr = otherPurchaseData.value
if (arr.length === 0) {
ElMessage.error('请至少选择一条数据')
return
}
console.log(11111)
for (let i = 0; i < arr.length; i++) {
if (!arr[i].buyStored) {
ElMessage.error('请输入入库数量')
const loading = ElLoading.service({
fullscreen: true,
text: '操作中...',
background: 'rgba(0, 0, 0, 0.3)',
})
try {
try {
await editFormRef.value?.validate()
} catch {
return
}
if (!arr[i].locationId) {
ElMessage.error('请选择库位')
const arr = otherPurchaseData.value
if (arr.length === 0) {
ElMessage.error('请至少选择一条数据')
return
}
const found = locationList.value.find(
(item: InterProductList) => item.locationId === arr[i].locationId,
)
if (!arr[i].locationCode) {
arr[i].locationCode = found ? found?.locationCode : ''
for (let i = 0; i < arr.length; i++) {
if (!arr[i].buyStored) {
ElMessage.error('请输入入库数量')
return
}
if (!arr[i].locationId) {
ElMessage.error('请选择库位')
return
}
const found = locationList.value.find(
(item: InterProductList) => item.locationId === arr[i].locationId,
)
if (!arr[i].locationCode) {
arr[i].locationCode = found ? found?.locationCode : ''
}
}
}
if (!formId.value) {
addSection()
} else {
upSection()
if (!formId.value) {
await addSection()
} else {
await upSection()
}
} catch (error) {
console.log(error)
} finally {
loading.close()
}
}
const filterSkuData = computed(() => {
const skuList = otherPurchaseData.value.map((el) => el.warehouseSku)
// console.log(skuList, skuData.value)
const item = userMarkList.value.find(u=>u.userId===userMark.value)
return skuData.value.filter((el) => !skuList.includes(el.warehouseSku)).map(e=>{
return {
...e,
userMark:userMark.value===0?'':item?.userMark
}
})
const item = userMarkList.value.find((u) => u.userId === userMark.value)
return skuData.value
.filter((el) => !skuList.includes(el.warehouseSku))
.map((e) => {
return {
...e,
userMark: userMark.value === 0 ? '' : item?.userMark,
}
})
})
const addSection = async () => {
const params = { ...editForm.value }
......@@ -1782,11 +1832,11 @@ const submitPurchase = async () => {
ElMessage.warning('请输入库存 SKU')
return
}
const item = userMarkList.value.find(e=>e.userId===batchUserMark.value)
const filteredSkusList = await batchAddCommodity(purchaseTextarea.value,'2')
const item = userMarkList.value.find((e) => e.userId === batchUserMark.value)
const filteredSkusList = await batchAddCommodity(purchaseTextarea.value, '2')
const mergedProductList = filteredSkusList.map((skuItem) => {
return {
customerId:batchUserMark.value !== 0 ?batchUserMark.value : null,
customerId: batchUserMark.value !== 0 ? batchUserMark.value : null,
customerName: batchUserMark.value !== 0 ? item?.userName || '' : null,
userMark: batchUserMark.value !== 0 ? item?.userMark : null,
skuImage: skuItem.skuImage,
......@@ -1851,7 +1901,7 @@ const searchDetail = async () => {
detailLoading.value = true
try {
const res = await getWarehouseInRecordDetailApi(currentRow.value?.id)
res.data.productList.forEach(item => {
res.data.productList.forEach((item) => {
item.currencyName = res.data.currencyName || ''
item.currencyCode = res.data.currencyCode || ''
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment