//  药品配送
import React from 'react';
import {Row, Col, Input, Select, DatePicker, Button, Card, Checkbox, Icon, Divider, message } from 'antd';
import PubilcTablePagination from 'pages/common/PubilcTablePagination';
import DrugDeliveryAddress from './component/DrugDeliveryAddress.jsx';
import ColumnAuthoritysModel from 'pages/columnAuthority/ColumnAuthoritysModel';
import store from 'store';
import '../outpha/style/outpha.less';
import './style/index.less';
import { $http } from 'containers/config/https';
import { $PrintPresc,$PrintLabel } from '../outpha/common/Print.jsx';
import Moment from 'moment';
import ReadCard from 'components/readcard/ReadCard';

let buttonStatus = true;

export default class DrugDelivery extends React.Component {
  constructor() {
    super();
    var userData = JSON.parse(sessionStorage.getItem('userData'));
    this.state = {
      userData,
      patID: "",
      patNo: undefined, // 病人ID/证件号
      cardType: undefined, // 卡类型
      cardNo: undefined, // 卡号
      startDate: Moment(), // 开始日期
      endDate: Moment(), // 结束日期
      inputStatus: undefined, // 录入状态
      examineStatus: undefined, // 审核状态
      rowId: "", // 选中行ID
      rowData: {}, // 选中行数据
      basicHeight: 0,
      sendOut: false, // 已发送
      mainInfo: [], // 处方明细基本数据
      detailInfo: [], // 处方明细PR
      selectData: {}, // 下拉框数据
      cardSlectData: [], // 卡类型下拉框数据
      defaultValue: "", // 默认卡类型
      page: 1,
      pageSize: 20,
      total: 0,
      tableData: [],
      loading: false,
      columns: [],
      widthTotal: 0
    };
    this.columns = [
      { title: '病人ID', dataIndex: 'patNo', key: '1', width: '120px', align: "center"},
      { title: '患者', dataIndex: 'patName', key: '2', width: '80px', align: "center"},
			{ title: '处方号', dataIndex: 'prescno', key: '3', width: '150px', align: "center"},
      { title: '发票号', dataIndex: 'ordDate', key: '4', width: '150px', align: "center"},
      { title: '发送标志', dataIndex: 'status', key: '5', width: '100px', align: "center"},
      { title: '收费时间', dataIndex: 'ordDate', key: '6', width: '100px', align: "center"},
      { title: '发送时间', dataIndex: 'sendDateTime', key: '7', width: '100px', align: "center"},
      { title: '发送地址', dataIndex: 'patAddress', key: '8', width: '100px', align: "center"},
    ];
    this.myRef1 = React.createRef();
  }

  componentDidMount() {
    this.handleQuery();
    this.getSelectData();
    this.getTableColumns();
    this.getCardSelectData();
    this.setState({basicHeight: document.getElementById("drug-delivery-header").clientHeight}, () => {
      setTimeout(() => {
        this.myRef1.current.focus();
      }, 300)
    });
  }

  // 下拉框数据查询
  getSelectData() {
    let data = {
      params: []
    }
    $http.post('urlS', this, {
      code: "02070001",
      data: data,
      success: function (res) {
        if (+res.errorCode === 0 && res.result) {
          this.setState({selectData: res.result})
        } else {
          this.setState({selectData: []})
        }
      }
    })
  }

  // 获取卡类型下拉框数据
  getCardSelectData = () => {
    let data = {
      params: [{}]
    }
    $http.post('urlS', this, {
      code: '02030052',
      data: data,
      success: function (res) {
        if (+res.errorCode === 0) {
          let defaultValue = '';
          for(var i = 0; i < res.result.length; i++) {
            if (res.result[i].defaultFlag === 'Y') {
              defaultValue = res.result[i].id;
            }
          }
          this.setState({cardSlectData: res.result, cardType: defaultValue, defaultValue: defaultValue})
        }
      }
    })
  }

  onRef = ref => {
    this.child = ref;
  }

  // 病人ID/证件号
  handlePatNoChange = e => {
    this.setState({patNo: e.target.value}, () => {
      if (!this.state.patNo) {
        this.setState({patID: ''})
      }
    });
  }

