/*
 * Creator:     ML
 * CreatDate:   2019-09-18
 * descripts：  查看病理报告
 * */
import React from 'react';
import { Form, Row, Col, Input, Select, Button, DatePicker, Modal, Table, Icon, Pagination, message,TimePicker,Tooltip} from 'antd';
import moment from 'moment';
import ColumnAuthoritysModel from 'pages/columnAuthority/ColumnAuthoritysModel';
import { $http } from '../../../containers/config/https';
import store from '../../../store';
import ViewSelectComponent from './ViewSelectComponent';
import CommonPagination from 'components/pagination/index';

const FormItem = Form.Item;
const Option = Select.Option;
const confirm = Modal.confirm;

const formItemLayout = { // label 和input宽度
  labelCol: { span: 6},
  wrapperCol: { span: 18 },
}
const formItemLayoutNo = { // label 和input宽度
    labelCol: { span: 6},
    wrapperCol: { span: 18 },
  }

const ViewPathologyReport = Form.create()(
  class ViewPathologyReport extends React.Component {
    constructor(props) {
      var userData = JSON.parse(sessionStorage.getItem('userData'));
      super(props)
      this.state = {
        userData: userData,
        loading: false,
        visible: false,
        total: 0,//表格总数据
        consuilationData: [],//查询出来的检查报告数据
        values: {},//查询条件数据
        searchLoading:false,//查询请求
        rowIds:'',//表格行选中 页面数据
        columns:[],//检查报告表头
        widthTotal:0,//宽
        columnsVisible:false,//配置表头显隐
        page:1,
        pageSize:10,
        starNoVisible:false,
        startNoMessage:"",
        search: "",
        size: "small",
        years: "",
        yearsLog: "",
        starData: "",
        endData: ""
      }
      
    }
    componentDidMount() {
      if (document.querySelector('.ant-table-body')) {
        if(this.props&&this.props.modal){
          //放置在弹窗上
          document.querySelector(".pathologyDom .ant-table-body").style.height =  store.getState().tableHeight.y - 136 + 'px';
          document.querySelector(".pathologyDom .ant-table-body").style.maxHeight =  store.getState().tableHeight.y -136 + 'px';
        }else{
          //放置在普通页面上
          document.querySelector(".pathologyDom .ant-table-body").style.height =  store.getState().tableHeight.y + 95 + 'px';
          document.querySelector(".pathologyDom .ant-table-body").style.maxHeight =  store.getState().tableHeight.y + 95 + 'px';
        }
      }
      this.getMainTableColumns()
      setTimeout(()=>{
        this.getFindDate("search");
      },600)
    }  
    onColumnRef = (ref) => {
      this.columnRef = ref;
    }
     //国际化
     setMessage(name, message) {
      return this.state.localeProvider ? this.state.localeProvider[name][message] : ''
    }
       // 获取主列表columns
       getMainTableColumns = () => {
        let data = {
			params: [{
                compontName: "ViewPathologyReport", // 病理
                reactCode: ['ViewPathologyReport'],
                type: 'C', // 卡类型id
            }]
		}
		$http.post('urlS', this, {
			code: '01040073',
			data: data,
			success: function (res) {
                if (+res.errorCode === 0) {
                    let arr = res.result&&res.result.C.length > 0 ? JSON.parse(JSON.stringify(res.result.C)).map(item => {
                        return  {
                            align: item.align,
                            widthNum: parseInt(item.width),
                            width: item.width,
                            dataIndex: item.dataIndex,
                            title: <div onDoubleClick={() => this.columnRef.onOpenModel()}>{this.state.userData.language == 'EN' ? item.enDescripts : item.title}</div>,
                            display: item.display,
                            key: item.seqNo
                        }
                    }) : '';
                    let filterArr = arr.filter(function(item){ return item.display === 'Y'});
                    this.setState({localeProvider: this.state.userData.language == 'EN' ? res.result.language.EN : res.result.language.CN,columns: filterArr, widthTotal:parseInt(res.totalWidth)+50})
                }
			}
		})
    }
    // 修改page和pageSize 跳转至---
    onChange = (page, pageSize) => {
      this.setState({ page: page, pageSize: this.state.pageSize }, () => {
        // 重新调用查询方法
        this.getFindDate();
      })
    }
    //下拉选择页数
    onShowSizeChange = (page, pageSize) => {
      this.setState({ page: 1, pageSize: pageSize }, () => {
        // 重新调用查询方法
        // if(this.state.consuilationData&&this.state.consuilationData.length>0){
          this.getFindDate("search");
        // }
      })
    }
    // 显示分页总条数
    showTotal(total) {
      return `共 ${total} 条`;
    }
    findDatas = () => {
      this.setState({
        rowIds: ""
      })
      this.setState({ page: 1, pageSize: this.state.pageSize }, () => {
        this.getFindDate("search")
      })
    }
    getValue = (years, yearsLog, starData, endData) => {
      // console.log(years, yearsLog, starData, endData)
      this.setState({
        years,
        yearsLog,
        starData,
        endData
      })
    }
    findData = () => {
      this.child.handleVail()
    }
     //--病理列表
     findDatas = () => {
          this.setState({
            rowIds:""
          })
          this.setState({ page: 1, pageSize: this.state.pageSize }, () => {
            this.getFindDate()
          })
    }
    //获取查询数据
    getFindDate = (e) => {
      if(this.state.total==0){
          this.setState({
          searchLoading:true
      })
      }
      let { page, pageSize, years,
        yearsLog,
        starData,
        endData } = this.state;
      let data = {}
      data = {
        params: [{ 
            // admID: 26351,
            years: years || "",
            admID: yearsLog || "",
            dateFrom: starData, 
            dateTo: endData ,
        }],
        pagination: [{
          pageSize: pageSize,
          currentPage: page,
        }]
      }
      $http.post('urlS', this, {
        code: '03060019',
        data: data,
        success: function (res) {
          if (+res.errorCode === 0) {
            this.setState({
              searchLoading:false,
              rowId:"",
            })
            this.setState({ consuilationData: res.result.data,search:e, total: res.result.totalCount&&res.result.totalCount!=undefined?res.result.totalCount:0, }, () => {
            },)
          } else {
            this.setState({
              searchLoading:false
            })
          }
        },
        error:function(){
          this.setState({
            searchLoading:false
          })
        }
      })
    }
   
    handleCancel = () => {
      this.handleRest()
      this.setState({
        visible: false, 
        bindMoreInfo:false,
        bindVail:true
        });
    }
  
    //点击查询后 表格行
    setRowClassNames=(record)=>{
      return record.admID === this.state.rowIds ? 'clickRowStyle' : '';
    }
     //点击Row
     onClickRow = (record) => {
      return {
        onClick: () => {
          this.setState({
            parms: record,
          })
          if (this.state.rowId === "") {
            this.setState({
              rowIds: record.admID,
            });
          } else {
            if (this.state.rowId !== record.admID) {
              this.setState({
                rowIds: record.admID,
              });
            } else {
              this.setState({
                rowIds: "",
                detailInfo: {},
              });
            }
          }
        },
      };
    }
     //隐藏提示信息
     visibleTip=()=>{
        this.setState({
          starNoVisible:false,
        })
      }
      onRefs = (ref) => {
        this.child = ref
      }
  
    render() {
      const { getFieldDecorator } = this.props.form;
      const { baseParms,searchLoading,localArr,doctorArr,exportLoading,widthTotal,columns} = this.state;
      const mesIcon = <Icon type="exclamation-circle" />
      return (
        <div style={{ padding: '4px 2px' }} className="pathologyDom">
           <Form>
            <Row gutter={60} style={{ margin: '0' }}>
            <ViewSelectComponent modal={this.props&&this.props.modal?this.props.modal:""} getValue={this.getValue} handleFind={this.findDatas} onRefs={this.onRefs} locale={this.state.userData.language}></ViewSelectComponent>
              <Col span={2} style={{ paddingLeft: "0 !important" }}>
                <FormItem  {...formItemLayout}>
                  {getFieldDecorator('export', {
                    initialValue: undefined,
                    rules: [{ required: false, message: '' }],
                  })(
                    <Button onClick={this.findData} loading={searchLoading} style={{ background: 'rgba(66,185,131,1)', color: '#fff' }}>
                      {this.state.localeProvider && this.state.localeProvider.ViewPathologyReportSearch? this.setMessage('ViewPathologyReportSearch', 'descripts') : "查询"}
                      </Button>
                  )}
                </FormItem>
              </Col>
            </Row>          
          </Form>
          <Table
            scroll={{ x: (columns&&columns.length>0?widthTotal:4000), y: store.getState().tableHeight.y +　51　 }}
            columns={columns&&columns.length>0?columns:[]}
            dataSource={this.state.consuilationData}
            pagination={false}
            rowKey={record => record.key}
            onRow={this.onClickRow}
            rowClassName={this.setRowClassNames}
            bordered
            style={{ height: this.props&&this.props.modal?store.getState().tableHeight.y -82 + 'px':store.getState().tableHeight.y + 147 + 'px',overflow:"auto" }}
          />
           <CommonPagination size={this.state.size} current={this.state.page} total={this.state.total} search={this.state.search}
            onShowSizeChange={this.onShowSizeChange.bind(this)} complete={true} dataSource={this.state.consuilationData}
            onChange={this.onChange.bind(this)} />
          {/* <Pagination
            showTotal={() => this.showTotal(this.state.total)}
            size="small"
            showQuickJumper
            showSizeChanger
            defaultCurrent={1}
            current={this.state.page ? this.state.page : 1}
            total={this.state.total ? this.state.total : 0}
            onChange={this.onChange}
            onShowSizeChange={this.onShowSizeChange}
            style={{ textAlign: "right", }}
          /> */}
               <ColumnAuthoritysModel
                    clientWidth='800px'
                    compontName= 'ViewPathologyReport'
                    configType="C"
                    onRef={this.onColumnRef}
                    reloadData={this.getMainTableColumns}
                />
        </div>
      )
    }
  })
export default ViewPathologyReport    