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
<!-- 待审核回款 -->
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { CrmReceivableApi } from '#/api/crm/receivable';
 
import { useRouter } from 'vue-router';
 
import { Button, message } from 'ant-design-vue';
 
import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { getReceivablePage, updateReceivableStatus } from '#/api/crm/receivable';
import { useGridColumns } from '#/views/crm/receivable/data';
 
import { AUDIT_STATUS } from '../data';
 
const { push } = useRouter();
const emit = defineEmits<{ refresh: [] }>();
 
/** 审核 */
async function handleAudit(row: CrmReceivableApi.Receivable) {
  const hideLoading = message.loading({
    content: '审核中...',
    duration: 0,
  });
  try {
    await updateReceivableStatus(row.id!, 20);
    message.success('审核成功');
    await gridApi.query();
    emit('refresh');
  } finally {
    hideLoading();
  }
}
 
/** 打开回款详情 */
function handleDetail(row: CrmReceivableApi.Receivable) {
  push({ name: 'CrmReceivableDetail', params: { id: row.id } });
}
 
/** 打开客户详情 */
function handleCustomerDetail(row: CrmReceivableApi.Receivable) {
  push({ name: 'CrmCustomerDetail', params: { id: row.customerId } });
}
 
/** 打开合同详情 */
function handleContractDetail(row: CrmReceivableApi.Receivable) {
  if (row.contractId) push({ name: 'CrmContractDetail', params: { id: row.contractId } });
}
 
function handleInvoiceDetail(row: CrmReceivableApi.Receivable) {
  if (row.invoiceId) push({ name: 'CrmInvoiceDetail', params: { id: row.invoiceId } });
}
 
const [Grid, gridApi] = useVbenVxeGrid({
  formOptions: {
    schema: [
      {
        fieldName: 'auditStatus',
        label: '审核状态',
        component: 'Select',
        componentProps: {
          allowClear: true,
          options: AUDIT_STATUS,
        },
        defaultValue: AUDIT_STATUS[0]!.value,
      },
    ],
  },
  gridOptions: {
    columns: useGridColumns(),
    height: 'auto',
    keepSource: true,
    proxyConfig: {
      ajax: {
        query: async ({ page }, formValues) => {
          return await getReceivablePage({
            pageNo: page.currentPage,
            pageSize: page.pageSize,
            sceneType: 1,
            ...formValues,
          });
        },
      },
    },
    rowConfig: {
      keyField: 'id',
      isHover: true,
    },
    toolbarConfig: {
      refresh: true,
      search: true,
    },
  } as VxeTableGridOptions<CrmReceivableApi.Receivable>,
});
</script>
 
<template>
  <Grid>
    <template #no="{ row }">
      <Button type="link" @click="handleDetail(row)">
        {{ row.no }}
      </Button>
    </template>
    <template #customerName="{ row }">
      <Button type="link" @click="handleCustomerDetail(row)">
        {{ row.customerName }}
      </Button>
    </template>
    <template #contractNo="{ row }">
      <Button v-if="row.contractId" type="link" @click="handleContractDetail(row)">
        {{ row.contract?.no ?? row.contractNo ?? '—' }}
      </Button>
      <span v-else>—</span>
    </template>
    <template #invoiceNo="{ row }">
      <template v-if="row.invoice">
        <Button type="link" @click="handleInvoiceDetail(row)">{{ row.invoice.no }}</Button>
        <span> / {{ row.invoice.invoiceNo ?? '—' }} / ¥{{ row.invoice.price ?? 0 }}</span>
      </template>
      <span v-else>—</span>
    </template>
    <template #actions="{ row }">
      <TableAction :actions="[{
        label: '审核',
        type: 'link',
        auth: ['crm:receivable:update'],
        ifShow: row.auditStatus === 10,
        onClick: handleAudit.bind(null, row),
      }]" />
    </template>
  </Grid>
</template>