
/*
 * Creator:     ML
 * CreatDate:   2019-10-31
 * descripts：医嘱大类设置 -- 查询
 * */
import React from 'react';
import { Form, Row, Col, Input, Select, DatePicker, Button, message,Checkbox } from 'antd';
import { $http } from '../../../containers/config/https';
import '../style/index.less';

const paddRightCol = {
    paddingRight: "0px"
}
const formItemLayoutType = {
    labelCol: { span: 9 },
    wrapperCol: { span: 15 }
}
const FormItem = Form.Item;
const Option = Select.Option;
const FindMajor = Form.create()(
    class FindMajor extends React.Component {
        cacheOriginData = {};
        constructor() {
            super()
            this.state = {
                bigTypeArr:[],
                adviceTypeArr:[],
                checked:true
            }
        }
        componentDidMount() {
            this.props.OnChild(this);
            this.getBigClass()
            this.getAdviceType()
        }
//点击是否生效
changeChecked = (e) => {
    this.setState({
        checked: e.target.checked,
    }, () => {
        this.handleFindMajor()
    })
}
//获取大类下拉框
getBigClass=()=>{
            let data = {}
               data = {
                params: [{
                }],
            } 
            $http.post('urlS', this, {
                code: '05100228',
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0 &&res.result.Data) {
                        this.setState({
                            bigTypeArr:res.result.Data
                        })
                    }
                }
            })
}
//获取医嘱类别下拉框
getAdviceType=()=>{
    let data = {}
       data = {
        params: [{
        }],
    } 
    $http.post('urlS', this, {
        code: '05100229',
        data: data,
        success: function (res) {
            if (+res.errorCode === 0 &&res.result.Data) {
                this.setState({
                    adviceTypeArr:res.result.Data
                })
            }
        }
    })
}
handleFindMajor=()=>{
    this.handleFind(1,10,"init")
    this.props.allClear()
}
   //查询医嘱子类
   handleFind=(page,pageSize,mes)=>{
    this.props.form.validateFields((err, values) => {
        if (!err) {
            this.props.FindMajorTable(this.state.checked==true?"Y":"N",values)
            // let checkFlag = ""
            // if (mes&&mes!="init") {
            //     checkFlag = mes
            // }
            // if (this.state.checked == true) {
            //     checkFlag = "Y"
            // } else {
            //     checkFlag = "N"
            // }
            // let data = {}
            //    data = {
            //     params: [{
            //         code: values.subCode,
            //         descripts: values.subDec,
            //         orderCatID: values.majorBigClassID,
            //         orderTypeID: values.majorType,
            //         status: checkFlag,
            //     }],
            //     pagination: [{
            //         pageSize: parseInt(pageSize),
            //         currentPage: parseInt(page),
            //     }]
            // } 
            // $http.post('urlS', this, {
            //     code: '05100227',
            //     data: data,
            //     success: function (res) {
            //         if (+res.errorCode === 0) {
            //             if(mes&&mes=="init"){
            //                 // this.props.FindMajorTable(res.result.Data,res.result.TotalCount,mes)
            //             }else{
            //                 // this.props.FindMajorTable(res.result.Data,res.result.TotalCount,)
            //             }
            //         }
            //     }
            // })
        }
    })
}
        render() {
            const { getFieldDecorator } = this.props.form;
            let { topInfo ,bigTypeArr,adviceTypeArr} = this.state
            let typeArr = [{
                code: "01",
                descripts: "医生开嘱",
                descriptsSPCode: "YSKZ",
                enDescripts: "",
                id: "D"
            }, {
                code: "02",
                descripts: "护士开嘱",
                descriptsSPCode: "HSKZ",
                enDescripts: "",
                id: "N"
            },
            //  {
            //     code: "03",
            //     descripts: "补录开嘱(费用)",
            //     descriptsSPCode: "BLKZ",
            //     enDescripts: "",
            //     id: "A"
            // },
            {
                code: "04",
                descripts: "自定价开嘱",
                descriptsSPCode: "ZDJKZ",
                enDescripts: "",
                id: "F"
            },]
            //开医嘱类型
            let typeOp = []
            typeArr && typeArr.map(item => {
                typeOp.push(<Option key={item.id}  value={String(item.id)}>{item.descripts}</Option>)
            })
            return (
                <div>
                    <Form>
                        <Row gutter={60}>
                            <Col span={8} style={paddRightCol}>
                                <FormItem {...formItemLayoutType} label='代码'>
                                    {getFieldDecorator('code', {
                                        initialValue: undefined,
                                        rules: [{ required: false, message: '' }],
                                    })(
                                        <Input onPressEnter={this.handleFindMajor}></Input>
                                    )}
                                </FormItem>
                            </Col>
                            <Col span={8} style={paddRightCol}>
                                <FormItem {...formItemLayoutType} label='描述'>
                                    {getFieldDecorator('descripts', {
                                        initialValue: undefined,
                                        rules: [{ required: false, message: '' }],
                                    })(
                                        <Input onPressEnter={this.handleFindMajor}></Input>
                                    )}
                                </FormItem>
                            </Col>
                            <Col span={8} style={{ paddingLeft: "42px" }}>
                                <FormItem >
                                    {getFieldDecorator('addCategories', {
                                        initialValue: undefined,
                                        rules: [{ required: false, message: '' }],
                                    })(
                                        <Checkbox checked={this.state.checked} onChange={this.changeChecked}>仅显示生效</Checkbox>
                                    )}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row>
                        <Col span={11} style={paddRightCol}>
                        <FormItem {...formItemLayoutType} label='开医嘱类型'>
                                    {getFieldDecorator('bigType', {
                                        initialValue: undefined,
                                        rules: [{ required: false, message: '' }],
                                    })(
                                        <Select
                                            allowClear
                                        >
                                            {typeOp}
                                        </Select>
                                    )}
                                </FormItem>
                            </Col>
                           
                            <Col span={10} style={{ textAlign: "right" }}>
                                <Button type="primary" onClick={this.handleFindMajor}>查询</Button>
                            </Col>
                        </Row>

                    </Form>
                </div>
            )
        }
    })
export default FindMajor