云
2 天以前 a241b66efcc41e973290a6722fb7a4d79b833ea1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<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>