Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -969,12 +969,13 @@ async function openAttributeDialog (itemCode) {
|
|||||||
return {
|
return {
|
||||||
...row,
|
...row,
|
||||||
AttributeCode: currentCode,
|
AttributeCode: currentCode,
|
||||||
|
OriginalAttributeCode: currentCode,
|
||||||
AllOptions: currentOptions,
|
AllOptions: currentOptions,
|
||||||
Options: [...currentOptions]
|
Options: [...currentOptions]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const useDraft = modeInfo.mode !== 'existing' && Array.isArray(existingDraft) && existingDraft.length
|
const useDraft = Array.isArray(existingDraft) && existingDraft.length
|
||||||
attributeRows.value = useDraft
|
attributeRows.value = useDraft
|
||||||
? JSON.parse(JSON.stringify(existingDraft))
|
? JSON.parse(JSON.stringify(existingDraft))
|
||||||
: JSON.parse(JSON.stringify(baseRows))
|
: JSON.parse(JSON.stringify(baseRows))
|
||||||
@@ -986,7 +987,7 @@ async function openAttributeDialog (itemCode) {
|
|||||||
row.Options = [...row.AllOptions]
|
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)))
|
store.setProductAttributeDraft(code, JSON.parse(JSON.stringify(baseRows)))
|
||||||
}
|
}
|
||||||
attributeDialogOpen.value = true
|
attributeDialogOpen.value = true
|
||||||
@@ -1016,11 +1017,44 @@ async function collectProductAttributesFromSelectedRows (selectedRows) {
|
|||||||
const out = []
|
const out = []
|
||||||
|
|
||||||
for (const code of codeSet) {
|
for (const code of codeSet) {
|
||||||
|
const modeInfo = store.classifyItemCode(code)
|
||||||
let rows = store.getProductAttributeDraft(code)
|
let rows = store.getProductAttributeDraft(code)
|
||||||
|
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) {
|
if (!Array.isArray(rows) || !rows.length) {
|
||||||
const lookup = await store.fetchProductAttributes(1)
|
const lookup = await store.fetchProductAttributes(1)
|
||||||
const baseRows = buildAttributeRowsFromLookup(lookup)
|
const baseRows = buildAttributeRowsFromLookup(lookup)
|
||||||
const dbCurrent = await store.fetchProductItemAttributes(code, 1)
|
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, true)
|
||||||
const dbMap = new Map(
|
const dbMap = new Map(
|
||||||
(dbCurrent || []).map(x => [
|
(dbCurrent || []).map(x => [
|
||||||
Number(x?.attribute_type_code || x?.AttributeTypeCode || 0),
|
Number(x?.attribute_type_code || x?.AttributeTypeCode || 0),
|
||||||
@@ -1033,15 +1067,31 @@ async function collectProductAttributesFromSelectedRows (selectedRows) {
|
|||||||
}))
|
}))
|
||||||
store.setProductAttributeDraft(code, JSON.parse(JSON.stringify(rows)))
|
store.setProductAttributeDraft(code, JSON.parse(JSON.stringify(rows)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Array.isArray(rows) || !rows.length) {
|
if (!Array.isArray(rows) || !rows.length) {
|
||||||
return { errMsg: `${code} icin urun ozellikleri secilmedi`, productAttributes: [] }
|
return { errMsg: `${code} icin urun ozellikleri secilmedi`, productAttributes: [] }
|
||||||
}
|
}
|
||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
const attributeTypeCode = Number(row?.AttributeTypeCodeNumber || 0)
|
const attributeTypeCode = Number(row?.AttributeTypeCodeNumber || 0)
|
||||||
const attributeCode = String(row?.AttributeCode || '').trim()
|
const attributeCode = String(row?.AttributeCode || '').trim()
|
||||||
if (!attributeTypeCode || !attributeCode) {
|
|
||||||
|
if (!attributeTypeCode) {
|
||||||
return { errMsg: `${code} icin urun ozellikleri eksik`, productAttributes: [] }
|
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({
|
out.push({
|
||||||
ItemTypeCode: 1,
|
ItemTypeCode: 1,
|
||||||
ItemCode: code,
|
ItemCode: code,
|
||||||
|
|||||||
Reference in New Issue
Block a user