<script lang="ts" setup>
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { CrmCustomerApi } from '#/api/crm/customer';
|
|
import { ref } from 'vue';
|
import { useRouter } from 'vue-router';
|
|
import { confirm, Page, useVbenModal } from '@vben/common-ui';
|
import { downloadFileFromBlobPart } from '@vben/utils';
|
|
import { Button, message } from 'ant-design-vue';
|
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import {
|
exportCustomer,
|
getCustomerPage,
|
receiveCustomer,
|
} from '#/api/crm/customer';
|
import { $t } from '#/locales';
|
|
import DistributeForm from '../detail/modules/distribute-form.vue';
|
import { useGridColumns, useGridFormSchema } from './data';
|
|
const { push } = useRouter();
|
const receiving = ref(false);
|
const [DistributeModal, distributeModalApi] = useVbenModal({
|
connectedComponent: DistributeForm,
|
destroyOnClose: true,
|
});
|
|
function handleRefresh() {
|
gridApi.grid.clearCheckboxRow();
|
gridApi.query();
|
}
|
|
function getCustomerIds(row?: CrmCustomerApi.Customer): number[] {
|
const records: CrmCustomerApi.Customer[] = row
|
? [row]
|
: gridApi.grid.getCheckboxRecords();
|
const ids = records.map((item) => item.id!);
|
if (ids.length === 0) {
|
message.warning('请先勾选客户');
|
}
|
return ids;
|
}
|
|
/** 领取单条或勾选的公海客户 */
|
async function handleReceive(row?: CrmCustomerApi.Customer) {
|
if (receiving.value) return;
|
const ids = getCustomerIds(row);
|
if (ids.length === 0) return;
|
receiving.value = true;
|
try {
|
try {
|
await confirm(
|
row
|
? `确定领取客户【${row.name}】吗?`
|
: `确定领取选中的 ${ids.length} 个客户吗?`,
|
);
|
} catch {
|
return;
|
}
|
await receiveCustomer(ids);
|
message.success('领取客户成功');
|
handleRefresh();
|
} finally {
|
receiving.value = false;
|
}
|
}
|
|
/** 分配单条或勾选的公海客户 */
|
function handleDistribute(row?: CrmCustomerApi.Customer) {
|
const ids = getCustomerIds(row);
|
if (ids.length === 0) return;
|
distributeModalApi.setData({ ids }).open();
|
}
|
|
/** 导出表格 */
|
async function handleExport() {
|
const data = await exportCustomer({
|
...(await gridApi.formApi.getValues()),
|
pool: true,
|
sceneType: 4,
|
});
|
downloadFileFromBlobPart({ fileName: '客户公海.xls', source: data });
|
}
|
|
/** 查看客户详情 */
|
function handleDetail(row: CrmCustomerApi.Customer) {
|
push({ name: 'CrmCustomerDetail', params: { id: row.id } });
|
}
|
|
const [Grid, gridApi] = useVbenVxeGrid({
|
formOptions: {
|
schema: useGridFormSchema(),
|
},
|
gridOptions: {
|
columns: useGridColumns(),
|
height: 'auto',
|
keepSource: true,
|
proxyConfig: {
|
ajax: {
|
query: async ({ page }, formValues) => {
|
return await getCustomerPage({
|
pageNo: page.currentPage,
|
pageSize: page.pageSize,
|
pool: true,
|
sceneType: 4,
|
...formValues,
|
});
|
},
|
},
|
},
|
rowConfig: {
|
keyField: 'id',
|
isHover: true,
|
},
|
toolbarConfig: {
|
refresh: true,
|
search: true,
|
},
|
} as VxeTableGridOptions<CrmCustomerApi.Customer>,
|
});
|
</script>
|
|
<template>
|
<Page auto-content-height>
|
<DistributeModal @success="handleRefresh" />
|
<Grid>
|
<template #toolbar-tools>
|
<TableAction
|
:actions="[
|
{
|
label: '领取客户',
|
type: 'primary',
|
auth: ['crm:customer:receive'],
|
disabled: receiving,
|
onClick: () => handleReceive(),
|
},
|
{
|
label: '分配客户',
|
auth: ['crm:customer:distribute'],
|
disabled: receiving,
|
onClick: () => handleDistribute(),
|
},
|
{
|
label: $t('ui.actionTitle.export'),
|
type: 'primary',
|
icon: ACTION_ICON.DOWNLOAD,
|
auth: ['crm:customer:export'],
|
onClick: handleExport,
|
},
|
]"
|
/>
|
</template>
|
<template #actions="{ row }">
|
<TableAction
|
:actions="[
|
{
|
label: '领取',
|
type: 'link',
|
auth: ['crm:customer:receive'],
|
disabled: receiving,
|
onClick: () => handleReceive(row),
|
},
|
{
|
label: '分配',
|
type: 'link',
|
auth: ['crm:customer:distribute'],
|
disabled: receiving,
|
onClick: () => handleDistribute(row),
|
},
|
]"
|
/>
|
</template>
|
<template #name="{ row }">
|
<Button type="link" @click="handleDetail(row)">
|
{{ row.name }}
|
</Button>
|
</template>
|
</Grid>
|
</Page>
|
</template>
|