/*
 * Creator:     ML
 * CreatDate:   2020-02-19
 * descripts：  黑名单信息 明细 暂时未用
 * */
import React from 'react';
import { Form, Input, Select, Button, message, Row, Icon, Divider, Popconfirm, DatePicker, TimePicker, Table, Col,Switch } from 'antd';
import { $http } from 'containers/config/https';
import moment from 'moment';
import store from 'store';
import CardTypeRead from 'components/cardType/index';

const { Option } = Select;

class BlacklistInformationDetails extends React.Component {
  constructor() {
    super();
    var userData = JSON.parse(sessionStorage.getItem('userData'))
    this.state = {
      userData: userData,
      info: {},
      n: 8,
      m: 12,
      isFlag: true,
      patientID:""
    };
  }

  componentDidMount() {
    this.props.onAttRef(this)
    // this.getHopSelect()
    // this.getBlackListType()
    this.getReason()
  }
  // //获取医院下拉框
  // getHopSelect = () => {
  //   let data = {
  //     params: [{
  //       hospID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).hospID : "",
  //       logonGroupID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).groupID : "",
  //       logonHospID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).hospID : "",
  //     }],
  //   }
  //   $http.post('urlS', this, {
  //     code: '01040001',
  //     data: data,
  //     success: function (res) {
  //       if (+res.errorCode === 0) {
  //         this.setState({
  //           hospArr: res.result
  //         })
  //       }
  //     }
  //   })
  // }
  // //获取黑名单类型下拉框
  // getBlackListType = () => {
  //   let data = {
  //     params: [{
  //       language: this.state.userData.language,
  //     }],
  //   }
  //   $http.post('urlS', this, {
  //     code: '03050187',
  //     data: data,
  //     success: function (res) {
  //       if (+res.errorCode === 0) {
  //         this.setState({
  //           blackListTypeArr: res.result.Data
  //         })
  //       }
  //     }
  //   })
  // }
    //获取原因下拉框
    getReason = () => {
      let data = {
        params: [{
          language: this.state.userData.language,
        }],
      }
      $http.post('urlS', this, {
        code: '03050188',
        data: data,
        success: function (res) {
          if (+res.errorCode === 0) {
            this.setState({
              reasonArr: res.result.Data
            })
          }
        }
      })
    }
  // getInfo = (info) => {
  //   if(info.activeFlag=="Y"){
  //     this.setState({
  //       isFlag:true
  //     })
  //   }else{
  //     this.setState({
  //       isFlag:false
  //     })
  //   }
  //   this.setState({
  //     info,
  //     patientID:info.patientID,
  //   })
  // }
  // clearInfo = (n) => {
  //   this.props.form.resetFields();
  //   this.setState({
  //     info: {},
  //     patientID:"",
  //     isFlag:true
  //   }, () => {
  //     if (n) this.props.newAdd()
  //   })
  // }
  saveAtt = () => {
    const { info,patientID } = this.state
    this.props.form.validateFields((err, values) => {
      if (!err&&patientID) {
        let data = {
          params: [{
            ID: info && info.ID ? info.ID : "",
            // hospID: values && values.hospID || "",
            // patientID,
            activeFlag: this.state.isFlag ? "Y" : "N",//是否立即生效,
            // name:this.props.form.getFieldValue('name'),
            // mobile:this.props.form.getFieldValue('mobile'),
            // blackListTypeID:this.props.form.getFieldValue('blackListTypeID'),
            blackReasonDr:this.props.form.getFieldValue('blackReasonDr'),
            // startDate: values.startDate ? moment(values.startDate).format('YYYY-MM-DD') : undefined,
            // endDate: values.stopDate ? moment(values.stopDate).format('YYYY-MM-DD') : undefined,
            createDate: moment(moment()).format('YYYY-MM-DD'),
            updateTime: moment(moment()).format('HH:mm'),
            // createTime: info && !info.ID ? moment(moment()).format('HH:mm') : "",
            createUserID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).userID : "",
            updateUserID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).userID : "",
          }]
        }
        $http.post('urlS', this, {
          code: '03050186',
          data: data,
          success: function (res) {
            if (+res.errorCode === 0) {
              if (info && info.ID) {
                message.success(this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacUpdateCompleted ? this.setMessage('BlacklistInformationInterfacUpdateCompleted', 'descripts') : '更新成功')
                this.props.handleQuery()
              } else {
                message.success(this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacAddedSuccessfully ? this.setMessage('BlacklistInformationInterfacAddedSuccessfully', 'descripts') : '添加成功')
                this.props.handleQuery()
              }
            }
          }
        })

      }else{
        if(!patientID){
          message.warning(this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacPleaseRetrievePatient? this.setMessage('BlacklistInformationInterfacPleaseRetrievePatient', 'descripts') : "请检索病人信息")
        }
      }
    })
  }
  // del = (info) => {
  //   let data = {
  //     params: [{
  //       ID: info && info.ID ? info.ID : "",
  //       updateUserID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).userID : ""
  //     }]
  //   }
  //   $http.post('urlS', this, {
  //     code: '03050182',
  //     data: data,
  //     success: function (res) {
  //       if (+res.errorCode === 0) {
  //         message.success(this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacSuccessfullyDeleted ? this.setMessage('BlacklistInformationInterfacSuccessfullyDeleted', 'descripts') : '删除成功')
  //         this.props.handleQuery()
  //         this.clearInfo("1")
  //       }
  //     }
  //   })
  // }
  //国际化
  setMessage(name, message) {
    return this.props.localeProvider ? this.props.localeProvider[name][message] : ''
  }
  getValue = (cardType, patCardNo) => {
    this.setState({
      cardType,
      patCardNo,
    })
  }
  handleSwithChange = (v) => {
    this.setState({
      isFlag: v
    })
  }
  //获取病人信息
  // getPersonInfo=()=>{
  //   const {cardType,patCardNo}=this.state
  //   let data = {
  //     params: [{
  //       number:this.props.form.getFieldValue('number'),
  //       cardTypeID:cardType,
  //       cardNo:patCardNo,
  //     }]
  //   }
  //   $http.post('urlS', this, {
  //     code: '03040004',
  //     data: data,
  //     success: function (res) {
  //       if (+res.errorCode === 0) {
  //         this.props.form.setFieldsValue({ name: res.data.patName,mobile:res.data.patMobile })
  //         this.setState({
  //           patientID:res.data.patID,
  //         })
  //       }else{
  //         this.props.form.setFieldsValue({ name: undefined,mobile:undefined })
  //         this.setState({
  //           patientID:""
  //         })
  //       }
  //     }
  //   })
  // }
  render() {
    const { info } = this.state;

    const { getFieldDecorator } = this.props.form;
    // //医院
    // let hosOp = []
    // this.state.hospArr && this.state.hospArr.map((item) => {
    //   hosOp.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
    // })
    // //黑名单类型
    // let blackListTypeOp = []
    // this.state.blackListTypeArr && this.state.blackListTypeArr.map((item) => {
    //   blackListTypeOp.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
    // })
    //原因
    let reasonOp = []
    this.state.reasonArr && this.state.reasonArr.map((item) => {
      reasonOp.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
    })
    const formLayout = {
      labelCol: { span: 10 },
      wrapperCol: { span: 14 },
    }
    // const formLayoutPerson = {
    //   labelCol: { span: 5 },
    //   wrapperCol: { span: 18 },
    // }
    const formLayoutRe = {
      labelCol: { span: 5 },
      wrapperCol: { span: 19 },
    }
    // const formLayoutType = {
    //   labelCol: { span: 12 },
    //   wrapperCol: { span: 12 },
    // }
    return (
      <div>
        <Form layout={'horizontal'}>
          {/* <Row>
            <Col span={12}>
              <Form.Item label={this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacPersonIdentification ? this.setMessage('BlacklistInformationInterfacPersonIdentification', 'descripts') : '人员标识'} {...formLayoutPerson}>
                {getFieldDecorator('number', {
                  initialValue: info.number && info.number ? info.number : undefined,
                  rules: [{ required: false, message: "" }],
                })(
                  <Input placeholder={this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacPatientIDNumber ? this.setMessage('BlacklistInformationInterfacPatientIDNumber', 'descripts') : "病人ID/身份证号码"} onPressEnter={this.getPersonInfo}></Input>
                )}
              </Form.Item>
            </Col>
            <Col span={12}>
              <CardTypeRead getValue={this.getValue} sendInfo={info} getQuery={this.getPersonInfo} n={this.state.n} m={this.state.m} ></CardTypeRead>
            </Col>
          </Row> */}
          {/* <Row>
            <Col span={6}>
              <Form.Item label={this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacName ? this.setMessage('BlacklistInformationInterfacName', 'descripts') : '姓名'} {...formLayout}>
                {getFieldDecorator('name', {
                  initialValue: info.name && info.name ? info.name : undefined,
                  rules: [{ required: false, message: "" }],
                })(
                  <Input disabled></Input>
                )}
              </Form.Item>
            </Col>
            <Col span={6}>
              <Form.Item label={this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacMobile ? this.setMessage('BlacklistInformationInterfacMobile', 'descripts') : '手机号码'} {...formLayout}>
                {getFieldDecorator('mobile', {
                  initialValue: info.mobile && info.mobile ? info.mobile : undefined,
                  rules: [{ required: false, message: "" }],
                })(
                  <Input disabled></Input>
                )}
              </Form.Item>
            </Col>
            <Col span={6}>
              <Form.Item label={this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacHospital ? this.setMessage('BlacklistInformationInterfacHospital', 'descripts') : '医院'} {...formLayout} {...formLayout}>
                {getFieldDecorator('hospID', {
                  initialValue: info.hospID && info.hospID ? String(info.hospID) : undefined,
                  rules: [{ required: true, message: this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacHospital ? this.setMessage('BlacklistInformationInterfacHospital', 'message') : '请选择医院' }],
                })(
                  <Select
                  >
                    {hosOp}
                  </Select>
                )}
              </Form.Item>
            </Col>
            <Col span={6}>
              <Form.Item label={this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacBlacklistType ? this.setMessage('BlacklistInformationInterfacBlacklistType', 'descripts') : '黑名单类型'} {...formLayout} {...formLayoutType}>
                {getFieldDecorator('blackListTypeID', {
                  initialValue: info.blackListTypeID && info.blackListTypeID ? String(info.blackListTypeID) : undefined,
                  rules: [{ required: true, message: this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacBlacklistType ? this.setMessage('BlacklistInformationInterfacBlacklistType', 'message') : '请选择黑名单类型' }],
                })(
                  <Select
                  >
                    {blackListTypeOp}
                  </Select>
                )}
              </Form.Item>
            </Col>
          </Row> */}
          <Row>
            {/* <Col span={6} className="starDataDom">
              <Form.Item label={this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacEffectiveDate ? this.setMessage('BlacklistInformationInterfacEffectiveDate', 'descripts') : '生效日期'} {...formLayout}>
                {getFieldDecorator('startDate', {
                  initialValue: info && info.startDate ? moment(info.startDate, "YYYY-MM-DD") : moment(),
                  rules: [{ required: true, message: this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacEffectiveDate ? this.setMessage('BlacklistInformationInterfacEffectiveDate', 'message') : '请选择开始日期' }],
                })(
                  <DatePicker style={{ width: '100%' }} disabledDate={(curDate) => {
                    return curDate && curDate > moment().endOf('day');
                  }} />
                )}
              </Form.Item>
            </Col>
            <Col span={6} >
              <Form.Item label={this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacExpirationDate ? this.setMessage('BlacklistInformationInterfacExpirationDate', 'descripts') : '失效日期'} {...formLayout}>
                {getFieldDecorator('stopDate', {
                  initialValue: info && info.endDate ? moment(info.endDate, "YYYY-MM-DD") : undefined,
                  rules: [{ required: false, message:"" }],
                })(
                  <DatePicker style={{ width: '100%' }} />
                )}
              </Form.Item>
            </Col > */}
            <Col span={6}>
              <Form.Item label={this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacReason ? this.setMessage('BlacklistInformationInterfacReason', 'descripts') : '原因'} {...formLayoutRe}>
                {getFieldDecorator('blackReasonDr', {
                  initialValue: info.blackReason && info.blackReason ? info.blackReason : undefined,
                  rules: [{ required: false, message: "" }],
                })(
                  <Select>
                    {reasonOp}
                  </Select>
                )}
              </Form.Item>
            </Col>
            {/* <Col span={6}>
              <Form.Item label={this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacEffectiveImmediately ? this.setMessage('BlacklistInformationInterfacEffectiveImmediately', 'descripts') : '即刻生效'} {...formLayout}>
                {getFieldDecorator('activeFlag', {
                  initialValue: undefined,
                  rules: [{ required: false, message: "" }],
                })(
                  <Switch checkedChildren={this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacYes ? this.setMessage('BlacklistInformationInterfacYes', 'descripts') : '是'} unCheckedChildren={this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacNo ? this.setMessage('BlacklistInformationInterfacNo', 'descripts') : '否'} checked={this.state.isFlag} onChange={(val) => this.handleSwithChange(val, 'isFlag')} />

                )}
              </Form.Item>
            </Col> */}
          </Row>
          <Row style={{ display: "flex", justifyContent: "space-between", justifyItems: "center", alignItems: "center", height: "48px" }}>
            <Button type="primary" onClick={this.saveAtt}>{info && info.ID ? this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacUpdate ? this.setMessage('BlacklistInformationInterfacUpdate', 'descripts') : '更新' : this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacAdd ? this.setMessage('BlacklistInformationInterfacAdd', 'descripts') : '新增'}</Button>
            {/* <Popconfirm title={this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacWhether ? this.setMessage('BlacklistInformationInterfacWhether', 'descripts') : '是否要删除该配置'} onConfirm={() => this.del(info)}>
              <Button disabled={info && !info.ID} type="danger">{this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacDelete ? this.setMessage('BlacklistInformationInterfacDelete', 'descripts') : '删除'}</Button>
            </Popconfirm> */}
            <Button type="primary" onClick={() => this.clearInfo("1")}>{this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacReset ? this.setMessage('BlacklistInformationInterfacReset', 'descripts') : '重置'}</Button>
          </Row>
        </Form>
      </div>
    )
  }
};
const BlacklistInformationDetail = Form.create()(BlacklistInformationDetails);
export default BlacklistInformationDetail;