Files
boursecu_admin/src/pages/menuPages/colleagueOrders/components/ColleagueAccountingAccounts.vue
T

242 lines
6.4 KiB
Vue
Raw Normal View History

<template>
<section v-if="visible" class="colleague-accounts">
<header class="colleague-accounts__head">
<div>
<h3 class="colleague-accounts__title">کد حسابداری معامله با همکار</h3>
<p class="colleague-accounts__desc">
برای هر خرید/فروشی که نزد همکار ثبت می‌شود، سند روی این کد حساب در سیستم حسابداری فعال زده می‌شود.
</p>
</div>
<BaseButton type="primary" :loading="saving" @click="save">
ذخیره کد
</BaseButton>
</header>
<label
v-if="activeField"
class="colleague-accounts__field colleague-accounts__field--active"
>
<span class="colleague-accounts__label">
{{ activeField.label }}
<span class="colleague-accounts__badge">فعال</span>
</span>
<a-input
v-model:value="values[activeField.key]"
:placeholder="activeField.placeholder"
allow-clear
class="colleague-accounts__input"
/>
</label>
</section>
</template>
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue'
import { message } from 'ant-design-vue'
import { getConfiguration, setConfiguration } from '@/api/configuration'
import type { Const } from '@/model/configuration'
import {
accountingProviderSetting,
initWalletSettingsFromApi,
priceProviderSetting,
type AccountingProvider,
} from '@/utils/config'
const props = withDefaults(
defineProps<{
/**
* اگر ست شود فقط وقتی provider فعال همین باشد نشان بده
* (مثلاً روی صفحهٔ همگام‌سازی ته‌حساب: provider-only="tahesab")
*/
providerOnly?: AccountingProvider | null
/** پیش‌فرض: فقط وقتی منبع قیمت Montzar است */
requireMontzar?: boolean
}>(),
{
providerOnly: null,
requireMontzar: true,
},
)
const KEYS = {
zarin: 'montzar_account_zarin',
tahesab: 'montzar_account_tahesab',
pargar: 'montzar_account_pargar',
} as const
const META: Record<
Exclude<AccountingProvider, 'none'>,
{ key: string; label: string; placeholder: string; titleFa: string }
> = {
zarin: {
key: KEYS.zarin,
label: 'کد حساب زرین',
placeholder: 'کد حساب همکار در زرین',
titleFa: 'کد حساب همکار در زرین',
},
tahesab: {
key: KEYS.tahesab,
label: 'کد حساب ته‌حساب',
placeholder: 'کد حساب همکار در ته‌حساب',
titleFa: 'کد حساب همکار در ته‌حساب',
},
pargar: {
key: KEYS.pargar,
label: 'کد حساب پرگار',
placeholder: 'کد حساب همکار در پرگار',
titleFa: 'کد حساب همکار در پرگار',
},
}
const values = reactive<Record<string, string>>({
[KEYS.zarin]: '',
[KEYS.tahesab]: '',
[KEYS.pargar]: '',
})
const rowIds = reactive<Record<string, number | null>>({
[KEYS.zarin]: null,
[KEYS.tahesab]: null,
[KEYS.pargar]: null,
})
const saving = ref(false)
const activeProvider = computed(() => accountingProviderSetting.value as AccountingProvider)
const activeField = computed(() => {
const provider = activeProvider.value
if (provider === 'none') return null
return META[provider] ?? null
})
const visible = computed(() => {
if (props.requireMontzar && priceProviderSetting.value !== 'montzar') {
return false
}
if (!activeField.value) {
return false
}
if (props.providerOnly && activeProvider.value !== props.providerOnly) {
return false
}
return true
})
async function load() {
await initWalletSettingsFromApi()
const rows = await getConfiguration()
const list = Array.isArray(rows) ? rows : []
for (const key of Object.values(KEYS)) {
const row = list.find((item) => item?.key === key)
values[key] = row?.value != null ? String(row.value) : ''
rowIds[key] = row?.id != null ? Number(row.id) : null
}
}
async function save() {
const field = activeField.value
if (!field) {
message.warning('سیستم حسابداری فعالی انتخاب نشده است')
return
}
saving.value = true
try {
await setConfiguration({
id: rowIds[field.key] ?? undefined,
key: field.key,
value: (values[field.key] ?? '').trim(),
title_fa: field.titleFa,
is_active: true,
can_edit: true,
type: 'text',
description:
'کد حساب طرف حساب همکار؛ سند خرید/فروش پوشش‌شده روی Montzar روی این حساب ثبت می‌شود.',
} satisfies Const)
message.success('کد حساب همکار ذخیره شد')
await load()
} catch (error) {
console.error(error)
message.error('ذخیره کد حساب همکار ناموفق بود')
} finally {
saving.value = false
}
}
onMounted(() => {
void load()
})
</script>
<style scoped lang="less">
.colleague-accounts {
margin-bottom: 1rem;
padding: 1rem 1.125rem;
border: 1px solid var(--admin-border, rgba(255, 255, 255, 0.12));
border-radius: 14px;
background: var(--admin-bg-elevated, rgba(28, 28, 34, 0.92));
}
.colleague-accounts__head {
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: space-between;
gap: 0.75rem;
margin-bottom: 1rem;
}
.colleague-accounts__title {
margin: 0;
font-size: 0.9375rem;
font-weight: 700;
color: var(--admin-text, #fff);
}
.colleague-accounts__desc {
margin: 0.35rem 0 0;
max-width: 42rem;
font-size: 0.75rem;
line-height: 1.7;
color: var(--admin-text-secondary, rgba(255, 255, 255, 0.65));
}
.colleague-accounts__field {
display: flex;
max-width: 28rem;
min-width: 0;
flex-direction: column;
gap: 0.4rem;
padding: 0.75rem;
border: 1px solid color-mix(in srgb, #d4af37 55%, transparent);
border-radius: 12px;
background: color-mix(in srgb, var(--admin-bg-muted, #1a1a1f) 80%, transparent);
box-shadow: inset 0 0 0 1px color-mix(in srgb, #d4af37 18%, transparent);
}
.colleague-accounts__label {
display: inline-flex;
align-items: center;
gap: 0.4rem;
font-size: 0.8125rem;
font-weight: 600;
color: var(--admin-text, #fff);
}
.colleague-accounts__badge {
display: inline-flex;
align-items: center;
padding: 0.1rem 0.4rem;
border-radius: 999px;
background: rgba(212, 175, 55, 0.18);
color: #d4af37;
font-size: 0.6875rem;
font-weight: 700;
}
.colleague-accounts__input {
width: 100%;
}
</style>