Merge remote-tracking branch 'origin/master'

This commit is contained in:
M_Kececi
2026-04-03 14:32:19 +03:00
parent f46532cee1
commit 415e3db084

View File

@@ -969,12 +969,13 @@ async function openAttributeDialog (itemCode) {
return {
...row,
AttributeCode: currentCode,
OriginalAttributeCode: currentCode,
AllOptions: currentOptions,
Options: [...currentOptions]
}
})
const useDraft = modeInfo.mode !== 'existing' && Array.isArray(existingDraft) && existingDraft.length
const useDraft = Array.isArray(existingDraft) && existingDraft.length
attributeRows.value = useDraft
? JSON.parse(JSON.stringify(existingDraft))
: JSON.parse(JSON.stringify(baseRows))
@@ -986,7 +987,7 @@ async function openAttributeDialog (itemCode) {
row.Options = [...row.AllOptions]
}
}
if ((!existingDraft || !existingDraft.length || modeInfo.mode === 'existing') && baseRows.length) {
if ((!existingDraft || !existingDraft.length) && baseRows.length) {
store.setProductAttributeDraft(code, JSON.parse(JSON.stringify(baseRows)))
}
attributeDialogOpen.value = true
@@ -1016,11 +1017,44 @@ async function collectProductAttributesFromSelectedRows (selectedRows) {
const out = []
for (const code of codeSet) {
const modeInfo = store.classifyItemCode(code)
let rows = store.getProductAttributeDraft(code)
if (!Array.isArray(rows) || !rows.length) {
let dbMap = new Map()
if (modeInfo.mode === 'existing') {
const dbCurrent = await store.fetchProductItemAttributes(code, 1, true)
dbMap = new Map(
(dbCurrent || []).map(x => [
Number(x?.attribute_type_code || x?.AttributeTypeCode || 0),
String(x?.attribute_code || x?.AttributeCode || '').trim()
]).filter(x => x[0] > 0)
)
// Existing kodda kullanıcı değişiklik yaptıysa draftı koru.
// Draft yoksa DB'den zorunlu/fresh çek.
if (!Array.isArray(rows) || !rows.length) {
const lookup = await store.fetchProductAttributes(1)
const baseRows = buildAttributeRowsFromLookup(lookup)
rows = baseRows.map(row => {
const currentCode = dbMap.get(Number(row.AttributeTypeCodeNumber || 0)) || ''
const currentOptions = Array.isArray(row.options) ? [...row.options] : []
if (currentCode && !currentOptions.some(opt => String(opt?.value || '').trim() === currentCode)) {
currentOptions.unshift({ value: currentCode, label: `${currentCode} - (Mevcut)` })
}
return {
...row,
AttributeCode: currentCode,
OriginalAttributeCode: currentCode,
AllOptions: currentOptions,
Options: [...currentOptions]
}
})
store.setProductAttributeDraft(code, JSON.parse(JSON.stringify(rows)))
}
} else if (!Array.isArray(rows) || !rows.length) {
const lookup = await store.fetchProductAttributes(1)
const baseRows = buildAttributeRowsFromLookup(lookup)
const dbCurrent = await store.fetchProductItemAttributes(code, 1)
const dbCurrent = await store.fetchProductItemAttributes(code, 1, true)
const dbMap = new Map(
(dbCurrent || []).map(x => [
Number(x?.attribute_type_code || x?.AttributeTypeCode || 0),
@@ -1033,15 +1067,31 @@ async function collectProductAttributesFromSelectedRows (selectedRows) {
}))
store.setProductAttributeDraft(code, JSON.parse(JSON.stringify(rows)))
}
if (!Array.isArray(rows) || !rows.length) {
return { errMsg: `${code} icin urun ozellikleri secilmedi`, productAttributes: [] }
}
for (const row of rows) {
const attributeTypeCode = Number(row?.AttributeTypeCodeNumber || 0)
const attributeCode = String(row?.AttributeCode || '').trim()
if (!attributeTypeCode || !attributeCode) {
if (!attributeTypeCode) {
return { errMsg: `${code} icin urun ozellikleri eksik`, productAttributes: [] }
}
if (modeInfo.mode === 'existing') {
const originalCode =
dbMap.get(attributeTypeCode) ||
String(row?.OriginalAttributeCode || '').trim()
const changed = attributeCode !== originalCode
if (!changed) continue
if (!attributeCode) {
return { errMsg: `${code} icin urun ozellikleri eksik`, productAttributes: [] }
}
} else if (!attributeCode) {
return { errMsg: `${code} icin urun ozellikleri eksik`, productAttributes: [] }
}
out.push({
ItemTypeCode: 1,
ItemCode: code,