// 疼痛评级
import React from 'react';
import { Form, message, Modal, Row, Col, Input, Radio } from 'antd';
import FormItem from 'antd/lib/form/FormItem';
import { $http } from '../../../containers/config/https';
import { Util } from 'tools/index';
import './index.less';
const formItemLayout = {    // label 和input宽度
    labelCol: { span: 8 },
    wrapperCol: { span: 16 },
};
const radioLayout = {    // label 和input宽度
    labelCol: { span: 4 },
    wrapperCol: { span: 20 },
};
// 用户数据
const userData = sessionStorage.userData ? JSON.parse(sessionStorage.userData) : {};
const PainRatingModal = Form.create()(
    class extends React.Component {
        constructor(props) {
            super(props);
            this.state = {
                visible: false,     // 弹框显示状态
                painMethod: [],      // 疼痛方法
                value: '',
                painRateSaved: false,   //保存标记
            }
        }

        componentDidMount() {
            this.getBasicData();
            this.props.onRef(this);
        }
        // 显示弹框
        showModal = () => {
            // console.log(this.props.params)
            this.setState({
                visible: true,
            });
        }

        // 获取基础数据
        getBasicData = () => {
            let data = {
                'params': [{}]
            };
            $http.post('urlADS', this, {
                code: "04140002",
                data: data,
                success: function (res) {
                    if (+res.errorCode == '0') {
                        this.setState({
                            painMethod: res.painMethod
                        })
                    }
                },
                error: function (error) {
                    message.error('失败：' + error);
                    this.setState({
                        showLoading: false
                    })
                }
            });
        }

        //根据评分记录ID查询详细评分数据
        loadFormData = () => {
            let data = {
                params: [{
                    painScoreID: this.props.patPainRateID
                }]
            }
            $http.post('urlS', this, {
                code: "04140010",
                data: data,
                success: (res) => {
                    if (+res.errorCode === 0) {
                        this.setState({
                            painRate: res.result.painScoreInfo
                        }
                        )
                    }
                }
            })
        }

        // 保存信息
        save = () => {
            const formData = this.props.form.getFieldsValue();
           
            let painRateInfo={
                    patID:this.props.patID,
                    // patTraumaGradeID:this.props.patTraumaGradeID,
                    score:formData.score,
                    position:formData.position,
                    duration:formData.duration,
                    nature:formData.nature,
                    method:formData.method,
            }
            this.props.handleOk({ painRateInfo: painRateInfo, painRate: false ,painRateSaved: true ,});
        }
        // 改变选项
        onChange = (a, b) => {
            this.props.form.validateFields((err, values) => {
                console.log(values)
            })
            // this.setState({value: })
        }
        onClick = (aa) => {
            // console.log(aa)
        }
        // 关闭弹框
        handleCancel = () => {
            this.props.form.resetFields(); // 清空表单
            this.props.handleOk({ painRateInfo: {}, painRate: false });
        }
        handleOk = (e) => {
            this.save();
        };

        render() {
            const { getFieldDecorator } = this.props.form;
            const painScore=this.state.painRate
            return (
                <Modal
                    width={'40%'}
                    title="疼痛评级"
                    visible={this.props.visible}   //{this.props.visible}
                    onCancel={this.handleCancel}
                    onOk={this.handleOk}
                    maskClosable={false}
                    className='clearPadding'
                    maskClosable={false}
                >
                    <div className='colors' style={{ width: '100%', height: '100%' }}>
                        <Form>
                            <Row>
                                <Col span={12}>
                                    <FormItem {...formItemLayout} label="疼痛分数">
                                        {getFieldDecorator('score', {
                                                initialValue: Util.isEmpty(painScore)?undefined:painScore.score,
                                            })(
                                            <Input />
                                        )}
                                    </FormItem>
                                </Col>
                                <Col span={12}>
                                    <FormItem {...formItemLayout} label="疼痛性质">
                                        {getFieldDecorator('position', {
                                                initialValue: Util.isEmpty(painScore)?undefined:painScore.position,
                                            })(
                                            <Input />
                                        )}
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col span={12}>
                                    <FormItem {...formItemLayout} label="疼痛部位">
                                        {getFieldDecorator('duration', {
                                                initialValue: Util.isEmpty(painScore)?undefined:painScore.duration,
                                            })(
                                            <Input />
                                        )}
                                    </FormItem>
                                </Col>
                                <Col span={12}>
                                    <FormItem {...formItemLayout} label="疼痛时间">
                                        {getFieldDecorator('nature', {
                                                initialValue: Util.isEmpty(painScore)?undefined:painScore.nature,
                                            })(
                                            <Input />
                                        )}
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row type="flex" justify="center">
                                <Col span={24}>
                                    <FormItem {...radioLayout} label="疼痛方法">
                                        {getFieldDecorator('method', {
                                            initialValue: Util.isEmpty(painScore)?undefined:painScore.method,
                                        })(
                                            <Radio.Group onChange={this.onChange}>
                                                {this.state.painMethod.map(item => (
                                                    <Radio value={item.id} onClick={this.onClick(item.code)}>{item.descripts}</Radio>
                                                ))}
                                            </Radio.Group>
                                        )}
                                    </FormItem>
                                </Col>
                            </Row>

                        </Form>
                    </div>
                </Modal>
            )
        }
    }
)
export default PainRatingModal;