zhangwencui
7 天以前 7619c19a67c2ac824f803090bab753fc5ea14408
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
import type { VbenFormSchema } from '@vben/common-ui';
 
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
 
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { handleTree } from '@vben/utils';
 
import { LimitConfType } from '#/api/crm/customer/limitConfig';
import { getSimpleDeptList } from '#/api/system/dept';
import { getSimpleUserList } from '#/api/system/user';
 
/** 新增/修改的表单 */
export function useFormSchema(confType: LimitConfType): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'type',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'userIds',
      label: '规则适用人群',
      component: 'ApiSelect',
      componentProps: {
        api: getSimpleUserList,
        labelField: 'nickname',
        valueField: 'id',
        mode: 'multiple',
        allowClear: true,
        placeholder: '请选择规则适用人群',
      },
    },
    {
      fieldName: 'deptIds',
      label: '规则适用部门',
      component: 'ApiTreeSelect',
      componentProps: {
        api: async () => {
          const data = await getSimpleDeptList();
          return handleTree(data);
        },
        multiple: true,
        fieldNames: { label: 'name', value: 'id', children: 'children' },
        placeholder: '请选择规则适用部门',
        treeDefaultExpandAll: true,
      },
    },
    {
      fieldName: 'maxCount',
      label:
        confType === LimitConfType.CUSTOMER_QUANTITY_LIMIT
          ? '拥有客户数上限'
          : '锁定客户数上限',
      component: 'InputNumber',
      componentProps: {
        class: '!w-full',
        placeholder: `请输入${
          LimitConfType.CUSTOMER_QUANTITY_LIMIT === confType
            ? '拥有客户数上限'
            : '锁定客户数上限'
        }`,
      },
      rules: 'required',
    },
    {
      fieldName: 'dealCountEnabled',
      label: '成交客户是否占用拥有客户数',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING, 'boolean'),
        buttonStyle: 'solid',
        optionType: 'button',
      },
      dependencies: {
        triggerFields: [''],
        show: () => confType === LimitConfType.CUSTOMER_QUANTITY_LIMIT,
      },
      defaultValue: false,
    },
  ];
}
 
/** 列表的字段 */
export function useGridColumns(
  confType: LimitConfType,
): VxeTableGridOptions['columns'] {
  return [
    {
      field: 'id',
      title: '编号',
      fixed: 'left',
    },
    {
      field: 'users',
      title: '规则适用人群',
      formatter: ({ cellValue }) => {
        return cellValue
          .map((user: any) => {
            return user.nickname;
          })
          .join(',');
      },
    },
    {
      field: 'depts',
      title: '规则适用部门',
      formatter: ({ cellValue }) => {
        return cellValue
          .map((dept: any) => {
            return dept.name;
          })
          .join(',');
      },
    },
    {
      field: 'maxCount',
      title:
        confType === LimitConfType.CUSTOMER_QUANTITY_LIMIT
          ? '拥有客户数上限'
          : '锁定客户数上限',
    },
    {
      field: 'dealCountEnabled',
      title: '成交客户是否占用拥有客户数',
      visible: confType === LimitConfType.CUSTOMER_QUANTITY_LIMIT,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING },
      },
    },
    {
      field: 'createTime',
      title: '创建时间',
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 180,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}