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
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { AftersalesCancellationApi } from '#/api/aftersales/cancellation';
 
/** 表单类型 */
export type CancellationFormType = 'create' | 'update';
 
/** 受理类型选项(对齐后端 AfterSaleCancellationDO.type) */
export const CANCELLATION_TYPE_OPTIONS = [
  { label: '客户退货', value: 'RETURN' },
  { label: '合同变更', value: 'CONTRACT_CHANGE' },
  { label: '合同终止', value: 'CONTRACT_TERMINATE' },
];
 
/** 状态选项 */
export const CANCELLATION_STATUS_OPTIONS = [
  { label: '草稿', value: 0 },
  { label: '待审批', value: 1 },
  { label: '已通过', value: 2 },
  { label: '已驳回', value: 3 },
  { label: '已取消', value: 4 },
];
 
/** 退货类型选项 */
export const RETURN_TYPE_OPTIONS = [
  { label: '退款退货', value: 1 },
  { label: '换货', value: 2 },
  { label: '仅退款', value: 3 },
];
 
/** 类型文案 */
export const CANCELLATION_TYPE_MAP: Record<string, string> =
  Object.fromEntries(
    CANCELLATION_TYPE_OPTIONS.map((o) => [o.value, o.label]),
  );
 
/** 状态文案 */
export const CANCELLATION_STATUS_MAP: Record<number, string> =
  Object.fromEntries(
    CANCELLATION_STATUS_OPTIONS.map((o) => [o.value, o.label]),
  );
 
/** 状态颜色 */
export const CANCELLATION_STATUS_COLOR: Record<number, string> = {
  0: 'default',
  1: 'processing',
  2: 'success',
  3: 'error',
  4: 'default',
};
 
/** 是否合同类受理 */
export function isContractType(type?: string) {
  return type === 'CONTRACT_CHANGE' || type === 'CONTRACT_TERMINATE';
}
 
/** 搜索表单 */
export function useCancellationSearchSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'code',
      label: '受理单号',
      component: 'Input',
      componentProps: { placeholder: '请输入受理单号' },
    },
    {
      fieldName: 'type',
      label: '受理类型',
      component: 'Select',
      componentProps: {
        options: CANCELLATION_TYPE_OPTIONS,
        placeholder: '请选择受理类型',
        allowClear: true,
      },
    },
    {
      fieldName: 'status',
      label: '状态',
      component: 'Select',
      componentProps: {
        options: CANCELLATION_STATUS_OPTIONS,
        placeholder: '请选择状态',
        allowClear: true,
      },
    },
  ];
}
 
/** 列表列 */
export function useCancellationGridColumns(): VxeTableGridOptions<AftersalesCancellationApi.Cancellation>['columns'] {
  return [
    { field: 'code', title: '受理单号', width: 170 },
    {
      field: 'type',
      title: '受理类型',
      width: 110,
      formatter: ({ cellValue }) =>
        CANCELLATION_TYPE_MAP[cellValue as string] ?? '-',
    },
    {
      field: 'status',
      title: '状态',
      width: 100,
      slots: { default: 'status' },
    },
    { field: 'reason', title: '申请原因', minWidth: 200, showOverflow: 'tooltip' },
    { field: 'customerId', title: '客户编号', width: 100 },
    { field: 'contractId', title: '合同编号', width: 100 },
    {
      field: 'expectedAmount',
      title: '预计金额',
      width: 120,
      align: 'right',
    },
    {
      field: 'executed',
      title: '下游执行',
      width: 200,
      slots: { default: 'executed' },
    },
    { field: 'creator', title: '创建人', width: 110 },
    { field: 'createTime', title: '创建时间', width: 170 },
    { field: 'operation', title: '操作', width: 220, fixed: 'right', slots: { default: 'operation' } },
  ];
}
 
/** 表单 Schema */
export function useCancellationFormSchema(
  formType: CancellationFormType,
): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: { show: () => false, triggerFields: [''] },
    },
    {
      fieldName: 'type',
      label: '受理类型',
      component: 'Select',
      componentProps: {
        options: CANCELLATION_TYPE_OPTIONS,
        placeholder: '请选择受理类型',
        // 已创建的受理单不允许改类型,避免下游动作错配
        disabled: formType === 'update',
      },
      rules: 'required',
    },
    {
      fieldName: 'ticketId',
      label: '售后工单',
      component: 'InputNumber',
      componentProps: {
        placeholder: '退货类型必填,填工单编号',
        class: 'w-full',
        min: 1,
      },
      dependencies: {
        triggerFields: ['type'],
        show: (values) => values.type === 'RETURN',
      },
    },
    {
      fieldName: 'returnType',
      label: '退货类型',
      component: 'Select',
      componentProps: {
        options: RETURN_TYPE_OPTIONS,
        placeholder: '请选择退货类型',
      },
      dependencies: {
        triggerFields: ['type'],
        show: (values) => values.type === 'RETURN',
      },
    },
    {
      fieldName: 'contractId',
      label: 'CRM 合同',
      component: 'InputNumber',
      componentProps: {
        placeholder: '合同变更/终止必填,填合同编号',
        class: 'w-full',
        min: 1,
      },
      dependencies: {
        triggerFields: ['type'],
        show: (values) => isContractType(values.type),
      },
    },
    {
      fieldName: 'customerId',
      label: '客户编号',
      component: 'InputNumber',
      componentProps: {
        placeholder: '退货类型必填',
        class: 'w-full',
        min: 1,
      },
      dependencies: {
        triggerFields: ['type'],
        show: (values) => values.type === 'RETURN',
      },
    },
    {
      fieldName: 'saleOrderNo',
      label: '销售订单号',
      component: 'Input',
      componentProps: { placeholder: '选填' },
    },
    {
      fieldName: 'expectedAmount',
      label: '预计金额',
      component: 'InputNumber',
      componentProps: { placeholder: '选填', class: 'w-full', min: 0 },
    },
    {
      fieldName: 'reason',
      label: '申请原因',
      component: 'Textarea',
      componentProps: {
        placeholder: '请填写申请原因',
        maxlength: 500,
        showCount: true,
        rows: 3,
      },
      rules: 'required',
    },
    {
      fieldName: 'remark',
      label: '备注',
      component: 'Textarea',
      componentProps: {
        placeholder: '选填',
        maxlength: 500,
        showCount: true,
        rows: 2,
      },
    },
  ];
}