245 lines
9.0 KiB
Vue
245 lines
9.0 KiB
Vue
<template>
|
|
<div class="h-full min-h-0 min-w-0 max-w-full overflow-hidden">
|
|
<BasicShowContext title="لیست مشتریان">
|
|
<template #extra>
|
|
<BaseButton type="primary" size="small" class="flex shrink-0 md:hidden" @click="emits('add')">
|
|
<div>افزودن</div>
|
|
<BaseIcon icon="vuesax-linear:user-add" Size="16px" />
|
|
</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">
|
|
<template #extraHeader>
|
|
<BaseButton type="primary" size="small" class="flex" @click="emits('add')">
|
|
<div>افزودن مشتری</div>
|
|
<BaseIcon icon="vuesax-linear:user-add" Size="16px" />
|
|
</BaseButton>
|
|
</template>
|
|
<template #action="{ record }">
|
|
<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>
|
|
<span>{{ record.active ? 'غیرفعال کردن حساب کاربری' : 'فعال کردن حساب کاربری' }}</span>
|
|
</template>
|
|
<Icon
|
|
:icon="record.active ? 'vuesax-linear:user-tick' : 'vuesax-linear:user-remove'"
|
|
:color="record.active ? '#54AD06' : '#ad0627'"
|
|
/>
|
|
</a-tooltip>
|
|
<a-tooltip placement="bottom" class="cursor-pointer" @click="emits('chargeMoney', record)">
|
|
<template #title><span>شارژ کیف پول ریالی</span></template>
|
|
<Icon icon="vuesax-linear:wallet-add" color="#9333ea" />
|
|
</a-tooltip>
|
|
<a-tooltip placement="bottom" class="cursor-pointer" @click="emits('chargeGold', record)">
|
|
<template #title><span>شارژ کیف پول طلایی</span></template>
|
|
<Icon icon="vuesax-linear:wallet-money" color="#ea580c" />
|
|
</a-tooltip>
|
|
<a-tooltip placement="bottom" class="cursor-pointer" @click="emits('info', record)">
|
|
<template #title><span>مشخصات</span></template>
|
|
<Icon icon="vuesax-linear:stickynote" color="#10913A" />
|
|
</a-tooltip>
|
|
<a-tooltip placement="bottom" class="cursor-pointer" @click="emits('edit', record)">
|
|
<template #title><span>ویرایش</span></template>
|
|
<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>
|
|
<span>{{ record.trade_active ? 'غیر مجاز کردن سفارش دهی' : 'مجاز کردن سفارش دهی' }}</span>
|
|
</template>
|
|
<Icon
|
|
:icon="record.trade_active === 1 ? 'vuesax-linear:box-tick' : 'vuesax-linear:box-remove'"
|
|
:color="record.trade_active === 1 ? '#54AD06' : '#ad0627'"
|
|
/>
|
|
</a-tooltip>
|
|
<a-tooltip
|
|
v-if="!record.is_legal"
|
|
placement="bottom"
|
|
class="cursor-pointer"
|
|
@click="openConfirmUser(record)"
|
|
>
|
|
<template #title><span>تایید کاربر</span></template>
|
|
<Icon icon="vuesax-linear:user-search" color="#0d9488" />
|
|
</a-tooltip>
|
|
</div>
|
|
</template>
|
|
</BaseTable>
|
|
|
|
<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)"
|
|
@chargeMoney="emits('chargeMoney', $event)"
|
|
@chargeGold="emits('chargeGold', $event)"
|
|
@toggleTrade="(item) => changeCustomerOrderActivationFunction(item.id)"
|
|
@confirmUser="openConfirmUser"
|
|
/>
|
|
</div>
|
|
|
|
<BasicModal
|
|
v-model:visible="confirmVisible"
|
|
width="50vw"
|
|
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>
|
|
</BasicShowContext>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { message, Modal } from 'ant-design-vue'
|
|
import { ref } from 'vue'
|
|
import {
|
|
changeCustomerActivation,
|
|
changeCustomerArchive,
|
|
changeCustomerOrderActivation,
|
|
confirmUser,
|
|
getCustomerTable
|
|
} from '@/api/customer'
|
|
import { cols } from '@/pages/menuPages/customers/base/hooks/customerColumns'
|
|
import CustomerMobileCardList from '@/pages/menuPages/customers/base/components/CustomerMobileCardList.vue'
|
|
import Icon from '@core/components/BaseIcon/src/Icon.vue'
|
|
import useBaseTable from '@core/components/BaseTable/hooks/useBaseTable'
|
|
import type { TableInput } from '@core/type/baseTable'
|
|
import { toJalaliNoTime } from '@core/utils/useDataTime'
|
|
import type { Customer } from '@/model/customer'
|
|
import { isMobile } from '@core/utils/is'
|
|
|
|
const [submit, reload] = useBaseTable()
|
|
const emits = defineEmits(['delete', 'edit', 'add', 'info', 'chargeMoney', 'chargeGold'])
|
|
|
|
const loading = ref(false)
|
|
const confirmVisible = ref(false)
|
|
const confirmInfo = ref<Customer>()
|
|
const mobileListRef = ref<null | { fetch: () => Promise<void> }>(null)
|
|
|
|
const tblProps = ref<any>({
|
|
columns: cols,
|
|
api: (params: TableInput) => getCustomerTable(params)
|
|
})
|
|
|
|
const fetch = async () => {
|
|
await Promise.allSettled([reload(), mobileListRef.value?.fetch?.() as Promise<void>])
|
|
}
|
|
|
|
defineExpose({ fetch })
|
|
|
|
async function changeCustomerActivationFunction(id: number) {
|
|
try {
|
|
loading.value = true
|
|
await changeCustomerActivation(id)
|
|
await fetch()
|
|
message.success('تغییر وضعیت با موفقیت انجام شد')
|
|
} catch (e) {
|
|
console.error(e)
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
function openConfirmUser(user: Customer) {
|
|
confirmInfo.value = user
|
|
confirmVisible.value = true
|
|
}
|
|
|
|
function handleArchive(customer: Customer) {
|
|
Modal.confirm({
|
|
title: 'آیا مشتری را بایگانی می کنید؟',
|
|
okText: 'تایید',
|
|
cancelText: 'رد',
|
|
centered: true,
|
|
onOk: () => archiveFunction(customer.id)
|
|
})
|
|
}
|
|
|
|
async function archiveFunction(id: number) {
|
|
try {
|
|
loading.value = true
|
|
await changeCustomerArchive(id)
|
|
await fetch()
|
|
message.success('مشتری با موفقیت بایگانی شد.')
|
|
} catch (e) {
|
|
console.error(e)
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
async function confirmUserFunction() {
|
|
try {
|
|
loading.value = true
|
|
await confirmUser(confirmInfo.value?.id)
|
|
await fetch()
|
|
confirmVisible.value = false
|
|
} catch (e) {
|
|
console.log(e)
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
async function changeCustomerOrderActivationFunction(id: number) {
|
|
try {
|
|
loading.value = true
|
|
await changeCustomerOrderActivation(id)
|
|
await fetch()
|
|
message.success('تغییر وضعیت سفارش دهی با موفقیت انجام شد')
|
|
} catch (e) {
|
|
console.error(e)
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="less">
|
|
.ant-popover,
|
|
.ant-tooltip {
|
|
z-index: 1001 !important;
|
|
}
|
|
</style>
|