// 床管中心
import React from 'react';
import { Table, Radio, Tabs, Button, message ,Select, Row, Col} from 'antd';
import { $http } from '../../../containers/config/https';
import store from 'store';
import CommonPagination from 'components/pagination/index';
import './style/style.less'

let userData = {}
class BedTubeCenter extends React.Component {
	constructor({ history }) {
		super();
    userData = sessionStorage.userData ? JSON.parse(sessionStorage.userData) : {};
		this.state = {
            data:[],
            columns:[],
            total: 0,
            page: 1,
            pageSize: 10,
            empt:"all",
            bedStatus:"a",
            locData:[],
            locCode:"",
            tableWidth:"",
            ENObj:{},
            CNObj:{},

		};
	
    }

    componentDidMount() {
      this.getDetailTableColumns()
    }

    componentWillReceiveProps() {

    }
    componentWillUnmount() {

    }

    queryBedInfo=()=>{
        let data = {
            params: [{
                hospID: userData.hospID,
                locID:this.state.locCode,
                empt:this.state.empt,
                bedStatus:this.state.bedStatus,
            }],
            pagination: [{
              pageSize: this.state.pageSize,
              currentPage: this.state.page,
            }]
        };
        $http.post('urlS', this, {
            code: "04170001",
            data: data,
            success: function (res) {
                let errorCode = res.errorCode;
                if (errorCode == "0") {
                    var locData = []
                    locData =  res.result.wardLoc
                    this.setState({
                        data: res.result.OperationPosition,
                        total:res.result.total,
                        locData:locData
                    })
                } else {
                    this.setState({
                        data: [],
                    })
                }
            }
        });
    }

     // 获取明系列表头数据
     getDetailTableColumns = () => {
      let data = {
          params: [{
              reactCode: ['BedTubeCenter'],
              compontName: 'BedTubeCenter',
              type: 'C',
          }]
      }
      $http.post('urlS', this, {
          code: '01040073',
          data: data,
          success: function (res) {
              if (+res.errorCode === 0) {
                  var columns = []
                  console.log(res)
                  columns = res.result.C
                  if (userData.language == 'EN') {
                    for (let i = 0; i < columns.length; i++) {
                      columns[i].title = columns[i].enDescripts
                    }
                  }
                  this.setState({
                      ENObj: res.result.language.EN,
                      CNObj: res.result.language.CN,
                      columns: columns,
                      tableWidth: res.totalWidth,
                  }, () => {
                      this.queryBedInfo()
                  })
              }
          }
      })
    }

    // 翻页
    onChange = (page, pageSize) => {
      this.setState({ page: page, pageSize: pageSize }, () => {
        // 重新调用查询方法
        this.queryBedInfo();
      });
    };

    onShowSizeChange = (current, size) => {
      this.setState({ page: current, pageSize: size }, () => {
        // 重新调用查询方法
        this.onChange(current, size);
      })
    };

    onChangeDay(e){
      this.setState({
        empt:e.target.value
      },()=>{
        this.queryBedInfo()
      })
    }

    onChangeBed(e){
      this.setState({
        bedStatus:e.target.value
      },()=>{
        this.queryBedInfo()
      })
    }

    handleChange=(value)=> {
      this.setState({
        locCode:value,
      },()=>{
        this.queryBedInfo()
      })
    }
    
    render(){
      let locArr = [];
      this.state.locData.map((item) => {
        locArr.push(
          <Option key={item.id} value={item.id} >
            {item.descripts}
          </Option>
        )
      })


      var language = userData.language
        var languageObj = {}
        if (language == "EN") {
            languageObj = this.state.ENObj
        } else {
            languageObj = this.state.CNObj
        }


        return(
            <div className="BedTubeCenter"  >   
              <div style={{marginLeft:'20px'}}>
                <Row>
                  <Col span={4}>
                    {languageObj.BedTubeCenterward != null ? languageObj.BedTubeCenterward.descripts : ""}<Select defaultValue="" style={{ width: 120 }} onChange={this.handleChange}>
                        <Option key="" value="">{languageObj.BedTubeCenterall != null ? languageObj.BedTubeCenterall.descripts : ""}</Option>
                        {locArr}
                    </Select>
                  </Col>


                  <Col span={4}>
                    <Radio.Group onChange={this.onChangeBed.bind(this)} defaultValue="a" >
                      <Radio.Button value="a">{languageObj.BedTubeCenterall != null ? languageObj.BedTubeCenterall.descripts : ""}</Radio.Button>
                      <Radio.Button value="b">{languageObj.BedTubeCenternullBed != null ? languageObj.BedTubeCenternullBed.descripts : ""}</Radio.Button>
                      <Radio.Button value="c">{languageObj.BedTubeCenteroccupy != null ? languageObj.BedTubeCenteroccupy.descripts : ""}</Radio.Button>
                      <Radio.Button value="d">{languageObj.BedTubeCenterPreempty != null ? languageObj.BedTubeCenterPreempty.descripts : ""}</Radio.Button>
                    </Radio.Group>
                  </Col>
                </Row>
              </div>

              <div style={{ width: '100%', height: '10px', background: '#f0f2f5',marginTop:'5px' }}></div>

              <div style={{ width: '100%', height: '92%', overflow: 'hidden'}}>
                <div style={{ width: '100%', height: 'calc(100% - 70px)', overflow: 'hidden' }}>
                  <Table
                    style={{ width: '100%',height:"100%" }}
                    scroll={{x: this.state.tableWidth,y:'calc(100% - 60px)'}}
                    dataSource={this.state.data}
                    columns={this.state.columns}
                    rowClassName="editable-row"
                    bordered 
                    pagination={false}    
                  /> 
                </div>
                <div>
                  <CommonPagination
                    size='small'
                    current={this.state.page}
                    total={this.state.total}
                    search='search'
                    onShowSizeChange={this.onShowSizeChange.bind(this)}
                    complete={true}
                    dataSource={this.state.data}
                    onChange={this.onChange.bind(this)}
                    scroll={{ y: store.getState().tableHeight.y + 'px' }}
                  />
                </div>
              </div>
            </div>
        )
    }

}
export default BedTubeCenter;