Files
iot-device-management-frontend/apps/web-antd/src/views/crm/receivable/plan/data.ts

280 lines
6.4 KiB
TypeScript
Raw Normal View History

2025-05-29 19:58:40 +08:00
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
2025-06-26 15:46:07 +08:00
import { useUserStore } from '@vben/stores';
2025-06-12 16:48:33 +08:00
import { floatToFixed2 } from '@vben/utils';
2025-06-25 15:43:15 +08:00
import { getContractSimpleList } from '#/api/crm/contract';
2025-05-29 19:58:40 +08:00
import { getCustomerSimpleList } from '#/api/crm/customer';
2025-06-26 15:46:07 +08:00
import { getSimpleUserList } from '#/api/system/user';
2025-06-12 16:48:33 +08:00
import { DICT_TYPE, getDictOptions } from '#/utils';
2025-05-29 19:58:40 +08:00
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
2025-06-26 15:46:07 +08:00
const userStore = useUserStore();
2025-05-29 19:58:40 +08:00
return [
{
fieldName: 'customerId',
label: '客户',
component: 'ApiSelect',
rules: 'required',
componentProps: {
2025-06-25 18:22:06 +08:00
api: () => getCustomerSimpleList(),
fieldNames: {
label: 'name',
value: 'id',
},
2025-05-29 19:58:40 +08:00
placeholder: '请选择客户',
},
},
{
fieldName: 'contractId',
label: '合同',
2025-06-25 15:43:15 +08:00
component: 'Select',
2025-05-29 19:58:40 +08:00
rules: 'required',
componentProps: {
2025-06-25 15:43:15 +08:00
options: [],
2025-05-29 19:58:40 +08:00
placeholder: '请选择合同',
},
2025-06-25 15:43:15 +08:00
dependencies: {
triggerFields: ['customerId'],
disabled: (values) => !values.customerId,
async componentProps(values) {
if (!values.customerId) {
return {
options: [],
placeholder: '请选择客户',
};
}
const res = await getContractSimpleList(values.customerId);
return {
options: res.map((item) => ({
label: item.name,
value: item.id,
})),
placeholder: '请选择合同',
};
},
},
2025-05-29 19:58:40 +08:00
},
{
fieldName: 'period',
label: '期数',
component: 'Input',
componentProps: {
placeholder: '保存时自动生成',
disabled: true,
},
},
2025-06-26 15:46:07 +08:00
{
fieldName: 'ownerUserId',
label: '负责人',
component: 'ApiSelect',
componentProps: {
api: () => getSimpleUserList(),
fieldNames: {
label: 'nickname',
value: 'id',
},
},
dependencies: {
triggerFields: ['id'],
disabled: (values) => !values.id,
},
defaultValue: userStore.userInfo?.id,
rules: 'required',
},
2025-05-29 19:58:40 +08:00
{
fieldName: 'price',
label: '计划回款金额',
component: 'InputNumber',
rules: 'required',
componentProps: {
placeholder: '请输入计划回款金额',
min: 0,
precision: 2,
},
},
{
fieldName: 'returnTime',
label: '计划回款日期',
component: 'DatePicker',
rules: 'required',
componentProps: {
placeholder: '请选择计划回款日期',
2025-06-26 15:46:07 +08:00
showTime: false,
valueFormat: 'x',
format: 'YYYY-MM-DD',
2025-05-29 19:58:40 +08:00
},
},
{
fieldName: 'remindDays',
label: '提前几天提醒',
component: 'InputNumber',
rules: 'required',
componentProps: {
placeholder: '请输入提前几天提醒',
min: 0,
},
},
{
fieldName: 'returnType',
label: '回款方式',
component: 'Select',
rules: 'required',
componentProps: {
options: getDictOptions(DICT_TYPE.CRM_RECEIVABLE_RETURN_TYPE, 'number'),
placeholder: '请选择回款方式',
},
},
{
fieldName: 'remark',
label: '备注',
component: 'Textarea',
componentProps: {
placeholder: '请输入备注',
rows: 4,
},
},
];
}
/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'customerId',
label: '客户',
component: 'ApiSelect',
componentProps: {
2025-06-25 18:22:06 +08:00
api: () => getCustomerSimpleList(),
fieldNames: {
label: 'name',
value: 'id',
},
2025-05-29 19:58:40 +08:00
placeholder: '请选择客户',
},
},
{
fieldName: 'contractNo',
label: '合同编号',
component: 'Input',
componentProps: {
placeholder: '请输入合同编号',
},
},
];
}
export function useGridColumns(): VxeTableGridOptions['columns'] {
return [
{
title: '客户名称',
field: 'customerName',
2025-06-02 20:52:10 +08:00
minWidth: 150,
2025-05-29 19:58:40 +08:00
fixed: 'left',
slots: { default: 'customerName' },
},
{
title: '合同编号',
field: 'contractNo',
2025-06-02 20:52:10 +08:00
minWidth: 200,
2025-05-29 19:58:40 +08:00
},
{
title: '期数',
field: 'period',
2025-06-02 20:52:10 +08:00
minWidth: 150,
2025-05-29 19:58:40 +08:00
slots: { default: 'period' },
},
{
title: '计划回款金额(元)',
field: 'price',
2025-06-02 20:52:10 +08:00
minWidth: 160,
formatter: 'formatAmount2',
2025-05-29 19:58:40 +08:00
},
{
title: '计划回款日期',
field: 'returnTime',
2025-06-02 20:52:10 +08:00
minWidth: 180,
2025-05-29 19:58:40 +08:00
formatter: 'formatDateTime',
},
{
title: '提前几天提醒',
field: 'remindDays',
2025-06-02 20:52:10 +08:00
minWidth: 150,
2025-05-29 19:58:40 +08:00
},
{
title: '提醒日期',
field: 'remindTime',
2025-06-02 20:52:10 +08:00
minWidth: 180,
2025-05-29 19:58:40 +08:00
formatter: 'formatDateTime',
},
{
title: '回款方式',
field: 'returnType',
2025-06-02 20:52:10 +08:00
minWidth: 130,
2025-05-29 19:58:40 +08:00
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.CRM_RECEIVABLE_RETURN_TYPE },
},
},
{
title: '备注',
field: 'remark',
2025-06-02 20:52:10 +08:00
minWidth: 120,
2025-05-29 19:58:40 +08:00
},
{
title: '负责人',
field: 'ownerUserName',
2025-06-02 20:52:10 +08:00
minWidth: 120,
2025-05-29 19:58:40 +08:00
},
{
title: '实际回款金额(元)',
field: 'receivable.price',
2025-06-02 20:52:10 +08:00
minWidth: 160,
formatter: 'formatAmount2',
2025-05-29 19:58:40 +08:00
},
{
title: '实际回款日期',
field: 'receivable.returnTime',
2025-06-02 20:52:10 +08:00
minWidth: 180,
2025-05-29 19:58:40 +08:00
formatter: 'formatDateTime',
},
{
title: '未回款金额(元)',
field: 'unpaidPrice',
2025-06-02 20:52:10 +08:00
minWidth: 160,
2025-05-29 19:58:40 +08:00
formatter: ({ row }) => {
if (row.receivable) {
return floatToFixed2(row.price - row.receivable.price);
2025-05-29 19:58:40 +08:00
}
return floatToFixed2(row.price);
2025-05-29 19:58:40 +08:00
},
},
{
title: '更新时间',
field: 'updateTime',
2025-06-02 20:52:10 +08:00
minWidth: 180,
2025-05-29 19:58:40 +08:00
formatter: 'formatDateTime',
},
{
title: '创建时间',
field: 'createTime',
2025-06-02 20:52:10 +08:00
minWidth: 180,
2025-05-29 19:58:40 +08:00
formatter: 'formatDateTime',
},
{
title: '创建人',
field: 'creatorName',
2025-06-02 20:52:10 +08:00
minWidth: 100,
2025-05-29 19:58:40 +08:00
},
{
title: '操作',
field: 'actions',
2025-06-26 15:46:07 +08:00
width: 220,
2025-05-29 19:58:40 +08:00
fixed: 'right',
slots: { default: 'actions' },
},
];
}