Files
boursecu_admin/src/pages/menuPages/accounting/components/tahesabTable.vue
T

188 lines
6.5 KiB
Vue
Raw Normal View History

2026-06-26 17:41:52 +03:30
<template>
<div class="min-w-0 w-full max-w-full overflow-x-hidden">
<BasicShowContext title="اسناد ته‌حساب">
<div v-if="!isMobile" class="min-w-0 w-full max-w-full overflow-x-auto">
<BaseTable v-bind="tblProps" @register="submit" ref="tbl">
<template #action="{ record }">
<div class="flex justify-center gap-2">
2026-06-28 21:48:17 +03:30
<!-- دکمه ۱: اطلاعات کلی (همیشه نمایان) -->
<a-tooltip placement="bottom" class="cursor-pointer" @click="openInfo(record)">
<template #title><span>اطلاعات سند</span></template>
2026-06-26 17:41:52 +03:30
<Icon icon="vuesax-linear:stickynote" color="#10913A" />
</a-tooltip>
2026-06-28 21:48:17 +03:30
<!-- دکمه ۲: ثبت مشتری در ته‌حساب (فقط اگر سند هنوز ثبت نشده و مشتری کد ندارد) -->
2026-06-26 17:41:52 +03:30
<a-tooltip
2026-06-28 21:48:17 +03:30
v-if="!record.tahesab_id && !record.customer?.moshtari_code"
2026-06-26 17:41:52 +03:30
placement="bottom"
class="cursor-pointer"
2026-06-28 21:48:17 +03:30
@click="openRegister(record)"
>
<template #title><span>ثبت مشتری در ته‌حساب</span></template>
<Icon icon="vuesax-linear:profile-add" color="#7C3AED" />
</a-tooltip>
<!-- دکمه ۳: ارسال به ته‌حساب (فقط اگر هنوز در ته‌حساب ثبت نشده) -->
<a-tooltip
v-if="!record.tahesab_id"
placement="bottom"
class="cursor-pointer"
@click="openSend(record)"
2026-06-26 17:41:52 +03:30
>
<template #title><span>ارسال به ته‌حساب</span></template>
2026-06-28 21:48:17 +03:30
<Icon icon="vuesax-linear:send-2" color="#CA8A04" />
2026-06-26 17:41:52 +03:30
</a-tooltip>
2026-06-28 21:48:17 +03:30
2026-06-26 17:41:52 +03:30
</div>
</template>
</BaseTable>
</div>
2026-06-28 21:48:17 +03:30
<TahesabMobileCardList v-else ref="mobileListRef" />
2026-06-26 17:41:52 +03:30
</BasicShowContext>
2026-06-28 21:48:17 +03:30
<!-- مودال اطلاعات کلی -->
<BasicModal v-model:visible="infoVisible" title="اطلاعات سند" width="36rem" :footer="null">
2026-06-26 17:41:52 +03:30
<div class="space-y-2 text-sm">
2026-06-28 21:48:17 +03:30
<div
v-for="item in infoItems"
:key="item.label"
class="flex justify-between gap-3 border-b border-gray-100 py-2"
>
2026-06-26 17:41:52 +03:30
<span class="text-gray-500">{{ item.label }}</span>
<span class="break-all text-left">{{ item.value ?? '-' }}</span>
</div>
2026-06-28 21:48:17 +03:30
<div v-if="selected?.res" class="rounded-lg bg-gray-100 p-3 text-xs font-mono text-gray-700 whitespace-pre-wrap">
{{ selected.res }}
</div>
2026-06-26 17:41:52 +03:30
<div v-if="selected?.sync_log" class="rounded-lg bg-red-50 p-3 text-red-700 whitespace-pre-wrap">
{{ selected.sync_log }}
</div>
</div>
</BasicModal>
2026-06-28 21:48:17 +03:30
<!-- مودال ارسال به ته‌حساب -->
2026-06-26 17:41:52 +03:30
<TahesabRetryModal
2026-06-28 21:48:17 +03:30
v-model="sendVisible"
2026-06-26 17:41:52 +03:30
mode="retry-sanad"
:tahesab-id="selected?.id"
@success="fetch"
/>
2026-06-28 21:48:17 +03:30
<!-- مودال ثبت مشتری در ته‌حساب -->
<TahesabRetryModal
v-model="registerVisible"
mode="register-customer"
:customer-id="selected?.customer_id"
:customer-name="selected?.customer?.name"
@success="fetch"
/>
2026-06-26 17:41:52 +03:30
</div>
</template>
<script setup lang="ts">
import { computed, ref } from 'vue'
import useBaseTable from '@core/components/BaseTable/hooks/useBaseTable'
import type { TableInput } from '@core/type/baseTable'
import { getTahesabTable, type TahesabRecord } from '@/api/tahesab'
import Icon from '@core/components/BaseIcon/src/Icon.vue'
import { isMobile } from '@core/utils/is'
import BasicModal from '@/components/BasicModal.vue'
import TahesabRetryModal from '@/components/TahesabRetryModal.vue'
2026-06-28 21:48:17 +03:30
import TahesabMobileCardList from '@/pages/menuPages/accounting/components/TahesabMobileCardList.vue'
import { tahesabStatusLabel } from '@/pages/menuPages/accounting/utils/tahesabStatus'
2026-06-26 17:41:52 +03:30
import { toJalali } from '@core/utils/useDataTime'
const [submit, reload] = useBaseTable()
2026-06-28 21:48:17 +03:30
const mobileListRef = ref<null | { fetch: () => Promise<void> }>(null)
const infoVisible = ref(false)
const sendVisible = ref(false)
const registerVisible = ref(false)
2026-06-26 17:41:52 +03:30
const selected = ref<TahesabRecord | null>(null)
const columns = [
2026-06-28 21:48:17 +03:30
{
title: 'ردیف',
dataIndex: 'id',
key: 'id',
filterable: false,
sortable: false,
customRender: (r: any) => r.index + 1
},
2026-06-26 17:41:52 +03:30
{ title: 'مشتری', dataIndex: 'customer.name', key: 'customer.name', type: 'Text' },
{ title: 'نوع', dataIndex: 'type', key: 'type', type: 'Text' },
{ title: 'مقدار', dataIndex: 'amount', key: 'amount', type: 'Number' },
{ title: 'شرح', dataIndex: 'desc', key: 'desc', type: 'Text' },
{
title: 'وضعیت',
dataIndex: 'sync_status',
key: 'sync_status',
type: 'Text',
2026-06-28 21:48:17 +03:30
filterable: false,
customRender: (r: any) => tahesabStatusLabel(r.record.sync_status, r.record.tahesab_id)
2026-06-26 17:41:52 +03:30
},
{
title: 'زمان',
dataIndex: 'created_at',
key: 'created_at',
type: 'Text',
customRender: (r: any) => toJalali(r.record.created_at)
},
2026-06-28 21:48:17 +03:30
{
title: 'عملیات',
dataIndex: 'action',
key: 'action',
slot: 'action',
filterable: false
}
2026-06-26 17:41:52 +03:30
]
const tblProps = ref({
columns,
api: (params: TableInput) => getTahesabTable(params)
})
2026-06-28 21:48:17 +03:30
/** اطلاعاتی که برای هر سند حسابداری نیاز است (بدون جزئیات ته‌حساب‌محور) */
const infoItems = computed(() => {
2026-06-26 17:41:52 +03:30
const row = selected.value
if (!row) return []
return [
2026-06-28 21:48:17 +03:30
{ label: 'شناسه سند', value: row.id },
2026-06-26 17:41:52 +03:30
{ label: 'مشتری', value: row.customer?.name },
{ label: 'موبایل', value: row.customer?.mobile },
{ label: 'نوع', value: row.type },
{ label: 'مقدار', value: row.amount },
{ label: 'شرح', value: row.desc },
2026-06-28 21:48:17 +03:30
{ label: 'زمان ثبت', value: row.created_at ? toJalali(row.created_at) : '-' },
{ label: 'وضعیت', value: tahesabStatusLabel(row.sync_status, row.tahesab_id) },
{ label: 'کد ته‌حساب', value: row.tahesab_id || 'ثبت نشده' }
2026-06-26 17:41:52 +03:30
]
})
2026-06-28 21:48:17 +03:30
function openInfo(record: TahesabRecord) {
2026-06-26 17:41:52 +03:30
selected.value = record
2026-06-28 21:48:17 +03:30
infoVisible.value = true
2026-06-26 17:41:52 +03:30
}
2026-06-28 21:48:17 +03:30
function openSend(record: TahesabRecord) {
2026-06-26 17:41:52 +03:30
selected.value = record
2026-06-28 21:48:17 +03:30
sendVisible.value = true
}
function openRegister(record: TahesabRecord) {
selected.value = record
registerVisible.value = true
2026-06-26 17:41:52 +03:30
}
async function fetch() {
2026-06-28 21:48:17 +03:30
if (isMobile.value) {
await mobileListRef.value?.fetch?.()
return
}
2026-06-26 17:41:52 +03:30
await reload()
}
defineExpose({ fetch })
</script>