gaoluyang
2026-06-29 27cd042df9aca0383a49f3514bc21958dd890912
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<script setup lang="ts">
import type { CrmCustomerApi } from '#/api/crm/customer';
import type { SystemOperateLogApi } from '#/api/system/operate-log';
 
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
 
import { confirm, Page, useVbenModal } from '../../../../packages/effects/common-ui/src';
import { useTabs } from '../../../../packages/effects/hooks/src';
 
import { Card, message, Tabs } from 'ant-design-vue';
 
import {
  getCustomer,
  lockCustomer,
  putCustomerPool,
  receiveCustomer,
  updateCustomerDealStatus,
} from '#/api/crm/customer';
import { getOperateLogPage } from '#/api/crm/operateLog';
import { BizTypeEnum } from '#/api/crm/permission';
import { useDescription } from '#/components/description';
import { OperateLog } from '#/components/operate-log';
import { ACTION_ICON, TableAction } from '#/components/table-action';
import { $t } from '#/locales';
import { BusinessDetailsList } from '#/views/crm/business/components';
import { ContactDetailsList } from '#/views/crm/contact/components';
import { ContractDetailsList } from '#/views/crm/contract/components';
import { FollowUp } from '#/views/crm/followup';
import { PermissionList, TransferForm } from '#/views/crm/permission';
import { ReceivableDetailsList } from '#/views/crm/receivable/components';
import { ReceivablePlanDetailsList } from '#/views/crm/receivable/plan/components';
 
import Form from '../modules/form.vue';
import { useDetailSchema } from './data';
import DistributeForm from './modules/distribute-form.vue';
import Info from './modules/info.vue';
 
const route = useRoute();
const router = useRouter();
const tabs = useTabs();
 
const loading = ref(false); // 加载中
const customerId = ref(0); // 客户编号
const customer = ref<CrmCustomerApi.Customer>({} as CrmCustomerApi.Customer); // 客户详情
const logList = ref<SystemOperateLogApi.OperateLog[]>([]); // 操作日志
const permissionListRef = ref<InstanceType<typeof PermissionList>>(); // 团队成员列表 Ref
 
const [Descriptions] = useDescription({
  bordered: false,
  column: 4,
  schema: useDetailSchema(),
});
 
const [FormModal, formModalApi] = useVbenModal({
  connectedComponent: Form,
  destroyOnClose: true,
});
 
const [TransferModal, transferModalApi] = useVbenModal({
  connectedComponent: TransferForm,
  destroyOnClose: true,
});
 
const [DistributeModal, distributeModalApi] = useVbenModal({
  connectedComponent: DistributeForm,
  destroyOnClose: true,
});
 
/** 加载客户详情 */
async function loadCustomerDetail() {
  loading.value = true;
  try {
    customer.value = await getCustomer(customerId.value);
    // 操作日志
    const res = await getOperateLogPage({
      bizType: BizTypeEnum.CRM_CUSTOMER,
      bizId: customerId.value,
    });
    logList.value = res.list;
  } finally {
    loading.value = false;
  }
}
 
/** 返回列表页 */
function handleBack() {
  tabs.closeCurrentTab();
  router.push({ name: 'CrmCustomer' });
}
 
/** 编辑客户 */
function handleEdit() {
  formModalApi.setData({ id: customerId.value }).open();
}
 
/** 转移线索 */
function handleTransfer() {
  transferModalApi.setData({ id: customerId.value }).open();
}
 
/** 锁定客户 */
async function handleLock(lockStatus: boolean): Promise<boolean | undefined> {
  try {
    await confirm(`确定锁定客户【${customer.value.name}】吗?`);
  } catch {
    return false;
  }
  // 锁定客户
  await lockCustomer(customerId.value, lockStatus);
  // 提示并返回成功
  message.success(lockStatus ? '锁定客户成功' : '解锁客户成功');
  return true;
}
 
/** 领取客户 */
async function handleReceive(): Promise<boolean | undefined> {
  try {
    await confirm(`确定领取客户【${customer.value.name}】吗?`);
  } catch {
    return false;
  }
  // 领取客户
  await receiveCustomer([customerId.value]);
  // 提示并返回成功
  message.success('领取客户成功');
  return true;
}
 
/** 分配客户 */
function handleDistributeForm() {
  distributeModalApi.setData({ id: customerId.value }).open();
}
 
/** 客户放入公海 */
async function handlePutPool(): Promise<boolean | undefined> {
  try {
    await confirm(`确定将客户【${customer.value.name}】放入公海吗?`);
  } catch {
    return false;
  }
  // 放入公海
  await putCustomerPool(customerId.value);
  // 提示并返回成功
  message.success('放入公海成功');
  return true;
}
 
