wallet fix 2

This commit is contained in:
2026-06-26 17:41:52 +03:30
parent edffc5df76
commit d7ca6706fb
11 changed files with 529 additions and 12 deletions
+126
View File
@@ -0,0 +1,126 @@
<template>
<BasicModal
v-model:visible="visible"
:title="title"
:ok-text="confirmText"
:loading="loading"
width="32rem"
@ok="confirm"
@close="visible = false"
>
<div class="space-y-3 text-sm">
<div v-for="item in items" :key="item.label" class="flex justify-between gap-3 border-b border-gray-100 pb-2">
<span class="text-gray-500">{{ item.label }}</span>
<span class="text-left break-all">{{ item.value ?? '-' }}</span>
</div>
<div v-if="logText" class="rounded-lg bg-red-50 p-3 text-red-700 whitespace-pre-wrap">{{ logText }}</div>
</div>
</BasicModal>
</template>
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import BasicModal from '@/components/BasicModal.vue'
import { message } from 'ant-design-vue/es'
import { getTahesabDetail, retryTahesabSanad, registerCustomerInTahesab, type TahesabRecord } from '@/api/tahesab'
const props = defineProps<{
modelValue: boolean
mode: 'retry-sanad' | 'register-customer'
tahesabId?: number
customerId?: number
customerName?: string
}>()
const emit = defineEmits<{
(e: 'update:modelValue', value: boolean): void
(e: 'success'): void
}>()
const loading = ref(false)
const detail = ref<TahesabRecord | null>(null)
const visible = computed({
get: () => props.modelValue,
set: (value: boolean) => emit('update:modelValue', value)
})
const title = computed(() =>
props.mode === 'register-customer' ? 'ثبت مشتری در ته‌حساب' : 'ارسال مجدد سند به ته‌حساب'
)
const confirmText = computed(() => (props.mode === 'register-customer' ? 'ثبت در ته‌حساب' : 'ارسال به ته‌حساب'))
const logText = computed(() => detail.value?.sync_log || '')
const items = computed(() => {
if (props.mode === 'register-customer') {
return [
{ label: 'نام مشتری', value: props.customerName || detail.value?.customer?.name },
{ label: 'شناسه مشتری', value: props.customerId || detail.value?.customer_id },
{ label: 'کد ته‌حساب', value: detail.value?.customer?.moshtari_code }
]
}
return [
{ label: 'شناسه سند', value: detail.value?.id },
{ label: 'مشتری', value: detail.value?.customer?.name },
{ label: 'موبایل', value: detail.value?.customer?.mobile },
{ label: 'نوع', value: detail.value?.type },
{ label: 'مقدار', value: detail.value?.amount },
{ label: 'شرح', value: detail.value?.desc },
{ label: 'وضعیت', value: statusLabel(detail.value?.sync_status) },
{ label: 'کد ته‌حساب', value: detail.value?.tahesab_id }
]
})
function statusLabel(status?: string) {
if (status === 'success') return 'موفق'
if (status === 'failed') return 'ناموفق'
return 'در انتظار'
}
watch(
() => [props.modelValue, props.tahesabId] as const,
async ([open, id]) => {
if (!open || props.mode !== 'retry-sanad' || !id) return
loading.value = true
try {
detail.value = await getTahesabDetail(id)
} catch (e) {
console.error(e)
} finally {
loading.value = false
}
},
{ immediate: true }
)
async function confirm() {
loading.value = true
try {
if (props.mode === 'register-customer' && props.customerId) {
const result = await registerCustomerInTahesab(props.customerId)
if (!result.ok) {
message.error(result.message || 'ثبت مشتری ناموفق بود')
return
}
message.success(result.message || 'مشتری در ته‌حساب ثبت شد')
} else if (props.mode === 'retry-sanad' && props.tahesabId) {
const result = await retryTahesabSanad(props.tahesabId)
if (!result.ok) {
message.error(result.message || 'ارسال مجدد ناموفق بود')
detail.value = result.tahesab || detail.value
return
}
message.success(result.message || 'سند با موفقیت ثبت شد')
}
visible.value = false
emit('success')
} catch (e) {
console.error(e)
} finally {
loading.value = false
}
}
</script>