fix bugs and added some feature for withdraw handling
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
<template>
|
||||
<BasicModal
|
||||
v-model:visible="visibleProxy"
|
||||
:width="isMobile ? '92vw' : '28rem'"
|
||||
title="ویرایش کد حسابداری"
|
||||
ok-text="ذخیره"
|
||||
:loading="loading"
|
||||
@ok="submit"
|
||||
@close="close"
|
||||
>
|
||||
<div class="flex flex-col gap-3">
|
||||
<p class="m-0 text-sm" style="color: var(--admin-text-secondary)">
|
||||
مشتری:
|
||||
<strong class="text-[var(--admin-text)]">{{ customer?.name || '—' }}</strong>
|
||||
</p>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="کد حسابداری" class="mb-0">
|
||||
<BasicInput
|
||||
v-model:value="code"
|
||||
placeholder="کد حسابداری را وارد کنید"
|
||||
dir="ltr"
|
||||
class="text-left"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
<p class="m-0 text-xs" style="color: var(--admin-text-secondary)">
|
||||
برای پاک کردن کد، فیلد را خالی بگذارید و ذخیره کنید.
|
||||
</p>
|
||||
</div>
|
||||
</BasicModal>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import BasicModal from '@/components/BasicModal.vue'
|
||||
import { updateCustomer } from '@/api/customer'
|
||||
import type { Customer } from '@/model/customer'
|
||||
import type { AccountingProvider } from '@/utils/config'
|
||||
import { displayAccountingCode, normalizeAccountingCode } from '@/utils/accountingCode'
|
||||
import { isMobile } from '@core/utils/is'
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
customer: Customer | null
|
||||
provider: AccountingProvider
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:visible', value: boolean): void
|
||||
(e: 'success'): void
|
||||
}>()
|
||||
|
||||
const loading = ref(false)
|
||||
const code = ref('')
|
||||
|
||||
const visibleProxy = computed({
|
||||
get: () => props.visible,
|
||||
set: (value: boolean) => emit('update:visible', value),
|
||||
})
|
||||
|
||||
function currentCodeOf(customer: Customer | null): string {
|
||||
if (!customer) return ''
|
||||
if (props.provider === 'pargar') return displayAccountingCode(customer.pargar_account_id)
|
||||
if (props.provider === 'tahesab') return displayAccountingCode(customer.moshtari_code)
|
||||
return ''
|
||||
}
|
||||
|
||||
watch(
|
||||
() => [props.visible, props.customer, props.provider] as const,
|
||||
([visible]) => {
|
||||
if (!visible) return
|
||||
const shown = currentCodeOf(props.customer)
|
||||
code.value = shown === '-' ? '' : shown
|
||||
}
|
||||
)
|
||||
|
||||
function close() {
|
||||
visibleProxy.value = false
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
if (!props.customer?.id) return
|
||||
if (props.provider !== 'pargar' && props.provider !== 'tahesab') {
|
||||
message.error('حسابداری فعال نیست.')
|
||||
return
|
||||
}
|
||||
|
||||
const normalized = normalizeAccountingCode(code.value)
|
||||
const payload =
|
||||
props.provider === 'pargar'
|
||||
? { pargar_account_id: normalized }
|
||||
: { moshtari_code: normalized }
|
||||
|
||||
try {
|
||||
loading.value = true
|
||||
await updateCustomer(props.customer.id, payload as Customer)
|
||||
message.success('کد حسابداری ذخیره شد.')
|
||||
emit('success')
|
||||
close()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user