Blame view

src/pages/OrderReport/index.tsx 10.4 KB
zhongnanhuang authored
1
import {
凌世锦 authored
2
3
  getOrderErpOrderZoNingSelectAll,
  postOrderErpOrderZoNingSelectSaleUserByProvince,
柏杨 authored
4
  postServiceOrderQueryReportFormsInformation,
zhongnanhuang authored
5
6
  postServiceOrderQuerySalesCode,
} from '@/services';
zhongnanhuang authored
7
8
9
import { enumToSelect } from '@/utils';
import {
  ProCard,
柏杨 authored
10
  ProForm,
zhongnanhuang authored
11
  ProFormCheckbox,
12
  ProFormDigit,
zhongnanhuang authored
13
14
15
  ProFormSelect,
  QueryFilter,
} from '@ant-design/pro-components';
柏杨 authored
16
import { Form, Space, Spin } from 'antd';
zhongnanhuang authored
17
import { useEffect, useState } from 'react';
zhongnanhuang authored
18
import { PRODUCT_BELONG_DEPARTMENT_OPTIONS } from '../Order/constant';
zhongnanhuang authored
19
20
import OrderDualAxes from './components/OrderDualAxes';
import OrderStatisticCard from './components/OrderStatisticCard';
zhongnanhuang authored
21
import './index.less';
zhongnanhuang authored
22
const OrderReportPage = () => {
zhongnanhuang authored
23
  const [salesCodeOptions, setSalesCodeOptions] = useState([]);
柏杨 authored
24
25
26
27
28
  const getCurrentMonth = () => {
    const month = new Date().getMonth(); // Returns a 0-based month (0-11)
    return month + 1; // To make it 1-based (1-12)
  };
  const month = getCurrentMonth();
柏杨 authored
29
  const [selectedYear, setSelectedYear] = useState('2025');
柏杨 authored
30
  const [selectedMonth, setSelectedMonth] = useState(month);
zhongnanhuang authored
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  /**
   * 获取销售代码枚举,在复制和编辑的时候判断是否为旧的代码
   */
  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);
  };
zhongnanhuang authored
46
47
48
49
50
51
52
  const [form] = Form.useForm<{
    salesCode: '';
    productBelongBusiness: '';
    dateRange: '';
  }>();
  const [statisticData, setStatisticData] = useState([]);
  const [loading, setLoading] = useState(false);
柏杨 authored
53
  const [statisticsMethod, setStatisticsMethod] = useState('MONTH_STATISTICS');
柏杨 authored
54
55
56
57
  // const onChange = (key: string) => {
  //   if (key === '本月') {
  //     setStatisticsMethod('MONTH_STATISTICS');
  //   }
zhongnanhuang authored
58
柏杨 authored
59
60
61
  //   if (key === '上月') {
  //     setStatisticsMethod('LAST_MONTH_STATISTICS');
  //   }
zhongnanhuang authored
62
柏杨 authored
63
64
65
66
67
68
69
70
71
  //   if (key === '本年') {
  //     setStatisticsMethod('YEAR_STATISTICS');
  //   }
  // };
  const [yearOptions] = useState([
    { value: '2025', label: '2025' },
    { value: '2024', label: '2024' },
    { value: '2023', label: '2023' },
  ]);
zhongnanhuang authored
72
柏杨 authored
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  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' },
  ]);
zhongnanhuang authored
88
89
90
91
  /**
   * 加载页面数据
   */
  const loadData = async () => {
柏杨 authored
92
93
94
95
96
    if (selectedMonth === '0') {
      setStatisticsMethod('YEAR_STATISTICS');
    } else {
      setStatisticsMethod('MONTH_STATISTICS');
    }
zhongnanhuang authored
97
98
99
    setLoading(true);
    let body = {
      statisticsMethod: '',
凌世锦 authored
100
      // salesCode: [null],
zhongnanhuang authored
101
      productBelongBusiness: form.getFieldValue('productBelongBusiness'),
102
      maxAccount: form.getFieldValue('maxAccount'),
zhongnanhuang authored
103
104
105
      includeExperimentalEquipment: form.getFieldValue(
        'includeExperimentalEquipment',
      ),
zhongnanhuang authored
106
107
108
      // beginTime:"",
      // endTime:""
    };
凌世锦 authored
109
110
    // console.log(form.getFieldValue('zoning').value);
凌世锦 authored
111
112
113
114
115
116
117
118
    // let res = await getOrderErpOrderZoNingSelectUserAll();
    // if (res && res.data) {
    //   let safeUserList = [];
    //   res.data.forEach((element) => {
    //     safeUserList.push(element.userName);
    //   });
    //   body = { ...body, salesCode: safeUserList };
    // }
凌世锦 authored
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
    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')) {
    }
zhongnanhuang authored
139
140
141
142
143

    // if(form.getFieldValue("dateRange")!==undefined){
    //   body.beginTime=formatDate(form.getFieldValue("dateRange")[0]),
    //   body.endTime=formatDate(form.getFieldValue("dateRange")[1])
    // }
柏杨 authored
144
145
146
147
148
    body.month = selectedMonth;
    body.year = selectedYear;
    const { data } = await postServiceOrderQueryReportFormsInformation({
      data: body,
    });
zhongnanhuang authored
149
150
151
152
    if (data !== undefined) {
      setStatisticData(data);
    }
zhongnanhuang authored
153
154
    setLoading(false);
  };
柏杨 authored
155
  const handleXValueClick = async (xValue, type) => {
柏杨 authored
156
157
    try {
      const [yearValue, monthValue] = xValue.split('-');
柏杨 authored
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
      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);
      }
