|
@@ -340,12 +340,19 @@ const statusOptions = [
|
|
|
const selectedCategory = ref(null);
|
|
const selectedCategory = ref(null);
|
|
|
|
|
|
|
|
const variationType = ref("tamanho");
|
|
const variationType = ref("tamanho");
|
|
|
|
|
+const previousVariationType = ref("tamanho");
|
|
|
const variations = ref([]);
|
|
const variations = ref([]);
|
|
|
const newVariationLabel = ref("");
|
|
const newVariationLabel = ref("");
|
|
|
const newVariationValue = ref(null);
|
|
const newVariationValue = ref(null);
|
|
|
const newVariationStock = ref(null);
|
|
const newVariationStock = ref(null);
|
|
|
const addingVariation = ref(false);
|
|
const addingVariation = ref(false);
|
|
|
|
|
|
|
|
|
|
+const savedVariationStates = reactive({
|
|
|
|
|
+ tamanho: null,
|
|
|
|
|
+ cor: null,
|
|
|
|
|
+ modelo: null,
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
const variationTypeOptions = computed(() => [
|
|
const variationTypeOptions = computed(() => [
|
|
|
{ label: t("loja.variation_tamanho"), value: "tamanho" },
|
|
{ label: t("loja.variation_tamanho"), value: "tamanho" },
|
|
|
{ label: t("loja.variation_cor"), value: "cor" },
|
|
{ label: t("loja.variation_cor"), value: "cor" },
|
|
@@ -370,12 +377,41 @@ const syncSizeVariations = () => {
|
|
|
}));
|
|
}));
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-const onVariationTypeChange = () => {
|
|
|
|
|
- variations.value = [];
|
|
|
|
|
|
|
+const onVariationTypeChange = (newType) => {
|
|
|
|
|
+ const prevType = previousVariationType.value;
|
|
|
|
|
+
|
|
|
|
|
+ if (prevType === "tamanho") {
|
|
|
|
|
+ savedVariationStates.tamanho = sizeSlots.map((s) => ({
|
|
|
|
|
+ label: s.label, enabled: s.enabled, value: s.value, stock: s.stock,
|
|
|
|
|
+ }));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ savedVariationStates[prevType] = variations.value.map((v) => ({ ...v }));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (newType === "tamanho") {
|
|
|
|
|
+ const saved = savedVariationStates.tamanho;
|
|
|
|
|
+ sizeSlots.forEach((s, i) => {
|
|
|
|
|
+ if (saved) {
|
|
|
|
|
+ s.enabled = saved[i].enabled;
|
|
|
|
|
+ s.value = saved[i].value;
|
|
|
|
|
+ s.stock = saved[i].stock;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ s.enabled = false;
|
|
|
|
|
+ s.value = null;
|
|
|
|
|
+ s.stock = null;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ syncSizeVariations();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ variations.value = savedVariationStates[newType]
|
|
|
|
|
+ ? [...savedVariationStates[newType]]
|
|
|
|
|
+ : [];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
newVariationLabel.value = "";
|
|
newVariationLabel.value = "";
|
|
|
newVariationValue.value = null;
|
|
newVariationValue.value = null;
|
|
|
newVariationStock.value = null;
|
|
newVariationStock.value = null;
|
|
|
- sizeSlots.forEach((s) => { s.enabled = false; s.value = null; s.stock = null; });
|
|
|
|
|
|
|
+ previousVariationType.value = newType;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
@@ -511,6 +547,7 @@ onMounted(async () => {
|
|
|
if (item.variations?.length) {
|
|
if (item.variations?.length) {
|
|
|
const type = item.variations[0].variation_type;
|
|
const type = item.variations[0].variation_type;
|
|
|
variationType.value = type;
|
|
variationType.value = type;
|
|
|
|
|
+ previousVariationType.value = type;
|
|
|
|
|
|
|
|
if (type === "tamanho") {
|
|
if (type === "tamanho") {
|
|
|
const labelMap = { P: 0, M: 1, G: 2, GG: 3 };
|
|
const labelMap = { P: 0, M: 1, G: 2, GG: 3 };
|