//手术风险评估
import React from 'react';
import { Form, Button, Col, Row, Input, message, Modal, Select, Card, Divider, Table, Switch } from 'antd';
import FormItem from 'antd/lib/form/FormItem';
import { $http } from 'containers/config/https';
import { Util, ArraySome } from 'tools/index';
import store from 'store';
import './style/Rick.less';
import PatientInfo from '../Patient/PatientInfo';

// 用户数据
let userData;
// 点击编辑时记录当前行数据
let tableRecord = {};
const { Option } = Select;

const formItemLayout = {
  labelCol: { span: 10 },
  wrapperCol: { span: 14 },
}
const formItemLayoutAdd = {
  labelCol: { span: 12 },
  wrapperCol: { span: 12 },
}

const RiskAssessment = Form.create()(
  class extends React.Component {
    constructor(props) {
      super(props);
      let patientData = JSON.parse(sessionStorage.getItem('patientData'));
      userData = sessionStorage.userData ? JSON.parse(sessionStorage.userData) : {};
      this.state = {
        admID: "",
        tableData: [],
        visible: false,//弹框显示状态
        patientData: patientData,
        operationID: '',
        selectedRowKeys: [],
        selectedRows: [],
        operationCountData: [],
        operation: [],
        dataArr: [],
        anesthesiaLevel: [],
        operationClass: [],
        times: [],
        heal: [],
        opArr: [],
        toArr: [],
        anArr: [],
        OpertionInfo:{},
        countScore:0,
        a:0,
        b:0,
        c:0,
      };


    }
    componentDidMount() {
      this.props.onRef(this);
    }

    componentWillReceiveProps(nextProps) {


    }
    // 获取下拉框数据
    getSelect = () => {
      let data = {
        params: [{

        }]
      };
      $http.post('urlDeault', this, {
        code: "03055018",
        data: data,
        success: function (res) {
          if (+res.errorCode === 0) {
            this.setState({
              dataArr: res.result.dataArr,
              anesthesiaLevel: res.result.anesthesiaLevel,
              operationClass: res.result.operationClass,
              times: res.result.times,
              heal: res.result.heal,
              opArr: res.result.opArr,
              toArr:res.result.toArr,
              anArr:res.result.anArr,
            })
          }
        },
        error: function (error) {
          message.error('失败：' + error);
        }
      });
    }
    //保存
    handleSubmit = (e) => {
      e.preventDefault();
      this.props.form.validateFields((err, values) => {
        if (!err) {  //!err
          let data = {
            "params": [{
              ordOperID:this.props.operationID,
              userID: JSON.parse(window.sessionStorage.userData).userID || '',
              admID: ((this.state.patientData) && (this.state.patientData.admID != '')) ? this.state.patientData.admID : '',
              incisionCleanessID:values.incisionCleanessID || '',
              incisionScore: values.incisionScore || '',
              anesthesiaGradeID: values.anesthesiaGradeID || '',
              anesthesiaScore: values.anesthesiaScore || '',
              operationClassID: values.operationClassID || '',
              healID: values.healID || '',
              times: values.times || '',
              timesScore: values.timesScore || '',
              emergency: Util.replaceTrueFalse(values.emergency) || '',  
              nNISLevel: values.nNISLevel || '',
              opUserID: values.opUserID || '',
              anesthesiaUserID:values.anesthesiaUserID || '',
              tourUserID: values.tourUserID || '',
              countScore: values.countScore,
            }]
          };
          $http.post('urlADS', this, {
            code: "03055017",
            data: data,
            success: function (res) {
              let errorCode = res.errorCode;
              if (res.errorCode === "0") {
                // 成功提示
                message.success('成功');
                //新增或编辑成功重置form表单
                // this.handleReset();
                this.close();
              } else {
                this.setState({
                  OpertionInfo: {}
                });
              }
            }
          });
        }

      });
     
    }
    // 关闭
    close = () => {
      this.setState({
        visible: false,
      }, () => {
        this.props.handleQuery()
      });
    };
    // 打开弹框
    showModal = () => {
      this.getSelect();
      this.loadPatientMsg()//获取接诊病人信息
      let patientData = JSON.parse(sessionStorage.getItem('patientData'))
      if ((!patientData) || (patientData.admID == '')) {
        message.warning('请选择患者');
      }
      this.setState({
        visible: true,
      });
    };
    //手术切口清洁度分级
    onIncisionCleanessChange=(value)=>{
      this.setState({
        a:value
      },()=>{
        this.addScore();
      })
      this.props.form.setFieldsValue({incisionScore:value});
 

    }
    //麻醉分级 
    onIncisionGradeChange =(value) => {
      this.setState({
        b:value
      },()=>{
        this.addScore();
      })
      this.props.form.setFieldsValue({anesthesiaScore:value});
     
    }
    //手术持续时间
    onIncisiontimesChange =(value)=>{
      this.setState({
        c:value
      },()=>{
        this.addScore();
      })
      this.props.form.setFieldsValue({timesScore:value});
    
    }
    addScore=()=>{
      this.props.form.setFieldsValue({
        countScore:Number.parseInt(this.state.a)+Number.parseInt(this.state.b)+Number.parseInt(this.state.c),
      });
    }
    loadPatientMsg() {
      let patientData = JSON.parse(sessionStorage.getItem('patientData'))
      if (!patientData || patientData.admID == '') {
        return;
      }
      var params = {
        params: [{
          admID: patientData.admID ? patientData.admID : '',
          userID: userData.userID
        }]
      }
      $http.post('urlDeault', this, {
        code: "04020007",
        data: params,
        success: function (res) {
          if (res.errorCode == '0') {
            sessionStorage.setItem('titleData', JSON.stringify(res.result))
            this.setState({
              titleData: res.result,
            })
          }
        }
      });
    }
    render() {
      const { getFieldDecorator } = this.props.form;
      let OpertionInfo = this.state.OpertionInfo ? this.state.OpertionInfo : {};
      return (
        <Modal
          width='60%'
          title="手术风险评估"
          visible={this.state.visible}
          onCancel={this.close}
          footer={null}
        >
          <div className="outpatient-station-body">
            <Row style={{ background: 'rgba(248,248,248)', height: '45px', textAlign: 'left', lineHeight: '45px' }}>
              <Col span={24} style={{ display: 'flex' }}>
                <div style={{ width: '100%', height: 45, display: 'flex' }}>
                  <div className="ther" style={{ display: 'flex', flexShrink: '1', flex: '0 0 auto', width: 100 }}>
                    <div className={this.state.titleData && this.state.titleData.basicInfo.patSexCode == '1' ?
                      'splice-Boy' : (this.state.titleData && this.state.titleData.basicInfo.patSexCode == '2' ? 'splice-Girl' : 'splice-ther')}></div>
                    {/* <span className="bed">{this.state.titleData ? this.state.titleData.admInfo.admBedCode : ''}</span> */}
                    {/* <span>床号</span> */}
                  </div>
                  <div style={{ display: 'flex', flex: '1 1 auto' }}>
                    <div style={{ padding: '10px 0 0 20px' }} className="item">
                      <div>
                        <span className="bed">{this.state.titleData ? this.state.titleData.admInfo.admBedCode : ''}</span>
                        <i className="icon"></i>
                        <span>{this.state.titleData ? this.state.titleData.basicInfo.patName : ''}</span>
                      </div>
                      <div>
                        <i className="icon"></i>
                        <span>{this.state.titleData ? this.state.titleData.basicInfo.patSexDesc : ''}</span>
                      </div>
                      <div>
                        <i className="icon"></i>
                        <span>{this.state.titleData ? this.state.titleData.basicInfo.patAge : ''}</span>
                      </div>
                    </div>
                    <div style={{ fontWeight: 400, color: '#666666', fontSize: '16px', padding: '10px 0 0 20px' }} className="item">
                      <div>
                        <i className="icon"></i>
                        <span>{this.state.titleData ? this.state.titleData.admInfo.admLocDesc : ''}</span>
                      </div>
                      <div>
                        <i className="icon"></i>
                        <span>{this.state.titleData ? this.state.titleData.admInfo.admWardDesc : ''}</span>
                      </div>
                    </div>
                    <div style={{ fontWeight: 400, color: '#666666', fontSize: '16px', padding: '10px 0 0 20px' }} className="item">
                      <div>
                        <i className="icon"></i>
                        <span>{this.state.titleData ? this.state.titleData.basicInfo.patBirthDate : ''}</span>
                        <span>{this.state.titleData ? this.state.titleData.basicInfo.patBirthTime : ''}</span>
                      </div>
                    </div>
                  </div>
                </div>
              </Col>
            </Row>
            <div>
              <div>
                <Form style={{ minHeight: '400px' }}>
                  <Row style={{ paddingTop: "15px" }}>
                    <Col span={8} style={{ paddingRight: '15px' }}>
                      <FormItem {...formItemLayout} label='手术切口清洁度'>
                        {getFieldDecorator('incisionCleanessID', {
                          initialValue:OpertionInfo.incisionCleanessID ? OpertionInfo.incisionCleanessID : '',
                        })(
                          <Select showSearch allowClear optionFilterProp="role">
                            {this.state.dataArr.map(data => (<Select.Option key={data.id} onClick={()=>this.onIncisionCleanessChange(data.score)} value={data.id} score={data.score} role={data.code + '^' + data.descripts + '^' + data.descriptsSPCode}>{data.descripts}</Select.Option>))}
                          </Select>
                        )}
                      </FormItem>
                    </Col>
                    <Col span={8} style={{ paddingRight: '15px' }}>
                      <FormItem {...formItemLayout} label='麻醉分级 (ASA分级)'>
                        {getFieldDecorator('anesthesiaGradeID', {
                            initialValue:OpertionInfo.incisionCleanessID ? OpertionInfo.incisionCleanessID : '',
                        })(
                          <Select showSearch allowClear optionFilterProp="role">
                            {this.state.anesthesiaLevel.map(data => (<Select.Option key={data.id}  onClick={()=>this.onIncisionGradeChange(data.score)}  value={data.id} role={data.code + '^' + data.descripts + '^' + data.descriptsSPCode}>{data.descripts}</Select.Option>))}
                          </Select>
                        )}
                      </FormItem>
                    </Col>
                    <Col span={8} style={{ paddingRight: '15px' }}>
                      <FormItem {...formItemLayout} label='手术类别'>
                        {getFieldDecorator('operationClassID', {
                             initialValue:OpertionInfo.incisionCleanessID ? OpertionInfo.incisionCleanessID : '',
                        })(
                          <Select showSearch allowClear optionFilterProp="role">
                            {this.state.operationClass.map(data => (<Select.Option key={data.id} value={data.id} role={data.code + '^' + data.descripts + '^' + data.descriptsSPCode}>{data.descripts}</Select.Option>))}
                          </Select>
                        )}
                      </FormItem>
                    </Col>
                  </Row>
                  <Row>
                    <Col span={8} style={{ paddingRight: '15px' }}>
                      <FormItem {...formItemLayout} label='手术持续时间'>
                        {getFieldDecorator('times', {
                            initialValue:OpertionInfo.incisionCleanessID ? OpertionInfo.incisionCleanessID : '',
                        })(
                          <Select showSearch allowClear optionFilterProp="role">
                            {this.state.times.map(data => (<Select.Option key={data.id}  onClick={()=>this.onIncisiontimesChange(data.value)} value={data.id} role={data.code + '^' + data.descripts + '^' + data.descriptsSPCode}>{data.descripts}</Select.Option>))}
                          </Select>
                        )}
                      </FormItem>
                    </Col>
                    <Col span={3} style={{ paddingRight: '15px' }}>
                      <FormItem {...formItemLayout} label='急诊'>
                        {getFieldDecorator('emergency', {
                          valuePropName: 'checked',
                          initialValue: OpertionInfo.emergency === "Y" ? true : false,
                        })(
                          <Switch checkedChildren="是" unCheckedChildren="否" />
                        )}
                      </FormItem>
                    </Col>
                  </Row>
                  <Row>
                    <Col>
                      <Row>
                        <Col span={5} style={{ paddingRight: '15px' }}>
                          <FormItem {...formItemLayoutAdd} label='手术切口清洁度'>
                            {getFieldDecorator('incisionScore', {
                                 initialValue:OpertionInfo.incisionCleanessID ? OpertionInfo.incisionCleanessID : '',
                            })(
                              <Input allowClear >
                              </Input>
                            )}
                          </FormItem>
                        </Col>
                        <Col span={1} style={{ marginTop: '10px' }}>
                          <span>分</span>
                        </Col>
                        <Col span={6} style={{ paddingRight: '15px' }}>
                          <FormItem  {...formItemLayoutAdd} label='麻醉分级 (ASA分级)'>
                            {getFieldDecorator('anesthesiaScore', {
                                  initialValue:OpertionInfo.anesthesiaScore ? OpertionInfo.anesthesiaScore : '',
                            })(
                              <Input allowClear >
                              </Input>
                            )}
                          </FormItem>
                        </Col>
                        <Col span={1} style={{ marginTop: '10px' }}>
                          <span>分</span>
                        </Col>
                        <Col span={4}>
                          <FormItem  {...formItemLayoutAdd} label='手术持续时间'>
                            {getFieldDecorator('timesScore', {
                                 initialValue:OpertionInfo.timesScore ? OpertionInfo.timesScore : '',
                            })(
                              <Input allowClear style={{ paddingRight: '15px' }} >
                              </Input>
                            )}
                          </FormItem>
                        </Col>
                        <Col span={1} style={{ marginTop: '10px' }}>
                          <span>分</span>
                        </Col>
                        <Col span={3}>
                          <FormItem  {...formItemLayoutAdd} label='总分'>
                            {getFieldDecorator('countScore', {
                                 initialValue:OpertionInfo.countScore ? OpertionInfo.countScore : '',
                            })(
                              <Input allowClear >
                              </Input>
                            )}
                          </FormItem>
                        </Col>
                        <Col span={3}>
                          <FormItem  {...formItemLayoutAdd} label='级数'>
                            {getFieldDecorator('nNISLevel', {
                                initialValue:OpertionInfo.nNISLevel ? OpertionInfo.nNISLevel : '',
                            })(
                              <Input allowClear >
                              </Input>
                            )}
                          </FormItem>
                        </Col>
                      </Row>
                      <Row style={{ height: "80px", borderTop: "1px solid #eee", paddingTop: "15px" }}>
                        <Col span={8} style={{ paddingRight: '15px' }}>
                          <FormItem {...formItemLayout} label='切口愈合与感染情况'>
                            {getFieldDecorator('healID', {
                                initialValue:OpertionInfo.healID ? OpertionInfo.healID : '',
                            })(
                              <Select showSearch allowClear optionFilterProp="role">
                                {this.state.heal.map(data => (<Select.Option key={data.id} value={data.id} role={data.code + '^' + data.descripts + '^' + data.descriptsSPCode}>{data.descripts}</Select.Option>))}
                              </Select>
                            )}
                          </FormItem>
                        </Col>
                      </Row>
                      <Row>
                        <Col span={8} style={{ paddingRight: '15px' }}>
                          <FormItem {...formItemLayout} label='手术医生签名'>
                            {getFieldDecorator('opUserID', {
                                 initialValue:OpertionInfo.opUserID ? OpertionInfo.opUserID : '',
                            })(
                              <Select showSearch allowClear optionFilterProp="role">
                                {this.state.opArr.map(data => (<Select.Option key={data.id} value={data.id} role={data.code + '^' + data.descripts + '^' + data.descriptsSPCode}>{data.descripts}</Select.Option>))}
                              </Select>
                            )}
                          </FormItem>
                        </Col>
                        <Col span={8} style={{ paddingRight: '15px' }}>
                          <FormItem {...formItemLayout} label='麻醉医师签名'>
                            {getFieldDecorator('anesthesiaUserID', {
                                initialValue:OpertionInfo.anesthesiaUserID ? OpertionInfo.anesthesiaUserID : '',
                            })(
                              <Select showSearch allowClear optionFilterProp="role">
                                {this.state.anArr.map(data => (<Select.Option key={data.id} value={data.id} role={data.code + '^' + data.descripts + '^' + data.descriptsSPCode}>{data.descripts}</Select.Option>))}
                              </Select>
                            )}
                          </FormItem>
                        </Col>
                        <Col span={8} style={{ paddingRight: '15px' }}>
                          <FormItem {...formItemLayout} label='巡回护士签名'>
                            {getFieldDecorator('tourUserID', {
                                 initialValue:OpertionInfo.tourUserID ? OpertionInfo.tourUserID : '',
                            })(
                              <Select showSearch allowClear optionFilterProp="role">
                                {this.state.toArr.map(data => (<Select.Option key={data.id} value={data.id} role={data.code + '^' + data.descripts + '^' + data.descriptsSPCode}>{data.descripts}</Select.Option>))}
                              </Select>
                            )}
                          </FormItem>
                        </Col>
                      </Row>
                      <Row>
                        <Col offset={11} span={1}>
                          <Button
                            style={{ marginTop: '30px' }}
                            type='primary'
                            htmlType="submit"
                            onClick={this.handleSubmit}
                          >保存
							          	</Button>
                        </Col>
                      </Row>

                    </Col>
                  </Row>
                </Form>
              </div>
            </div>
          </div>
        </Modal>
      )
    }

  }

)
export default RiskAssessment;