feat: add shayegan inbound charges tab and floating alert host

This commit is contained in:
2026-11-05 17:16:02 +03:30
parent 29904adf02
commit c9b7876734
7 changed files with 688 additions and 2 deletions
@@ -0,0 +1,346 @@
<template>
<div class="min-w-0 w-full max-w-full overflow-x-hidden">
<BasicShowContext title="واریزی‌های شایگان" :help="help">
<template #extra>
<div class="flex items-center gap-2">
<a-select
v-model:value="statusFilter"
size="small"
style="width: 140px"
placeholder="فیلتر وضعیت"
@change="reloadTable"
>
<a-select-option value="">همه وضعیت‌ها</a-select-option>
<a-select-option value="pending">در انتظار تایید</a-select-option>
<a-select-option value="approved">تایید شده</a-select-option>
<a-select-option value="rejected">رد شده</a-select-option>
</a-select>
<a-button
size="small"
type="primary"
:loading="syncLoading"
@click="runSyncFromShayegan"
>
استعلام از شایگان
</a-button>
<a-button size="small" @click="reloadTable">
بروزرسانی
</a-button>
</div>
</template>
<a-alert
v-if="syncMessage"
:type="syncOk ? 'success' : 'error'"
:message="syncMessage"
show-icon
closable
class="mb-3"
@close="syncMessage = ''"
/>
<div class="min-w-0 w-full max-w-full overflow-x-auto">
<BaseTable v-bind="tblProps" @register="submit">
<template #customer="{ record }">
<div class="flex flex-col">
<span class="font-medium text-gray-800">{{ customerLabel(record) }}</span>
<span class="text-xs text-gray-400" v-if="record.customer?.mobile">{{ record.customer.mobile }}</span>
<span class="text-[11px] text-gray-400" v-if="record.customer_tafsil || record.customer?.moshtari_code">
تفصیلی: {{ record.customer_tafsil || record.customer?.moshtari_code }}
</span>
</div>
</template>
<template #status="{ record }">
<a-tag :color="statusColor(record.status)">{{ statusLabel(record.status) }}</a-tag>
</template>
<template #ops="{ record }">
<div class="flex items-center justify-center gap-1.5" v-if="record.status === 'pending'">
<a-tooltip placement="bottom">
<template #title><span>تأیید و شارژ کیف پول در بورس مس</span></template>
<a-button
type="primary"
size="small"
class="!bg-emerald-600 !border-emerald-600 hover:!bg-emerald-700 !px-2"
:loading="actionLoadingId === record.id"
@click="handleApprove(record)"
>
تأیید واریزی
</a-button>
</a-tooltip>
<a-tooltip placement="bottom">
<template #title><span>رد درخواست</span></template>
<a-button
danger
size="small"
class="!px-2"
:disabled="actionLoadingId === record.id"
@click="handleReject(record)"
>
رد
</a-button>
</a-tooltip>
</div>
<div v-else class="text-xs text-gray-400 text-center">
<span v-if="record.status === 'approved'">
واریز شد
<div v-if="record.approver?.name" class="text-[11px] text-gray-500">
توسط {{ record.approver.name }}
</div>
</span>
<span v-else-if="record.status === 'rejected'">
رد شده
<div v-if="record.reject_reason" class="text-[11px] text-red-500">
{{ record.reject_reason }}
</div>
</span>
</div>
</template>
</BaseTable>
</div>
</BasicShowContext>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { message, Modal } from 'ant-design-vue'
import useBaseTable from '@core/components/BaseTable/hooks/useBaseTable'
import type { TableInput } from '@core/type/baseTable'
import { toJalali } from '@core/utils/useDataTime'
import { usePrice } from '@core/utils/usePrice'
import {
getShayeganChargesTable,
approveShayeganCharge,
rejectShayeganCharge,
syncShayeganCharges,
type ShayeganInboundChargeRecord
} from '@/api/shayegan'
const help =
'واریزی‌های ثبت شده در پنل حسابداری شایگان. با زدن دکمه «تأیید واریزی»، کیف پول ریالی مشتری در بورس مس شارژ خواهد شد.'
const [submit, reload] = useBaseTable()
const statusFilter = ref('')
const syncLoading = ref(false)
const syncOk = ref(false)
const syncMessage = ref('')
const actionLoadingId = ref<number | null>(null)
const columns = [
{ title: 'شناسه', dataIndex: 'id', key: 'id', width: 70, type: 'Number', filterable: false, sortable: false },
{
title: 'مشتری',
dataIndex: 'customer',
key: 'customer',
slot: 'customer',
type: 'Text'
},
{
title: 'مبلغ واریزی (ریال)',
dataIndex: 'amount',
key: 'amount',
type: 'Number',
filterable: false,
customRender: (r: any) => usePrice(r.record?.amount || 0, true, ' ریال')
},
{ title: 'شماره سند شایگان', dataIndex: 'shayegan_number', key: 'shayegan_number', type: 'Text' },
{ title: 'توضیحات', dataIndex: 'description', key: 'description', type: 'Text' },
{
title: 'منبع',
dataIndex: 'source',
key: 'source',
type: 'Text',
width: 90,
customRender: (r: any) => (r.record?.source === 'sync' ? 'استعلام' : 'وب‌هوک')
},
{
title: 'وضعیت',
dataIndex: 'status',
key: 'status',
slot: 'status',
type: 'Text',
width: 120
},
{
title: 'تاریخ دریافت',
dataIndex: 'created_at',
key: 'created_at',
type: 'DateTime',
filterable: false,
customRender: (r: any) => (r.record?.created_at ? toJalali(r.record.created_at) : '-')
},
{
title: 'عملیات',
dataIndex: 'ops',
key: 'ops',
slot: 'ops',
width: 150,
filterable: false,
sortable: false
}
]
function asTable(res: any, params: TableInput) {
if (res?.query) {
return {
rows: Array.isArray(res.rows) ? res.rows : [],
query: {
...params,
...res.query,
filters: res.query.filters ?? []
}
}
}
const rows = Array.isArray(res)
? res
: Array.isArray(res?.data)
? res.data
: Array.isArray(res?.rows)
? res.rows
: []
return {
rows,
query: {
page: Number(res?.current_page ?? params.page ?? 1),
limit: Number(res?.per_page ?? params.limit ?? 20),
total: Number(res?.total ?? rows.length),
filters: params.filters ?? [],
search: params.search ?? '',
select: params.select ?? []
}
}
}
const tblProps = {
columns,
defaultPageLimit: 20,
api: async (params: TableInput) => {
try {
const mergedParams = {
...params,
status: statusFilter.value || undefined
}
return asTable(await getShayeganChargesTable(mergedParams), params)
} catch (e: any) {
message.error(e?.message || 'خطا در دریافت لیست واریزی‌های شایگان')
throw e
}
}
}
function customerLabel(record?: ShayeganInboundChargeRecord) {
if (record?.customer?.name?.trim()) return record.customer.name.trim()
if (record?.customer?.fname || record?.customer?.lname) {
const fullName = `${record?.customer?.fname || ''} ${record?.customer?.lname || ''}`.trim()
if (fullName) return fullName
}
return '-'
}
function statusLabel(status?: string) {
switch (status) {
case 'approved':
return 'تأیید شده'
case 'rejected':
return 'رد شده'
case 'pending':
default:
return 'در انتظار تأیید'
}
}
function statusColor(status?: string) {
switch (status) {
case 'approved':
return 'green'
case 'rejected':
return 'red'
case 'pending':
default:
return 'orange'
}
}
function reloadTable() {
reload()
}
async function runSyncFromShayegan() {
syncLoading.value = true
syncMessage.value = ''
try {
const res = await syncShayeganCharges()
syncOk.value = !!res?.ok
syncMessage.value = res?.message || 'استعلام با موفقیت انجام شد.'
if (res?.ok) {
message.success(syncMessage.value)
reloadTable()
} else {
message.error(syncMessage.value)
}
} catch (e: any) {
syncOk.value = false
syncMessage.value = e?.response?.data?.message || e?.message || 'خطا در استعلام از شایگان'
message.error(syncMessage.value)
} finally {
syncLoading.value = false
}
}
async function handleApprove(record: ShayeganInboundChargeRecord) {
Modal.confirm({
title: 'تأیید واریزی شایگان',
content: `آیا تأیید می‌کنید مبلغ ${usePrice(record.amount, true, ' ریال')} به کیف پول ${customerLabel(record)} در بورس مس واریز شود؟`,
okText: 'تأیید و شارژ',
cancelText: 'انصراف',
async onOk() {
actionLoadingId.value = record.id
try {
const res = await approveShayeganCharge(record.id)
if (res && res.ok) {
message.success(res.message || 'کیف پول با موفقیت شارژ شد.')
reloadTable()
} else {
message.error(res?.message || 'خطا در شارژ کیف پول')
}
} catch (e: any) {
message.error(e?.response?.data?.message || 'خطا در شارژ کیف پول مشتری')
} finally {
actionLoadingId.value = null
}
}
})
}
function handleReject(record: ShayeganInboundChargeRecord) {
let reasonInput = ''
Modal.confirm({
title: 'رد واریزی شایگان',
content: `آیا از رد واریزی ${usePrice(record.amount, true, ' ریال')} برای ${customerLabel(record)} اطمینان دارید؟`,
okText: 'رد درخواست',
cancelText: 'انصراف',
okType: 'danger',
async onOk() {
actionLoadingId.value = record.id
try {
const res = await rejectShayeganCharge(record.id, reasonInput)
if (res && res.ok) {
message.info(res.message || 'درخواست رد شد.')
reloadTable()
} else {
message.error(res?.message || 'خطا در رد درخواست')
}
} catch (e: any) {
message.error(e?.response?.data?.message || 'خطا در رد درخواست')
} finally {
actionLoadingId.value = null
}
}
})
}
</script>
@@ -73,6 +73,13 @@ const healthMessage = ref('')
const columns = [
{ title: 'شناسه', dataIndex: 'id', key: 'id', width: 80, type: 'Number', filterable: false, sortable: false },
{
title: 'مشتری',
dataIndex: 'customer.name',
key: 'customer.name',
type: 'Text',
customRender: (r: any) => customerLabel(r.record)
},
{
title: 'نوع',
dataIndex: 'type',
@@ -160,6 +167,15 @@ const tblProps = {
}
}
function customerLabel(record?: any) {
if (record?.customer?.name?.trim()) return record.customer.name.trim()
if (record?.customer?.fname || record?.customer?.lname) {
const fullName = `${record?.customer?.fname || ''} ${record?.customer?.lname || ''}`.trim()
if (fullName) return fullName
}
return '-'
}
function typeLabel(type?: string | null) {
if (!type) return '-'
return TYPE_LABELS[type] ?? type
+16 -2
View File
@@ -18,6 +18,7 @@
<ATabPane v-if="pargarEnabled" key="pargar-customer-sync" tab="همگام سازی مشتریان در پرگار" />
<ATabPane v-if="pargarEnabled" key="pargar-wallet-sync" tab="مانده کیف پرگار" />
<ATabPane v-if="shayeganEnabled" key="shayegan" tab="اسناد شایگان" />
<ATabPane v-if="shayeganEnabled" key="shayegan-charges" tab="واریزی‌های شایگان" />
</ATabs>
<tbl v-if="activeTab === 'reports'" ref="table" class="min-h-0 flex-1" />
<tahesabTbl v-else-if="tahesabEnabled && activeTab === 'tahesab'" ref="tahesabTable" class="min-h-0 flex-1" />
@@ -30,6 +31,7 @@
<pargarCustomerSync v-else-if="pargarEnabled && activeTab === 'pargar-customer-sync'" class="shrink-0" />
<pargarWalletSync v-else-if="pargarEnabled && activeTab === 'pargar-wallet-sync'" class="shrink-0" />
<shayeganTbl v-else-if="shayeganEnabled && activeTab === 'shayegan'" ref="shayeganTable" class="min-h-0 flex-1" />
<shayeganChargesTab v-else-if="shayeganEnabled && activeTab === 'shayegan-charges'" class="min-h-0 flex-1" />
</div>
</BasicMainCard>
<BasicModal
@@ -156,7 +158,8 @@
// import BasicInfoModal from '@/components/BasicInfoModal'
import { inputLenRules, inputRules, inputRulesNumber } from '@/utils/inputRules'
import { useStaticApiListsStore } from '@/store/staticApisStore'
import { ref, computed } from 'vue'
import { ref, computed, watch } from 'vue'
import { useRoute } from 'vue-router'
import tbl from './components/table.vue'
import tahesabTbl from './components/tahesabTable.vue'
import customerSync from './components/TahesabCustomerSync.vue'
@@ -165,6 +168,7 @@ import zarinTbl from './components/zarinTable.vue'
import zarinCustomerSync from './components/ZarinCustomerSync.vue'
import zarinWalletSync from './components/ZarinWalletBulkSync.vue'
import shayeganTbl from './components/shayeganTable.vue'
import shayeganChargesTab from './components/ShayeganChargesTab.vue'
import pargarTbl from './components/pargarTable.vue'
import pargarCustomerSync from './components/PargarCustomerSync.vue'
import pargarWalletSync from './components/PargarWalletBulkSync.vue'
@@ -189,14 +193,24 @@ import { metalLabel } from '@/utils/adminMetalLabels'
import { initAccountingSettingsFromApi, tahesabEnabledSetting, zarinEnabledSetting, pargarEnabledSetting, shayeganEnabledSetting } from '@/utils/config'
//loading
const route = useRoute()
const loading = ref<boolean>(false)
const submitError = ref('')
const activeTab = ref<'reports' | 'tahesab' | 'customer-sync' | 'tahesab-wallet-sync' | 'zarin' | 'zarin-customer-sync' | 'zarin-wallet-sync' | 'pargar' | 'pargar-customer-sync' | 'pargar-wallet-sync' | 'shayegan'>('reports')
const activeTab = ref<'reports' | 'tahesab' | 'customer-sync' | 'tahesab-wallet-sync' | 'zarin' | 'zarin-customer-sync' | 'zarin-wallet-sync' | 'pargar' | 'pargar-customer-sync' | 'pargar-wallet-sync' | 'shayegan' | 'shayegan-charges'>((route.query.tab as any) || 'reports')
const tahesabEnabled = tahesabEnabledSetting
const zarinEnabled = zarinEnabledSetting
const pargarEnabled = pargarEnabledSetting
const shayeganEnabled = shayeganEnabledSetting
watch(
() => route.query.tab,
(tab) => {
if (tab && typeof tab === 'string') {
activeTab.value = tab as any
}
}
)
//define store
const store = useStaticApiListsStore()