/** 更新成交状态操作 */
async function handleUpdateDealStatus(): Promise<boolean | undefined> {
  const dealStatus = !customer.value.dealStatus;
  try {
    await confirm(
      `确定更新成交状态为【${dealStatus ? '已成交' : '未成交'}】吗?`,
    );
  } catch {
    return false;
  }
  // 更新成交状态
  await updateCustomerDealStatus(customerId.value, dealStatus);
  // 提示并返回成功
  message.success('更新成交状态成功');
  return true;
}
 
/** 加载数据 */
onMounted(() => {
  customerId.value = Number(route.params.id);
  loadCustomerDetail();
});
</script>
 
<template>
  <Page auto-content-height :title="customer?.name" :loading="loading">
    <FormModal @success="loadCustomerDetail" />
    <TransferModal @success="loadCustomerDetail" />
    <DistributeModal @success="loadCustomerDetail" />
    <template #extra>
      <TableAction
        :actions="[
          {
            label: '返回',
            type: 'default',
            icon: 'lucide:arrow-left',
            onClick: handleBack,
          },
          {
            label: $t('ui.actionTitle.edit'),
            type: 'primary',
            icon: ACTION_ICON.EDIT,
            auth: ['crm:customer:update'],
            ifShow: permissionListRef?.validateWrite,
            onClick: handleEdit,
          },
          {
            label: '转移',
            type: 'primary',
            ifShow: permissionListRef?.validateOwnerUser,
            onClick: handleTransfer,
          },
          {
            label: '更改成交状态',
            type: 'default',
            ifShow: permissionListRef?.validateWrite,
            onClick: handleUpdateDealStatus,
          },
          {
            label: '锁定',
            type: 'default',
            ifShow:
              !customer.lockStatus && permissionListRef?.validateOwnerUser,
            onClick: handleLock.bind(null, true),
          },
          {
            label: '解锁',
            type: 'default',
            ifShow: customer.lockStatus && permissionListRef?.validateOwnerUser,
            onClick: handleLock.bind(null, false),
          },
          {
            label: '领取',
            type: 'primary',
            ifShow: !customer.ownerUserId,
            onClick: handleReceive,
          },
          {
            label: '分配',
            type: 'default',
            ifShow: !customer.ownerUserId,
            onClick: handleDistributeForm,
          },
          {
            label: '放入公海',
            type: 'default',
            ifShow:
              !!customer.ownerUserId && permissionListRef?.validateOwnerUser,
            onClick: handlePutPool,
          },
        ]"
      />
    </template>
    <Card class="min-h-[10%]">
      <Descriptions :data="customer" />
    </Card>
    <Card class="mt-4 min-h-[60%]">
      <Tabs>
        <Tabs.TabPane tab="跟进记录" key="1" :force-render="true">
          <FollowUp :biz-id="customerId" :biz-type="BizTypeEnum.CRM_CUSTOMER" />
        </Tabs.TabPane>
        <Tabs.TabPane tab="基本信息" key="2" :force-render="true">
          <Info :customer="customer" />
        </Tabs.TabPane>
        <Tabs.TabPane tab="联系人" key="3" :force-render="true">
          <ContactDetailsList
            :biz-id="customerId"
            :biz-type="BizTypeEnum.CRM_CUSTOMER"
            :customer-id="customerId"
          />
        </Tabs.TabPane>
        <Tabs.TabPane tab="团队成员" key="4" :force-render="true">
          <PermissionList
            ref="permissionListRef"
            :biz-id="customerId"
            :biz-type="BizTypeEnum.CRM_CUSTOMER"
            :show-action="true"
            @quit-team="handleBack"
          />
        </Tabs.TabPane>
        <Tabs.TabPane tab="商机" key="5" :force-render="true">
          <BusinessDetailsList
            :biz-id="customerId"
            :biz-type="BizTypeEnum.CRM_CUSTOMER"
            :customer-id="customerId"
          />
        </Tabs.TabPane>
        <Tabs.TabPane tab="合同" key="6" :force-render="true">
          <ContractDetailsList
            :biz-id="customerId"
            :biz-type="BizTypeEnum.CRM_CUSTOMER"
          />
        </Tabs.TabPane>
        <Tabs.TabPane tab="回款" key="7" :force-render="true">
          <ReceivablePlanDetailsList :customer-id="customerId" />
          <ReceivableDetailsList :customer-id="customerId" />
        </Tabs.TabPane>
        <Tabs.TabPane tab="操作日志" key="8" :force-render="true">
          <OperateLog :log-list="logList" />
        </Tabs.TabPane>
      </Tabs>
    </Card>
  </Page>
</template>