
/*
 * Creator:     ML
 * CreatDate:   2019-08-15
 * descripts：  门诊医生医嘱录入 外院会诊病理申请单 
*/
import React from 'react';
import moment from 'moment';
import { Form, Row, Col, Input,Table ,Select,Radio, DatePicker, Button, Modal, message,Divider,Tooltip,Icon,Card,Checkbox,Badge,Fragment,Pagination  } from 'antd';
import { $http } from '../../containers/config/https';
import store from '../../store';
import './css/OrderTemple.less';
const { TextArea } = Input;
const renderContent = function (value, row, index) {
  const obj = {
      children: value,
      props: {},
  };
  if (!row.ordTempletDesc) {
      obj.props.colSpan = 0;
  }
  return obj;
};

const formItemLayout = { // label 和input宽度
    labelCol: { span: 9 },
    wrapperCol: { span: 15 }
}
const formItemLayoutD = { // label 和input宽度
    labelCol: { span: 8 },
    wrapperCol: { span: 15 }
}
const formItemLayoutR = { 
labelCol: { span: 9 },
wrapperCol: { span: 13 }
}
const formItemLayoutAc= { 
    labelCol: { span: 7 },
    wrapperCol: { span: 13 }
}
const formItemLayoutCli = {
    labelCol: { span: 2 },
    wrapperCol: { span: 22 }
}
//左侧可选项
const plainOptions = ['检查', '检验', '病理'];
const CheckboxGroup = Checkbox.Group;

