|
|
|
@@ -309,6 +309,47 @@
|
|
|
|
|
function amountPlain(v) { return String(parseInt(String(v || "0").replace(/,/g, ""), 10) || 0); }
|
|
|
|
|
function norm(s) { return String(s || "").replace(/\s+/g, "").toLowerCase(); }
|
|
|
|
|
|
|
|
|
|
// 판매 가격 칸 = 기본 정보 판매가 + 추가금액. 화면 계산용이고 저장되는 값은 추가금액뿐이다.
|
|
|
|
|
function basePrice() {
|
|
|
|
|
var el = root.querySelector('#cf24-basic-form [name="price"]');
|
|
|
|
|
return parseInt(amountPlain(el && el.value), 10);
|
|
|
|
|
}
|
|
|
|
|
function salePrice(amount) { return String(basePrice() + parseInt(amountPlain(amount), 10)); }
|
|
|
|
|
function salePriceCell(amount) {
|
|
|
|
|
return '<td class="cf24-v-amount"><input type="text" class="cf24-sale-price" inputmode="numeric" value="' + salePrice(amount) + '" /></td>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function bindSalePrice(tbody) {
|
|
|
|
|
// capture: 불러오기·입력 복원이 보내는 input 이벤트는 버블링하지 않는다.
|
|
|
|
|
tbody.addEventListener("input", function (e) {
|
|
|
|
|
var tr = e.target.closest("tr");
|
|
|
|
|
var sale = tr.querySelector(".cf24-sale-price");
|
|
|
|
|
var amount = tr.querySelector('[name="additional_amount"]');
|
|
|
|
|
if (e.target === sale) {
|
|
|
|
|
sale.value = sale.value.replace(/\D/g, "");
|
|
|
|
|
amount.value = sale.value ? String(parseInt(sale.value, 10) - basePrice()) : "0";
|
|
|
|
|
amount.dispatchEvent(new Event("input")); // 변경 표시
|
|
|
|
|
} else if (e.target === amount && document.activeElement !== sale) {
|
|
|
|
|
sale.value = salePrice(amount.value);
|
|
|
|
|
}
|
|
|
|
|
}, true);
|
|
|
|
|
tbody.addEventListener("focusout", function (e) {
|
|
|
|
|
if (!e.target.classList.contains("cf24-sale-price")) return;
|
|
|
|
|
e.target.value = salePrice(e.target.closest("tr").querySelector('[name="additional_amount"]').value);
|
|
|
|
|
});
|
|
|
|
|
tbody.addEventListener("keydown", function (e) {
|
|
|
|
|
if (!e.target.classList.contains("cf24-sale-price")) return;
|
|
|
|
|
var down = e.key === "Enter" || e.key === "ArrowDown";
|
|
|
|
|
if (!down && e.key !== "ArrowUp") return;
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
var tr = e.target.closest("tr")[down ? "nextElementSibling" : "previousElementSibling"];
|
|
|
|
|
if (!tr) return;
|
|
|
|
|
var next = tr.querySelector(".cf24-sale-price");
|
|
|
|
|
next.focus();
|
|
|
|
|
next.select();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ═══════════════════════════════════════════════════════════
|
|
|
|
|
화면 분기
|
|
|
|
|
═══════════════════════════════════════════════════════════ */
|
|
|
|
@@ -380,6 +421,7 @@
|
|
|
|
|
: '<span class="cf24-muted">저장 시 부여</span>') + "</td>" +
|
|
|
|
|
'<td class="cf24-v-code"><input type="text" name="custom_variant_code" maxlength="40" value="' + esc(variant ? variant.custom_variant_code : "") + '" /></td>' +
|
|
|
|
|
'<td class="cf24-v-amount"><input type="text" name="additional_amount" inputmode="numeric" value="' + esc(amountPlain(variant ? variant.additional_amount : "0")) + '" /></td>' +
|
|
|
|
|
salePriceCell(variant ? variant.additional_amount : "0") +
|
|
|
|
|
'<td class="cf24-v-flag">' + toggleBtn("display", variant ? !!variant.display : true) + "</td>" +
|
|
|
|
|
'<td class="cf24-v-flag">' + toggleBtn("selling", variant ? !!variant.selling : true) + "</td>" +
|
|
|
|
|
'<td class="cf24-u-del">' + (awaiting ? "" : '<button type="button" class="cf24-u-remove" title="' + (isNewRow ? "행 삭제" : "품목 삭제 (카페24에 바로 반영)") + '">✕</button>') + "</td>" +
|
|
|
|
@@ -406,7 +448,7 @@
|
|
|
|
|
"</div>" +
|
|
|
|
|
'<div class="cf24-u-tablewrap"><table class="cf24-variants cf24-u-table"><thead><tr>' +
|
|
|
|
|
'<th class="cf24-u-drag"></th><th class="cf24-u-thumb">썸네일</th><th>옵션값 이름</th><th class="cf24-v-syscode">품목코드</th>' +
|
|
|
|
|
'<th class="cf24-v-code">자체 품목코드</th><th class="cf24-v-amount">추가금액</th><th class="cf24-v-flag">진열</th><th class="cf24-v-flag">판매</th><th class="cf24-u-del"></th>' +
|
|
|
|
|
'<th class="cf24-v-code">자체 품목코드</th><th class="cf24-v-amount">추가금액</th><th class="cf24-v-amount">판매 가격</th><th class="cf24-v-flag">진열</th><th class="cf24-v-flag">판매</th><th class="cf24-u-del"></th>' +
|
|
|
|
|
"</tr></thead><tbody id=\"cf24-u-body\">";
|
|
|
|
|
rows.forEach(function (r, i) { html += rowHtml(r, canDrag, i); });
|
|
|
|
|
if (isNew) html += rowHtml({ index: null, value: null, variant: null }, true, null);
|
|
|
|
@@ -436,6 +478,7 @@
|
|
|
|
|
var tbody = body.querySelector("#cf24-u-body");
|
|
|
|
|
var msg = body.querySelector("#cf24-u-msg");
|
|
|
|
|
trackDirty(wrap);
|
|
|
|
|
bindSalePrice(tbody);
|
|
|
|
|
bindToggles(tbody);
|
|
|
|
|
bindCopy(tbody);
|
|
|
|
|
bindThumbUploads(tbody, msg);
|
|
|
|
@@ -964,7 +1007,7 @@
|
|
|
|
|
html += '<p class="cf24-muted">품목이 아직 조회되지 않았습니다. 잠시 뒤 창을 닫았다 다시 여세요.</p>';
|
|
|
|
|
} else {
|
|
|
|
|
html += '<div class="cf24-variants-wrap"><table class="cf24-variants"><thead><tr><th class="cf24-v-imgcol"></th><th>옵션</th><th class="cf24-v-syscode">품목코드</th>' +
|
|
|
|
|
'<th class="cf24-v-code">자체 품목코드</th><th class="cf24-v-amount">추가금액</th><th class="cf24-v-flag">진열</th><th class="cf24-v-flag">판매</th><th class="cf24-u-del"></th></tr></thead><tbody>';
|
|
|
|
|
'<th class="cf24-v-code">자체 품목코드</th><th class="cf24-v-amount">추가금액</th><th class="cf24-v-amount">판매 가격</th><th class="cf24-v-flag">진열</th><th class="cf24-v-flag">판매</th><th class="cf24-u-del"></th></tr></thead><tbody>';
|
|
|
|
|
variants.forEach(function (v) {
|
|
|
|
|
var label = v.options.map(function (o) { return o.value; }).join(" / ") || v.variant_code;
|
|
|
|
|
html += '<tr class="cf24-v-item" data-code="' + esc(v.variant_code) + '">' +
|
|
|
|
@@ -973,6 +1016,7 @@
|
|
|
|
|
'<td class="cf24-v-syscode"><button type="button" class="cf24-v-copy" data-copy-text="' + esc(v.variant_code) + '">' + esc(v.variant_code) + "</button></td>" +
|
|
|
|
|
'<td class="cf24-v-code"><input type="text" name="custom_variant_code" maxlength="40" value="' + esc(v.custom_variant_code) + '" /></td>' +
|
|
|
|
|
'<td class="cf24-v-amount"><input type="text" name="additional_amount" inputmode="numeric" value="' + esc(amountPlain(v.additional_amount)) + '" /></td>' +
|
|
|
|
|
salePriceCell(v.additional_amount) +
|
|
|
|
|
'<td class="cf24-v-flag">' + toggleBtn("display", !!v.display) + "</td><td class=\"cf24-v-flag\">" + toggleBtn("selling", !!v.selling) + "</td>" +
|
|
|
|
|
'<td class="cf24-u-del"><button type="button" class="cf24-u-remove" data-code="' + esc(v.variant_code) + '" title="품목 삭제 (카페24에 바로 반영)">✕</button></td></tr>';
|
|
|
|
|
});
|
|
|
|
@@ -990,6 +1034,7 @@
|
|
|
|
|
var wrap = body.querySelector(".cf24-variants-wrap");
|
|
|
|
|
if (wrap) {
|
|
|
|
|
trackDirty(wrap);
|
|
|
|
|
bindSalePrice(wrap.querySelector("tbody"));
|
|
|
|
|
bindToggles(wrap);
|
|
|
|
|
bindCopy(wrap);
|
|
|
|
|
body.querySelector("#cf24-var-save").addEventListener("click", function () { saveMultiVariants(wrap); });
|
|
|
|
|