/*
 * Creator:     ML
 * CreatDate:   2019-09-16
 * descripts： 病人自定义列表设置
 * */
import React from 'react';
import { Form, Row, Col, Input,message,Select, Button, Modal, Table, Pagination,Card, CheckBox ,Switch } from 'antd';
import { $http } from '../../containers/config/https';
const FormItem = Form.Item;

const PatientListSettings = Form.create()(
  class PatientListSettings extends React.Component {
    constructor(props) {
      super(props)
      var userData = JSON.parse(sessionStorage.getItem('userData'));
      this.state = {
        tableData:[],//角色列表table数据
        findInfo:[],//查找关联角色提示
        page:1,
        pageSize:10,
        parms:{},
        rowId:"",//点击table行选中
        pageSigeData:[],//左侧页签
        userData:userData
      }
    }
    componentDidMount() {
    }
    handleOk = (e) => {
    }
  
   
    //查询
    handleQuery = () => {
        message.warning("开发中...",this.state.userData && this.state.userData.messageTime)
    //   this.setState({ page: 1, pageSize: 10 }, () => {
    //     let { number } = this.state;
    //     this.getTableData();
    //   })
    }
    // 修改page和pageSize 跳转至---
    onChange = (page, pageSize) => {
      this.setState({ page: page, pageSize: pageSize }, () => {
        // 重新调用查询方法
        let { number, name } = this.state;
        this.getTableData(this.props.form.getFieldValue('number'));
      })
    }
    //下拉选择页数
    onShowSizeChange = (page, pageSize) => {
      this.setState({ page: 1, pageSize: pageSize }, () => {
        // 重新调用查询方法
        let { number, name } = this.state;
        this.getTableData(this.props.form.getFieldValue('number'));
      })
    }
    // 显示分页总条数
    showTotal(total) {
      return `共 ${total} 条`;
    }
    //点击Row
    onClickRow = (record) => {
      return {
        onClick: () => {
          // console.log("rerere",record)
          this.setState({
            parms: record,
          })
          if (this.state.rowId === "") {
            this.setState({
              rowId: record.patNo,
            });
          } else {
            if (this.state.rowId !== record.patNo) {
              this.setState({
                rowId: record.patNo,
              });
            } else {
              this.setState({
                rowId: "",
              });
            }
          }

        },
        onDoubleClick: () => {
          this.setState({
            rowId: record.patNo,
            parms: record,
          })
          this.handleRow()
        }
      };
    }
    //设置点击row颜色
    setRowClassName = (record) => {
      return record.patNo === this.state.rowId ? 'clickRowStyle' : '';
    }
    resetEditFieldData = () => {
      this.setState({
        rowId: "",
      });
    }
    // 请求列表数据
    getTableData = (number) => {
      let { page, pageSize, } = this.state;
      let data = {}
      data = {
        params: [{
          number: this.props.form.getFieldValue('number'),
        }],
        pagination: [{
          pageSize: pageSize,
          currentPage: page,
        }]
      }
      $http.post('urlS', this, {
        code: '03030004',
        data: data,
        success: function (res) {
          if (+res.errorCode === 0 && res.result) {
            for (var i = 0; i < res.result.Data.length; i++) {
              res.result.Data[i]["key"] = i + "find"
            }
            this.setState({ tableData: res.result.Data, total: res.result.TotalCount,rowId:res.result.Data&&res.result.Data.length!=0?res.result.Data[0].patNo:"",findInfo:res.result.Data&&res.result.Data.length==0?'暂未关联角色，左侧选择角色关联配置':''})
          } else {
          
          }
        }
      })
    }
    //选中行--确认
    handleRow = () => {
      this.handleCancel()
      this.props.handleParms(this.state.parms)
    }
    changeVisi=()=>{

    }
    cleanData=()=>{

    }
    onSubmit=()=>{

    }
    render() {
      const { getFieldDecorator } = this.props.form;
      const { total, } = this.state
      const columns = [{
        key: '1',
        title: '关联角色',
        dataIndex: 'patNo',
        width: '15%',
        align: "center",
      },  {
        key: '2',
        title: "操作",
        dataIndex: 'patMobile',
        width: '20%',
        align: "center",
        render:()=>{
            return (
                <span style={{textAlign:"center"}}>
                  <a onClick={(e) => this.toggleEditable(e, record.key,record)}>编辑</a>
                  <a style={{color:"red"}} onClick={(e) => this.toggleEditable(e, record.key,record)}>删除</a>
                </span>
              )
        }
      }]
      let pageSige = []
      this.state.pageSigeData.map((item,i)=>{
        pageSige.push(<div style={{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"}}><span>查看申请单</span><span>费用审核</span><span>执行医嘱</span><span>补录费用</span><span>手术记账</span></div>) 
      })
      return (
        <div style={{display:"flex"}}>
            <Card title={"可配置页签列表"} style={{width:"10%"}}>
                    <div style={{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"}}><span>查看申请单</span><span>费用审核</span><span>执行医嘱</span><span>补录费用</span><span>手术记账</span></div>
            </Card>
            <Card title={"查看设置—查看申请单"} style={{width:"55%"}}>
                <Form>
                <Row gutter={8}>
                    <Col span={24} >
                        <FormItem label='请选择需要关联的角色' wrapperCol={{ span: 16 }} labelCol={{ span: 6 }}>
                            {getFieldDecorator('role', {
                                initialValue: undefined,
                                rules: [{ required: true, message: '请输入角色名称 回车检索' }],
                            })(
                                <Input placeholder="输入角色名称查询"></Input>
                            )}
                        </FormItem>
                    </Col >
                </Row> 
                <Row>
                  <Col span={14} >
                        <FormItem label='就诊类型' wrapperCol={{ span: 16 }} labelCol={{ span: 6 }}>
                            {getFieldDecorator('visitype', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                               <Select>
                                   
                               </Select>
                            )}
                        </FormItem>
                        </Col>
                        <Col span={10} >
                           <FormItem label='默认项' wrapperCol={{ span: 15}} labelCol={{ span: 4 }}>
                            {getFieldDecorator('defalutVisitype', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                                <Select>

                                </Select>
                            )}
                        </FormItem>
                    </Col >
                </Row>
                <Row>
                  <Col span={14} >
                        <FormItem label='科室' wrapperCol={{ span: 16 }} labelCol={{ span: 6 }}>
                            {getFieldDecorator('loca', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                               <Select>
                                   
                               </Select>
                            )}
                        </FormItem>
                        </Col>
                        <Col span={10} >
                           <FormItem label='默认项' wrapperCol={{ span: 15}} labelCol={{ span: 4 }}>
                            {getFieldDecorator('defalutLoca', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                                <Select>

                                </Select>
                            )}
                        </FormItem>
                    </Col >
                </Row>
                <Row>
                  <Col span={14} >
                        <FormItem label='病人状态' wrapperCol={{ span: 16 }} labelCol={{ span: 6 }}>
                            {getFieldDecorator('patStatus', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                               <Select>
                                   
                               </Select>
                            )}
                        </FormItem>
                        </Col>
                        <Col span={10} >
                           <FormItem label='默认项' wrapperCol={{ span: 15}} labelCol={{ span: 4 }}>
                            {getFieldDecorator('defalutPatStatus', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                                <Select>

                                </Select>
                            )}
                        </FormItem>
                    </Col >
                </Row>
                <Row>
                  <Col span={14} >
                        <FormItem label='手术安排状态' wrapperCol={{ span: 16 }} labelCol={{ span: 6 }}>
                            {getFieldDecorator('OperativeArrangement', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                               <Select>
                                   
                               </Select>
                            )}
                        </FormItem>
                        </Col>
                        <Col span={10} >
                           <FormItem label='默认项' wrapperCol={{ span: 15}} labelCol={{ span: 4 }}>
                            {getFieldDecorator('defalutArrangement', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                                <Select>

                                </Select>
                            )}
                        </FormItem>
                    </Col >
                </Row>
                <Row>
                  <Col span={14} >
                        <FormItem label='补记账状态' wrapperCol={{ span: 16 }} labelCol={{ span: 6 }}>
                            {getFieldDecorator('SupplementAccount', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                               <Select>
                                   
                               </Select>
                            )}
                        </FormItem>
                        </Col>
                        <Col span={10} >
                           <FormItem label='默认项' wrapperCol={{ span: 15}} labelCol={{ span: 4 }}>
                            {getFieldDecorator('defalutSupAcc', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                                <Select>

                                </Select>
                            )}
                        </FormItem>
                    </Col >
                </Row>
                <Row>
                  <Col span={14} >
                        <FormItem label='病人性质' wrapperCol={{ span: 16 }} labelCol={{ span: 6 }}>
                            {getFieldDecorator('patBody', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                               <Select>
                                   
                               </Select>
                            )}
                        </FormItem>
                        </Col>
                        <Col span={10} >
                           <FormItem label='默认项' wrapperCol={{ span: 15}} labelCol={{ span: 4 }}>
                            {getFieldDecorator('defalutPatBody', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                                <Select>

                                </Select>
                            )}
                        </FormItem>
                    </Col >
                </Row>
                <Row>
                  <Col span={14} >
                        <FormItem label='选择日期' wrapperCol={{ span: 16 }} labelCol={{ span: 6 }}>
                            {getFieldDecorator('Data', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                               <Select>
                                   
                               </Select>
                            )}
                        </FormItem>
                        </Col>
                        <Col span={10} >
                           <FormItem label='默认项' wrapperCol={{ span: 15}} labelCol={{ span: 4 }}>
                            {getFieldDecorator('defalutData', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                                <Select>

                                </Select>
                            )}
                        </FormItem>
                    </Col >
                    </Row>  
                    <Row>
                    <Col span={9} >
                        <FormItem label='默认项日期开始 值' wrapperCol={{ span: 14 }} labelCol={{ span: 9 }}>
                            {getFieldDecorator('defaultStartData', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                            <Select>
                                
                            </Select>
                            )}
                    </FormItem>
                    </Col>
                    <Col span={2} >
                    <FormItem wrapperCol={{ span: 24 }} labelCol={{ span: 2 }}>
                            {getFieldDecorator('startDay', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                           <Input placeholder="天数"></Input>
                            )}
                    </FormItem>
                    </Col>
                    <Col span={9} >
                        <FormItem label='- 默认项日期结束值' wrapperCol={{ span: 14 }} labelCol={{ span: 9 }}>
                            {getFieldDecorator('defaultEndData', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                            <Select>
                                
                            </Select>
                            )}
                    </FormItem>
                    </Col>
                    <Col span={2} >
                    <FormItem wrapperCol={{ span: 24 }} labelCol={{ span: 2 }}>
                            {getFieldDecorator('endDay', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                           <Input placeholder="天数"></Input>
                            )}
                    </FormItem>
                    </Col>
                    </Row>  
                    <Row>  
                        <Col span={14} >
                        <FormItem label='审核状态' wrapperCol={{ span: 16 }} labelCol={{ span: 6 }}>
                            {getFieldDecorator('checkStatus', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                                <Select>

                                </Select>
                            )}
                        </FormItem>
                    </Col >
                    <Col span={10} >
                           <FormItem label='默认项' wrapperCol={{ span: 15}} labelCol={{ span: 4 }}>
                            {getFieldDecorator('defalutCheckStatus', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                                <Select>

                                </Select>
                            )}
                        </FormItem>
                    </Col >
                </Row>
                <Row>
                  <Col span={14} >
                        <FormItem label='执行状态' wrapperCol={{ span: 16 }} labelCol={{ span: 6 }}>
                            {getFieldDecorator('doStatus', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                               <Select>
                                   
                               </Select>
                            )}
                        </FormItem>
                        </Col>
                        <Col span={10} >
                           <FormItem label='默认项' wrapperCol={{ span: 15}} labelCol={{ span: 4 }}>
                            {getFieldDecorator('defalutDoStatus', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                                <Select>

                                </Select>
                            )}
                        </FormItem>
                    </Col >
                </Row>
                <Row>  
                        <Col span={14} >
                        <FormItem label='默认打开页签' wrapperCol={{ span: 16 }} labelCol={{ span: 6 }}>
                            {getFieldDecorator('defalutOpenSign', {
                                initialValue: undefined,
                                rules: [{ required: false, message: '' }],
                            })(
                                <Switch />
                            )}
                        </FormItem>
                    </Col >
                </Row>
                <Row style={{ width: '92%', textAlign: 'right', marginTop: "30px" }}>
                        <Button onClick={this.cleanData} >取消</Button>
                        <Button onClick={this.onSubmit} type='primary' style={{ marginLeft: '20px', background: '#1890FF' }}  >保存</Button>
                    </Row>
                </Form>
            </Card>
            <Card title={"已设置角色列表"} style={{width:"35%"}}>
                <Row>
                    <Col span={24}>
                        <Input placeholder="输入角色名称回车查询" onPressEnter={this.handleQuery}></Input>
                    </Col>
                </Row>
              <Table
                pagination={false}
                columns={columns}
                dataSource={this.state.tableData}
                rowClassName={this.setRowClassName}
                onRow={this.onClickRow}
                rowKey={record => record.key}
                locale={{emptyText:this.state.findInfo}}
                style={{
                  marginTop: '12px', height: '496px',
                  overflow: 'auto'
                }}
              />
              {
                this.state.tableData&&this.state.tableData.length>0?<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", marginTop: '13px' }}
              />:""
            }
            </Card>
            </div>
      )
    }
  })
export default PatientListSettings    