Files
boursecu_admin/src/pages/menuPages/customers/base/components/table.vue
T

395 lines
14 KiB
Vue
Raw Normal View History

2026-01-24 17:45:54 +03:30
<template>
2026-05-31 11:51:52 +03:30
<div class="h-full min-h-0 min-w-0 max-w-full overflow-hidden">
<BasicShowContext title="لیست مشتریان">
<template #extra>
2026-06-14 21:04:26 +03:30
<BaseButton
v-if="isMobile"
type="primary"
size="small"
icon="vuesax-linear:user-add"
@click="emits('add')"
>
افزودن
2026-05-31 11:51:52 +03:30
</BaseButton>
</template>
<div class="flex h-full min-h-0 flex-col">
<BaseTable v-if="!isMobile" class="h-full min-h-0 min-w-0" v-bind="tblProps" @register="submit" ref="tbl">
2026-01-24 17:45:54 +03:30
<template #extraHeader>
2026-06-14 21:04:26 +03:30
<BaseButton type="primary" size="small" icon="vuesax-linear:user-add" @click="emits('add')">
افزودن مشتری
2026-01-24 17:45:54 +03:30
</BaseButton>
</template>
<template #accountingCode="{ record }">
<button
type="button"
class="inline-flex items-center gap-1.5 border-none bg-transparent p-0 text-sm cursor-pointer"
style="color: var(--admin-text)"
@click="openAccountingCodeEdit(record)"
>
<span dir="ltr">{{ accountingCodeOf(record) }}</span>
<Icon icon="vuesax-linear:edit-2" size="16" color="#4572E9" />
</button>
</template>
2026-05-31 11:51:52 +03:30
<template #action="{ record }">
2026-01-24 17:45:54 +03:30
<div class="gap-2 hidden md:flex justify-center">
<a-tooltip :key="record.is_archive" placement="bottom" class="cursor-pointer">
<template #title>
<span>{{ record.is_archive ? 'بیرون بردن از بایگانی' : 'بایگانی کردن' }}</span>
</template>
<a-popconfirm
title="آیا مشتری را بایگانی می کنید؟"
ok-text="تایید"
cancel-text="رد"
placement="topLeft"
@confirm="archiveFunction(record.id)"
>
<Icon class="cursor-pointer" icon="vuesax-linear:archive-tick" color="#e3bf00" />
</a-popconfirm>
</a-tooltip>
<a-tooltip
:key="record.active"
placement="bottom"
class="cursor-pointer"
@click="changeCustomerActivationFunction(record.id)"
>
<template #title>
2026-05-31 11:51:52 +03:30
<span>{{ record.active ? 'غیرفعال کردن حساب کاربری' : 'فعال کردن حساب کاربری' }}</span>
2026-01-24 17:45:54 +03:30
</template>
<Icon
:icon="record.active ? 'vuesax-linear:user-tick' : 'vuesax-linear:user-remove'"
:color="record.active ? '#54AD06' : '#ad0627'"
/>
</a-tooltip>
2026-07-11 11:42:12 +03:30
<a-tooltip placement="bottom" class="cursor-pointer" @click="emits('chargeWallet', record)">
<template #title><span>شارژ کیف پول</span></template>
2026-01-24 17:45:54 +03:30
<Icon icon="vuesax-linear:wallet-add" color="#9333ea" />
</a-tooltip>
2026-06-26 17:41:52 +03:30
<a-tooltip
v-if="tahesabEnabled && !isValidAccountingCode(record.moshtari_code)"
2026-06-26 17:41:52 +03:30
placement="bottom"
class="cursor-pointer"
@click="openTahesabRegister(record)"
>
2026-06-28 21:48:17 +03:30
<template #title><span>در ته‌حساب ثبت نشده — کلیک برای ثبت</span></template>
<Icon icon="vuesax-linear:profile-add" color="#CA8A04" />
2026-06-26 17:41:52 +03:30
</a-tooltip>
2026-07-05 16:41:45 +03:30
<a-tooltip
v-if="pargarEnabled && !isValidAccountingCode(record.pargar_account_id)"
2026-07-05 16:41:45 +03:30
placement="bottom"
class="cursor-pointer"
@click="openPargarRegister(record)"
>
<template #title><span>در پرگار ثبت نشده — کلیک برای ثبت</span></template>
<Icon icon="vuesax-linear:profile-add" color="#7C3AED" />
</a-tooltip>
<a-tooltip
v-if="accountingEnabled"
placement="bottom"
class="cursor-pointer"
@click="openAccountingCodeEdit(record)"
>
<template #title><span>ویرایش کد حسابداری</span></template>
<Icon icon="vuesax-linear:card-edit" color="#0d9488" />
</a-tooltip>
2026-01-24 17:45:54 +03:30
<a-tooltip placement="bottom" class="cursor-pointer" @click="emits('info', record)">
2026-05-31 11:51:52 +03:30
<template #title><span>مشخصات</span></template>
2026-01-24 17:45:54 +03:30
<Icon icon="vuesax-linear:stickynote" color="#10913A" />
</a-tooltip>
<a-tooltip placement="bottom" class="cursor-pointer" @click="emits('edit', record)">
2026-05-31 11:51:52 +03:30
<template #title><span>ویرایش</span></template>
2026-01-24 17:45:54 +03:30
<Icon icon="vuesax-linear:edit" color="#4572E9" />
</a-tooltip>
<a-tooltip
:key="record.trade_active"
placement="bottom"
class="cursor-pointer"
@click="changeCustomerOrderActivationFunction(record.id)"
>
<template #title>
2026-05-31 11:51:52 +03:30
<span>{{ record.trade_active ? 'غیر مجاز کردن سفارش دهی' : 'مجاز کردن سفارش دهی' }}</span>
2026-01-24 17:45:54 +03:30
</template>
<Icon
2026-05-31 11:51:52 +03:30
:icon="record.trade_active === 1 ? 'vuesax-linear:box-tick' : 'vuesax-linear:box-remove'"
2026-01-24 17:45:54 +03:30
:color="record.trade_active === 1 ? '#54AD06' : '#ad0627'"
/>
</a-tooltip>
2026-07-18 22:22:21 +03:30
<a-tooltip
v-if="customerDirectSmsEnabled"
placement="bottom"
class="cursor-pointer"
@click="openDirectSms(record)"
>
<template #title><span>ارسال پیامک</span></template>
<Icon icon="vuesax-linear:sms" color="#0ea5e9" />
</a-tooltip>
2026-01-24 17:45:54 +03:30
<a-tooltip
v-if="!record.is_legal"
placement="bottom"
class="cursor-pointer"
@click="openConfirmUser(record)"
>
2026-05-31 11:51:52 +03:30
<template #title><span>تایید کاربر</span></template>
2026-01-24 17:45:54 +03:30
<Icon icon="vuesax-linear:user-search" color="#0d9488" />
</a-tooltip>
</div>
</template>
</BaseTable>
2026-05-31 11:51:52 +03:30
<CustomerMobileCardList
v-else
ref="mobileListRef"
class="min-h-0 flex-1"
@info="emits('info', $event)"
@edit="emits('edit', $event)"
@archive="handleArchive"
@toggleActive="(item) => changeCustomerActivationFunction(item.id)"
2026-07-11 11:42:12 +03:30
@chargeWallet="emits('chargeWallet', $event)"
2026-05-31 11:51:52 +03:30
@toggleTrade="(item) => changeCustomerOrderActivationFunction(item.id)"
@confirmUser="openConfirmUser"
2026-07-18 22:22:21 +03:30
@sendSms="openDirectSms"
@editAccounting="openAccountingCodeEdit"
2026-05-31 11:51:52 +03:30
/>
</div>
2026-07-18 22:22:21 +03:30
<CustomerDirectSmsModal v-model:visible="directSmsVisible" :customer="directSmsCustomer" />
<CustomerAccountingCodeModal
v-model:visible="accountingCodeVisible"
:customer="accountingCodeCustomer"
:provider="accountingProviderSetting"
@success="fetch"
/>
2026-01-24 17:45:54 +03:30
<BasicModal
v-model:visible="confirmVisible"
2026-06-04 22:35:57 +03:30
:width="isMobile ? '92vw' : '50vw'"
2026-01-24 17:45:54 +03:30
title="تایید مشتری"
@ok="confirmUserFunction"
ok-text="تایید"
:loading="loading"
@close="confirmVisible = false"
>
<div class="mt-[-10px] mb-10 font-bold">آیا از اطلاعات وارد شده اطمینان دارید؟</div>
<div class="grid grid-cols-4 gap-2">
<BasicInfoItem title="نام و نام خانوادگی" :value="confirmInfo?.name" />
<BasicInfoItem title="شماره همراه" :value="confirmInfo?.mobile" />
<BasicInfoItem
title="تاریخ تولد"
:value="confirmInfo?.birth_date ? toJalaliNoTime(confirmInfo?.birth_date) : '_'"
/>
<BasicInfoItem title="شماره تلفن" :value="confirmInfo?.phone_number ?? '_'" />
<BasicInfoItem title="نام استان" :value="confirmInfo?.province" />
<BasicInfoItem title="نام شهر" :value="confirmInfo?.city" />
<BasicInfoItem title="شماره ملی" :value="confirmInfo?.n_code" />
</div>
</BasicModal>
2026-06-26 17:41:52 +03:30
<TahesabRetryModal
v-if="tahesabEnabled"
v-model="tahesabRegisterVisible"
mode="register-customer"
:customer-id="tahesabCustomer?.id"
:customer-name="tahesabCustomer?.name"
@success="fetch"
/>
2026-07-05 16:41:45 +03:30
<PargarRetryModal
v-if="pargarEnabled"
v-model="pargarRegisterVisible"
mode="register-customer"
:customer-id="pargarCustomer?.id"
:customer-name="pargarCustomer?.name"
@success="fetch"
/>
2026-01-24 17:45:54 +03:30
</BasicShowContext>
</div>
</template>
2026-05-31 11:51:52 +03:30
<script setup lang="ts">
import { message, Modal } from 'ant-design-vue'
import { onMounted, ref, computed } from 'vue'
2026-01-24 17:45:54 +03:30
import {
changeCustomerActivation,
changeCustomerArchive,
changeCustomerOrderActivation,
confirmUser,
getCustomerTable
} from '@/api/customer'
2026-06-23 22:31:07 +03:30
import { buildCustomerColumns } from '@/pages/menuPages/customers/base/hooks/customerColumns'
2026-05-31 11:51:52 +03:30
import CustomerMobileCardList from '@/pages/menuPages/customers/base/components/CustomerMobileCardList.vue'
2026-07-18 22:22:21 +03:30
import CustomerDirectSmsModal from '@/pages/menuPages/customers/base/components/CustomerDirectSmsModal.vue'
import CustomerAccountingCodeModal from '@/pages/menuPages/customers/base/components/CustomerAccountingCodeModal.vue'
2026-05-31 11:51:52 +03:30
import Icon from '@core/components/BaseIcon/src/Icon.vue'
import useBaseTable from '@core/components/BaseTable/hooks/useBaseTable'
import type { TableInput } from '@core/type/baseTable'
2026-01-24 17:45:54 +03:30
import { toJalaliNoTime } from '@core/utils/useDataTime'
import type { Customer } from '@/model/customer'
2026-06-04 22:35:57 +03:30
import { MODAL_ABOVE_ACTION_SHEET_Z_INDEX } from '@/constants/overlayZIndex'
2026-05-31 11:51:52 +03:30
import { isMobile } from '@core/utils/is'
2026-06-26 17:41:52 +03:30
import TahesabRetryModal from '@/components/TahesabRetryModal.vue'
2026-07-05 16:41:45 +03:30
import PargarRetryModal from '@/components/PargarRetryModal.vue'
2026-07-18 22:22:21 +03:30
import {
tahesabEnabledSetting,
pargarEnabledSetting,
accountingProviderSetting,
2026-07-18 22:22:21 +03:30
customerDirectSmsEnabledSetting,
initAccountingSettingsFromApi,
initWalletSettingsFromApi
} from '@/utils/config'
import { displayAccountingCode, isValidAccountingCode } from '@/utils/accountingCode'
2026-01-24 17:45:54 +03:30
const [submit, reload] = useBaseTable()
2026-07-11 11:42:12 +03:30
const emits = defineEmits(['delete', 'edit', 'add', 'info', 'chargeWallet'])
2026-01-24 17:45:54 +03:30
2026-05-31 11:51:52 +03:30
const loading = ref(false)
const confirmVisible = ref(false)
2026-01-24 17:45:54 +03:30
const confirmInfo = ref<Customer>()
2026-06-26 17:41:52 +03:30
const tahesabRegisterVisible = ref(false)
const tahesabCustomer = ref<Customer>()
const tahesabEnabled = tahesabEnabledSetting
2026-07-05 16:41:45 +03:30
const pargarRegisterVisible = ref(false)
const pargarCustomer = ref<Customer>()
const pargarEnabled = pargarEnabledSetting
2026-07-18 22:22:21 +03:30
const customerDirectSmsEnabled = customerDirectSmsEnabledSetting
const accountingCodeVisible = ref(false)
const accountingCodeCustomer = ref<Customer | null>(null)
const accountingEnabled = computed(() => {
const provider = accountingProviderSetting.value
return provider === 'pargar' || provider === 'tahesab'
})
function accountingCodeOf(record: Customer) {
const provider = accountingProviderSetting.value
if (provider === 'pargar') return displayAccountingCode(record.pargar_account_id)
if (provider === 'tahesab') return displayAccountingCode(record.moshtari_code)
return '-'
}
function openAccountingCodeEdit(user: Customer) {
accountingCodeCustomer.value = user
accountingCodeVisible.value = true
}
2026-07-18 22:22:21 +03:30
const directSmsVisible = ref(false)
const directSmsCustomer = ref<Customer | null>(null)
2026-05-31 11:51:52 +03:30
const mobileListRef = ref<null | { fetch: () => Promise<void> }>(null)
const catalogMetals = ref<Parameters<typeof buildCustomerColumns>[0]>([])
function rebuildColumns(metals = catalogMetals.value) {
catalogMetals.value = metals
tblProps.value.columns = buildCustomerColumns(metals, {
accountingProvider: accountingProviderSetting.value
})
}
2026-01-24 17:45:54 +03:30
const tblProps = ref<any>({
columns: buildCustomerColumns([], { accountingProvider: accountingProviderSetting.value }),
2026-06-23 22:31:07 +03:30
api: async (params: TableInput) => {
await initAccountingSettingsFromApi()
2026-06-23 22:31:07 +03:30
const data = await getCustomerTable(params)
const metals = data?.catalogMetals ?? []
rebuildColumns(metals)
2026-06-23 22:31:07 +03:30
return data
}
2026-01-24 17:45:54 +03:30
})
2026-05-31 11:51:52 +03:30
const fetch = async () => {
await Promise.allSettled([reload(), mobileListRef.value?.fetch?.() as Promise<void>])
}
defineExpose({ fetch })
2026-01-24 17:45:54 +03:30
2026-06-26 17:41:52 +03:30
onMounted(() => {
2026-07-05 16:41:45 +03:30
void initAccountingSettingsFromApi()
2026-07-18 22:22:21 +03:30
void initWalletSettingsFromApi()
2026-06-26 17:41:52 +03:30
})
2026-07-18 22:22:21 +03:30
function openDirectSms(user: Customer) {
directSmsCustomer.value = user
directSmsVisible.value = true
}
2026-01-24 17:45:54 +03:30
async function changeCustomerActivationFunction(id: number) {
try {
loading.value = true
await changeCustomerActivation(id)
2026-05-31 11:51:52 +03:30
await fetch()
2026-01-24 17:45:54 +03:30
message.success('تغییر وضعیت با موفقیت انجام شد')
} catch (e) {
console.error(e)
} finally {
loading.value = false
}
}
function openConfirmUser(user: Customer) {
confirmInfo.value = user
confirmVisible.value = true
}
2026-06-26 17:41:52 +03:30
function openTahesabRegister(user: Customer) {
tahesabCustomer.value = user
tahesabRegisterVisible.value = true
}
2026-07-05 16:41:45 +03:30
function openPargarRegister(user: Customer) {
pargarCustomer.value = user
pargarRegisterVisible.value = true
}
2026-05-31 11:51:52 +03:30
function handleArchive(customer: Customer) {
Modal.confirm({
title: 'آیا مشتری را بایگانی می کنید؟',
okText: 'تایید',
cancelText: 'رد',
centered: true,
2026-06-04 22:35:57 +03:30
zIndex: MODAL_ABOVE_ACTION_SHEET_Z_INDEX,
2026-05-31 11:51:52 +03:30
onOk: () => archiveFunction(customer.id)
})
}
2026-01-24 17:45:54 +03:30
async function archiveFunction(id: number) {
try {
loading.value = true
await changeCustomerArchive(id)
2026-05-31 11:51:52 +03:30
await fetch()
2026-01-24 17:45:54 +03:30
message.success('مشتری با موفقیت بایگانی شد.')
} catch (e) {
console.error(e)
} finally {
loading.value = false
}
}
async function confirmUserFunction() {
try {
loading.value = true
await confirmUser(confirmInfo.value?.id)
2026-05-31 11:51:52 +03:30
await fetch()
2026-01-24 17:45:54 +03:30
confirmVisible.value = false
} catch (e) {
console.log(e)
} finally {
loading.value = false
}
}
async function changeCustomerOrderActivationFunction(id: number) {
try {
loading.value = true
await changeCustomerOrderActivation(id)
2026-05-31 11:51:52 +03:30
await fetch()
2026-01-24 17:45:54 +03:30
message.success('تغییر وضعیت سفارش دهی با موفقیت انجام شد')
} catch (e) {
console.error(e)
} finally {
loading.value = false
}
}
</script>
<style lang="less">
.ant-popover,
.ant-tooltip {
z-index: 1001 !important;
2026-01-24 17:45:54 +03:30
}
</style>