
/*
 * Creator:     ML
 * CreatDate:   2019-10-09
 * descripts 科室评估单配置 -- 查询
 * */
import React from 'react';
import { Form, Row, Col, Input, Select, DatePicker, Button, message,Checkbox } from 'antd';
import { $http } from '../../../containers/config/https';

const paddRightCol = {
    paddingRight: "0px"
}
const formItemCode = {
    labelCol: { span: 10 },
    wrapperCol: { span: 14 }
}
const formItemLoc = {
    labelCol: { span: 9 },
    wrapperCol: { span: 15 }
}
const FormItem = Form.Item;
const Option = Select.Option;
const DepAssFind = Form.create()(
    class DepAssFind extends React.Component {
        cacheOriginData = {};
        constructor() {
            super()
            this.state = {
                checked:true
            }
        }
        componentDidMount() {
            this.props.OnChild(this);
            this.getLocTypeSelect()
        }
//点击是否生效
changeChecked = (e) => {
    this.setState({
        checked: e.target.checked,
    }, () => {
        this.handleDepAssModal()
    })
}
//取消选择
initCheck=()=>{
    this.setState({
        checked:false
    })
}
    //获取科室  字段  类型下拉框
    getLocTypeSelect = () => {
        let data = {}
        data = {
            params: [{
                userID:sessionStorage.userData ? JSON.parse(sessionStorage.userData).userID : "",
                hospID:sessionStorage.userData ? JSON.parse(sessionStorage.userData).hospID : "",
                locFlag:"Y",
                fileFlag:"Y"
            }],
        }
        $http.post('urlS', this, {
            code: '03040029',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0 && res.result) {
                    let arr = res.result.locList && res.result.locList.map((item, index) => {
                        res.result.locList[index].key = Number(index)
                    })
                    this.setState({
                        locArr: res.result.locList
                    })
                    this.props.sendLoc(res.result.locList)
                    this.props.sendFile(res.result.fileList)
                } else {

                }
            }
        })
    }
handleSearch=()=>{
    this.props.form.validateFields((err, values) => {
        if(!err){
            this.props.handleQuery(this.state.checked,values,)
        }
    })
}
handleDepAssModal=()=>{
    // this.handleFind(1,10,"init")
    this.props.onShowSizeChange()
    this.props.sarchInit()
    
}
   //查询
   handleFind=(page,pageSize,mes)=>{
    this.props.form.validateFields((err, values) => {
        if (!err) {
            let checkFlag = ""
            if (mes&&mes!="init") {
                checkFlag = mes
            }
            if (this.state.checked == true) {
                checkFlag = "Y"
            } else {
                checkFlag = " "
            }
            let data = {}
               data = {
                params: [{
                    userID:sessionStorage.userData ? JSON.parse(sessionStorage.userData).userID : "",
                    hospID:sessionStorage.userData ? JSON.parse(sessionStorage.userData).hospID : "",
                    groupID:sessionStorage.userData ? JSON.parse(sessionStorage.userData).groupID : "",
                    locID: values.locID,
                    searchCode:values.searchCode,
                    active: checkFlag,
                }],
                pagination: [{
                    pageSize: pageSize,
                    currentPage: page,
                }]
            } 
            $http.post('urlS', this, {
                code: '03040023',
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        // if(mes&&mes=="init"){
                        //     this.props.DepAssModalTable(res.result.Data,res.result.TotalCount,mes)
                        // }else{
                        //     this.props.DepAssModalTable(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 locOp = []
            this.state.locArr && this.state.locArr.map(item => {
                locOp.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
            })
            
            return (
                <div>
                    <Form>
                        <Row gutter={60}>
                            <Col span={8} style={paddRightCol}>
                                <FormItem {...formItemLoc} label='科室'>
                                    {getFieldDecorator('locID', {
                                        initialValue: undefined,
                                        rules: [{ required: false, message: '' }],
                                    })(
                                        <Select
                                            style={{ width: "100%" }}
                                            allowClear={true}
                                            showSearch={true}
                                            optionFilterProp="role"
                                        >
                                            {locOp}
                                        </Select>
                                    )}
                                </FormItem>
                            </Col>
                            <Col span={15} style={paddRightCol}>
                                <FormItem {...formItemCode} label='评估单名称/拼音首拼'>
                                    {getFieldDecorator('searchCode', {
                                        initialValue: undefined,
                                        rules: [{ required: false, message: '' }],
                                    })(
                                        <Input onPressEnter={this.handleDepAssModal}></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>
                            <Col span={16} style={{ textAlign: "right" }}>
                                <Button type="primary" onClick={this.handleDepAssModal}>查询</Button>
                            </Col>
                        </Row>

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