added setting for users

This commit is contained in:
2026-08-16 22:00:48 +03:30
parent 84b0a4767a
commit 17dea2a52f
13 changed files with 635 additions and 29 deletions
@@ -0,0 +1,170 @@
<template>
<a-form :model="form" ref="formRef" layout="vertical" class="space-y-3">
<a-form-item label="عنوان پکیج" name="title" :rules="[{ required: true, message: 'عنوان الزامی است' }]">
<BasicInput v-model:value="form.title" placeholder="مثلاً مشتریان VIP" />
</a-form-item>
<a-form-item label="گروه دسته‌بندی" name="category_names" :rules="[{ required: true, type: 'array', min: 1, message: 'دسته را انتخاب کنید' }]">
<BasicSelect
v-model:value="form.category_names"
:items="categoryItems"
valueName="value"
keyName="key"
mode="multiple"
class="w-full"
placeholder="یک یا چند دسته"
/>
</a-form-item>
<a-form-item label="محصول" name="product_ids" :rules="[{ required: true, type: 'array', min: 1, message: 'محصول را انتخاب کنید' }]">
<BasicSelect
v-model:value="form.product_ids"
:items="productItems"
valueName="title"
keyName="id"
mode="multiple"
class="w-full"
:disabled="!form.category_names?.length"
placeholder="ابتدا دسته را انتخاب کنید"
/>
</a-form-item>
<a-form-item label="لیست کاربران زیر مجموعه" name="customer_ids" :rules="[{ required: true, type: 'array', min: 1, message: 'کاربر را انتخاب کنید' }]">
<a-select
v-model:value="form.customer_ids"
mode="multiple"
class="w-full"
placeholder="جستجو نام یا شماره…"
show-search
:filter-option="false"
:options="customerOptions"
@search="onCustomerSearch"
/>
</a-form-item>
<div class="grid gap-3 md:grid-cols-2">
<a-form-item label="سود فروش" name="profit_sell">
<BasicInput v-model:value="form.profit_sell" type="price" addon-before="ریال" />
</a-form-item>
<a-form-item label="سود خرید" name="profit_buy">
<BasicInput v-model:value="form.profit_buy" type="price" addon-before="ریال" />
</a-form-item>
</div>
<a-form-item label="نمایش محصول">
<a-switch v-model:checked="form.show_product">
<template #checkedChildren>فعال</template>
<template #unCheckedChildren>مخفی</template>
</a-switch>
<p class="m-0 mt-1 text-xs text-gray-500">
خاموش = این محصولات برای کاربران پکیج در اپ مخفی می‌شوند.
</p>
</a-form-item>
<a-form-item label="وضعیت پکیج">
<a-switch v-model:checked="form.is_active">
<template #checkedChildren>فعال</template>
<template #unCheckedChildren>غیرفعال</template>
</a-switch>
</a-form-item>
</a-form>
</template>
<script setup lang="ts">
import type { FormInstance } from 'ant-design-vue'
import { debounce } from 'lodash'
import { onMounted, ref, watch } from 'vue'
import BasicInput from '@/components/BasicInput.vue'
import BasicSelect from '@/components/BasicSelect.vue'
import { syncAndLoadCategories, type CategorySelectItem } from '@/utils/categorySelect'
import {
getProductsByCategories,
searchSpecialPriceCustomers
} from '@/api/customerSpecialPrice'
export type SpecialPriceForm = {
title: string
category_names: string[]
product_ids: number[]
customer_ids: number[]
profit_buy: number | string
profit_sell: number | string
show_product: boolean
is_active: boolean
}
const props = defineProps<{
form: SpecialPriceForm
}>()
const formRef = ref<FormInstance>()
const categoryItems = ref<CategorySelectItem[]>([])
const productItems = ref<Array<{ id: number; title: string }>>([])
const customerOptions = ref<Array<{ value: number; label: string }>>([])
async function loadCategories() {
categoryItems.value = await syncAndLoadCategories({ selectOnly: true })
}
async function loadProducts() {
const names = props.form.category_names || []
if (!names.length) {
productItems.value = []
props.form.product_ids = []
return
}
const res: any = await getProductsByCategories(names)
const rows = res?.products ?? res?.data?.products ?? res ?? []
productItems.value = (Array.isArray(rows) ? rows : []).map((p: any) => ({
id: Number(p.id),
title: `${p.title || '-'} (${p.group_type || '-'})`
}))
const allowed = new Set(productItems.value.map((p) => p.id))
props.form.product_ids = (props.form.product_ids || []).filter((id) => allowed.has(Number(id)))
}
const onCustomerSearch = debounce(async (q: string) => {
const res: any = await searchSpecialPriceCustomers(q || '')
const rows = res?.customers ?? res?.data?.customers ?? []
const mapped = (Array.isArray(rows) ? rows : []).map((c: any) => ({
value: Number(c.id),
label: `${c.name || '-'} — ${c.mobile || ''} (#${c.id})`
}))
const selected = new Set((props.form.customer_ids || []).map(Number))
for (const item of customerOptions.value) {
if (selected.has(item.value) && !mapped.some((m) => m.value === item.value)) {
mapped.push(item)
}
}
customerOptions.value = mapped
}, 300)
watch(
() => [...(props.form.category_names || [])],
() => {
void loadProducts()
}
)
onMounted(async () => {
await loadCategories()
await loadProducts()
await onCustomerSearch('')
})
defineExpose({
validate: () => formRef.value?.validate(),
seedCustomers: (rows: Array<{ id: number; name?: string; mobile?: string }>) => {
customerOptions.value = rows.map((c) => ({
value: Number(c.id),
label: `${c.name || '-'} — ${c.mobile || ''} (#${c.id})`
}))
},
seedProducts: (rows: Array<{ id: number; title?: string; group_type?: string }>) => {
productItems.value = rows.map((p) => ({
id: Number(p.id),
title: `${p.title || '-'} (${p.group_type || '-'})`
}))
}
})
</script>
@@ -0,0 +1,74 @@
<template>
<div class="h-full min-h-0 min-w-0 max-w-full overflow-hidden">
<BasicShowContext title="پکیج‌های قیمت ویژه">
<template v-if="isMobile" #extra>
<BaseButton type="primary" size="small" icon="vuesax-linear:add" @click="emits('add')">
افزودن
</BaseButton>
</template>
<BaseTable v-bind="tblProps" @register="submit" class="h-full min-h-0">
<template #extraHeader>
<BaseButton type="primary" size="small" icon="vuesax-linear:add" @click="emits('add')">
افزودن پکیج
</BaseButton>
</template>
<template #action="{ record }">
<div class="flex items-center justify-center gap-2">
<a-tooltip placement="bottom" class="cursor-pointer" @click="emits('edit', record)">
<template #title><span>ویرایش</span></template>
<Icon icon="vuesax-linear:edit-2" color="#4572E9" />
</a-tooltip>
<a-tooltip placement="bottom" class="cursor-pointer" @click="emits('toggle', record)">
<template #title>
<span>{{ record.is_active ? 'غیرفعال کردن' : 'فعال کردن' }}</span>
</template>
<Icon
:icon="record.is_active ? 'vuesax-linear:toggle-on-circle' : 'vuesax-linear:toggle-off-circle'"
:color="record.is_active ? '#54AD06' : '#ad0627'"
/>
</a-tooltip>
<a-popconfirm
title="پکیج حذف شود؟"
ok-text="تایید"
cancel-text="انصراف"
@confirm="emits('delete', record)"
>
<a-tooltip placement="bottom" class="cursor-pointer">
<template #title><span>حذف</span></template>
<Icon icon="vuesax-linear:trash" color="#C53030" />
</a-tooltip>
</a-popconfirm>
</div>
</template>
</BaseTable>
</BasicShowContext>
</div>
</template>
<script setup lang="ts">
import type { TableInput } from '@core/type/baseTable'
import useBaseTable from '@core/components/BaseTable/hooks/useBaseTable'
import Icon from '@core/components/BaseIcon/src/Icon.vue'
import BasicShowContext from '@/components/BasicShowContext.vue'
import { getCustomerSpecialPricePackageTable } from '@/api/customerSpecialPrice'
import { getSpecialPricePackageColumns } from '../hooks/specialPriceColumns'
import { isMobile } from '@core/utils/is'
import { ref } from 'vue'
const emits = defineEmits<{
(e: 'add'): void
(e: 'edit', record: any): void
(e: 'toggle', record: any): void
(e: 'delete', record: any): void
}>()
const [submit, reload] = useBaseTable()
const tblProps = ref({
columns: getSpecialPricePackageColumns(),
api: (params: TableInput) => getCustomerSpecialPricePackageTable(params)
})
defineExpose({ fetch: reload })
</script>