  // 卡类型
  handleCardTypeChange = e => {
    this.setState({patNo: e});
  }

  // 卡号
  handleCardNoChange = e => {
    this.setState({cardNo: e.target.value}, () => {
      if (!this.state.cardNo) {
        this.setState({patID: ''})
      }
    });
  }

  // 开始日期
  handleStartDateChange = e => {
    this.setState({ startDate: e });
  }

  // 查询条件 --- 截止日期
  handleEndDate = (e) => {
      this.setState({ endDate: e });
  }

  // 录入状态
  handleInputStatusChange = (e) => {
    this.setState({ inputStatus: e });
  }

  // 审核状态
  handleExamineStatusChange = (e) => {
    this.setState({ examineStatus: e });
  }

  // 获取表格数据
  getTableData = () => {
    let {page, pageSize, startDate, endDate, patID, inputStatus, examineStatus, sendOut} = this.state;
    this.setState({loading: true});
		let data = {}
		data = {
			params: [{
        startDate: startDate ? Moment(startDate).format('YYYY-MM-DD') : undefined, // 开始日期
        endDate: endDate ? Moment(endDate).format('YYYY-MM-DD') : undefined, // 截至日期
        patID: patID, // 病人Id
        auditFlag: examineStatus, // 审核状态Id
        addressFlag: inputStatus, // 录入状态
        sendFlag: sendOut ? 1 : 0, // 
			}],
			pagination:[{
				pageSize: pageSize,
				currentPage: page,
				sort: "",
				dir: "Asc"
			}]
		}
		$http.post('urlS', this, {
			code: "02070002",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0 && res.result) {
					for(var i = 0; i < res.result.rows.length; i++) {
						res.result.rows[i].key = i
          }
					this.setState({
            rowId: '', rowData: {}, mainInfo: [], detailInfo: [], 
            tableData: res.result.rows, total: res.result.total, loading: false
          }, () => {
						// 数据加载成功关闭loading
						this.child.handleLoading()
					})
				} else {
					this.setState({rowId: '', rowData: {}, mainInfo: [], detailInfo: [], tableData: [], total: 0, loading: false}, () => {
						// 数据加载成功关闭loading
						this.child.handleLoading();
					})
				}
			},
			error: function () {
				this.setState({tableData: [], total: 0, loading: false}, () => {
					// 数据加载成功关闭loading
					this.child.handleLoading();
				})
			}
		})
  }

  // 查询
  handleQuery = () => {
    this.setState({page: 1}, () => {
      this.getTableData();
    })
  }

  // 操作行
	onClickRowPublic = (record) => {
		return {
			// 单击行选中
			onClick: () => {
				if (this.state.rowId === '') {
					// 保存行数据以及ID
					this.setState({rowId: record.prescno, rowData: record}, () => {
            // 获取处方明细
            this.getDetailData(record.prescno);
					})
				} else {
					if (this.state.rowId !== record.prescno) {
						this.setState({rowId: record.prescno, rowData: record}, () => {
              // 获取处方明细
              this.getDetailData(record.prescno);
						})
					}
				}
			}
		}
  }
    
  // 选中行操作
	setRowClassNamePublic = (record) => {
		return record.prescno === this.state.rowId ? 'clickRowStyle' : '';
  }
 
  // 提供给子组件修改条数的方法
  compilePage = (page, pageSize) => {
    this.setState({page: page, pageSize: pageSize}, () => {
      // 修改page, pageSize之后重新调用查询方法
      this.getTableData()
    })
  }
    
    // 获取处方明细
	getDetailData(ordPrescNo) {
		let data = {
			params: [{
        ordPrescNo: ordPrescNo
      }]
		}
		$http.post('urlS', this, {
			code: "02030020",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					this.setState({mainInfo: res.result[0].mainInfo, detailInfo: res.result[0].detailInfo})
				} else {
					this.setState({mainInfo: [], detailInfo: []})
				}
			}
		})
  }
   //打印中草药处方 
   handlePrintPresc = () => {
    let {rowId} = this.state;
    let params;
    
    params={
        prescno:rowId,
        phFlag:1,
    }
    $PrintPresc(params);
}

  // 已发送
  handlesSdOutChange = e => {
    this.setState({sendOut: e.target.checked}, () => {
      this.handleQuery(); // 重新查询列表数据
    });
  }

  // 西药时需要处理关联医嘱
  processAssociatedData = (data) => {
    let tempArr = [];
    let afterData = [];
    if (!(data&&data.length > 0)) {
      return afterData;
    }
    for (let i = 0; i < data.length; i++) {
      if (tempArr.indexOf(data[i].ordMainID) === -1) {
        afterData.push({
          ordMainID: data[i].ordMainID,
          children: [data[i]]
        });
        tempArr.push(data[i].ordMainID);
      } else {
        for (let j = 0; j < afterData.length; j++) {
          if (afterData[j].ordMainID == data[i].ordMainID) {
            afterData[j].children.push(data[i]);
            break;
          }
        }
      }
    }
    // console.log(afterData);
    return afterData;
  }

  // 输入下拉框option
  exportSelectOption = (data) => {
		let selectOption = data && data.map((item, index) => {
			return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
    })
    return selectOption;
  }

  // 查询病人id
  handlePatient = (e, name) => {
    if (!e.target.value) {
      this.setState({patID: ''})
      return;
    }
    this.setState({cardNo: undefined, cardType: this.state.defaultValue}, () => {
      setTimeout(() => {
        this.getPatientInformation('patient', name);
      }, 300)
    })
  }

  // 3.2.1.3.13.根据卡号取病人信息
  getPatientInformation = (flag, name) => {
    if (!this.state.patNo && !this.state.cardNo) {
      return;
    }
    let data = {
      params: [{
        number: this.state.patNo, // 病人登记号/证件号
        cardTypeID: flag === 'readCard' ? this.state.cardType : undefined, // 卡类型id
        cardNo: this.state.cardNo, // 卡号
      }]
    }
    setTimeout(() => {
      buttonStatus = true;
    }, 500)
    $http.post('urlS', this, {
      code: '03040004',
      data: data,
      success: function (res) {
        if (+res.errorCode === 0) {
          this.setState({patID: res.data&&res.data.patID ? res.data.patID : '', patNo: flag === "patient" ? res.data.patNo : undefined}, () => {
            if (name === 'enter') {
              this.handleQuery();
            }
          })
        } else if (res.errorFlag === 'N') {
          this.setState({page: 1, rowId: '', tableData: [], total: 0, mainInfo: [], detailInfo: [], patID: 'aaaaa'})
          message.error(res.errorMessage)
        }
      }
    })
  }

  // 读卡 --- 根据卡号取病人信息
  handleReadCard = () => {
    if (!buttonStatus) {
      return;
    }
    let {cardType} = this.state;
    this.readCard.ReadCard(cardType,"R",(json) => {
      this.setState({patID: json.patInfo&&json.patInfo.patID ? json.patInfo.patID : 'aaaaa', cardNo: json.cardNo}, () => {
        this.handleQuery()
      })
    })
  }

  handleReadCardOnBlur = (e, name) => {
    if (!e.target.value) {
      this.setState({patID: ''})
      return;
    }
    if (name === 'blur') {
      buttonStatus = false
    }
    this.setState({patNo: undefined}, () => {
      setTimeout(() => {
        this.getPatientInformation('readCard', name);
      }, 300)
    })
  }

  // 审核
  handleToExamine = () => {
    let {rowData} = this.state;
    let data = {
			params: [{
        KMID: rowData&&rowData.KMID ? rowData.KMID : ''
      }]
		}
		$http.post('urlS', this, {
			code: '02070011',
			data: data,
			success: function (res) {
        if (+res.errorCode === 0) {
          message.success(res.errorMessage);
          this.getTableData();
        }
			}
		})
  }

  modalOnRef = ref => {
    this.modalChild = ref;
  }

  // 送家里
  handleHomeDelivery = () => {
    let {rowData, selectData} = this.state;
    this.modalChild.handleShowModal(rowData, selectData, 2);
  }

  // 送医院
  handleToHospital = () => {
    let {rowData, selectData} = this.state;
    this.modalChild.handleShowModal(rowData, selectData, 1);
  }

  // 发送
  handleSendOut = () => {
    let {rowData} = this.state;
    let data = {
			params: [{
        prescno: rowData&&rowData.prescno ? rowData.prescno : '',
        KMID: rowData&&rowData.KMID ? rowData.KMID : ''
      }]
		}
		$http.post('urlS', this, {
			code: '02070010',
			data: data,
			success: function (res) {
        if (+res.errorCode === 0) {
          message.success(res.errorMessage);
          this.getTableData();
        }
			}
		})
  }

  onColumnRef = (ref) => {
    this.columnRef = ref;
  }

  // 获取主列表columns
  getTableColumns = () => {
    let {userData} = this.state;
    let data = {
      params: [{
        compontName: "KMDrugDistribution",
        reactCode: ['KMDrugDistribution'],
        type: 'C',
      }]
    }
    $http.post('urlS', this, {
      code: '01040073',
      data: data,
      success: function (res) {
        if (+res.errorCode === 0) {
          let arr = res.result.C&&res.result.C.length > 0 ? JSON.parse(JSON.stringify(res.result.C)).map((item, index) => {
            return  {
              ...item,
              key: index + 1, 
              title: <div onDoubleClick={() => this.columnRef.onOpenModel()}>{userData.language == 'EN' ? (item&&item.enDescripts ? item.enDescripts : item.title) : item.title}</div>
            }
          }) : '';
          let filterArr = arr.filter(function(item){ return item.display === 'Y'});
          this.setState({
            columns: filterArr, widthTotal: res.totalWidth,
            localeProvider: userData.language == 'EN' ? res.result.language.EN : res.result.language.CN
          })
        }
      }
    })
  }

	//国际化
	setMessage = (name, message, defaultTitle) => {
		return this.state.localeProvider&&this.state.localeProvider[name] ? this.state.localeProvider[name][message] : defaultTitle
  }
 
  render() {
    let {patNo, cardType, cardNo, startDate, endDate, inputStatus, examineStatus, rowId, basicHeight, tableData, page, total, sendOut, mainInfo, detailInfo,
      selectData, loading, cardSlectData, columns, widthTotal
    } = this.state;
    const param = {
			// 表头配置
			columns: columns&&columns.length > 0 ? columns : this.columns,
			// 表格数据
			data: tableData,
			// 数据总条数
			total: total,
			// 当前页数
			page: page,
			// 表格的宽度
			x: columns&&columns.length > 0 ? widthTotal : 900,
			y: store.getState().tableHeight.y + 90 - basicHeight,
			height: store.getState().tableHeight.y + 136 - basicHeight + 'px',
			isOnRow: true,
      rowClassName: true,
      TableClassName: 'table-scroll-height',
      loading,
      pageSize: "20"
    };

    let colTop = {
      xs: {span: 12},
      sm: {span: 12},
      md: {span: 10},
      lg: {span: 10},
      xl: {span: 10},
      xxl: {span: 8}
    };
    let colBottom = {
      xs: {span: 12},
      sm: {span: 12},
      md: {span: 14},
      lg: {span: 14},
      xl: {span: 14},
      xxl: {span: 16}
    }

    let mainInfoObj = mainInfo&&mainInfo.length > 0 ? mainInfo[0] : {};
    let detailData = detailInfo&&detailInfo.length > 0 ? detailInfo[0].rows : [];
    return (
      <div className="drug-delivery">
        <Row id="drug-delivery-header" style={{padding: '0 24px'}}>
          <Col span={18}>
            <div style={{marginBottom: '8px'}}>
              <Select value={cardType} onChange={this.handleCardTypeChange} showSearch optionFilterProp="seatchprop" 
                allowClear placeholder={this.setMessage("KMDrugDistributionperHealthCard", "descripts", "居民健康卡")} style={{width: '150px', margin: '8px 8px 0 0'}}
              >
                {this.exportSelectOption(cardSlectData)}
              </Select>
              <Input value={cardNo} onBlur={(e) => this.handleReadCardOnBlur(e, 'blur')} onChange={this.handleCardNoChange} 
                onPressEnter={(e) =>this.handleReadCardOnBlur(e, 'enter')} placeholder={this.setMessage("KMDrugDistributioncardNumTips", "descripts", "请输入卡号(Enter)")} 
                style={{width: '160px', marginTop: '8px', borderRight: '0'}} 
                allowClear
              />
              <Button style={{marginRight: '12px', background: 'rgba(77,193,130,1)', color: '#fff'}} onClick={this.handleReadCard}>{this.setMessage("KMDrugDistributionCardReading", "descripts", "读卡")}</Button>
              <Input
                title={this.setMessage("KMDrugDistributionenterToSeachPatID", "descripts", "回车触发病人ID查询")}
                placeholder={this.setMessage("KMDrugDistributionpatId/CardNum", "descripts", "病人ID/证件号(Enter)")}
                style={{width: '180px', margin: '8px 20px 0 0'}}
                ref={this.myRef1}
                value={patNo}
                onBlur={(e) => this.handlePatient(e, 'blur')}
                onChange={this.handlePatNoChange}
                onPressEnter={(e) => this.handlePatient(e, 'enter')} 
                allowClear
              />
              <div style={{display: 'inline-block'}}>
                {this.setMessage("KMDrugDistributionchargeDate", "descripts", "收费日期：")}<DatePicker style={{width: '120px', marginTop: '8px'}} placeholder={this.setMessage("KMDrugDistributionstartDate", "descripts", "开始日期")} value={startDate} 
                            onChange={this.handleStartDateChange} allowClear={false}
                          />
                <span style={{display: 'inline-block', margin: '0 5px'}}>{this.setMessage("KMDrugDistributionReach", "descripts", "到")}</span>
                <DatePicker style={{width: '120px', marginRight: '15px'}} placeholder={this.setMessage("KMDrugDistributiondeadline", "descripts", "结束日期")} value={endDate} onChange={this.handleEndDate} />
                <Select showSearch optionFilterProp="seatchprop" allowClear placeholder={this.setMessage("KMDrugDistributioninputStatus", "descripts", "录入状态")} style={{width: '120px', margin: '8px 15px 0 0'}} value={inputStatus} onChange={this.handleInputStatusChange}>
                  {this.exportSelectOption(selectData&&selectData.addressStatus ? selectData.addressStatus : [])}
                </Select>
                <Select showSearch optionFilterProp="seatchprop" allowClear placeholder={this.setMessage("KMDrugDistributionexamineStatus", "descripts", "审核状态")} style={{width: '120px', margin: '8px 20px 0 0'}} value={examineStatus} onChange={this.handleExamineStatusChange}>
                  {this.exportSelectOption(selectData&&selectData.auditStatus ? selectData.auditStatus : [])}
                </Select>
                <Button style={{marginTop: '8px'}} onClick={this.handleQuery}>{this.setMessage("KMDrugDistributionsearch", "descripts", "查询")}</Button>
              </div>
            </div>
          </Col>
          <Col span={6} style={{textAlign: 'right'}}>
            <Button
              type="primary"
              icon="file-search"
              style={{margin: '8px 10px 0 0'}}
              disabled={rowId ? false : true}
              onClick={this.handleToExamine}
            >{this.setMessage("KMDrugDistributionCheck", "descripts", "审核")}</Button>
            <Button
              type="dashed"
              style={{margin: '8px 10px 0 0'}}
              icon="home"
              disabled={rowId ? false : true}
              onClick={this.handleHomeDelivery}
            >{this.setMessage("KMDrugDistributionsendHome", "descripts", "送家里")}</Button>
            <Button
              type="dashed"
              style={{margin: '8px 10px 0 0'}}
              icon="medicine-box"
              disabled={rowId ? false : true}
              onClick={this.handleToHospital}
            >{this.setMessage("KMDrugDistributionsendToHospital", "descripts", "送医院")}</Button>
            <Button
              icon="cloud-upload"
              style={{margin: '8px 10px 0 0'}}
              disabled={rowId ? false : true}
              onClick={this.handleSendOut}
            >{this.setMessage("KMDrugDistributionsend", "descripts", "发送")}</Button>
          </Col>
        </Row>
        <div style={{height: '6px', background: 'rgba(240, 242, 245, 1)', width: '100%'}}></div>
        <Row>
          <Col span={10}>
            <div style={{paddingRight: '6px', position: 'relative'}}>
              <Card
                size="small"
                title={
                  <div className="card-title-left-icon">
                    <div></div>
                    {this.setMessage("KMDrugDistributiondataList", "descripts", "数据列表")}
                    <div style={{display: "inline-block", float: "right"}}>
                      <span>
                        <Checkbox onChange={this.handlesSdOutChange} checked={sendOut} />
                        {this.setMessage("KMDrugDistributionhasBeenSent", "descripts", "已发送")}
                      </span>
                      <Divider type="vertical" />
                      <span onClick={this.handlePrintPresc}>
                        <Icon type="printer" />
                        {this.setMessage("KMDrugDistributionprint", "descripts", "打印")}
                      </span>
                    </div>
                  </div>
                }
              >
                <div>
                  <PubilcTablePagination param={param} handelThis={this} onRef={this.onRef} onClickRowPublic={this.onClickRowPublic} setRowClassNamePublic={this.setRowClassNamePublic} />
                </div>
              </Card>
              <div style={{width: '6px', background: 'rgba(240, 242, 245, 1)', position: 'absolute', top: 0, right: 0, height: '100%'}}></div>
            </div>
          </Col>
          <Col span={14}>
            <Card
                size="small"
                title={this.setMessage("KMDrugDistributionprescriptionNotes", "descripts", "处方笺")}
                // extra={<a href="#">More</a>}
                className="catd-head-bg-img prescription"
            >
                <div style={{height: store.getState().tableHeight.y + 198 - basicHeight + 'px', overflow: 'hidden'}}>
                    <p style={{textAlign: 'center', display: !rowId ? 'block' : 'none', textDecoration: 'underline'}}>{this.setMessage("KMDrugDistributionviewPrescriptionFormTips", "descripts", "选择左侧处方来查看处方单")}</p>
                    {/* 麻醉剂药品处方：'pink'、急诊处方：、儿科处方：、普通处方：#fff */}
                    <div style={{
                      width: '100%',
                      height: '100%',
                      display: rowId ? 'block' : 'none', 
                      background: mainInfoObj&&mainInfoObj.backGroupColor ? mainInfoObj.backGroupColor : '#fff'
                    }}>
                      <div style={{borderBottom: '1px solid #ccc', paddingTop: '12px'}}>
                        <h1 style={{textAlign: 'center', position: 'relative', fontSize: '24px', marginBottom: '24px'}}>
                          {mainInfoObj.hospDesc+this.setMessage("KMDrugDistributionprescriptionNotes", "descripts", "处方笺")}
                          <span style={{position: 'absolute', right: '10px', top: '10px', fontSize: '14px', fontWeight: 100, textAlign: 'right', color:'rgba(153,153,153,1)'}}>
                            <Row>{mainInfoObj.prescType}</Row>
                            <Row>{this.setMessage("KMDrugDistributionordPrescNo", "descripts", "处方号：")+mainInfoObj.ordPrescNo}</Row>
                          </span>
                        </h1>
                        <div style={{padding: '0 48px 12px', fontSize: '14px'}}>
                          <Row>
                            <Col span={6}>
                              {this.setMessage("KMDrugDistributionloc", "descripts", "科室：")}{mainInfoObj.ordLocDesc}
                            </Col>
                            <Col span={6}>
                              {this.setMessage("KMDrugDistributionpatID", "descripts", "病人ID：")}{mainInfoObj.patNo}
                            </Col>
                            <Col span={6}>
                              {this.setMessage("KMDrugDistributiondate", "descripts", "日期：")}{mainInfoObj.ordDate}
                            </Col>
                            <Col span={6}>
                              {this.setMessage("KMDrugDistributioncostCategory", "descripts", "费别：")}{mainInfoObj.admReasonDesc}
                            </Col>
                          </Row>
                          <Row style={{margin: '4px 0'}}>
                              <Col span={6}>
                                {this.setMessage("KMDrugDistributionpatName", "descripts", "患者：")}{mainInfoObj.patName}
                              </Col>
                              <Col span={6}>
                                {this.setMessage("KMDrugDistributionpatSexDesc", "descripts", "性别：")}{mainInfoObj.patSexDesc}
                              </Col>
                              <Col span={6}>
                                {this.setMessage("KMDrugDistributionpatAge", "descripts", "年龄：")}{mainInfoObj.patAge}
                              </Col>
                              <Col span={6}>
                                {this.setMessage("KMDrugDistributionpatWeight", "descripts", "体重：")}{mainInfoObj.patWeight}
                              </Col>
                          </Row>
                          <Row>
                            {this.setMessage("KMDrugDistributionadmDiag", "descripts", "诊断：")}{mainInfoObj.admDiag}
                          </Row>
                        </div>
                      </div>
                      {/* mainInfoObj.cmPrescFlag === '1' 中草药格式 */}
                      <div 
                        style={{
                          borderBottom: '1px solid #ccc', padding: '0 24px', 
                          height: store.getState().tableHeight.y - 60 - this.state.basicHeight + 'px', overflow: 'auto'
                        }} 
                        className="pr-style prescription-bar"
                      >
                        <h1 style={{fontSize: '20px'}}>Rp:</h1>
                        {mainInfoObj.cmPrescFlag === '1'? <div className="marginRight">
                          <Row>
                            {detailData&&detailData.map((item, index) => {
                              return (
                                <Col span={8} key={index} style={{marginBottom: '20px'}}>
                                  {item.medDesc}
                                  <span style={{marginLeft: '8px', position: 'relative', display: 'inline-block'}}>
                                    {item.ordQty + item.ordUnitDesc}
                                    {item.ordCMNote ? <b style={{position: 'absolute', top: '-8px', right: '-30px', fontWeight: 900, fontSize: '12px', color: 'blue', display: 'inline-blick'}}>{'(' + item.ordCMNote + ')'}</b> : ''}
                                  </span>
                                </Col>
                              )
                            })}
                          </Row>
                          <div style={{textAlign: 'center', paddingRight: '150px'}}>
                            --------------------------------------------------
                            <span style={{fontWeight: '900'}}>{this.setMessage("KMDrugDistributionblank", "descripts", "(以下空白)")}</span>
                            --------------------------------------------------
                          </div>
                          <Row style={{fontWeight: '900', }}>
                            用法：{mainInfoObj.cmFreqDesc + '，' + mainInfoObj.cmExplainDesc + '，' + mainInfoObj.cmUsageDesc}
                            <span style={{margin: '0 8px'}}>{this.setMessage("KMDrugDistributiontotal", "descripts", "共：") + mainInfoObj.cmFac + this.setMessage("KMDrugDistributiondoses", "descripts", "剂")}</span>
                            {mainInfoObj.cmCookTypeDesc}
                          </Row>
                          </div>: <div>
                            <ul style={{fontSize: '14px', paddingLeft: '24px'}}>
                              {this.processAssociatedData(detailData).map((item, index) => {
                                let num = item.children&&item.children.length ? item.children.length : 0;
                                return (
                                  <li key={index}>
                                    <div style={{paddingLeft: "24px", position: 'relative'}} className="prescription-list">
                                      <span style={{position: "absolute", left: 0, top: 0, display: 'inline-block', lineHeight: "30px"}}>{index + 1}、</span>
                                      {item.children&&item.children.map((childItem, childIndex) => {
                                        return (
                                          <div key={childIndex} style={{lineHeight: "30px"}}>
                                            <span style={{display: "inline-block", width: "300px"}}>{childItem.medDesc}</span>
                                            <span style={{display: "inline-block", width: "200px", marginRight: "50px", textAlign: "right"}}>
                                              {childItem.medSpec}
                                              <span style={{margin: '0 6px'}}>x</span>
                                              {childItem.ordQty + childItem.ordUnitDesc}
                                            </span>
                                            <span style={{display: num > 1 ? "inline-block" : "none", width: "60px", textAlign: "right", borderRight: '1px solid #333', paddingRight: '10px'}}>
                                              {childItem.ordDoseUnitDesc}
                                            </span>
                                            <span style={{display: num > 1 ? "inline-block" : "none"}} className={num > 1 ? "show-last-span" : ""}>
                                              <span style={{margin: "0 10px"}}>X</span> {childItem.ordDurationDesc}
                                            </span>
                                          </div>
                                        )
                                      })}
                                    </div>
                                    <Row className="marginRight">{this.setMessage("KMDrugDistributionusage", "descripts", "用法：")}{
                                      (item&&item.children&&item.children.length > 1 ? '' : item.children[0].ordDoseUnitDesc) +  ' ' + 
                                      (item&&item.children&&item.children[0]&&item.children[0].ordFreqDesc ? item.children[0].ordFreqDesc : "") + ' ' + 
                                      (item&&item.children&&item.children[0]&&item.children[0].ordUsageDesc ? item.children[0].ordUsageDesc : "")+ ' ' + 
                                      (item&&item.children&&item.children.length > 1 ? '' :  item.children[0].ordDurationDesc)}
                                    </Row>
                                  </li>
                                )
                              })}
                            </ul>
                          <div className="diagonal"></div>
                        </div>}
                      </div>
                      <div style={{padding: '12px'}}>
                        <Row style={{marginBottom: '4px'}}>
                          <Col span={8}>
                            <Row>
                              <Col {...colTop} className="alignRight">{this.setMessage("KMDrugDistributiondoctorSignName", "descripts", "医生签名：")}</Col>
                              <Col {...colBottom}>{mainInfoObj.ordDocDesc}</Col>
                            </Row>
                          </Col>
                          <Col span={8}>
                            <Row>
                              <Col {...colTop} className="alignRight">{this.setMessage("KMDrugDistributionCheck", "descripts", "审核")}：</Col>
                              <Col {...colBottom}>{mainInfoObj.auditUserName}</Col>
                            </Row>
                          </Col>
                          <Col span={8}>
                            <Row>
                              <Col {...colTop} className="alignRight">{this.setMessage("KMDrugDistributionamount", "descripts", "金额：")}</Col>
                              <Col {...colBottom}>{mainInfoObj.prescAmt}</Col>
                            </Row>
                          </Col>
                        </Row>
                        <Row>
                          <Col span={8}>
                            <Row>
                              <Col {...colTop} className="alignRight">{this.setMessage("KMDrugDistributionprovisioning", "descripts", "调配：")}</Col>
                              <Col {...colBottom}></Col>
                            </Row>
                          </Col>
                          <Col span={8}>
                            <Row>
                              <Col {...colTop} className="alignRight">{this.setMessage("KMDrugDistributionverify", "descripts", "核对：")}</Col>
                              <Col {...colBottom}></Col>
                            </Row>
                          </Col>
                          <Col span={8}>
                            <Row>
                              <Col {...colTop} className="alignRight">{this.setMessage("KMDrugDistributiondrugDistribution", "descripts", "发药：")}</Col>
                              <Col {...colBottom}></Col>
                            </Row>
                          </Col>
                        </Row>
                        <p style={{textAlign: 'center', marginTop: '12px', marginBottom: 0}}>{this.setMessage("KMDrugDistributionthisPreCurrentlyValid", "descripts", "本处方当前有效")}</p>
                      </div>
                    </div>
                </div>
            </Card>
          </Col>
        </Row>
        <ReadCard  ref={r => this.readCard = r}/>
        <DrugDeliveryAddress onRef={this.modalOnRef} handleQuery={this.getTableData} />
        <ColumnAuthoritysModel
            clientWidth='800px'
            compontName='KMDrugDistribution'
            configType="C"
            onRef={this.onColumnRef}
            reloadData={this.getTableColumns}
        />
      </div>
    )
  }
}