Files
appco_dist/.output/server/chunks/build/handle-C_30e_aJ.mjs
T
2025-08-06 17:55:47 +03:30

279 lines
8.8 KiB
JavaScript

import { ref, reactive, computed } from 'vue';
import { cloneDeep } from 'lodash-es';
import { y as supabaseService } from './server.mjs';
const getFeatureList = async () => supabaseService.fetch("attributes", "select", {
columns: "*, attribute_values(*)"
// field: 'borrower_id',
// value: id
});
const getOneFeature = async (id) => supabaseService.fetch("attributes", "select", {
columns: "*, attribute_values(*)",
field: "id",
value: id
});
const createFeature = async (obj) => {
await supabaseService.fetch("attributes", "insert", {
data: obj
});
};
const createFeatureAttribute = async (obj) => {
await supabaseService.fetch("attribute_values", "insert", {
data: obj
});
};
const previewImg = ref();
const loading = ref(false);
const priceType = ref(1);
let temp = [];
const defaultVariant = ref();
const myAttributeValue = ref([]);
const myAttributes = ref([]);
const mediaFilesUrl = ref([]);
const original = ref({ url: void 0, index: 0 });
const originalFile = ref();
ref();
const items = ref([]);
const variants = ref([]);
const selectedFeatures = ref([]);
const featureItems = ref([]);
const formFields = reactive(
{
title_fa: "",
title: "",
price: 0,
body: "",
is_show: true,
is_active: true,
box_size: 0,
sell_type: "numeric",
original_image: void 0,
product_attributes: [],
files: [],
price_type: "manual",
auto_calculate: false,
sku: null,
created_at: void 0,
updated_at: void 0,
deleted_at: null,
count_order: void 0,
count_fav: void 0,
count_view: void 0,
min_price: void 0,
max_price: void 0,
type: "simple",
owner_id: void 0,
users: void 0,
saved: [],
variants: [],
code: void 0,
brand_id: void 0,
// brand: undefined,
collection_id: void 0,
discount: void 0,
discount_type: void 0,
// main_slider: false,
// bottom_slider: false,
id: void 0,
count: void 0,
display_price: void 0,
// weight: null,
meta: void 0,
seo_title: void 0,
description: void 0,
product_type: void 0,
weight: void 0,
rial_fee: void 0,
percent_fee: void 0
}
);
const baseFormFields = cloneDeep(formFields);
function resetFormFields() {
Object.assign(formFields, baseFormFields);
myAttributes.value = [];
myAttributeValue.value = [];
variants.value = [];
priceType.value = 1;
original.value = { url: void 0, index: 0 };
mediaFilesUrl.value = [];
defaultVariant.value = void 0;
previewImg.value = void 0;
}
const files = computed(() => {
let tempMedia = cloneDeep(mediaFilesUrl.value);
tempMedia == null ? void 0 : tempMedia.splice(0, 0, original.value);
tempMedia = tempMedia == null ? void 0 : tempMedia.map((value, index) => {
return value;
});
console.log(tempMedia);
return tempMedia;
});
function addToVariants() {
var _a, _b;
let attrIds = [];
let attrNames = [];
(_a = myAttributeValue.value) == null ? void 0 : _a.forEach((attributeValue) => {
if (!attributeValue.valueId) ;
attrIds.push(attributeValue.valueId);
attrNames.push(attributeValue.valueName);
});
console.log(attrIds, myAttributeValue.value);
(_b = formFields.variants) == null ? void 0 : _b.push({
id: void 0,
attribute_values: [],
attribute_values_name: [],
price: 0,
weight: 0,
stock: 0,
auto_calculate: false,
discount_type: void 0,
discount: void 0,
is_default: false,
sku: ""
});
}
function updateMyAttrs(newValue, flag) {
if (flag == 1) {
return;
}
let tempAttributes = newValue;
priceType.value = 1;
myAttributes.value = [];
myAttributeValue.value = [];
console.log(newValue);
console.log("why");
let tempIndex = 0;
let tempIndexArray = [];
newValue == null ? void 0 : newValue.forEach((x, index) => {
var _a, _b, _c;
console.log(x, index);
if (x.show_in_variable) {
priceType.value = 2;
if (formFields.variants.length === 0) addToVariants();
myAttributes.value.push({
attributeId: x.id,
name: x.name,
values: x.new_feature,
show: x.show_in_variable,
valueKey: index
});
(_a = x.new_feature) == null ? void 0 : _a.forEach((val, i) => {
myAttributeValue.value.push({
attributeName: x.name,
attributeId: x.id,
valueId: val.id,
valueName: val.value,
valueKey: tempIndex
});
});
} else {
(_b = variants.value) == null ? void 0 : _b.forEach((val) => {
console.log("val.attribute_values>", index);
console.log(val.attribute_values);
console.log("myAttributes.value.length " + tempAttributes.length);
console.log("val.attribute_values.length " + val.attribute_values.length);
if (tempAttributes.length > val.attribute_values.length && val.attribute_values[index] != null) {
if (val.attribute_values.length != index) {
val.attribute_values.splice(index, 0, null);
val.attribute_values_name.splice(index, 0, null);
} else {
val.attribute_values = [...val.attribute_values, null];
val.attribute_values_name = [...val.attribute_values_name, null];
}
}
console.log("val.attribute_values After slice>" + index);
console.log(val.attribute_values);
});
}
tempIndex++;
(_c = variants.value) == null ? void 0 : _c.forEach((val) => {
if (tempAttributes.length > val.attribute_values.length && val.attribute_values[index] != null) {
val.attribute_values = [...val.attribute_values, null];
val.attribute_values_name = [...val.attribute_values_name, null];
}
});
tempIndexArray.push(index);
console.log("variants+++");
});
console.log("tempIndexArray");
console.log(tempIndexArray);
sortAttributeByValueKey(variants.value);
}
function sortAttributeByValueKey(x) {
console.log("444444", x);
x == null ? void 0 : x.forEach((val, ind) => {
temp = cloneDeep(val.attribute_values);
if (myAttributes.value.length <= temp.length) {
temp == null ? void 0 : temp.forEach((x2, i) => {
var _a;
(_a = myAttributeValue.value) == null ? void 0 : _a.forEach((item, index) => {
if (temp.find((e) => e == (item == null ? void 0 : item.valueId)) && val.attribute_values[item.valueKey] != temp.find((e) => e == item.valueId)) {
val.attribute_values[item.valueKey] = temp.find((e) => e == item.valueId);
val.attribute_values_name[item.valueKey] = item.valueName;
}
console.log((val == null ? void 0 : val.attribute_values) + "AFTER CHANGE ITEM" + ind);
});
});
}
if (ind == 0) {
defaultVariant.value = showDefaultVal(val.attribute_values_name);
}
if (val.is_default) {
console.log("val.attribute_values", val.attribute_values_name);
defaultVariant.value = showDefaultVal(val.attribute_values_name);
console.log("defaultVariant", defaultVariant.value);
}
});
}
function showDefaultVal(val) {
console.log(val, defaultVariant.value);
let res = "";
val.forEach((x, index) => {
if (x) return res += (index !== 0 ? " - " : "") + x;
});
return res;
}
async function getFeatures() {
try {
loading.value = true;
featureItems.value = await getFeatureList();
} catch (e) {
console.log(e);
} finally {
loading.value = false;
}
}
async function setItems(new_features) {
let featureTemp;
if (new_features[new_features.length - 1] != null)
featureTemp = await getOneFeature(new_features[new_features.length - 1]);
let feature;
feature = featureTemp[0];
Object.assign(feature, {
new_feature: [],
show_in_product: false,
show_in_variable: false
});
items.value.push(feature);
}
async function editItems(id) {
var _a, _b;
const featureTemp = await getOneFeature(id);
const forEditAttribute = items.value.find((x) => x.id === id);
if (forEditAttribute) {
console.log(forEditAttribute.attribute_values, featureTemp[0].attribute_values);
forEditAttribute.attribute_values = [];
forEditAttribute.attribute_values = ((_a = featureTemp[0]) == null ? void 0 : _a.attribute_values) ? cloneDeep((_b = featureTemp[0]) == null ? void 0 : _b.attribute_values) : [];
console.log(forEditAttribute.attribute_values);
}
}
const findEdit = (val) => {
console.log("fsdfuygiuhguighuisdf", val);
return val.split("-")[0] === "edit";
};
const firstFiles = ref([]);
ref([]);
export { files as a, setItems as b, formFields as c, findEdit as d, priceType as e, firstFiles as f, addToVariants as g, myAttributes as h, items as i, featureItems as j, getFeatures as k, createFeature as l, mediaFilesUrl as m, createFeatureAttribute as n, original as o, previewImg as p, editItems as q, resetFormFields as r, selectedFeatures as s, loading as t, updateMyAttrs as u, variants as v, originalFile as w };
//# sourceMappingURL=handle-C_30e_aJ.mjs.map