fix some bugs from accounting 3
This commit is contained in:
@@ -6,6 +6,7 @@ export interface AppNotification {
|
||||
body: string
|
||||
severity: 'info' | 'success' | 'warning' | 'danger'
|
||||
is_active: boolean
|
||||
is_system?: boolean
|
||||
created_by?: number | null
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
@@ -18,6 +19,17 @@ export interface AppNotification {
|
||||
customer_ids?: number[]
|
||||
}
|
||||
|
||||
export type AppNotificationSourceFilter = 'all' | 'admin' | 'system'
|
||||
|
||||
export const APP_NOTIFICATION_SOURCE_TABS: Array<{
|
||||
value: AppNotificationSourceFilter
|
||||
label: string
|
||||
}> = [
|
||||
{ value: 'all', label: 'همه' },
|
||||
{ value: 'admin', label: 'اعلان ادمین' },
|
||||
{ value: 'system', label: 'سیستمی' },
|
||||
]
|
||||
|
||||
export const APP_NOTIFICATION_SEVERITIES = [
|
||||
{ value: 'info', label: 'اطلاعات (info)' },
|
||||
{ value: 'success', label: 'موفق (success)' },
|
||||
|
||||
@@ -2,9 +2,23 @@
|
||||
<div>
|
||||
<BasicShowContext title="اعلانهای اپ">
|
||||
<template #extra>
|
||||
<div class="flex items-center gap-2">
|
||||
<div class="flex items-center gap-2 flex-wrap">
|
||||
<a-radio-group
|
||||
v-model:value="sourceFilter"
|
||||
button-style="solid"
|
||||
size="small"
|
||||
@change="onSourceChange"
|
||||
>
|
||||
<a-radio-button
|
||||
v-for="tab in sourceTabs"
|
||||
:key="tab.value"
|
||||
:value="tab.value"
|
||||
>
|
||||
{{ tab.label }}
|
||||
</a-radio-button>
|
||||
</a-radio-group>
|
||||
<AdminFieldHelp
|
||||
text="اعلان را برای همه، گروه (مثلاً کسانی که مدتی نیامدهاند) یا مشتری تکی بفرستید. کاربران آنلاین از طریق اتصال زنده اپ، بلافاصله بج اعلان را میبینند."
|
||||
text="اعلان ادمین را دستی میفرستید؛ اعلان سیستمی خودکار برای خرید/فروش/واریز/برداشت ساخته میشود. از تبها برای جدا کردن لیست استفاده کنید."
|
||||
/>
|
||||
<BaseButton type="primary" size="small" @click="emits('add')">
|
||||
<span>افزودن اعلان</span>
|
||||
@@ -34,7 +48,7 @@
|
||||
@click="emits('readers', record)"
|
||||
/>
|
||||
</a-tooltip>
|
||||
<a-tooltip placement="bottom">
|
||||
<a-tooltip v-if="!isSystemRecord(record)" placement="bottom">
|
||||
<template #title>ویرایش</template>
|
||||
<Icon
|
||||
icon="vuesax-linear:edit"
|
||||
@@ -69,15 +83,23 @@
|
||||
</template>
|
||||
|
||||
<script lang="tsx" setup>
|
||||
import { computed, ref } from 'vue'
|
||||
import type { TableInput } from '@core/type/baseTable'
|
||||
import useBaseTable from '@core/components/BaseTableOld/hooks/useBaseTable'
|
||||
import Icon from '@core/components/BaseIcon/src/Icon.vue'
|
||||
import { cols } from '../hooks/appNotificationsColumns'
|
||||
import { getAppNotificationsTable } from '@/api/appNotifications'
|
||||
import AdminFieldHelp from '@/components/AdminFieldHelp.vue'
|
||||
import {
|
||||
APP_NOTIFICATION_SOURCE_TABS,
|
||||
type AppNotificationSourceFilter,
|
||||
} from '@/model/appNotifications'
|
||||
|
||||
const [submit, reload] = useBaseTable()
|
||||
|
||||
const sourceFilter = ref<AppNotificationSourceFilter>('all')
|
||||
const sourceTabs = APP_NOTIFICATION_SOURCE_TABS
|
||||
|
||||
const emits = defineEmits<{
|
||||
add: []
|
||||
edit: [record: Record<string, unknown>]
|
||||
@@ -87,9 +109,23 @@ const emits = defineEmits<{
|
||||
recipients: [record: Record<string, unknown>]
|
||||
}>()
|
||||
|
||||
const tblProps = {
|
||||
function isSystemRecord(record: Record<string, unknown>) {
|
||||
if (typeof record.is_system === 'boolean') return record.is_system
|
||||
const label = String(record.audience_label || '')
|
||||
return record.created_by == null && label.startsWith('سیستمی')
|
||||
}
|
||||
|
||||
const tblProps = computed(() => ({
|
||||
columns: cols,
|
||||
api: (params: TableInput) => getAppNotificationsTable(params),
|
||||
api: (params: TableInput) =>
|
||||
getAppNotificationsTable({
|
||||
...params,
|
||||
source: sourceFilter.value,
|
||||
} as TableInput & { source: AppNotificationSourceFilter }),
|
||||
}))
|
||||
|
||||
function onSourceChange() {
|
||||
reload()
|
||||
}
|
||||
|
||||
function fetch() {
|
||||
|
||||
@@ -28,6 +28,22 @@ const audienceTypeColor: Record<string, string> = {
|
||||
customers: 'gold',
|
||||
}
|
||||
|
||||
function isSystemRow(record: any): boolean {
|
||||
if (typeof record?.is_system === 'boolean') return record.is_system
|
||||
if (record?.created_by == null && String(record?.audience_label || '').startsWith('سیستمی')) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function audienceDisplayLabel(record: any): string {
|
||||
const raw = String(record.audience_label || 'همه کاربران')
|
||||
if (isSystemRow(record)) {
|
||||
return raw.replace(/^سیستمی\s*[—\-–]\s*/, '') || raw
|
||||
}
|
||||
return raw
|
||||
}
|
||||
|
||||
export const cols: BaseTableColumn[] = [
|
||||
{
|
||||
title: 'ردیف',
|
||||
@@ -35,6 +51,17 @@ export const cols: BaseTableColumn[] = [
|
||||
key: 'id',
|
||||
customRender: (record: any) => record.index + 1,
|
||||
},
|
||||
{
|
||||
title: 'منبع',
|
||||
dataIndex: 'is_system',
|
||||
key: 'is_system',
|
||||
width: 110,
|
||||
customRender: ({ record }) => (
|
||||
<CustomTag color={isSystemRow(record) ? 'default' : 'geekblue'}>
|
||||
{isSystemRow(record) ? 'سیستمی' : 'ادمین'}
|
||||
</CustomTag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: 'عنوان',
|
||||
dataIndex: 'title',
|
||||
@@ -56,7 +83,7 @@ export const cols: BaseTableColumn[] = [
|
||||
dataIndex: 'audience_label',
|
||||
key: 'audience_label',
|
||||
customRender: ({ record }) => {
|
||||
const label = record.audience_label || 'همه کاربران'
|
||||
const label = audienceDisplayLabel(record)
|
||||
const count =
|
||||
record.audience_type && record.audience_type !== 'all'
|
||||
? ` (${Number(record.recipients_count ?? 0)} نفر)`
|
||||
|
||||
@@ -192,6 +192,10 @@ function openAdd() {
|
||||
}
|
||||
|
||||
function openEdit(record: AppNotification) {
|
||||
if (record.is_system) {
|
||||
message.warning('اعلان سیستمی قابل ویرایش نیست')
|
||||
return
|
||||
}
|
||||
editId.value = record.id
|
||||
form.value = cloneDeep({
|
||||
title: record.title,
|
||||
|
||||
Reference in New Issue
Block a user