Files
boursecu_admin/src/pages/menuPages/automations/components/table.vue
T

122 lines
4.1 KiB
Vue
Raw Normal View History

2026-08-24 09:48:27 +03:30
<template>
<div class="h-full min-h-0 min-w-0 max-w-full overflow-hidden">
<BasicShowContext title="اتوماسیون">
<template #extra>
<BaseButton type="primary" size="small" icon="vuesax-linear:add" @click="emits('add')">
افزودن
</BaseButton>
</template>
<div v-if="isMobile" class="flex min-h-0 flex-1 flex-col gap-2 overflow-y-auto p-1">
<div
v-for="item in mobileItems"
:key="item.id"
class="flex flex-col gap-2 rounded-xl border border-solid border-gray-100 bg-white p-3 dark:border-slate-700 dark:bg-slate-800/40"
>
<div class="flex items-start justify-between gap-2">
<div class="min-w-0">
<div class="truncate font-bold text-slate-800 dark:text-slate-100">{{ item.name }}</div>
<div class="text-xs text-gray-500">{{ item.code }}</div>
</div>
<a-switch :checked="item.is_active" size="small" @change="emits('toggle', item)" />
</div>
<div class="line-clamp-2 text-sm text-slate-600 dark:text-slate-300">{{ item.body }}</div>
<div class="flex items-center justify-between text-xs text-gray-500">
<span>ارسال {{ Number(item.sent_count ?? 0) }} · ناموفق {{ Number(item.failed_count ?? 0) }}</span>
<div class="flex gap-3">
<Icon
icon="vuesax-linear:edit"
color="#4572E9"
class="cursor-pointer"
@click="emits('edit', item)"
/>
<Icon
icon="vuesax-linear:trash"
color="#C53030"
class="cursor-pointer"
@click="emits('delete', item.id)"
/>
</div>
</div>
</div>
<div v-if="!mobileLoading && mobileItems.length === 0" class="py-8 text-center text-gray-500">
اتوماسیونی نیست
</div>
</div>
<BaseTable v-else class="h-full min-h-0 min-w-0" v-bind="tblProps" @register="submit" ref="tbl">
<template #is_active="{ record }">
<a-switch :checked="record.is_active" size="small" @change="emits('toggle', record)" />
</template>
<template #action="{ record }">
<div class="flex justify-center gap-2">
<a-tooltip placement="bottom">
<template #title>ویرایش</template>
<Icon
icon="vuesax-linear:edit"
color="#4572E9"
class="cursor-pointer"
@click="emits('edit', record)"
/>
</a-tooltip>
<a-tooltip placement="bottom">
<template #title>حذف</template>
<Icon
icon="vuesax-linear:trash"
color="#C53030"
class="cursor-pointer"
@click="emits('delete', record.id)"
/>
</a-tooltip>
</div>
</template>
</BaseTable>
</BasicShowContext>
</div>
</template>
<script lang="tsx" setup>
import { onMounted, 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 { isMobile } from '@core/utils/is'
import { cols } from '../hooks/automationsColumns'
import { getAutomationsTable } from '@/api/automations'
import type { Automation } from '@/model/automations'
import { useMobileTableList } from '@/components/mobile/composables/useMobileTableList'
const [submit, reload] = useBaseTable()
const emits = defineEmits<{
add: []
edit: [record: Automation]
toggle: [record: Automation]
delete: [id: number]
}>()
const tblProps = {
columns: cols,
api: (params: TableInput) => getAutomationsTable(params),
}
const {
loading: mobileLoading,
items: mobileItems,
reload: reloadMobile,
} = useMobileTableList<Automation>({
fetchApi: getAutomationsTable,
})
onMounted(() => {
if (isMobile.value) reloadMobile()
})
function fetch() {
if (isMobile.value) reloadMobile()
else reload()
}
defineExpose({ fetch })
</script>