forked from gzzfw/frontEnd/gzDyh

dminyi
2024-08-09 a2a5220469a3e1f8bc216f47c887ca4c941920b0
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
/*
 * @Company: hugeInfo
 * @Author: lwh
 * @Date: 2022-03-07 09:05:38
 * @LastEditTime: 2022-05-17 15:36:35
 * @LastEditors: lwh
 * @Version: 1.0.0
 * @Description:   客户管理,新增修改
 */
import React, { useState, useEffect } from 'react';
import './index.less';
import { Steps, Input, Cascader, Button, Form, Select, DatePicker, Row, Col } from 'antd';
import { EyeTwoTone, EyeInvisibleOutlined } from '@ant-design/icons';
import moment from 'moment';
import { useNavigate } from 'react-router-dom';
import * as $$ from '../../../utils/utility';
const { Step } = Steps;
const { Option } = Select;
const { RangePicker } = DatePicker;
 
// 地区Option
const location = $$.locationOption;
const CustomerFormView = ({ list1, list2, formData, status, save = (data) => {} }) => {
    const [form] = Form.useForm();
    const [form1] = Form.useForm();
    const [form2] = Form.useForm();
    const [versionList, setVersionList] = useState(list1);
    const [mealList, setMealList] = useState(list2);
    const navigate = useNavigate();
    // 步骤0第一步   1.第二步
    const [steps, setSteps] = useState(0);
    const inputonChange = (e) => {
        const tableData = form.getFieldValue();
        // inputChange(tableData);
    };
 
    //第一步(下一步)
    const saveStep1 = async () => {
        const row = await form.validateFields();
        setSteps(1);
    };
 
    //第二步(提交)
    const saveStep2 = async () => {
        const row = await form1.validateFields();
        const tableData = form.getFieldValue();
        const tableData1 = form1.getFieldValue();
 
        save({ ...tableData, ...tableData1 });
    };
    //修改客户提交
    const saveStepEdit = async () => {
        const row = await form.validateFields();
        const tableData = form.getFieldValue();
        const tableData1 = form1.getFieldValue();
 
        save({ ...tableData1, ...tableData });
    };
 
    const reset = () => {
        form.resetFields();
    };
 
    const back = () => {
        navigate(-1);
    };
 
    // 第二步(上一步)
    const backStep2 = () => {
        setSteps(0);
    };
 
    //初始化组件回显
    useEffect(() => {
        form.setFieldsValue({
            ...formData.seCustom,
            regionals: formData.seCustom
                ? formData.seCustom.prov
                    ? [formData.seCustom.prov, formData.seCustom.city, formData.seCustom.areaName]
                    : undefined
                : undefined,
        });
        form1.setFieldsValue({ ...formData });
    }, []);
 
    //地域选择
    const cascaderChange = (name, value, selectedOptions) => {
        console.log('value', value);
        console.log('selectedOptions', selectedOptions);
        const tableData = form.getFieldValue();
        form.setFieldsValue({
            ...tableData,
            // [name]: value,
            [name + 's']: selectedOptions.map((i) => i.value),
            [name + 'Names']: selectedOptions.map((i) => i.label),
            prov: selectedOptions.map((i) => i.value)[0],
            provName: selectedOptions.map((i) => i.label)[0],
            city: selectedOptions.map((i) => i.value)[1],
            cityName: selectedOptions.map((i) => i.label)[1],
            area: selectedOptions.map((i) => i.value)[2],
            areaName: selectedOptions.map((i) => i.label)[2],
        });
    };
 
    // 版本选择
    const selectOnChange = (name, e, data) => {
        const tableData1 = form1.getFieldValue();
        const version = versionList.find((i) => i.id == e);
 
        //
        form1.setFieldsValue({
            ...tableData1,
            [name + 'Id']: data.value,
            [name + 'Name']: data.name,
            versionPrice: version.price,
            planPrice: version.price,
            mealId: undefined,
            mealIds: undefined,
            mealName: undefined,
            time: [moment(new Date()), moment(moment(new Date()).valueOf() + 86400000 * version.dead)],
            openTime: moment([moment(new Date()), moment(moment(new Date()).valueOf() + 86400000 * version.dead)][0]).valueOf(),
            expireTime: moment([moment(new Date()), moment(moment(new Date()).valueOf() + 86400000 * version.dead)][1]).valueOf(),
            // time: [moment(new Date()), moment(new Date())],
        });
    };
 
    // 增强包选择
    const selectMealOnChange = (name, e, data) => {
        const tableData1 = form1.getFieldValue();
 
        const mealPrice = eval(
            mealList
                .filter((i) => e.find((item) => item == i.id))
                .map((item) => item.price)
                .join('+')
        );
 
        form1.setFieldsValue({
            ...tableData1,
            [name + 'Ids']: data.map((i) => i.value).join(','),
            [name + 'Names']: data.map((i) => i.name).join(','),
            mealPrice,
            planPrice: tableData1.versionPrice + (mealPrice || 0),
        });
    };
 
    const rangePickerChange = (name, date, dateString) => {
        const tableData1 = form1.getFieldValue();
        form1.setFieldsValue({
            ...tableData1,
            openTime: moment(date[0]).valueOf(),
            expireTime: moment(date[1]).valueOf(),
        });
    };
    return (
        <>
            {status !== '2' && (
                <div style={{ width: '100%', display: 'flex', paddingRight: '108px', justifyContent: 'center' }}>
                    <Steps style={{ width: '600px' }} current={steps}>
                        <Step title="填写客户信息" />
                        <Step title="填写订购信息" />
                    </Steps>
                </div>
            )}
            {steps === 0 && (
                <Form form={form} layout="vertical">
                    <Row gutter={[24, 24]}>
                        <Col span={8}>
                            <Form.Item
                                label="客户名称"
                                name="trueName"
                                rules={[
                                    { required: true, message: `请输入客户名称` },
                                    {
                                        pattern: /^[^\s]*$/,
                                        message: '禁止输入空格',
                                    },
                                ]}
                            >
                                <Input onChange={inputonChange} placeholder={`请输入客户名称`} />
                            </Form.Item>
                        </Col>
                        <Col span={8}>
                            <Form.Item
                                label="管理员账号"
                                name="acc"
                                rules={[
                                    { required: true, message: `请输入管理员账号` },
                                    {
                                        pattern: /^[^\s]*$/,
                                        message: '禁止输入空格',
                                    },
                                ]}
                            >
                                <Input onChange={inputonChange} placeholder={`请输入管理员账号`} />
                            </Form.Item>
                        </Col>
                        <Col span={8}>
                            <Form.Item
                                label="密码"
                                name="cipherOpen"
                                rules={[
                                    { required: true, message: `请输入密码` },
                                    {
                                        pattern: /^[^\s]*$/,
                                        message: '禁止输入空格',
                                    },
                                ]}
                            >
                                <Input.Password
                                    placeholder="请输入密码"
                                    onChange={inputonChange}
                                    iconRender={(visible) => (visible ? <EyeTwoTone /> : <EyeInvisibleOutlined />)}
                                />
                            </Form.Item>
                        </Col>
                        <Col span={8}>
                            <Form.Item
                                label="负责人"
                                name="dutyName"
                                rules={[
                                    { required: true, message: `请输入负责人` },
                                    {
                                        pattern: /^[^\s]*$/,
                                        message: '禁止输入空格',
                                    },
                                ]}
                            >
                                <Input onChange={inputonChange} placeholder={`请输入负责人`} />
                            </Form.Item>
                        </Col>
                        <Col span={8}>
                            <Form.Item
                                label="负责人联系方式"
                                name="dutyMobile"
                                rules={[
                                    { required: false, message: `请输入负责人联系方式` },
                                    {
                                        pattern: /^[^\s]*$/,
                                        message: '禁止输入空格',
                                    },
                                ]}
                            >
                                <Input onChange={inputonChange} placeholder={`请输入负责人联系方式`} />
                            </Form.Item>
                        </Col>
                        <Col span={8}>
                            <Form.Item
                                label="联系地址"
                                name="addr"
                                rules={[
                                    { required: false, message: `请输入联系地址` },
                                    {
                                        pattern: /^[^\s]*$/,
                                        message: '禁止输入空格',
                                    },
                                ]}
                            >
                                <Input onChange={inputonChange} placeholder={`请输入联系地址`} />
                            </Form.Item>
                        </Col>
                        <Col span={8}>
                            <Form.Item label="地域" name="regionals" rules={[{ required: true, message: `请选择地域` }]}>
                                <Cascader
                                    placeholder="省/市/区(县)"
                                    options={location}
                                    allowClear
                                    // changeOnSelect
                                    onChange={(value, selectedOptions) => cascaderChange('regional', value, selectedOptions)}
                                />
                            </Form.Item>
                        </Col>
                        <Col span={8}>
                            <Form.Item
                                label="平台访问url"
                                name="url"
                                rules={[
                                    { required: true, message: `请输入平台访问url` },
                                    {
                                        pattern: /^[^\s]*$/,
                                        message: '禁止输入空格',
                                    },
                                ]}
                            >
                                <Input onChange={inputonChange} placeholder={`请输入平台访问url`} />
                            </Form.Item>
                        </Col>
                        <Col span={8}>
                            <Form.Item
                                label="备注"
                                name="remake"
                                rules={[
                                    { required: false, message: `请输入备注` },
                                    {
                                        pattern: /^[^\s]*$/,
                                        message: '禁止输入空格',
                                    },
                                ]}
                            >
                                <Input onChange={inputonChange} placeholder={`请输入备注`} />
                            </Form.Item>
                        </Col>
                    </Row>
                </Form>
            )}
            {steps === 1 && (
                <Form form={form1} layout="vertical">
                    <Row gutter={[24, 24]}>
                        <Col span={8}>
                            <Form.Item label="版本" name="verId" rules={[{ required: true, message: `请选择版本` }]}>
                                <Select onChange={(e, data) => selectOnChange('ver', e, data)} placeholder="请选择版本" allowClear>
                                    {versionList.map((item, index) => (
                                        <Option key={item.id} name={item.name} value={item.id}>
                                            {item.name}
                                        </Option>
                                    ))}
                                </Select>
                            </Form.Item>
                        </Col>
                        <Col span={8}>
                            <Form.Item label="增强包" name="mealId" rules={[{ required: false, message: `请选择增强包` }]}>
                                <Select mode="multiple" placeholder="请选择增强包" onChange={(e, data) => selectMealOnChange('meal', e, data)} allowClear>
                                    {mealList.map((item, index) => (
                                        <Option key={item.id} name={item.name} value={item.id}>
                                            {item.name}
                                        </Option>
                                    ))}
                                </Select>
                            </Form.Item>
                        </Col>
                        <Col span={8}>
                            <Form.Item label="资费总金额" name="planPrice" rules={[{ required: false, message: `请输入资费总金额` }]}>
                                <Input type={'number'} prefix={'¥'} suffix={'元'} onChange={inputonChange} placeholder={`请输入资费总金额`} />
                            </Form.Item>
                        </Col>
                        <Col span={8}>
                            <Form.Item label="版本开通(结束)时间" name="time" rules={[{ required: true, message: `请选择版本开通(结束)时间` }]}>
                                <RangePicker
                                    onChange={(date, dateString) => {
                                        rangePickerChange('time', date, dateString);
                                    }}
                                    format="YYYY-MM-DD"
                                    disabledDate={(current) => current < moment().startOf('day')}
                                />
                            </Form.Item>
                        </Col>
                    </Row>
                </Form>
            )}
            <div className="customer-form-view">
                <div style={{ width: '100%' }}>
                    <div className="customer-form-view-form">
                        <div>
                            {steps === 0 && status !== '2' && (
                                <div className="customer-form-view-foot-buttton">
                                    <Button onClick={saveStep1} type="primary">
                                        下一步
                                    </Button>
                                    <Button style={{ marginLeft: '12px' }} onClick={back}>
                                        返回
                                    </Button>
                                </div>
                            )}
                            {status == '2' && (
                                <div className="customer-form-view-foot-buttton">
                                    <Button onClick={saveStepEdit} type="primary">
                                        提交
                                    </Button>
                                    <Button style={{ marginLeft: '12px' }} onClick={reset}>
                                        重置
                                    </Button>
                                    <Button style={{ marginLeft: '12px' }} onClick={back}>
                                        返回
                                    </Button>
                                </div>
                            )}
                            {steps === 1 && (
                                <div className="customer-form-view-foot-buttton">
                                    <Button onClick={backStep2}>上一步</Button>
                                    <Button style={{ marginLeft: '12px' }} type="primary" onClick={saveStep2}>
                                        提交
                                    </Button>
                                </div>
                            )}
                        </div>
                    </div>
                </div>
            </div>
        </>
    );
};
CustomerFormView.propTypes = {};
export default CustomerFormView;