Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -942,6 +942,41 @@ function onFilterAttributeOption (row, val, update) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mergeAttributeDraftWithLookupOptions (draftRows, lookupRows) {
|
||||||
|
const byType = new Map(
|
||||||
|
(lookupRows || []).map(r => [Number(r?.AttributeTypeCodeNumber || 0), r]).filter(x => x[0] > 0)
|
||||||
|
)
|
||||||
|
|
||||||
|
return (draftRows || []).map(d => {
|
||||||
|
const typeCode = Number(d?.AttributeTypeCodeNumber || 0)
|
||||||
|
const base = byType.get(typeCode)
|
||||||
|
const selectedCode = String(d?.AttributeCode || '').trim()
|
||||||
|
|
||||||
|
const baseAllOptions = Array.isArray(base?.AllOptions)
|
||||||
|
? [...base.AllOptions]
|
||||||
|
: (Array.isArray(base?.Options) ? [...base.Options] : [])
|
||||||
|
|
||||||
|
const draftAllOptions = Array.isArray(d?.AllOptions)
|
||||||
|
? [...d.AllOptions]
|
||||||
|
: (Array.isArray(d?.Options) ? [...d.Options] : [])
|
||||||
|
|
||||||
|
const allOptions = baseAllOptions.length ? baseAllOptions : draftAllOptions
|
||||||
|
|
||||||
|
if (selectedCode && !allOptions.some(opt => String(opt?.value || '').trim() === selectedCode)) {
|
||||||
|
allOptions.unshift({ value: selectedCode, label: `${selectedCode} - (Secili)` })
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...(base || d),
|
||||||
|
...d,
|
||||||
|
AttributeTypeCodeNumber: typeCode,
|
||||||
|
AttributeCode: selectedCode,
|
||||||
|
AllOptions: allOptions,
|
||||||
|
Options: [...allOptions]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
async function openAttributeDialog (itemCode) {
|
async function openAttributeDialog (itemCode) {
|
||||||
const code = String(itemCode || '').trim().toUpperCase()
|
const code = String(itemCode || '').trim().toUpperCase()
|
||||||
if (!code) return
|
if (!code) return
|
||||||
@@ -980,9 +1015,9 @@ async function openAttributeDialog (itemCode) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const useDraft = Array.isArray(existingDraft) && existingDraft.length
|
const useDraft = modeInfo.mode !== 'existing' && Array.isArray(existingDraft) && existingDraft.length
|
||||||
attributeRows.value = useDraft
|
attributeRows.value = useDraft
|
||||||
? JSON.parse(JSON.stringify(existingDraft))
|
? JSON.parse(JSON.stringify(mergeAttributeDraftWithLookupOptions(existingDraft, baseRows)))
|
||||||
: JSON.parse(JSON.stringify(baseRows))
|
: JSON.parse(JSON.stringify(baseRows))
|
||||||
for (const row of (attributeRows.value || [])) {
|
for (const row of (attributeRows.value || [])) {
|
||||||
if (!Array.isArray(row.AllOptions)) {
|
if (!Array.isArray(row.AllOptions)) {
|
||||||
@@ -992,7 +1027,9 @@ async function openAttributeDialog (itemCode) {
|
|||||||
row.Options = [...row.AllOptions]
|
row.Options = [...row.AllOptions]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((!existingDraft || !existingDraft.length) && baseRows.length) {
|
if (modeInfo.mode === 'existing') {
|
||||||
|
store.setProductAttributeDraft(code, JSON.parse(JSON.stringify(baseRows)))
|
||||||
|
} else if ((!existingDraft || !existingDraft.length) && baseRows.length) {
|
||||||
store.setProductAttributeDraft(code, JSON.parse(JSON.stringify(baseRows)))
|
store.setProductAttributeDraft(code, JSON.parse(JSON.stringify(baseRows)))
|
||||||
}
|
}
|
||||||
attributeDialogOpen.value = true
|
attributeDialogOpen.value = true
|
||||||
|
|||||||
Reference in New Issue
Block a user