|
|
|
|
@ -435,10 +435,10 @@ const formData = ref({
|
|
|
|
|
salePrice: undefined,
|
|
|
|
|
minPrice: undefined,
|
|
|
|
|
safetyNumber: undefined,
|
|
|
|
|
devices: [] as { id: number; name: string }[],
|
|
|
|
|
molds: [] as { id: number; name: string }[],
|
|
|
|
|
packagingSchemes: [] as { packagingSchemeId: number | undefined; defaultStatus: number }[],
|
|
|
|
|
suppliers: [] as { supplierId: number | undefined; defaultStatus: number }[],
|
|
|
|
|
devices: [] as { id: string | number; name: string }[],
|
|
|
|
|
molds: [] as { id: string | number; name: string }[],
|
|
|
|
|
packagingSchemes: [] as { packagingSchemeId: string | number | undefined; defaultStatus: number }[],
|
|
|
|
|
suppliers: [] as { supplierId: string | number | undefined; defaultStatus: number }[],
|
|
|
|
|
fragileFlag: undefined as number | undefined,
|
|
|
|
|
purchaseCycle: undefined as number | undefined,
|
|
|
|
|
brand: undefined as string | undefined,
|
|
|
|
|
@ -450,13 +450,13 @@ const formData = ref({
|
|
|
|
|
})
|
|
|
|
|
const selectedDeviceRows = ref<any[]>([])
|
|
|
|
|
const selectedMoldRows = ref<any[]>([])
|
|
|
|
|
const findCategoryNameById = (id: number | undefined, tree: any[]): string => {
|
|
|
|
|
if (!id || !Array.isArray(tree) || !tree.length) return ''
|
|
|
|
|
const findCategoryNameById = (id: string | number | undefined, tree: any[]): string => {
|
|
|
|
|
if (id == null || !Array.isArray(tree) || !tree.length) return ''
|
|
|
|
|
const queue = [...tree]
|
|
|
|
|
while (queue.length) {
|
|
|
|
|
const node = queue.shift()
|
|
|
|
|
if (!node) continue
|
|
|
|
|
if (Number(node.id) === Number(id)) {
|
|
|
|
|
if (String(node.id) === String(id)) {
|
|
|
|
|
return String(node.name || node.label || '')
|
|
|
|
|
}
|
|
|
|
|
if (Array.isArray(node.children) && node.children.length) {
|
|
|
|
|
@ -467,7 +467,7 @@ const findCategoryNameById = (id: number | undefined, tree: any[]): string => {
|
|
|
|
|
}
|
|
|
|
|
const selectedCategoryName = computed(() => findCategoryNameById(formData.value.categoryId as any, categoryList.value))
|
|
|
|
|
const isProductCategory = computed(() => selectedCategoryName.value === '产品')
|
|
|
|
|
const getRelationName = (item: Record<string, any>, nameKeys: string[], fallbackPrefix: string, id: number) => {
|
|
|
|
|
const getRelationName = (item: Record<string, any>, nameKeys: string[], fallbackPrefix: string, id: string | number) => {
|
|
|
|
|
for (const key of nameKeys) {
|
|
|
|
|
const value = item[key]
|
|
|
|
|
if (value !== undefined && value !== null && String(value).trim() !== '') {
|
|
|
|
|
@ -481,11 +481,10 @@ const normalizeRelationList = (
|
|
|
|
|
fallbackRows: any[] | undefined,
|
|
|
|
|
nameKeys: string[],
|
|
|
|
|
fallbackPrefix: string
|
|
|
|
|
): { id: number; name: string }[] => {
|
|
|
|
|
const fallbackMap = new Map<number, string>()
|
|
|
|
|
): { id: string | number; name: string }[] => {
|
|
|
|
|
const fallbackMap = new Map<string | number, string>()
|
|
|
|
|
; (fallbackRows || []).forEach((row) => {
|
|
|
|
|
const id = Number(row?.id)
|
|
|
|
|
if (!Number.isFinite(id)) return
|
|
|
|
|
const id = String(row?.id)
|
|
|
|
|
fallbackMap.set(id, getRelationName(row, nameKeys, fallbackPrefix, id))
|
|
|
|
|
})
|
|
|
|
|
const parseArray = (source: unknown): any[] => {
|
|
|
|
|
@ -505,30 +504,31 @@ const normalizeRelationList = (
|
|
|
|
|
return parseArray(value)
|
|
|
|
|
.map((item) => {
|
|
|
|
|
if (typeof item === 'object' && item !== null) {
|
|
|
|
|
const id = Number((item as any).id)
|
|
|
|
|
if (!Number.isFinite(id)) return undefined
|
|
|
|
|
const rawId = (item as any).id
|
|
|
|
|
if (rawId == null) return undefined
|
|
|
|
|
const id = rawId
|
|
|
|
|
return {
|
|
|
|
|
id,
|
|
|
|
|
name: getRelationName(item as any, nameKeys, fallbackPrefix, id)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const id = Number(item)
|
|
|
|
|
if (!Number.isFinite(id)) return undefined
|
|
|
|
|
const rawId = String(item).trim()
|
|
|
|
|
if (!rawId) return undefined
|
|
|
|
|
return {
|
|
|
|
|
id,
|
|
|
|
|
name: fallbackMap.get(id) || `${fallbackPrefix}ID:${id}`
|
|
|
|
|
id: rawId,
|
|
|
|
|
name: fallbackMap.get(rawId) || `${fallbackPrefix}ID:${rawId}`
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.filter((item): item is { id: number; name: string } => Boolean(item))
|
|
|
|
|
.filter((item): item is { id: string | number; name: string } => Boolean(item))
|
|
|
|
|
}
|
|
|
|
|
const toDeviceRows = (devices: { id: number; name: string }[]) => {
|
|
|
|
|
const toDeviceRows = (devices: { id: string | number; name: string }[]) => {
|
|
|
|
|
return devices.map((item) => ({
|
|
|
|
|
id: item.id,
|
|
|
|
|
deviceName: item.name,
|
|
|
|
|
name: item.name
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
const toMoldRows = (molds: { id: number; name: string }[]) => {
|
|
|
|
|
const toMoldRows = (molds: { id: string | number; name: string }[]) => {
|
|
|
|
|
return molds.map((item) => ({
|
|
|
|
|
id: item.id,
|
|
|
|
|
name: item.name
|
|
|
|
|
@ -565,7 +565,7 @@ const fetchDeviceLedgerPage = (params: Record<string, any>) => {
|
|
|
|
|
}
|
|
|
|
|
const openDeviceSelectDialog = () => {
|
|
|
|
|
const rows = selectedDeviceRows.value.length
|
|
|
|
|
? selectedDeviceRows.value.map((item) => ({ ...item, id: Number(item.id) }))
|
|
|
|
|
? selectedDeviceRows.value.map((item) => ({ ...item, id: String(item.id) }))
|
|
|
|
|
: toDeviceRows(formData.value.devices)
|
|
|
|
|
deviceSelectDialogRef.value?.open(rows)
|
|
|
|
|
}
|
|
|
|
|
@ -578,27 +578,25 @@ const openMoldSelectDialog = () => {
|
|
|
|
|
const handleDeviceSelectConfirm = (payload: { ids: (number | string)[]; rows: any[] }) => {
|
|
|
|
|
formData.value.devices = payload.rows
|
|
|
|
|
.map((item) => {
|
|
|
|
|
const id = Number(item.id)
|
|
|
|
|
if (!Number.isFinite(id)) return undefined
|
|
|
|
|
const id = String(item.id)
|
|
|
|
|
return {
|
|
|
|
|
id,
|
|
|
|
|
name: item.deviceName || item.name || item.code || `设备ID:${id}`
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.filter((item): item is { id: number; name: string } => Boolean(item))
|
|
|
|
|
.filter((item): item is { id: string | number; name: string } => Boolean(item))
|
|
|
|
|
selectedDeviceRows.value = payload.rows
|
|
|
|
|
}
|
|
|
|
|
const handleMoldSelectConfirm = (payload: { ids: (number | string)[]; rows: any[] }) => {
|
|
|
|
|
formData.value.molds = payload.rows
|
|
|
|
|
.map((item) => {
|
|
|
|
|
const id = Number(item.id)
|
|
|
|
|
if (!Number.isFinite(id)) return undefined
|
|
|
|
|
const id = String(item.id)
|
|
|
|
|
return {
|
|
|
|
|
id,
|
|
|
|
|
name: item.name || item.code || `模具ID:${id}`
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.filter((item): item is { id: number; name: string } => Boolean(item))
|
|
|
|
|
.filter((item): item is { id: string | number; name: string } => Boolean(item))
|
|
|
|
|
selectedMoldRows.value = payload.rows
|
|
|
|
|
}
|
|
|
|
|
const validateBarCode = (_rule, value, callback) => {
|
|
|
|
|
@ -935,7 +933,7 @@ const supplierList = ref<any[]>([])
|
|
|
|
|
|
|
|
|
|
let openRequestId = 0
|
|
|
|
|
|
|
|
|
|
const open = async (type: string, id?: number) => {
|
|
|
|
|
const open = async (type: string, id?: string | number) => {
|
|
|
|
|
const currentOpenId = ++openRequestId
|
|
|
|
|
dialogTitle.value = t('action.' + type)
|
|
|
|
|
formType.value = type
|
|
|
|
|
@ -1114,8 +1112,8 @@ const handleQrcodeRefreshSuccess = async (data: any) => {
|
|
|
|
|
formData.value.barCode = productData?.barCode ?? formData.value.barCode
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const buildRelationIdListString = (list: { id: number; name: string }[]) => {
|
|
|
|
|
return list.map((item) => Number(item.id)).filter((id) => Number.isFinite(id))
|
|
|
|
|
const buildRelationIdListString = (list: { id: string | number; name: string }[]) => {
|
|
|
|
|
return list.map((item) => String(item.id)).filter((id) => id !== '')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const getDefaultPackagingSchemeId = () => {
|
|
|
|
|
|