Ver código fonte

admin updates

master
unknown 9 meses atrás
pai
commit
5aaf00d66a
1 arquivos alterados com 22 adições e 45 exclusões
  1. +22
    -45
      src/views/live-preview/pages/discounts/editDiscount.vue

+ 22
- 45
src/views/live-preview/pages/discounts/editDiscount.vue Ver arquivo

@@ -137,11 +137,10 @@
<label class="form-label">محصول</label> <label class="form-label">محصول</label>
<VueSelect <VueSelect
style="--vs-min-height: 48px; --vs-border-radius: 8px" style="--vs-min-height: 48px; --vs-border-radius: 8px"
:isLoading="productSelectorLoader"
:isLoading="categorySelectorLoader"
v-model="selectedProduct" v-model="selectedProduct"
:options="formattedProducts" :options="formattedProducts"
placeholder="محصولی را انتخاب کنید " placeholder="محصولی را انتخاب کنید "
@search="handleProductSearch"
/> />
</div> </div>
<small v-if="errors.selectedProduct" class="text-danger"> <small v-if="errors.selectedProduct" class="text-danger">
@@ -225,17 +224,12 @@ export default {
}, },
setup() { setup() {
const route = useRoute(); const route = useRoute();
const productSelectorLoader = ref(false);
const title = ref(); const title = ref();
const discountType = ref(); const discountType = ref();
const amount = ref(); const amount = ref();
const minOrder = ref(); const minOrder = ref();
const selectedCat = ref(); const selectedCat = ref();
const selectedProduct = ref({
value: 'product-id-123', // Example selected product ID
label: 'Amazing Product', // Example selected product label
});

const selectedProduct = ref();
const startDate = ref(); const startDate = ref();
const expire = ref(); const expire = ref();
const maxUsage = ref(); const maxUsage = ref();
@@ -255,39 +249,14 @@ export default {
: [] : []
); );


const handleProductSearch = async (searchTerm) => {
if (searchTerm.length < 3) return;
productSelectorLoader.value = true;
try {
const response = await ApiServiece.get(
`admin/products?title=${searchTerm}`
);
products.value = response.data.data;
productSelectorLoader.value = false;
} catch (error) {
productSelectorLoader.value = false;
products.value = [];
}
};

const formattedProducts = computed(() => {
// If products are available, map them to options
if (Array.isArray(products.value) && products.value.length > 0) {
return products.value.map((product) => ({
value: product.id,
label: product.title,
}));
}

// If no products are available, show a placeholder option
return [
{
value: "",
label: "برای جستجو شروع به تایپ کنید...",
disabled: true,
},
];
});
const formattedProducts = computed(() =>
Array.isArray(products.value)
? products.value.map((product) => ({
value: product.id,
label: product.title,
}))
: []
);


const getCats = () => { const getCats = () => {
ApiServiece.get(`admin/categories`) ApiServiece.get(`admin/categories`)
@@ -299,6 +268,16 @@ export default {
}); });
}; };


const getProduct = () => {
ApiServiece.get(`admin/products`)
.then((resp) => {
products.value = resp.data.data;
})
.catch((err) => {
console.log(err);
});
};

const getDiscount = () => { const getDiscount = () => {
ApiServiece.get(`admin/discounts/${route.params.id}`) ApiServiece.get(`admin/discounts/${route.params.id}`)
.then((resp) => { .then((resp) => {
@@ -316,9 +295,9 @@ export default {
whichPart.value = "all"; whichPart.value = "all";
} }


selectedProduct.value = discount.value.product_id;
if (discount.value.product_id) { if (discount.value.product_id) {
whichPart.value = "product"; whichPart.value = "product";
} }


if (discount?.value.starts_at) { if (discount?.value.starts_at) {
@@ -389,7 +368,7 @@ export default {


onMounted(() => { onMounted(() => {
getCats(); getCats();
getProduct();
getDiscount(); getDiscount();
}); });


@@ -473,8 +452,6 @@ export default {
loading, loading,
formattedCategories, formattedCategories,
formattedProducts, formattedProducts,
handleProductSearch,
productSelectorLoader,
}; };
}, },
}; };


Carregando…
Cancelar
Salvar