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

@@ -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 символов.";