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

254 lines
9.4 KiB
Vue
Raw Normal View History

2026-07-05 16:41:45 +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">
<!-- دکمه ۱: اطلاعات کلی (همیشه نمایان) -->
<a-tooltip placement="bottom" class="cursor-pointer" @click="openInfo(record)">
<template #title><span>اطلاعات سند</span></template>
<Icon icon="vuesax-linear:stickynote" color="#10913A" />
</a-tooltip>
<!-- دکمه ۲: ثبت مشتری در پرگار (فقط اگر سند هنوز ثبت نشده و مشتری کد ندارد) -->
<a-tooltip
2026-07-20 15:49:53 +03:30
v-if="canRetryPargar(record) && !record.customer?.pargar_account_id"
2026-07-05 16:41:45 +03:30
placement="bottom"
class="cursor-pointer"
@click="openRegister(record)"
>
<template #title><span>ثبت مشتری در پرگار</span></template>
<Icon icon="vuesax-linear:profile-add" color="#7C3AED" />
</a-tooltip>
<!-- دکمه ۳: ارسال به پرگار (فقط اگر هنوز در پرگار ثبت نشده) -->
<a-tooltip
2026-07-20 15:49:53 +03:30
v-if="canRetryPargar(record)"
2026-07-05 16:41:45 +03:30
placement="bottom"
class="cursor-pointer"
@click="openSend(record)"
>
<template #title><span>ارسال به پرگار</span></template>
<Icon icon="vuesax-linear:send-2" color="#CA8A04" />
</a-tooltip>
</div>
</template>
</BaseTable>
</div>
<PargarMobileCardList v-else ref="mobileListRef" />
</BasicShowContext>
<!-- مودال اطلاعات کلی -->
<BasicModal v-model:visible="infoVisible" title="اطلاعات سند" width="36rem" :footer="null">
<div class="space-y-2 text-sm">
<div
v-for="item in infoItems"
:key="item.label"
class="flex justify-between gap-3 border-b border-gray-100 py-2"
>
<span class="text-gray-500">{{ item.label }}</span>
<span class="break-all text-left">{{ item.value ?? '-' }}</span>
</div>
<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-07-21 12:35:45 +03:30
<div v-if="parsedPayload?.transactions.length" class="space-y-2">
<div class="text-sm font-600 text-gray-700">جزئیات اسناد دریافتی از پرگار</div>
<div
v-for="(tx, idx) in parsedPayload.transactions"
:key="idx"
class="rounded-lg border border-gray-100 bg-gray-50 p-3 text-xs space-y-1"
>
<div class="flex justify-between gap-2">
<span class="text-gray-500">شرح</span>
<span class="text-left">{{ tx.desc || tx.docType || '-' }}</span>
</div>
<div class="flex justify-between gap-2">
<span class="text-gray-500">تاریخ</span>
<span class="text-left">{{ tx.date || '-' }}</span>
</div>
<div class="flex justify-between gap-2">
<span class="text-gray-500">شماره سند</span>
<span class="text-left">{{ tx.docId || '-' }}</span>
</div>
<div class="flex justify-between gap-2">
<span class="text-gray-500">مبالغ</span>
<span class="text-left">{{ formatTransactionAmount(tx) }}</span>
</div>
<div v-if="tx.remainGold || tx.remainRial" class="flex justify-between gap-2">
<span class="text-gray-500">مانده</span>
<span class="text-left">
{{ tx.remainGold ? `${tx.remainGold} گرم` : '' }}
{{ tx.remainRial ? `${tx.remainRial} ریال` : '' }}
</span>
</div>
</div>
</div>
<div v-else-if="selected?.data" class="rounded-lg bg-gray-100 p-3 text-xs font-mono text-gray-700 whitespace-pre-wrap overflow-x-auto">
{{ selected.data }}
</div>
2026-07-05 16:41:45 +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>
<!-- مودال ارسال به پرگار -->
<PargarRetryModal
v-model="sendVisible"
mode="retry-sanad"
:pargar-id="selected?.id"
@success="fetch"
/>
<!-- مودال ثبت مشتری در پرگار -->
<PargarRetryModal
v-model="registerVisible"
mode="register-customer"
:customer-id="selected?.customer_id"
:customer-name="selected?.customer?.name"
@success="fetch"
/>
</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 { getPargarTable, type PargarRecord } from '@/api/pargar'
import Icon from '@core/components/BaseIcon/src/Icon.vue'
import { isMobile } from '@core/utils/is'
import BasicModal from '@/components/BasicModal.vue'
import PargarRetryModal from '@/components/PargarRetryModal.vue'
import PargarMobileCardList from '@/pages/menuPages/accounting/components/PargarMobileCardList.vue'
2026-07-20 15:49:53 +03:30
import { canRetryPargar, pargarStatusLabel } from '@/pages/menuPages/accounting/utils/pargarStatus'
2026-07-21 12:35:45 +03:30
import {
formatTransactionAmount,
parsePargarPayload,
pargarCustomerLabel,
pargarDescLabel,
2026-07-29 16:02:41 +03:30
pargarMetalAmountLabel,
pargarRialAmountLabel,
2026-07-21 12:35:45 +03:30
pargarTypeLabel
} from '@/pages/menuPages/accounting/utils/pargarDisplay'
2026-07-05 16:41:45 +03:30
import { toJalali } from '@core/utils/useDataTime'
const [submit, reload] = useBaseTable()
const mobileListRef = ref<null | { fetch: () => Promise<void> }>(null)
const infoVisible = ref(false)
const sendVisible = ref(false)
const registerVisible = ref(false)
const selected = ref<PargarRecord | null>(null)
const columns = [
{
title: 'ردیف',
dataIndex: 'id',
key: 'id',
filterable: false,
sortable: false,
customRender: (r: any) => r.index + 1
},
2026-07-21 12:35:45 +03:30
{ title: 'مشتری', dataIndex: 'customer.name', key: 'customer.name', type: 'Text', customRender: (r: any) => pargarCustomerLabel(r.record) },
{ title: 'نوع', dataIndex: 'type', key: 'type', type: 'Text', customRender: (r: any) => pargarTypeLabel(r.record.type) },
2026-07-29 16:02:41 +03:30
{
title: 'مقدار',
dataIndex: 'amount',
key: 'amount',
type: 'Number',
filterable: false,
customRender: (r: any) => pargarMetalAmountLabel(r.record),
},
{
title: 'مبلغ ریالی',
dataIndex: 'rial_amount',
key: 'rial_amount',
type: 'Text',
filterable: false,
sortable: false,
customRender: (r: any) => pargarRialAmountLabel(r.record),
},
2026-07-21 12:35:45 +03:30
{ title: 'شرح', dataIndex: 'desc', key: 'desc', type: 'Text', customRender: (r: any) => pargarDescLabel(r.record) },
2026-07-05 16:41:45 +03:30
{
title: 'وضعیت',
dataIndex: 'sync_status',
key: 'sync_status',
type: 'Text',
filterable: false,
2026-07-20 15:49:53 +03:30
customRender: (r: any) => pargarStatusLabel(r.record.sync_status, r.record.pargar_ref, r.record.desc)
2026-07-05 16:41:45 +03:30
},
{
title: 'زمان',
dataIndex: 'created_at',
key: 'created_at',
type: 'Text',
customRender: (r: any) => toJalali(r.record.created_at)
},
{
title: 'عملیات',
dataIndex: 'action',
key: 'action',
slot: 'action',
filterable: false
}
]
const tblProps = ref({
columns,
api: (params: TableInput) => getPargarTable(params)
})
2026-07-21 12:35:45 +03:30
/** اطلاعاتی که برای هر سند حسابداری نیاز است */
2026-07-05 16:41:45 +03:30
const infoItems = computed(() => {
const row = selected.value
if (!row) return []
2026-07-21 12:35:45 +03:30
const payload = parsePargarPayload(row.data)
2026-07-05 16:41:45 +03:30
return [
{ label: 'شناسه سند', value: row.id },
2026-07-21 12:35:45 +03:30
{ label: 'مشتری', value: pargarCustomerLabel(row) },
{ label: 'موبایل', value: row.customer?.mobile || '-' },
{ label: 'کد حساب پرگار', value: payload?.accountId || row.pargar_ref || '-' },
{ label: 'نوع', value: pargarTypeLabel(row.type) },
2026-07-29 16:02:41 +03:30
{ label: 'مقدار', value: pargarMetalAmountLabel(row) },
{ label: 'مبلغ ریالی', value: pargarRialAmountLabel(row) },
2026-07-21 12:35:45 +03:30
{ label: 'شرح', value: pargarDescLabel(row) },
{ label: 'تعداد سطر سند', value: payload?.transactions.length ? String(payload.transactions.length) : '-' },
2026-07-05 16:41:45 +03:30
{ label: 'زمان ثبت', value: row.created_at ? toJalali(row.created_at) : '-' },
2026-07-20 15:49:53 +03:30
{ label: 'وضعیت', value: pargarStatusLabel(row.sync_status, row.pargar_ref, row.desc) },
2026-07-05 16:41:45 +03:30
{ label: 'کد پرگار', value: row.pargar_ref || 'ثبت نشده' }
]
})
2026-07-21 12:35:45 +03:30
const parsedPayload = computed(() => parsePargarPayload(selected.value?.data))
2026-07-05 16:41:45 +03:30
function openInfo(record: PargarRecord) {
selected.value = record
infoVisible.value = true
}
function openSend(record: PargarRecord) {
selected.value = record
sendVisible.value = true
}
function openRegister(record: PargarRecord) {
selected.value = record
registerVisible.value = true
}
async function fetch() {
if (isMobile.value) {
await mobileListRef.value?.fetch?.()
return
}
await reload()
}
defineExpose({ fetch })
</script>