gaoluyang
13 小时以前 cb9cd49627b65a4c0e137e08063271a8cefe1826
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
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { CrmFollowUpApi } from '#/api/crm/followup';
 
import { watch } from 'vue';
import { useRouter } from 'vue-router';
 
import { useVbenModal } from '@vben/common-ui';
 
import { Button, message } from 'ant-design-vue';
 
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
  deleteFollowUpRecord,
  getFollowUpRecordPage,
} from '#/api/crm/followup';
import { $t } from '#/locales';
 
import { useGridColumns } from './data';
import FollowUpRecordForm from './modules/form.vue';
 
/** 跟进记录列表 */
defineOptions({ name: 'FollowUpRecord' });
 
const props = defineProps<{
  bizId: number;
  bizType: number;
}>();
 
const { push } = useRouter();
 
/** 刷新表格 */
function handleRefresh() {
  gridApi.query();
}
 
/** 添加跟进记录 */
function handleCreate() {
  formModalApi.setData({ bizId: props.bizId, bizType: props.bizType }).open();
}
 
/** 删除跟进记录 */
async function handleDelete(row: CrmFollowUpApi.FollowUpRecord) {
  const hideLoading = message.loading({
    content: $t('ui.actionMessage.deleting', [row.id]),
    duration: 0,
  });
  try {
    await deleteFollowUpRecord(row.id);
    message.success($t('ui.actionMessage.deleteSuccess', [row.id]));
    handleRefresh();
  } finally {
    hideLoading();
  }
}
 
/** 打开联系人详情 */
function openContactDetail(id: number) {
  push({ name: 'CrmContactDetail', params: { id } });
}
 
/** 打开商机详情 */
function openBusinessDetail(id: number) {
  push({ name: 'CrmBusinessDetail', params: { id } });
}
 
const [FormModal, formModalApi] = useVbenModal({
  connectedComponent: FollowUpRecordForm,
  destroyOnClose: true,
});
 
const [Grid, gridApi] = useVbenVxeGrid({
  gridOptions: {
    columns: useGridColumns(props.bizType),
    height: 600,
    keepSource: true,
    proxyConfig: {
      ajax: {
        query: async ({ page }) => {
          return await getFollowUpRecordPage({
            pageNo: page.currentPage,
            pageSize: page.pageSize,
            bizType: props.bizType,
            bizId: props.bizId,
          });
        },
      },
    },
    rowConfig: {
      keyField: 'id',
      isHover: true,
    },
    toolbarConfig: {
      refresh: true,
    },
  } as VxeTableGridOptions<CrmFollowUpApi.FollowUpRecord>,
});
 
/** 监听业务 ID 变化 */
watch(
  () => props.bizId,
  () => {
    gridApi.query();
  },
);
</script>
 
<template>
  <div>
    <FormModal @success="handleRefresh" />
    <Grid>
      <template #toolbar-tools>
        <TableAction
          :actions="[
            {
              label: '写跟进',
              type: 'primary',
              icon: ACTION_ICON.EDIT,
              onClick: handleCreate,
            },
          ]"
        />
      </template>
      <template #contacts="{ row }">
        <Button
          v-for="contact in row.contacts || []"
          :key="`contact-${contact.id}`"
          type="link"
          class="ml-2"
          @click="openContactDetail(contact.id)"
        >
          {{ contact.name }}
        </Button>
      </template>
      <template #businesses="{ row }">
        <Button
          v-for="business in row.businesses || []"
          :key="`business-${business.id}`"
          type="link"
          class="ml-2"
          @click="openBusinessDetail(business.id)"
        >
          {{ business.name }}
        </Button>
      </template>
      <template #actions="{ row }">
        <TableAction
          :actions="[
            {
              label: $t('common.delete'),
              type: 'link',
              danger: true,
              icon: ACTION_ICON.DELETE,
              popConfirm: {
                title: $t('ui.actionMessage.deleteConfirm', [row.id]),
                confirm: handleDelete.bind(null, row),
              },
            },
          ]"
        />
      </template>
    </Grid>
  </div>
</template>