diff --git a/src/api/category.ts b/src/api/category.ts index e2af07d..2d79984 100644 --- a/src/api/category.ts +++ b/src/api/category.ts @@ -10,6 +10,9 @@ export type CategoryListParams = { export const getCategories = async (params?: CategoryListParams) => await useAxios.get('/admin/categories', { params }) +export const createCategory = async (payload: CategoryInput) => + await useAxios.post('/admin/categories', payload) + export const updateCategory = async (id: number, payload: Partial) => await useAxios.put(`/admin/categories/${id}`, payload) diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue index 60e5ca1..95ae9d9 100644 --- a/src/pages/login/index.vue +++ b/src/pages/login/index.vue @@ -31,13 +31,11 @@ function enterTest() { .login-page__toggle { position: absolute; top: 16px; - left: 16px; + inset-inline-start: 16px; z-index: 1001; display: flex; align-items: center; - justify-content: center; - width: 40px; - height: 40px; + padding: 4px 10px 4px 6px; border-radius: 9999px; background: var(--admin-bg-elevated); border: 1px solid var(--admin-border); diff --git a/src/pages/menuPages/giftCards/components/GiftCardCodesSheet.vue b/src/pages/menuPages/giftCards/components/GiftCardCodesSheet.vue index 34d95cf..222afa5 100644 --- a/src/pages/menuPages/giftCards/components/GiftCardCodesSheet.vue +++ b/src/pages/menuPages/giftCards/components/GiftCardCodesSheet.vue @@ -11,7 +11,33 @@ @cancel="close" @close="close" > -
لیست کدهای کارت هدیه
+
+
+

+ {{ codes.length }} کد — دانلود به صورت اکسل یا PDF +

+
+ + + دانلود + + + +
+ + +

+ نام دسته را وارد کنید؛ بعد از ثبت در لیست پایین و سلکت افزودن محصول قابل استفاده است. +

+ + + + + + + + + + + +
@@ -66,14 +100,26 @@ import { message } from 'ant-design-vue' import type { TableColumnType } from 'ant-design-vue' import { useResizeObserver } from '@vueuse/core' import { debounce } from 'lodash' +import type { FormInstance } from 'ant-design-vue' import { onMounted, onUnmounted, ref } from 'vue' -import { getCategories, syncCategoriesFromProducts, updateCategory } from '@/api/category' +import { createCategory, getCategories, syncCategoriesFromProducts, updateCategory } from '@/api/category' import type { Category } from '@/model/category' import AdminFieldHelp from '@/components/AdminFieldHelp.vue' +import BasicActionSheet from '@/components/BasicActionSheet.vue' +import BasicInput from '@/components/BasicInput.vue' import { productsCategoriesPageIntro } from '@/utils/adminHelpCopy' +import { inputRules } from '@/utils/inputRules' const loading = ref(false) const syncing = ref(false) +const adding = ref(false) +const addVisible = ref(false) +const addFormRef = ref() +const addForm = ref({ + name: '', + active: true, + show_in_select: true, +}) const savingOrder = ref(false) const items = ref([]) const tableWrapRef = ref(null) @@ -400,6 +446,52 @@ async function handleSync() { await syncList(true) } +function resetAddForm() { + addForm.value = { + name: '', + active: true, + show_in_select: true, + } + addFormRef.value?.clearValidate?.() +} + +function openAddModal() { + resetAddForm() + addVisible.value = true +} + +function closeAddModal() { + addVisible.value = false +} + +async function submitAdd() { + try { + await addFormRef.value?.validateFields?.() + } catch { + return + } + + adding.value = true + try { + const created = await createCategory({ + name: addForm.value.name.trim(), + active: addForm.value.active ? 1 : 0, + show_in_select: addForm.value.show_in_select ? 1 : 0, + }) + items.value = [...items.value, created].sort( + (a, b) => (a.sort_order ?? 0) - (b.sort_order ?? 0) || a.id - b.id + ) + message.success('دسته‌بندی با موفقیت ثبت شد') + closeAddModal() + updateTableScrollY() + } catch (e: any) { + console.error(e) + message.error(e?.response?.data?.message || 'خطا در ثبت دسته‌بندی') + } finally { + adding.value = false + } +} + onMounted(() => { void fetchList() updateTableScrollY()