255 lines
8.1 KiB
JavaScript
255 lines
8.1 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(false);
|
|
ref();
|
|
const items = ref([]);
|
|
const variants = ref([]);
|
|
const selectedFeatures = ref([]);
|
|
const featureItems = ref([]);
|
|
const formFields = reactive({
|
|
code: void 0,
|
|
title_fa: "",
|
|
title: "",
|
|
brand_id: void 0,
|
|
// brand: undefined,
|
|
collection_id: void 0,
|
|
price: 0,
|
|
body: "",
|
|
// image_ids: [],
|
|
discount: void 0,
|
|
discount_type: void 0,
|
|
// main_slider: false,
|
|
// bottom_slider: false,
|
|
is_show: true,
|
|
is_active: true,
|
|
// created_at: null,
|
|
// updated_at: null,
|
|
box_size: 0,
|
|
sell_type: "numeric",
|
|
// caj: '',
|
|
// original_image_id: null,
|
|
original_image: "",
|
|
count: void 0,
|
|
display_price: void 0,
|
|
// weight: null,
|
|
product_attributes: [],
|
|
// appearance: undefined,
|
|
meta: void 0,
|
|
seo_title: void 0,
|
|
description: void 0,
|
|
files: [],
|
|
variants: [],
|
|
product_type: void 0,
|
|
weight: void 0,
|
|
rial_fee: void 0,
|
|
percent_fee: void 0,
|
|
price_type: "manual",
|
|
auto_calculate: false
|
|
});
|
|
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("dddddaaawqqwqww");
|
|
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 firstFiles = ref([]);
|
|
ref([]);
|
|
|
|
export { firstFiles as a, setItems as b, formFields as c, priceType as d, addToVariants as e, files as f, myAttributes as g, featureItems as h, items as i, getFeatures as j, createFeature as k, createFeatureAttribute as l, mediaFilesUrl as m, editItems as n, original as o, previewImg as p, loading as q, originalFile as r, selectedFeatures as s, updateMyAttrs as u, variants as v };
|
|
//# sourceMappingURL=handle-DbjkEnGN.mjs.map
|