| @@ -137,11 +137,10 @@ | |||
| <label class="form-label">محصول</label> | |||
| <VueSelect | |||
| style="--vs-min-height: 48px; --vs-border-radius: 8px" | |||
| :isLoading="productSelectorLoader" | |||
| :isLoading="categorySelectorLoader" | |||
| v-model="selectedProduct" | |||
| :options="formattedProducts" | |||
| placeholder="محصولی را انتخاب کنید " | |||
| @search="handleProductSearch" | |||
| /> | |||
| </div> | |||
| <small v-if="errors.selectedProduct" class="text-danger"> | |||
| @@ -225,17 +224,12 @@ export default { | |||
| }, | |||
| setup() { | |||
| const route = useRoute(); | |||
| const productSelectorLoader = ref(false); | |||
| const title = ref(); | |||
| const discountType = ref(); | |||
| const amount = ref(); | |||
| const minOrder = 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 expire = 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 = () => { | |||
| 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 = () => { | |||
| ApiServiece.get(`admin/discounts/${route.params.id}`) | |||
| .then((resp) => { | |||
| @@ -316,9 +295,9 @@ export default { | |||
| whichPart.value = "all"; | |||
| } | |||
| selectedProduct.value = discount.value.product_id; | |||
| if (discount.value.product_id) { | |||
| whichPart.value = "product"; | |||
| } | |||
| if (discount?.value.starts_at) { | |||
| @@ -389,7 +368,7 @@ export default { | |||
| onMounted(() => { | |||
| getCats(); | |||
| getProduct(); | |||
| getDiscount(); | |||
| }); | |||
| @@ -473,8 +452,6 @@ export default { | |||
| loading, | |||
| formattedCategories, | |||
| formattedProducts, | |||
| handleProductSearch, | |||
| productSelectorLoader, | |||
| }; | |||
| }, | |||
| }; | |||