const userData = sessionStorage.userData ? JSON.parse(sessionStorage.userData) : {}
const FormItem = Form.Item;
const Option = Select.Option;
const PathologicalApplicationForm = Form.create()(
class PathologicalApplicationForm extends React.Component {
  cacheOriginData = {};
    constructor() {
        super()
        this.state = {
          leftData:[],//左边查询到的表格数据
          rightData:[],//右边双击后的表格数据
          rightUnitDr:[],
          findInfo:'请输入查询条件',//查询提示信息
          checked:true,//默认选择生效
          visible:false,//添加/修改医嘱模板弹窗显示
          isMod:-1,//是否点击编辑
          ordTempletID:"",//编辑行id
          ordTempletDesc:"",//模板名称
          ordTempletAlias:"",//模板别名
          ordTempletCat:"",//医嘱分类
          rowId:"",//表格行id 设置颜色
          ordShow:false,//当前模板显示
          baseOrdTepCat:[],//添加医嘱模板类型选择
          baseTempType:[],//添加医嘱模板类型选择
          baseUnit:[],//添加医嘱明细单位类型选择
          selectedData: [],//医嘱明细选中
          selectedId: [],//医嘱明细选中
          tempChildDis:false,//左侧编辑 选择类型
          btnStatus:true,
          selectedRowKeys_right:[],//右侧勾选中行
          selectedRow_right:[],
          selectrow: "",//获取行 当前选中行
          deteleOrdId:"",//选中删除行
          leftDisRow:false,
          ordTempId:1,//医嘱大类选择值
          isAdd:false,//是否点击添加
          ordDetailValue:"",//医嘱明细输入值
          ordDetailData:[],//医嘱项表格数据
          OrdDaShow:false,//医嘱项表格数据显隐
          OrdDaRowId:"",//医嘱项表格行id
          OrdCanType:"",//医嘱项允许录入类型
          ordTemPrice:0,//医嘱项行单价
          editDis:true,//未选中
          total: 0,//医嘱项表格总数据
          page: 1,//页数
          pageSize: 10,//显示数
          nowRowID:"",//医嘱明细表格行id
          canSaveStatus:true,//能否保存
          initRored:{},//原始右侧表格行
          ordTempletDetailItemDesc:"",
          ordTempletDetailQty:"",
          ordTempletDetailQtyUnitDr:"",
          ordTempletDetailID:"",
          disAdd:false,//是否可新增
          newOpen:[],



          checkAll: false,//左侧全选
          checkedList:[],//左侧可选项
          rightTopTableData:[],//右上小表格数据
          acValue:1,//默认选中处理方式
          formDieLenght:0,//自病发至死亡过程描述字数
          TherProcessLenght:0,//病史及治疗过程描述字数
          checclinicalExaminationkInpLenght:0,//临床体格检查及化验检查描述字数
        }
        this.detailDeInput = React.createRef();
    }
    componentDidMount=()=>{
      // 初始化设置table的高度以及表体的高度
      if(document.querySelector('.ant-table-body')){
        document.querySelector('.ant-table-body').style.height = store.getState().tableHeight.y + 'px'
    }
    
    
      this.handleQuery()
      //获取医嘱模板类型下拉框数据
      let data = {}
      data = {
        params: [{
          ordTempletCatFlag:"1",
          orderTemplItemTypeFlag:"1",
          unitFlag:"1"
        }],
      }
      $http.post('urlS', this, {
        code: '03050017',
        data:data,
        success: function (res) {
          if (+res.errorCode === 0) {
            //   console.log("添加医嘱模板",res)
              this.setState({
                baseOrdTepCat:res.ordTempletCat,
                baseTempType:res.orderTemplItemType,
                baseUnit:res.unit
              })
          } 
        }
      })
    }
    //获取病发到死亡过程描述字数
    getFormDieLenght=(name)=>{
       this.setState({
         [name + "Lenght"]:this.props.form.getFieldValue(name)&&this.props.form.getFieldValue(name)?this.props.form.getFieldValue(name).length:0
       })
       
    }
    //处理方式选择
    acOnChange = e => {
        this.setState({
          value: e.target.value,
        });
      };
    //回车查找医嘱模板数据
    handleQuery=()=>{
        // console.log("111111",this.props.form.getFieldValue('info'))
      let data = {}
      data = {
        params: [{
          templetTypeID:"1",
          status:this.state.checked==true?"Y":"N",
          input: this.props.form.getFieldValue('info'),
        }],
      }
      $http.post('urlS', this, {
        code: '03050011',
        data: data,
        success: function (res) {
          if (+res.errorCode === 0 && res.result) {
            //   console.log("医嘱",res)
            // for (var i = 0; i < res.result.length; i++) {
            //   res.result[i].key = i + "person"
             
              // if(res.result[i].ordTempletStatus=="Y"){
              //   res.result[i].ordTempletStatus = "生效"
              // } if(res.result[i].ordTempletStatus=="N"){
              //   res.result.ordTempletStatus = "失效"
              // }
            // }
            // children
            let newOpen = []
            let arr = res.result&&res.result.map((item, index) => {
              res.result[index].key = Number(index)
              newOpen.push(Number(index))
              return {
                  id: item.ordTempletID, 
                  templetCatDesc: item.templetCatDesc,
                  key: Number(index),
                  children: item.data&&item.data.map((childItem, childIndex) => {
                    this.setState({
                      // rowId:item.data[0].ordTempletID,
                     
                    })
                       if(childItem.ordTempletStatus=="Y"){
                          childItem.ordTempletStatus = "生效"
                        } if(childItem.ordTempletStatus=="N"){
                          childItem.ordTempletStatus = "失效"
                        }
                      return {
                          key: childItem.ordTempletID,
                          ...childItem,
                      }
                  })
              }
          })
            this.setState({
              newOpen,
              leftData: arr,
              text:arr[0],
              findInfo:res.result&&res.result.length==0?'未查询到满足条件的病人信息，请核对信息':''
            })
            // console.log(newOpen)
          } else {
          
          }
        }
      })
    }
    //添加医嘱模板弹出
    openDocMes=()=>{
      this.props.form.setFieldsValue({ overTime: undefined,})
      this.setState({
        visible:true
      })
    }
    //点击是否生效
    changeChecked=(e)=>{
      this.setState({
        checked:e.target.checked
      },()=>{
        this.handleQuery()
      })
    }
    //点击添加/修改遗嘱模板弹窗确认按钮
    handleOk = (e) => {
      this.props.form.validateFields((err, values) => {
        // console.log("点击确认",this.state.ordTempletID)
        if(!err){
          let data = {}
          data = {
            params: [{
              ordTempletID:this.state.isMod==1?this.state.ordTempletID:"",
              ordTempletTypeID:"1",
              ordTempletDesc: this.props.form.getFieldValue('docMesName'),
              ordTempletCatID:this.props.form.getFieldValue('docMesType'),
              ordTempletAlias:this.props.form.getFieldValue('othName'),
              ordTempletStartDate:moment(this.props.form.getFieldValue('startTime')).format('YYYY-MM-DD'),
              ordTempletStopDate:this.props.form.getFieldValue('overTime')?moment(this.props.form.getFieldValue('overTime')).format('YYYY-MM-DD'):undefined,
            }],
          }
          $http.post('urlS', this, {
            code: '03050012',
            data: data,
            success: function (res) {
              if (+res.errorCode === 0) {
                //   console.log("新建",res)
                  this.setState({
                    visible:false
                  })
                  if(this.state.isMod==1){
                    message.success("修改成功");
                    this.handleQuery()
                    this.setState({
                      rowId:this.state.ordTempletID,
                    });
                  }else{
                    message.success("新建成功");
                    this.handleQuery()
                  }
                  this.initData()
              } else {
              
              }
            }
          })
        }
      })
    }
    //点击Row 左侧表格
    onClickRow = (record) => {
      return {
        onClick: () => {
          if(record.ordTempletID){
            if (this.state.rowId === "") {
              this.setState({
                rowId: record.ordTempletID,
              });
            } else {
              if (this.state.rowId !== record.ordTempletID) {
                this.setState({
                  rowId: record.ordTempletID,
                });
              } else {
                this.setState({
                  rowId: "",
                });
              }
            }
          }
        },
        onDoubleClick: () => {
          // console.log("获",record)
          if(record.ordTempletID){
              this.setState({ 
              rowId: record.ordTempletID,
              ordTempletDesc:record.ordTempletDesc,
              ordTempletAlias:record.ordTempletAlias,
              ordTempletCat:record.ordTempletCatDesc,
              ordShow:true,
              OrdCanType:record.ordTempletCatDesc,
              canSaveStatus:true,
              btnStatus:true,
              disAdd:false,
              selectedRowKeys_right:[]
            })
            //获取医嘱模板明细
            let data = {}
            data = {
              params: [{
                ordTempletID:record.ordTempletID,
              }],
            }
            $http.post('urlS', this, {
              code: '03050014',
              data: data,
              success: function (res) {
                if (+res.errorCode === 0 && res.result) {
                  // console.log("获取医嘱模板明细信息",res)
                    for (var i = 0; i < res.result.length; i++) {
                      res.result[i].key = res.result[i].ordTempletDetailID
                      this.setState({
                        rightUnitDr:res.result[i].ordTempletDetailQtyUnitDr,
                        selectedRowKeys_right:[]
                      })
                    }
                    this.setState({
                      rightData:res.result
                    })
                  
                } 
              }
            }) 
          }
         
        }
      };
    }
    //设置点击row颜色 --左侧表格
    setRowClassName = (record) => {
      return record.ordTempletID === this.state.rowId ? 'clickRowStyle' : '';
    }
    //点击右侧表格行
    onClickRightRow = (record)=>{
      const {rightData} = this.state
      return {
        onClick: () => {
          this.setState({
            initRored:record
          })
            if (this.state.selectrow === "") {
              this.setState({
                  selectrow: record.ordTempletDetailID,
              }, () => {
              });
          } else {
              if (this.state.selectrow !== record.ordTempletDetailID) {
                  this.setState({
                      // selectrow: record.ordTempletDetailID,
                  }, () => {
                  });
              } else {
                  this.setState({
                      selectrow: "",
                  });
              }
          }
        },
    }
    }
    setRowClassNames = (record) => {
      return (("^" + this.state.selectedRowKeys_right.join("^") + "^").indexOf("^" + record.ordTempletDetailID + "^") > -1) ? 'clickRowStyle' : '';
      // return record.ordTempletDetailTemplItemTypeID === this.state.selectedRowKeys_right ? 'clickRowStyle' : '';
  }
    //编辑医嘱模板
    editDocMes=(data,num)=>{
      console.log(data)
      if(num=="1"){
        this.props.form.setFieldsValue({ docMesName: data.ordTempletDesc});
        this.props.form.setFieldsValue({ othName: data.ordTempletAlias});
        this.props.form.setFieldsValue({ docMesType: String(data.ordTempletCatID)});
        this.props.form.setFieldsValue({ startTime: moment(data.ordTempletStartDate)});
        this.props.form.setFieldsValue({ overTime:data.ordTempletStopDate?moment(data.ordTempletStopDate):undefined});
        this.setState({
          isMod:1,
          visible:true,
          ordTempletID:data.ordTempletID
        })
        if(!data.ordTempletChildFlag=="Y"){
          this.setState({
            tempChildDis:true
          })
        }
      }else{
        //删除医嘱模板
        let datas = {}
        datas = {
          params: [{
            ordTempletID:data.ordTempletID,
          }],
        }
        $http.post('urlS', this, {
          code: '03050013',
          data: datas,
          success: function (res) {
            if (+res.errorCode === 0) {
                message.success("删除成功");
                this.handleQuery()
            } 
          }
        })

      }
     
    }
    //上移
    moveUp = (arr, index) => {
      if (index === 0) {
          message.warning('已经到顶啦')
      } else {
          arr[index] = arr.splice(index - 1, 1, arr[index])[0]
      }
      return arr
  }
  //下移
  moveDown = (arr, index) => {
      if (index === arr.length - 1) {
          message.warning('已经到底啦')
      } else {
          arr[index] = arr.splice(index + 1, 1, arr[index])[0]
      }
      //console.log(arr, index)
      return arr
  }
//移动医嘱项
    handleMove = status => {
      const that = this
      let { rightData , selectedRowKeys_right } = this.state;
      function _mapData(arr) {
          for (let index = 0, len = arr.length; index < len; index++) {
              const item = arr[index]
              if (selectedRowKeys_right.some(ele => ele === item.key)) {
                  if (status === 'up') {
                      arr = that.moveUp(arr, index)
                  } else if (status === 'down') {
                      arr = that.moveDown(arr, index)
                      index += 1
                  }
              }
              if (item.children && item.children.length > 0) {
                  _mapData(item.children)
              }
          }
      }
      _mapData(rightData)
      this.setState({
        rightData
      })
  }
  //删除医嘱项选中行
  getOrdDeteil=()=>{
    let data = {}
      data = {
        params: [{
          ordTempletID:this.state.rowId,
        }],
      }
      $http.post('urlS', this, {
        code: '03050014',
        data: data,
        success: function (res) {
          if (+res.errorCode === 0 && res.result) {
            // console.log("获取医嘱模板明细信息",res)
              for (var i = 0; i < res.result.length; i++) {
                res.result[i].key = res.result[i].ordTempletDetailID
              }
              this.setState({
                rightData:res.result
              })
          } 
        }
      })
  }

  //删除医嘱项模板
  handleDetele=()=>{ 
      const {selectedRow_right} = this.state
      let arr = []
      if(selectedRow_right&&selectedRow_right.length>0){
        selectedRow_right.map(item=>{
          arr.push(item.ordTempletDetailID)
        })
         let data = {
        params: [{
            ordTempletDetailIDs:arr
        }]
    }
    $http.post('urlS', this, {
        code: '03050016',
        data: data,
        success: function (res) {
            if (+res.errorCode === 0) {
                message.success('删除成功');
                  this.setState({
                    selectedRowKeys_right:[],
                    btnStatus:true,
                    canSaveStatus:true
                  })
                //获取医嘱模板明细
                this.getOrdDeteil()
            }
        },
        error: function (error) {
            message.error('删除失败：' + error);
        }
    }) 
   }
  }
  openTemp=(data)=>{
    this.setState({
      ordTempId:data
    })
    this.addOrd()
  }
  //新增医嘱项模板
  addOrd=()=>{
    const { rightData } = this.state;
    const newData = {
      ordTempletDetailTemplItemTypeCode:"01",
      ordTempletDetailID:"",
      key : `NEW_TEMP_ID_${this.index}`,
      ordTempletDetailItemDesc:"",
      ordTempletDetailQty:"",
      ordTempletDetailQtyUnitDr:"",
      editable:true,
      isAdd:true,
    }
    this.index += 1;
    this.setState({isAdd:true,disAdd:true,ordTemPrice:0, rightData : [...rightData,newData] },()=>{
      setTimeout(() => {
        this.detailDeInput.current.focus();
    }, 300)
    });
  }
  //获取操作行数据对象
  getRowByKey(key, newData) {
    // console.log("获取操作行数据对象",newData)
    const { rightData } = this.state;
    return (newData || rightData).filter(item => item.key === key)[0];
  }
  //文本框数据修改
  handleFieldChange=(e, fieldName, key)=>{
    const { rightData,baseUnit} = this.state;
    const newData = rightData.map(item => ({ ...item }));
    const target = this.getRowByKey(key, newData);
    if(fieldName=="ordTempletDetailQtyUnitDr"){
      for (var i = 0; i < newData.length; i++) {
        if (newData[i].key === key) {
          newData[i].ordTempletDetailQtyUnitDr = e
          for(var j=0;j<baseUnit.length;j++){
            if(newData[i].ordTempletDetailQtyUnitDr==baseUnit[j].id){
              newData[i].ordTempletDetailQtyUnitDesc = baseUnit[j].descripts
            }
          }
        }
      }
      this.setState({
        rightData:newData,
        canSaveStatus:false,
      })
      return
    }
    if (target) {
      target[fieldName] = e.target.value;
      this.setState({
        rightData: newData,
        canSaveStatus:false,
      })
      if(fieldName=="ordTemNumber"){
          this.props.form.setFieldsValue({ ordTemNumber:  e.target.value });
          this.props.form.setFieldsValue({ ordTemToalPrice: e.target.value*this.state.ordTemPrice});
      }
      else{
          this.props.form.setFieldsValue({ ordTemName:  e.target.value });
          this.setState({ 
            ordDetailValue:e.target.value
          });
      }
    }
  }
  
  //名称/规格信息明细
  openNameDetail=(e, fieldName, key,data)=>{
    // console.log(this.state.ordDetailValue)
    this.setState({
      nowRowID:key
    })
    const { ordTempId,ordDetailValue ,page, pageSize,rightData} = this.state;
    const newData = rightData.map(item => ({ ...item }));
    const target = this.getRowByKey(key, newData);
    let targetValue = ""
    if(target){
      targetValue = e.target.value;
    }
    if(ordDetailValue&&ordDetailValue){
      //获取医嘱项信息
      let data = {}
          data = {
            params: [{
              hospID: userData.hospID,
              findCode:ordDetailValue?ordDetailValue:targetValue,
              ordCatID:ordTempId,
              detailFlag:1,
            }],
            pagination: [{
              pageSize: pageSize,
              currentPage: page,
            }]
          }
          $http.post('urlS', this, {
            code: '01010002',
            data: data,
            success: function (res) {
            //   console.log("0-0-0-0",res)
              if (+res.errorCode === 0&&res.result.Data&&res.result.Data.length>0) {
                for (var i = 0; i < res.result.Data.length; i++) {
                  res.result.Data[i].key = i 
                }
                this.setState({
                   OrdDaShow:true,
                   ordDetailData:res.result.Data,
                   total:res.result.TotalCount
                })
              } 
            }
          })
    }
  }
  //医嘱项明细 保存/修改
  handleSave=()=>{
    //保存/修改医嘱项信息
    // console.log("医嘱",this.state.rightData)

    let data = {}
    const {rightData,rowId} = this.state
    for(var i=0;i<rightData.length;i++){
      rightData[i]['ordTempletID']=rowId
      rightData[i].ordTempletDetailSeqNo=i+1
      if(rightData[i].ordTempletDetailItemID==""){
        message.warning("请回车检索药品")
        return
      }if(rightData[i].ordTempletDetailItemDesc==""){
        message.warning("请回车检索药品")
        return
      }if(rightData[i].ordTempletDetailQty<=0){
        message.warning("请输入数量")
        return
      }if(rightData[i].ordTempletDetailQtyUnitDr==""){
        message.warning("请选择数量")
        return
      }
    }
    data = {
      params: this.state.rightData,
    }
    $http.post('urlS', this, {
      code: '03050015',
      data: data,
      success: function (res) {
        if (+res.errorCode === 0) {
          this.setState({
            selectedRowKeys_right:[],
            btnStatus:true,
            canSaveStatus:true
           })
         message.success("保存成功")
          this.setState({
            selectedRowKeys_right:[],
            btnStatus:true,
            disAdd:false,
            canSaveStatus:true
          })
         this.getOrdDeteil()
        } 
      }
    })
  }
  //点击医嘱项表行信息
  onClickOrdDaRow=(record)=>{
    return {
      onClick: () => {
        if (this.state.OrdDaRowId === "") {
          this.setState({
            OrdDaRowId: record.medID,
          });
        } else {
          if (this.state.OrdDaRowId !== record.id) {
            this.setState({
              OrdDaRowId: record.medID,
            });
          } else {
            this.setState({
              OrdDaRowId: "",
            });
          }
        }
      },
      onDoubleClick: () => {
        const {rightData,nowRowID} = this.state
        // console.log("信息带回",record,rightData)
        this.setState({ 
          OrdDaRowId: record.medID,
          // ordDetailValue:record.medDesc,
          isAdd:true,
          OrdDaShow:false,
          ordTempletDetailItemDesc:record.medDesc
        })
        for(var i=0;i<rightData.length;i++){
          if(nowRowID==rightData[i].key){
            rightData[i].ordTempletDetailItemID =record.medID;
            rightData[i].ordTempletDetailQty =record.medDurQty?record.medDurQty:1;
            rightData[i].ordTempletDetailQtyUnitDesc =record.medUnitDesc;
            rightData[i].ordTempletDetailQtyUnitDr =record.medUnitID;
            rightData[i].ordTempletDetailItemPrice =record.medPrice;
            // rightData[i].ordTempletDetailTemplItemTypeCode =record.ordTempletDetailTemplItemTypeCode;
            // rightData[i].ordTempletDetailQty 
          }
        }
        this.setState({
          ordTemPrice:record.medPrice,
          editDis:false,
          addInfo:true
        },()=>{
          const {rightData} = this.state
            rightData.map((item,index)=>{
              const ordTemDec = {}
              if(this.state.ordTempletDetailID==rightData[index].ordTempletDetailID){
                rightData[index].ordTempletDetailItemDesc = this.state.ordTempletDetailItemDesc;
                this.props.form.setFieldsValue({ 
                  ordTempletDetailID:this.state.ordTempletDetailItemDesc
                  });
        
              }
            })
        })
      }
    };
  }
  //设置医嘱项表row颜色
  setOrdDaRowClassName = (record) => {
    return record.medID === this.state.OrdDaRowId ? 'clickRowStyle' : '';
  }
  //编辑 医嘱项表格行
  toggleEditable = (e , key,record) => {
    console.log("geren--key",key)
    e.preventDefault();
    this.setState({
      ordTempletDetailItemDesc:record.ordTempletDetailItemDesc,
      ordTempletDetailQty:record.ordTempletDetailQty,
      ordTempletDetailQtyUnitDr:record.ordTempletDetailQtyUnitDr,
      ordTempletDetailID:record.ordTempletDetailID,
      disAdd:true
    })
    const { rightData } = this.state;
    const newData = rightData.map(item => ({ ...item }));
    const target = this.getRowByKey(key, newData);
    if (target) {
      if (!target.editable) {
        this.cacheOriginData[key] = { ...target};
      }
      target.editable = !target.editable;
      this.setState({
        rightData : newData,
        // canSaveStatus:false,
      })
    }
    setTimeout(() => {
      this.detailDeInput.current.focus();
  }, 300)
  }
  //取消 医嘱项表格行
  cancel=(e, key)=>{
    this.clickedCancel = true;
    e.preventDefault();
    const { rightData } = this.state;
    const newData = rightData.map((item) => ({ ...item}));
    const target = this.getRowByKey(key,newData);
    console.log("取消",target,"this.cacheOriginData",this.cacheOriginData)
    if (this.cacheOriginData[key]) {
      Object.assign(target,this.cacheOriginData[key]);
      delete this.cacheOriginData[key];
    }
    target.editable = false;
    this.setState({ rightData : newData,canSaveStatus:true,disAdd:false});
    this.ClickedCancel = false;
  } 
 //删除 医嘱项表格行
 cut=(e,key)=>{
  // e.stopPropagation();
  // e.nativeEvent.stopImmediatePropagation();
  // e.preventDefault();
  const { rightData } = this.state;
  // const { onChange } = this.props;
  console.log("rightData",rightData,"key",key)
  const newData = rightData.filter(item => item.key !== key);
  this.setState({ rightData: newData,disAdd:false,canSaveStatus:true, });
  // onChange(newData);
}
   // 显示分页总条数
   showTotal(total) {
    return `共 ${total} 条`;
  }
   // 修改page和pageSize 跳转至---
   onChange = (page, pageSize) => {
    this.setState({ page: page, pageSize: pageSize }, () => {
      // 重新调用查询方法
      this.openNameDetail();
    })
  }
  //下拉选择页数
  onShowSizeChange = (page, pageSize) => {
    this.setState({ page: 1, pageSize: pageSize }, () => {
     // 重新调用查询方法
     this.openNameDetail();
    })
  }
  handleTemDaCancel=()=>{
    this.setState({
      OrdDaShow:false
    })
  }
    //初始化信息
    initData=()=>{
      this.setState({
        isMod:-1,
        ordShow:false,
        tempChildDis:false
      })
      this.props.form.setFieldsValue({ docMesName: undefined});
      this.props.form.setFieldsValue({ othName: undefined});
      this.props.form.setFieldsValue({ docMesType: "1"});
    }
    //点击添加/修改遗嘱模板弹窗取消按钮
    handleCancel=()=>{
      this.setState({
        visible:false
      })
      this.initData()
    }

    //左侧全选
    onCheckAllChange = e => {
        this.setState({
          checkedList: e.target.checked ? plainOptions : [],
          indeterminate: false,
          checkAll: e.target.checked,
        });
      };
      //左侧单选
      onChange = checkedList => {
        this.setState({
          checkedList,
          checkAll: checkedList.length === plainOptions.length,
        });
      };
    render() {
      // console.log("------",this.state.text)
        const { getFieldDecorator } = this.props.form;
        let {ordTempletDesc,ordTempletAlias,ordTempletCat,ordShow,baseOrdTepCat,baseTempType,baseUnit,tempChildDis,OrdDaShow} = this.state
        let ordtype = []
        baseOrdTepCat && baseOrdTepCat.map(item => {
          ordtype.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
        })
        let ordTemp = []
        baseTempType && baseTempType.map(item => {
          ordTemp.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
        })
      
        //右上小表格
        const columns = [{
            key: '1',
            title: '序号',
            dataIndex: 'code',
            align: "center",
            width:80,
          }, {
            width:160,
            key: '2',
            title: '名称',
            dataIndex: 'patName',
            align: 'center'
          }, {
            width:80,
            key: '3',
            title: '数量',
            dataIndex: 'patSexDesc',
            align: "center",
          }, {
            width:80,
            key: '4',
            title: '玻片/蜡片',
            dataIndex: 'patBirthDate',
            align: "center",
          },{
            width:80,
            key: '5',
            title: '原病理号',
            dataIndex: 'patBirthDate',
            align: "center",
          },]
           //左侧查询数据表
           const leftDetailColumns = [
            { 
              // align: "center",
              title: '类型', 
              dataIndex: 'templetCatDesc',
              key: '1',
              width: '100px',
              render(text, row, index) {
                if (row.ordTempletDesc) {
                    return text;
                }
                return {
                    children: text,
                    props: {
                        colSpan: 6,
                    },
                };
            },
            },
            {
              align: "center",
              width: '100px',
              title: '名称',
              dataIndex: 'ordTempletDesc', 
              key: '2' ,
              render: renderContent,
            },
            { 
              align: "center",
              width: '100px',
              title: '别名',
              dataIndex: 'ordTempletAlias', 
              key: '3',
              render: renderContent,
            },
            { 
              align: "center",
              width: '100px',
              title: '操作员',
              dataIndex: 'ordTempletUserDesc',
              key: '4',
              render: renderContent,
            },
            { 
              align: "center",
              width: '100px',
              title: '状态',
               dataIndex: 'ordTempletStatus',
                key: '5' ,
                render: renderContent,
            },
            { 
              align: "center",
              width: '160px',
              title: '操作', 
              dataIndex: 'createdAt', 
              key: '6',
            //   // render: (text, record) => (
            //   //     <span className="table-operation">
            //   //       <Button onClick={()=>this.editDocMes(record,"1")} type="primary" style={{border:"0",background:"0",boxShadow: "0 0 0",color:"#1890ff"}}>编辑</Button>
            //   //       <Button disabled={record.ordTempletStatus=="失效"} type="primary" style={{border:"0",background:"0",boxShadow: "0 0 0",color:(record.ordTempletStatus=="失效"?"rgba(0, 0, 0, 0.25)":"#1890ff")}}  onClick={()=>this.editDocMes(record,"2")} >删除</Button>
            //   //     </span>
            //   //   ),
             },
          ];
            
         
        
        return (
            <div>
                <Row gutter={60} style={{marginRight: "0"}}>
                        <Col span={6} style={{paddingRight:"0",marginTop:"4px",}}>
                            <Card title="科室申请单" bordered={false} style={{marginRight:"4px",textAlign:"center"}}>
                            <Row>
                            <Col span={24} style={{ marginRight: '10px' }}>
                                <FormItem>
                                {getFieldDecorator('info', {
                                    initialValue:undefined,
                                })(
                                    <Input allowClear placeholder='输入分类名称后回车查询' onPressEnter={this.handleQuery} autoFocus  />
                                )}
                                </FormItem>
                            </Col>
                            </Row>
                            <Row>
                            <Checkbox
                                indeterminate={this.state.indeterminate}
                                onChange={this.onCheckAllChange}
                                checked={this.state.checkAll}
                            >
                                全部
                            </Checkbox>
                            <CheckboxGroup
                                options={plainOptions}
                                value={this.state.checkedList}
                                onChange={this.onChange}
                                />
                            </Row>
                            <Table
                                className="components-table-demo-nested"
                                columns={leftDetailColumns}
                                pagination={false}
                                rowClassName={this.setRowClassName}
                                onRow={this.onClickRow}
                                rowKey={record => record.key}
                                showHeader={false}
                                // expandedRowRender={expandedRowRender}
                                // defaultExpandedRowKeys={this.state.newOpen&&this.state.newOpen.length > 0 ? this.state.newOpen : [0]} 
                                // defaultExpandAllRows={true}
                                // defaultExpandAllRows={true}
                                dataSource={this.state.leftData}
                                /> 
                        </Card>
                    </Col>
                    <div>
                    <p style={{margin:"0",color:"red"}}><span style={{marginLeft:"8px"}}>未收费申请单金额</span><span style={{margin:"0 8px"}}>￥255.85</span> 申请单总金额 <span style={{margin:"0 8px"}}>￥2558.50</span><span style={{display:"inline-block",width: "80px",height: "32px",lineHeight: "32px",textAlign: "center",color: "#40a9ff",border: "1px solid #40a9ff",borderRadius: "4px",marginLeft: "12px"}}> ￥卡消费</span><span style={{position:"absolute",top:"4px",right:"2px"}}><a>西药及其他</a><a style={{marginLeft:"16px"}}>草药录入</a></span></p>
                    <Col span={13} style={{paddingLeft: "6px",marginTop:"4px"}} className="autopsyApplicationCardDom">
                        <Card title="病理 >>外院会诊病理申请单" bordered={false} className="moreInfoCard">
                          <div style={{marginTop: "4px",width: "160px",height: "74px",textAlign: "center",border: "2px solid #40a9ff",display: "flex",alignItems: "center",justifyContent: "center",background: "#efeeee"}}>
                          疑难病理会诊申请
                           {/* <span className="myicon-tick-checked"></span> */}
                          </div>
                          <Form>
                            <Row gutter={60}>
                            <Col span={5} style={{paddingRight:"0"}}>
                             <FormItem label="医嘱名称"  {...formItemLayoutR}>
                                {getFieldDecorator('nameOfdoctorsAdvice', {
                                    initialValue: undefined,
                                    rules: [{ required: false, message: '' }],
                                })(
                                    <Input></Input>
                                )}
                                </FormItem>
                             </Col>
                             <Col span={5} style={{padding:"0"}}>
                             <FormItem label="执行科室"  {...formItemLayoutR}>
                                {getFieldDecorator('executiveSection', {
                                    initialValue: undefined,
                                    rules: [{ required: false, message: '' }],
                                })(
                                    <Select></Select>
                                )}
                                </FormItem>
                             </Col>
                             <Col span={5} style={{padding:"0"}}>
                             <FormItem label="申请科室"  {...formItemLayoutR}>
                                {getFieldDecorator('applicationSection', {
                                    initialValue: undefined,
                                    rules: [{ required: false, message: '' }],
                                })(
                                    <Select></Select>
                                )}
                                </FormItem>
                             </Col>
                             <Col span={5} style={{padding:"0"}}>
                             <FormItem label="申请医生"  {...formItemLayoutR}>
                                {getFieldDecorator('applicationDoctor', {
                                    initialValue: undefined,
                                    rules: [{ required: false, message: '' }],
                                })(
                                    <Select></Select>
                                )}
                                </FormItem>
                             </Col>
                             </Row>
                             <p style={{ background: "#e2f0fb",color: "#1890ff",padding: "6px",margin: "-6px 0 8px"}}>标本信息</p>
                             <Row>
                             <Table
                                pagination={false}
                                columns={columns}
                                dataSource={this.state.rightTopTableData}
                                rowKey={record => record.key}
                                style={{
                                    height: '204px',
                                  }}
                            />
                             </Row>
                             <p style={{ background: "#e2f0fb",color: "#1890ff",padding: "6px",margin: "8px 0 "}}>检查及会诊信息</p>
                             <Row>
                                <Col span={6} style={{paddingRight:"0"}}>
                                <FormItem label="送检医生"  {...formItemLayoutD}>
                                    {getFieldDecorator('inspectionDoctor', {
                                        initialValue: undefined,
                                        rules: [{ required: false, message: '' }],
                                    })(
                                        <Input></Input>
                                    )}
                                    </FormItem>
                                </Col>
                                <Col span={6} style={{paddingRight:"0"}}>
                                <FormItem label="送检医院"  {...formItemLayoutD}>
                                    {getFieldDecorator('inspectionHospita', {
                                        initialValue: undefined,
                                        rules: [{ required: false, message: '' }],
                                    })(
                                        <Input></Input>
                                    )}
                                    </FormItem>
                                </Col>
                             </Row>
                             <Row>
                                <Col span={24}>
                                <FormItem label="病理原诊断"  {...formItemLayoutCli}>
                                    {getFieldDecorator('pathologicalDiagnosis', {
                                        initialValue: undefined,
                                        rules: [{ required: false, message: '' }],
                                    })(
                                        <TextArea  style={{height:"66px",resize:"none",overflow:"auto"}}/>
                                    )}
                                    </FormItem>
                                </Col>
                             </Row>
                             <Row>
                                <Col span={24}>
                                <FormItem label="会诊要求" {...formItemLayoutCli}>
                                    {getFieldDecorator('consultationRequirements', {
                                        initialValue: undefined,
                                        rules: [{ required: false, message: '' }],
                                    })(
                                        <TextArea style={{height:"66px",resize:"none",overflow:"auto"}}/>
                                    )}
                                    </FormItem>
                                </Col>
                             </Row>
                             <Row>
                                <Col span={24}>
                                <FormItem label="会诊专家" {...formItemLayoutCli}>
                                    {getFieldDecorator('consultationExperts', {
                                        initialValue: undefined,
                                        rules: [{ required: false, message: '' }],
                                    })(
                                        <TextArea style={{height:"66px",resize:"none",overflow:"auto"}}/>
                                    )}
                                    </FormItem>
                                </Col>
                             </Row>
                             <Col style={{textAlign:"right",marginTop:"18px"}}>
                             <Button key="submitca" type="primary" size="small" onClick={this.handleCancel}>取消申请</Button>,
                             <Button key="submitsa" type="primary" size="small" onClick={this.handleOk}>保存申请</Button>,
                             <Button key="submitse" type="primary" size="small" onClick={this.handleCancel}>发送申请</Button>,
                             <Button key="submitdo" type="primary" size="small" onClick={this.handleOk}>打印申请</Button>,
                             <Button key="submitre" type="primary" size="small" onClick={this.handleCancel}>清空</Button>,
                             </Col>
                             </Form>
                        </Card>
                    </Col>
                    <Col span={5} style={{padding: "4px 0 0 ",marginTop:"0px"}}>
                        <Card  bordered={false} className="moreInfoCard">
                            <div>
                              <p style={{margin:"0",fontWeight:"600"}}>本次就诊申请单列表</p>
                            </div>
                            <Row>
                              <Col span={12}>
                              <FormItem label='开始日期' {...formItemLayout}>
                                {getFieldDecorator('dateFrom', {
                                  initialValue:moment(),
                                  rules: [{ required: false, message: '' }],
                                })(
                                  <DatePicker  style={{width:'100%'}} disabledDate={(curDate) => {
                                    return curDate && curDate > moment().endOf('day');
                                  }} />
                                )}
                              </FormItem>
                              </Col>
                              <Col span={12}>
                              <FormItem label='结束日期' {...formItemLayout}>
                                {getFieldDecorator('dataOver', {
                                  initialValue:moment(),
                                  rules: [{ required: false, message: '' }],
                                })(
                                  <DatePicker  style={{width:'100%'}} disabledDate={(curDate) => {
                                    return curDate && curDate > moment().endOf('day');
                                  }} />
                                )}
                              </FormItem>
                              </Col>
                              <div>
                                <span>暂无申请单</span>
                                <div>
                                  <p style={{textAlign:"center",margin:"0",height:"40px",lineHeight:"40px",background:"rgba(24,114,255,0.2)"}}>心脏彩超检查心脏彩超检查.....</p>
                                  <div style={{border:"1px solid #e8e8e8",padding:"6px"}}>
                                  <p style={{margin:"0"}}>开单时间：<span>2019-12-13 12:00</span></p>
                                  <p style={{margin:"0"}}><a>项目金额：<span>￥288.55</span></a></p>
                                  <p style={{margin:"0"}}>执行科室：<span>超声医学科</span></p>
                                  </div>
                                </div>
                              </div>
                            </Row>
                        </Card>
                    </Col>
                    </div>
                    </Row>
                </div>
        )
    }
})
export default PathologicalApplicationForm