import React, { useState, useEffect } from 'react';
import { Form, Modal, Button, Table, message, Input, Icon, Pagination,Radio } from 'antd';
import request from '../../../utils/request';
import apis from '../../../services/apis';
import router from 'umi/router';
import styles from './style.less'

const { Column, ColumnGroup } = Table;
const ModelForm = props => {
    const formItemLayout = {
        labelCol: { span: 6 },
        wrapperCol: { span: 14 },
      };

    const {visible,currentData} = props;

    const { getFieldDecorator } = props.form

    const onCancel = () => {
        props.onCancel()
    }

    const updateContact = () => {
        request({ ...apis.promote.update, urlData: { id: currentData.serialNo }, data: {...props.form.getFieldsValue()} }).then((data) => {
            message.success('添加成功!');
            props.onCancel("success")
        })
    }

    return (
        <Modal
                title={currentData.status ==2 ? "立即跟进" : '添加备注'}
                width="900px"
                visible={visible}
                onCancel={onCancel}
                onOk={updateContact}
            >
                <Form {...formItemLayout} >
                    <Form.Item label="公司名称">
                        {getFieldDecorator('company',{
                            initialValue: currentData.company,
                        })(
                            <Input
                                disabled
                                prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
                                placeholder="公司名称"
                            />,
                        )}
                    </Form.Item>
                   { currentData.status ==2 && <Form.Item label="联系人">
                        {getFieldDecorator('name',{
                            initialValue: currentData.name
                        })(
                            <Input
                                disabled
                                prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
                                placeholder="联系人"
                            />,
                        )}
                    </Form.Item>}
                    {currentData.status ==2 && <Form.Item label="手机号">
                        {getFieldDecorator('phone',{
                            initialValue: currentData.phone
                        })(
                            <Input
                                disabled
                                prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
                                placeholder="手机号"
                            />,
                        )}
                    </Form.Item>}
                    {currentData.status ==2 && <Form.Item label="需求备注">
                        {getFieldDecorator('demand',{
                            initialValue: currentData.demand
                        })(
                            <Input
                                disabled
                                prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
                                placeholder="需求备注"
                            />,
                        )}
                    </Form.Item>}
                    {currentData.status ==2 && <Form.Item label="跟进状态">
                        {getFieldDecorator('status',{
                            initialValue: "0"
                        })(
                            <Radio.Group>
                                <Radio value="1">有效表单</Radio>
                                <Radio value="0">无效表单</Radio>
                            </Radio.Group>,
                        )}
                    </Form.Item>}
                 {currentData.status ==2 &&  <Form.Item label="跟进备注">
                        {getFieldDecorator('follow',{
                            initialValue: currentData.follow
                        })(
                            <Input
                                prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
                                placeholder="跟进备注"
                            />,
                        )}
                    </Form.Item>}
             {   currentData.status !=2 &&    <Form.Item label="备注信息">
                        {getFieldDecorator('remark',{
                            initialValue: currentData.remark
                        })(
                            <Input
                                prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
                                placeholder="备注信息"
                            />,
                        )}
                    </Form.Item>}
                </Form>
            </Modal>
    )
}

const WrappedRegistrationForm = Form.create()(ModelForm);
export default WrappedRegistrationForm;