/*
 * Creator:     ML
 * CreatDate:   2020-03-14
 * descripts：  快递单查询 选择打印弹窗
 * */
import React from 'react';
import { Form, Row, Col, Input, message, Select, Button, Modal, DatePicker, Table, Pagination, Popconfirm,Checkbox } from 'antd';
import { $http } from 'containers/config/https';
import { Util, dayFormat } from 'tools/index';
import { $loadTemplate } from '../../lodop/Common/Print.js';
  class CourierOrderPrintModal extends React.Component {
    constructor(props) {
      super(props)
      var userData = JSON.parse(sessionStorage.getItem('userData'))
      this.state = {
        userData: userData,
        visible: false,//弹窗
        recipeList:false,
        printList:false
      }
    }
    componentDidMount() {
      this.props.onSelectPrint(this);
    }
    showModal = (record) => {
      this.setState({
        record,
        recordName: record.name,
        visible: true,
      });
    }
    handleCancel = () => {
      this.setState({
        visible: false,
        recipeList:false,
        printList:false,
        record: {},
      })
    }
    handleOk = () => {
      const {recipeList,printList,record} = this.state
      if(recipeList || printList){
        var params = {
          params: [{
              hospID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).hospID : "",
              userID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).userID : "",
              orderID: record.orderID
          }]
      }
      if(recipeList){
        $http.post('urlS', this, {
          code:'03030066',
          data: params,
          success: function (res) {
              if (res.errorCode == '0') {
                  message.success('正在打印....')
                  if (!Util.isEmpty(res.result)) {
                      var data = res.result
                      for (var i = 0; i < data.length; i++) {
                          $loadTemplate(data[i].template, data[i].printStr);
                      }
                      this.handleCancel()
                  }
              }
          }
      })
      }if(printList){
        $http.post('urlS', this, {
          code:'03030059',
          data: params,
          success: function (res) {
              if (res.errorCode == '0') {
                  message.success('正在打印....')
                  if (!Util.isEmpty(res.result)) {
                      var data = res.result
                      for (var i = 0; i < data.length; i++) {
                          $loadTemplate(data[i].template, data[i].printStr);
                      }
                      this.handleCancel()
                  }
              }
          }
      })
      }
      }else{
        message.warning("请选择需要打印的单子")
      }
         

    }
   
    //国际化
    setMessage(name, message) {
      return this.props.localeProvider ? this.props.localeProvider[name][message] : ''
    }
    changeCheckBox(name, e) {
      this.setState({
          [name]: e.target.checked
      })
  }
    render() {
      return (
        <div
          tabIndex={1}
          onKeyDown={this.handleOnKeydown}
          style={{ outline: 'none' }}
        >
          <Modal
            className='breakTimes'
            width='500px'
            height="212px"
            visible={this.state.visible}
            title={this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacReasonForJoining ? this.setMessage('BlacklistInformationInterfacReasonForJoining', 'descripts') : "选择打印"}
            // onOk={this.handleOk}
            onCancel={this.handleCancel}
            footer={
              <div>
                <Button onClick={this.handleCancel}>{this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacCancel ? this.setMessage('BlacklistInformationInterfacCancel', 'descripts') : '取消'}</Button>
                <Button type="primary" onClick={this.handleOk}>{this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacOk ? this.setMessage('BlacklistInformationInterfacOk', 'descripts') : '确定'}</Button>
              </div>
            }
          >
            <div style={{ minHeight: '30px' }}>
              <Row style={{display:"flex"}}>
                <div><Checkbox disabled={true} />打印发票</div>
                <div style={{ marginLeft: 16 }}><Checkbox checked={this.state.recipeList}
                  onChange={this.changeCheckBox.bind(this, 'recipeList')} />打印处方</div>
                <div style={{ marginLeft: 16 }}><Checkbox checked={this.state.printList}
                  onChange={this.changeCheckBox.bind(this, 'printList')} />打印配送清单</div>
              </Row>
            </div>
          </Modal>
        </div>
      )
    }
  }
export default CourierOrderPrintModal    