category qosishsh to'g'irlandi

This commit is contained in:
2026-04-29 13:40:10 +05:00
parent 0254b616a9
commit e1f79a58ec
6 changed files with 312 additions and 160 deletions

View File

@@ -793,7 +793,16 @@ export default {
.catch((error) => {
if (error.response) {
this.error = true;
this.errors = error.response.data.errors;
this.errors =
error.response.data.errors ||
error.response.data.details ||
[
[
error.response.data.error ||
error.response.data.message ||
"Server error",
],
];
}
});
},

View File

@@ -804,7 +804,16 @@ export default {
.catch((error) => {
if (error.response) {
this.error = true;
this.errors = error.response.data.errors;
this.errors =
error.response.data.errors ||
error.response.data.details ||
[
[
error.response.data.error ||
error.response.data.message ||
"Server error",
],
];
}
});
},

View File

@@ -63,51 +63,28 @@
<multiselect
:options="categories"
v-model="category.first"
v-model="category.path[0]"
label="category"
@change="
DetectCategory($event)
"
track-by="category"
@input="selectCategoryLevel(0)"
track-by="id"
></multiselect>
<!-- //@change="getCharacteristics($event)"-->
</div>
</div>
<div
class="col-4"
v-if="category.two_view"
v-for="level in categoryLevels"
:key="'category-level-' + level"
>
<div class="form-group">
<label>Суб категория *</label>
<multiselect
:options="
category.first.parents
"
v-model="category.two"
:options="categoryOptions(level)"
v-model="category.path[level]"
label="category"
@change="DetectCategoryTwo"
track-by="category"
></multiselect>
</div>
</div>
<div
class="col-4"
v-if="category.three_view"
>
<div class="form-group">
<label>Под категория *</label>
<multiselect
:options="
category.two.parents
"
v-model="category.three"
label="category"
@change="DetectCategory"
track-by="category"
@input="selectCategoryLevel(level)"
track-by="id"
></multiselect>
</div>
</div>
@@ -1074,6 +1051,22 @@ export default {
this.watch_count.three = 2;
},
"category.path": {
deep: true,
handler() {
const selected = this.lastSelectedCategory();
if (!selected) {
this.products.category_id = null;
this.characteristics = [];
return;
}
this.products.category_id = selected.id;
this.getCharacteristics(selected.id);
},
},
},
data: function () {
@@ -1106,6 +1099,7 @@ export default {
three: {},
two_view: false,
three_view: false,
path: [],
},
watch_count: {
@@ -1136,6 +1130,22 @@ export default {
}
},
computed: {
categoryLevels() {
const levels = [];
let current = this.category.path[0];
let level = 1;
while (current && current.parents && current.parents.length > 0) {
levels.push(level);
current = this.category.path[level];
level++;
}
return levels;
},
},
methods: {
getPosterPreview() {
if (this.products.poster instanceof File) {
@@ -1145,35 +1155,58 @@ export default {
},
setCategory() {
if (this.products.categories[0]) {
if (this.products.categories[0].parent) {
if (this.products.categories[0].parent.parent) {
this.category.two_view = true;
this.category.three_view = true;
this.products.category_id =
this.products.categories[0].id;
this.category.first =
this.products.categories[0].parent.parent;
this.category.two = this.products.categories[0].parent;
this.category.three = this.products.categories[0];
} else {
this.products.category_id =
this.products.categories[0].id;
this.category.first =
this.products.categories[0].parent;
this.category.two = this.products.categories[0];
this.category.two_view = true;
}
} else {
this.products.category_id = this.products.categories[0].id;
this.category.first = this.products.categories[0];
}
this.products.category_id = this.products.categories[0].id;
this.category.path = this.findCategoryPath(
this.categories,
this.products.categories[0].id
);
this.getCharacteristics(this.product.categories[0].id);
}
},
findCategoryPath(categories, id, path = []) {
for (const category of categories || []) {
const currentPath = [...path, category];
if (category.id === id) {
return currentPath;
}
const childPath = this.findCategoryPath(
category.parents || [],
id,
currentPath
);
if (childPath.length > 0) {
return childPath;
}
}
return [];
},
categoryOptions(level) {
const parent = this.category.path[level - 1];
return parent && parent.parents ? parent.parents : [];
},
selectCategoryLevel(level) {
this.category.path.splice(level + 1);
},
lastSelectedCategory() {
for (let i = this.category.path.length - 1; i >= 0; i--) {
if (this.category.path[i] && this.category.path[i].id) {
return this.category.path[i];
}
}
return null;
},
DetectCategory() {
this.category.two = {
parents: [],

View File

@@ -59,51 +59,28 @@
<multiselect
:options="categories"
v-model="category.first"
v-model="category.path[0]"
label="category"
@change="
DetectCategory($event)
"
track-by="category"
@input="selectCategoryLevel(0)"
track-by="id"
></multiselect>
<!-- //@change="getCharacteristics($event)"-->
</div>
</div>
<div
class="col-4"
v-if="category.two_view"
v-for="level in categoryLevels"
:key="'category-level-' + level"
>
<div class="form-group">
<label>Суб категория *</label>
<multiselect
:options="
category.first.parents
"
v-model="category.two"
:options="categoryOptions(level)"
v-model="category.path[level]"
label="category"
@change="DetectCategoryTwo"
track-by="category"
></multiselect>
</div>
</div>
<div
class="col-4"
v-if="category.three_view"
>
<div class="form-group">
<label>Под категория *</label>
<multiselect
:options="
category.two.parents
"
v-model="category.three"
label="category"
@change="DetectCategory"
track-by="category"
@input="selectCategoryLevel(level)"
track-by="id"
></multiselect>
</div>
</div>
@@ -1136,6 +1113,7 @@ export default {
three: {},
two_view: false,
three_view: false,
path: [],
},
characteristic: false,
@@ -1149,6 +1127,20 @@ export default {
uploadDisabled() {
return this.files.length === 0;
},
categoryLevels() {
const levels = [];
let current = this.category.path[0];
let level = 1;
while (current && current.parents && current.parents.length > 0) {
levels.push(level);
current = this.category.path[level];
level++;
}
return levels;
},
},
watch: {
@@ -1181,6 +1173,22 @@ export default {
this.DetectCategoryThree();
},
"category.path": {
deep: true,
handler() {
const selected = this.lastSelectedCategory();
if (!selected) {
this.product.category_id = null;
this.characteristics = [];
return;
}
this.product.category_id = selected.id;
this.getCharacteristics(selected.id);
},
},
},
methods: {
@@ -1312,11 +1320,37 @@ export default {
.catch((error) => {
if (error.response) {
this.error = true;
this.errors = error.response.data.errors;
this.errors = error.response.data.errors || {
product: [
error.response.data.messages ||
error.response.data.message ||
"Ошибка при сохранении",
],
};
}
});
},
categoryOptions(level) {
const parent = this.category.path[level - 1];
return parent && parent.parents ? parent.parents : [];
},
selectCategoryLevel(level) {
this.category.path.splice(level + 1);
},
lastSelectedCategory() {
for (let i = this.category.path.length - 1; i >= 0; i--) {
if (this.category.path[i] && this.category.path[i].id) {
return this.category.path[i];
}
}
return null;
},
remaincharRUCount: function () {
if (this.product.short_body.ru.length > 300) {
this.short_limit.ru = "Превышен лимит в 300 символов.";