index.tsx
10.2 KB
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
import {
getOrderErpOrderZoNingSelectAll,
postOrderErpOrderZoNingSelectSaleUserByProvince,
postServiceOrderQueryReportFormsInformation,
postServiceOrderQuerySalesCode,
} from '@/services';
import { enumToSelect } from '@/utils';
import {
ProCard,
ProForm,
ProFormCheckbox,
ProFormDigit,
ProFormSelect,
QueryFilter,
} from '@ant-design/pro-components';
import { Form, Space, Spin } from 'antd';
import { useEffect, useState } from 'react';
import { PRODUCT_BELONG_DEPARTMENT_OPTIONS } from '../Order/constant';
import OrderDualAxes from './components/OrderDualAxes';
import OrderStatisticCard from './components/OrderStatisticCard';
import './index.less';
const OrderReportPage = () => {
const [salesCodeOptions, setSalesCodeOptions] = useState([]);
const [selectedYear, setSelectedYear] = useState('2025');
const [selectedMonth, setSelectedMonth] = useState('0');
/**
* 获取销售代码枚举,在复制和编辑的时候判断是否为旧的代码
*/
const getSalesCodeOptions = async () => {
const res = await postServiceOrderQuerySalesCode();
let options = res.data?.map((item) => {
return {
label: item.userName,
value: item.userName,
number: item.number,
};
});
setSalesCodeOptions(options);
};
const [form] = Form.useForm<{
salesCode: '';
productBelongBusiness: '';
dateRange: '';
}>();
const [statisticData, setStatisticData] = useState([]);
const [loading, setLoading] = useState(false);
const [statisticsMethod, setStatisticsMethod] = useState('YEAR_STATISTICS');
// const onChange = (key: string) => {
// if (key === '本月') {
// setStatisticsMethod('MONTH_STATISTICS');
// }
// if (key === '上月') {
// setStatisticsMethod('LAST_MONTH_STATISTICS');
// }
// if (key === '本年') {
// setStatisticsMethod('YEAR_STATISTICS');
// }
// };
const [yearOptions] = useState([
{ value: '2025', label: '2025' },
{ value: '2024', label: '2024' },
{ value: '2023', label: '2023' },
]);
const [monthOptions] = useState([
{ value: '0', label: '全部' },
{ value: '1', label: '1' },
{ value: '2', label: '2' },
{ value: '3', label: '3' },
{ value: '4', label: '4' },
{ value: '5', label: '5' },
{ value: '6', label: '6' },
{ value: '7', label: '7' },
{ value: '8', label: '8' },
{ value: '9', label: '9' },
{ value: '10', label: '10' },
{ value: '11', label: '11' },
{ value: '12', label: '12' },
]);
/**
* 加载页面数据
*/
const loadData = async () => {
if (selectedMonth === '0') {
setStatisticsMethod('YEAR_STATISTICS');
} else {
setStatisticsMethod('MONTH_STATISTICS');
}
setLoading(true);
let body = {
statisticsMethod: '',
// salesCode: [null],
productBelongBusiness: form.getFieldValue('productBelongBusiness'),
maxAccount: form.getFieldValue('maxAccount'),
includeExperimentalEquipment: form.getFieldValue(
'includeExperimentalEquipment',
),
// beginTime:"",
// endTime:""
};
// console.log(form.getFieldValue('zoning').value);
// let res = await getOrderErpOrderZoNingSelectUserAll();
// if (res && res.data) {
// let safeUserList = [];
// res.data.forEach((element) => {
// safeUserList.push(element.userName);
// });
// body = { ...body, salesCode: safeUserList };
// }
if (form.getFieldValue('salesCode')) {
body = { ...body, salesCode: [form.getFieldValue('salesCode')] };
}
if (form.getFieldValue('zoning')) {
if (
form.getFieldValue('zoning').value !== '' ||
form.getFieldValue('zoning').value !== null ||
form.getFieldValue('zoning').value !== undefined
) {
let res = await postOrderErpOrderZoNingSelectSaleUserByProvince({
data: form.getFieldValue('zoning').value,
});
if (res && res.data) {
body = { ...body, salesCode: res.data };
}
}
}
if (form.getFieldValue('zoning')) {
}
// if(form.getFieldValue("dateRange")!==undefined){
// body.beginTime=formatDate(form.getFieldValue("dateRange")[0]),
// body.endTime=formatDate(form.getFieldValue("dateRange")[1])
// }
body.month = selectedMonth;
body.year = selectedYear;
const { data } = await postServiceOrderQueryReportFormsInformation({
data: body,
});
if (data !== undefined) {
setStatisticData(data);
}
setLoading(false);
};
const handleXValueClick = async (xValue, type) => {
try {
const [yearValue, monthValue] = xValue.split('-');
if (type?.includes('年')) {
const adjustedYearValue = (parseInt(yearValue, 10) - 1).toString();
const adjustedMonthValue = monthValue.startsWith('0')
? monthValue.slice(1)
: monthValue;
// 更新年份和月份选项的选中值
setSelectedYear(adjustedYearValue);
setSelectedMonth(adjustedMonthValue);
} else {
// 更新年份和月份选项的选中值
const adjustedMonthValue = monthValue.startsWith('0')
? monthValue.slice(1)
: monthValue;
setSelectedYear(yearValue);
setSelectedMonth(adjustedMonthValue);
}
} catch (error) {
console.error('Failed to fetch updated data:', error);
}
};
useEffect(() => {
loadData();
}, [selectedMonth, selectedYear]);
useEffect(() => {
loadData();
getSalesCodeOptions();
}, []);
// const items: TabsProps['items'] = [
// {
// key: 'MONTH_STATISTICS',
// label: '本月统计',
// children: '',
// },
// {
// key: 'YEAR_STATISTICS',
// label: '本年统计',
// children: '',
// },
// ];
return (
<div>
<Space direction="vertical" size="middle" className="flex">
<Spin spinning={loading}>
<OrderStatisticCard
data={statisticData}
statisticsMethod={statisticsMethod}
reFreshData={loadData}
/>
</Spin>
<ProCard tooltip="这是提示" bordered>
<QueryFilter
split
className="!p-0 order-statistic-search"
labelWidth="auto"
defaultCollapsed={false}
form={form}
onFinish={async () => {
loadData();
return true;
}}
>
<ProFormSelect
name="salesCode"
key="salesCode"
width="lg"
showSearch
label="销售代表"
placeholder="请选择销售代表"
options={salesCodeOptions}
/>
<ProFormSelect
key="productBelongBusiness"
placeholder="请输入所属事业部"
name="productBelongBusiness"
label="所属事业部"
options={enumToSelect(PRODUCT_BELONG_DEPARTMENT_OPTIONS)}
onChange={(val: any) => {
if (val === 'EXPERIMENTAL_EQUIPMENT') {
//勾选上包含设备事业部
form.setFieldValue('includeExperimentalEquipment', true);
}
}}
/>
<ProFormDigit label="排除大订单金额" name="maxAccount" min={0} />
<ProFormCheckbox
key="includeExperimentalEquipment"
name="includeExperimentalEquipment"
initialValue={false}
label="包含实验设备事业部汇总统计"
/>
<ProFormSelect
key="zoning"
name="zoning"
width="md"
label="所属地区"
fieldProps={{
labelInValue: true,
}}
placeholder="请选择"
request={async () => {
let zoningOptions = [];
let res = await getOrderErpOrderZoNingSelectAll();
if (res && res.data) {
console.log(res.data);
zoningOptions = res.data.map((item) => ({
value: item.zoning,
label: item.zoning,
}));
}
return zoningOptions;
}}
/>
</QueryFilter>
</ProCard>
<ProCard
id="order-dual-axes-card"
title="汇总统计"
tooltip="下方汇总统计未统计实验设备事业部数据,如需要请勾选包含实验设备事业部汇总统计"
extra={
<div>
<div>
<ProForm.Group>
<ProFormSelect
name="selectedMonth"
key="selectedMonth"
width="100px"
// actionRef={mainTableRef}
// formRef={mainTableFormRef}
value={selectedMonth}
showSearch
placeholder="全部"
options={monthOptions}
onChange={(value) => {
const newValue = value === undefined ? '0' : value;
setSelectedMonth(newValue);
}}
/>
<ProFormSelect
name="selectedYear"
key="selectedYear"
width="100px"
// actionRef={mainTableRef}
// formRef={mainTableFormRef}
value={selectedYear}
showSearch
placeholder="2025"
options={yearOptions}
onChange={(value) => {
const newValue = value === undefined ? '2025' : value;
setSelectedYear(newValue); // 更新选中值
}}
/>
</ProForm.Group>
</div>
</div>
}
bordered
>
<Spin spinning={loading}>
<OrderDualAxes
data={statisticData}
statisticMethod={selectedMonth}
onXValueClick={handleXValueClick}
/>
</Spin>
</ProCard>
</Space>
</div>
);
};
export default OrderReportPage;