柏杨 authored
174
175
176
177
    } catch (error) {
      console.error('Failed to fetch updated data:', error);
    }
  };
zhongnanhuang authored
178
179
180

  useEffect(() => {
    loadData();
柏杨 authored
181
  }, [selectedMonth, selectedYear]);
zhongnanhuang authored
182
183
184

  useEffect(() => {
    loadData();
zhongnanhuang authored
185
    getSalesCodeOptions();
zhongnanhuang authored
186
187
  }, []);
zhongnanhuang authored
188
189
190
191
192
193
194
195
196
197
198
199
  // const items: TabsProps['items'] = [
  //   {
  //     key: 'MONTH_STATISTICS',
  //     label: '本月统计',
  //     children: '',
  //   },
  //   {
  //     key: 'YEAR_STATISTICS',
  //     label: '本年统计',
  //     children: '',
  //   },
  // ];
zhongnanhuang authored
200
  return (
201
    <div>
zhongnanhuang authored
202
      <Space direction="vertical" size="middle" className="flex">
zhongnanhuang authored
203
        <Spin spinning={loading}>
zhongnanhuang authored
204
205
206
207
208
          <OrderStatisticCard
            data={statisticData}
            statisticsMethod={statisticsMethod}
            reFreshData={loadData}
          />
zhongnanhuang authored
209
210
        </Spin>
zhongnanhuang authored
211
        <ProCard tooltip="这是提示" bordered>
zhongnanhuang authored
212
213
214
215
          <QueryFilter
            split
            className="!p-0 order-statistic-search"
            labelWidth="auto"
216
            defaultCollapsed={false}
zhongnanhuang authored
217
218
219
220
221
222
223
224
225
            form={form}
            onFinish={async () => {
              loadData();
              return true;
            }}
          >
            <ProFormSelect
              name="salesCode"
              key="salesCode"
zhongnanhuang authored
226
              width="lg"
zhongnanhuang authored
227
228
              showSearch
              label="销售代表"
zhongnanhuang authored
229
230
              placeholder="请选择销售代表"
              options={salesCodeOptions}
zhongnanhuang authored
231
232
233
234
235
236
237
            />
            <ProFormSelect
              key="productBelongBusiness"
              placeholder="请输入所属事业部"
              name="productBelongBusiness"
              label="所属事业部"
              options={enumToSelect(PRODUCT_BELONG_DEPARTMENT_OPTIONS)}
zhongnanhuang authored
238
239
240
241
242
243
              onChange={(val: any) => {
                if (val === 'EXPERIMENTAL_EQUIPMENT') {
                  //勾选上包含设备事业部
                  form.setFieldValue('includeExperimentalEquipment', true);
                }
              }}
zhongnanhuang authored
244
            />
245
246
            <ProFormDigit label="排除大订单金额" name="maxAccount" min={0} />
zhongnanhuang authored
247
248
249
250
251
252
            <ProFormCheckbox
              key="includeExperimentalEquipment"
              name="includeExperimentalEquipment"
              initialValue={false}
              label="包含实验设备事业部汇总统计"
            />
凌世锦 authored
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276

            <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;
              }}
            />
zhongnanhuang authored
277
          </QueryFilter>
zhongnanhuang authored
278
279
        </ProCard>
zhongnanhuang authored
280
281
        <ProCard
          id="order-dual-axes-card"
zhongnanhuang authored
282
283
          title="汇总统计"
          tooltip="下方汇总统计未统计实验设备事业部数据,如需要请勾选包含实验设备事业部汇总统计"
zhongnanhuang authored
284
          extra={
柏杨 authored
285
286
287
288
            <div>
              <div>
                <ProForm.Group>
                  <ProFormSelect
柏杨 authored
289
290
                    name="selectedMonth"
                    key="selectedMonth"
柏杨 authored
291
292
293
                    width="100px"
                    // actionRef={mainTableRef}
                    // formRef={mainTableFormRef}
柏杨 authored
294
                    value={selectedMonth}
柏杨 authored
295
                    showSearch
柏杨 authored
296
                    placeholder="全部"
柏杨 authored
297
                    options={monthOptions}
柏杨 authored
298
299
300
301
                    onChange={(value) => {
                      const newValue = value === undefined ? '0' : value;
                      setSelectedMonth(newValue);
                    }}
柏杨 authored
302
303
                  />
                  <ProFormSelect
柏杨 authored
304
305
                    name="selectedYear"
                    key="selectedYear"
柏杨 authored
306
307
308
                    width="100px"
                    // actionRef={mainTableRef}
                    // formRef={mainTableFormRef}
柏杨 authored
309
                    value={selectedYear}
柏杨 authored
310
                    showSearch
柏杨 authored
311
                    placeholder="2025"
柏杨 authored
312
                    options={yearOptions}
柏杨 authored
313
                    onChange={(value) => {
柏杨 authored
314
315
                      const newValue = value === undefined ? '2025' : value;
                      setSelectedYear(newValue); // 更新选中值
柏杨 authored
316
                    }}
柏杨 authored
317
318
319
320
                  />
                </ProForm.Group>
              </div>
            </div>
zhongnanhuang authored
321
322
323
324
          }
          bordered
        >
          <Spin spinning={loading}>
zhongnanhuang authored
325
326
            <OrderDualAxes
              data={statisticData}
柏杨 authored
327
328
              statisticMethod={selectedMonth}
              onXValueClick={handleXValueClick}
zhongnanhuang authored
329
            />
zhongnanhuang authored
330
          </Spin>
zhongnanhuang authored
331
332
        </ProCard>
      </Space>
333
    </div>
zhongnanhuang authored
334
  );
zhongnanhuang authored
335
};
zhongnanhuang authored
336
337

export default OrderReportPage;