//成人专项点评
import React from 'react';
import { Card, Row, Col, Form, DatePicker, Select, Button, Icon, Table, Checkbox , message, Input  } from 'antd';
import { $http } from 'containers/config/https';
import Moment from 'moment';
import store from 'store';
import './style/index.less';;
const { Option } = Select;
const FormItem = Form.Item;
const formItemLayout = {    // label 和input宽度
    labelCol: { span:7 },
    wrapperCol: { span: 17 },
};

const AdultSpecial = Form.create()(
    class extends React.Component {
        constructor() {
            super();
            this.state = {
                userInfo: JSON.parse(window.sessionStorage.userData),
                data: [],
                SelectData: {},
                ChineseEnglishSize: [],
                detailWidthTotal: '',
                total: '',
                pid: '',
            }
        }

        componentDidMount() {
            // 初始化数据
            this.getTacitlyApproveData();
            this.getDetailTableColumns();
        }

        componentWillUnmount() {
            // 组件销毁前将静止让setState修改state的状态，防止内存泄漏
            this.setState = (state,callback)=>{ return; }
        }
        //清空表格内容
        handleReset = () => {
            this.setState({total: ''})
            this.props.form.resetFields();
        };
        // 获取明系列表头数据
        getDetailTableColumns = () => {
            let {userInfo} = this.state;
            let data = {
                params: [{
                    reactCode: ['StorageDetailsQuery'],
                    type: 'C',
                }]
            }
            $http.post('urlS', this, {
                code: '01040073',
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        let arr = res.result.C&&res.result.C.length > 0 ? JSON.parse(JSON.stringify(res.result.C)).map((item, index) => {
                            return  {
                                ...item,
                                key: index + 1,
                                title: <div onDoubleClick={() => { this.columnRef.onOpenModel();}}>{userInfo.language== 'EN' ? item.enDescripts : item.title}</div>
                            }
                        }) : '';
                        let filterArr = arr.filter(function(item){ return item.display === 'Y'});
                        // this.setState({columns: filterArr, detailWidthTotal: res.totalWidth,ChineseEnglishSize:userInfo.language=='EN' ? res.result.language.EN : res.result.language.CN})
                    }
                }
            });
        };

        // 获取界面默认值
        getTacitlyApproveData() {
            let data = {
                params: []
            };
            // 获取下拉数据
            $http.post('urlS', this, {
                code: "02020307",
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        this.setState({SelectData: res})
                    }
                }
            })
        }

        // 获取成人专项点评总数
        getAdultSpecialData=()=>{
            let {ChineseEnglishSize,userInfo} = this.state;
            this.props.form.validateFields((error, value)=>{
                let obj = JSON.parse(JSON.stringify(value));
                if(error == null){
                    let data = {
                        params: [{
                            outpatient: obj.outpatient ? obj.outpatient : '',
                            startDate: obj.StartDate ? Moment(obj.StartDate).format( 'YYYY-MM-DD') : '',
                            endDate: obj.EndData ? Moment(obj.EndData).format('YYYY-MM-DD') : '',
                            admType: obj.stkCat ? obj.stkCat : "",
                            maxAge: obj.maxAge ? obj.maxAge : "",

                        }]
                    };
                    $http.post('urlS', this, {
                        code: "02020308",
                        data: data,
                        success: function (res) {
                            if(res.errorCode == 0){
                                this.setState({ total: res.total,pid: res.pid});
                                this.props.form.setFieldsValue({total: res.total});
                                if (userInfo.language == 'EN'){
                                    message.success(res.errorEnMessage)
                                } else {
                                    message.success(res.errorMessage)
                                }

                            }
                        },
                        error: function (err) {
                            message.error(err.errorMessage)
                        }
                    });
                }
            })

        };
        // 抽取处方样本
        getExtractionData=()=>{
            let {ChineseEnglishSize,userInfo} = this.state;

            let random = this.props.form.getFieldValue('random');
            this.props.form.validateFields((error, value)=>{
                let obj = JSON.parse(JSON.stringify(value));
                if(error == null){
                    let data = {
                        params: [{
                            outpatient: obj.outpatient ? obj.outpatient : '',
                            startDate: obj.StartDate ? Moment(obj.StartDate).format( 'YYYY-MM-DD') : '',
                            endDate: obj.EndData ? Moment(obj.EndData).format('YYYY-MM-DD') : '',
                            admType: obj.stkCat ? obj.stkCat : "",
                            maxAge: obj.maxAge ? obj.maxAge : "",

                            random : obj.random  ? obj.random  : "",
                            // total: this.state.total,
                            // pid: this.state.pid,

                        }]
                    };
                    $http.post('urlS', this, {
                        code: "02020309",
                        data: data,
                        success: function (res) {
                            if(res.errorCode == 0){
                                this.handleReset();
                                // this.setState({ total: res.total,});
                                this.props.form.setFieldsValue({prescNo: res.prescNo});
                                if (userInfo.language == 'EN'){
                                    message.success(res.errorEnMessage)
                                } else {
                                    message.success(res.errorMessage)
                                }

                            }
                        }
                    })
                }
            })

        };
        render() {
            const { getFieldDecorator } = this.props.form;
            let {ChineseEnglishSize,userInfo} = this.state;
            //科室列表
            let OutpatientLoc = [];
            this.state.SelectData.Outpatient && this.state.SelectData.Outpatient.map((item, i) => {
                OutpatientLoc.push(<Option value={item.id} key={i} seatchprop={item.descripts + item.descriptsSPCode}>{item.descripts}</Option>)
            });
            //类组列表
            let stkCatSelect = [];
            this.state.SelectData.admType && this.state.SelectData.admType.map((item, i) => {
                stkCatSelect.push(<Option value={item.id} key={i}>{item.descripts}</Option>)
            });
            return (
                <div className="AdultSpecial">
                    <Row>
                        <Card
                            size="small"
                            title={<div className="card-title-left-icon"><div></div>{ChineseEnglishSize.InventoryAlarmAccordingToConsuaccToConsumption2 ? ChineseEnglishSize.InventoryAlarmAccordingToConsuaccToConsumption.descripts:'成人专项点评'}</div>}
                        >
                            <Col span={14}>
                                <Form>
                                    <Row >
                                        <Col span={8}>
                                            <FormItem {...formItemLayout} label={ChineseEnglishSize.InventoryAlarmAccordingToConsuStartDate ? ChineseEnglishSize.InventoryAlarmAccordingToConsuStartDate.descripts:'起初日期'}>
                                                {getFieldDecorator('StartDate',{
                                                    initialValue: this.state.SelectData.params&&this.state.SelectData.params.startDate ? Moment(this.state.SelectData.params.startDate, 'YYYY-MM-DD') : Moment(),
                                                    rules: [{required: true, message: '起初日期不能为空',}],
                                                })(
                                                    <DatePicker format="YYYY-MM-DD" style={{width:'100%'}}/>
                                                ) }
                                            </FormItem>
                                        </Col>
                                        <Col span={8}>
                                            <FormItem {...formItemLayout} label={ChineseEnglishSize.InventoryAlarmAccordingToConsudeadline ? ChineseEnglishSize.InventoryAlarmAccordingToConsudeadline.descripts:'截止日期'}>
                                                {getFieldDecorator('EndData',{
                                                    initialValue: this.state.SelectData.params&&this.state.SelectData.params.endDate ? Moment(this.state.SelectData.params.endDate, 'YYYY-MM-DD') : Moment(),
                                                    rules: [{required: true, message: '截止日期不能为空',}],
                                                })(
                                                    <DatePicker  format="YYYY-MM-DD" style={{width:'100%'}}/>
                                                ) }
                                            </FormItem>
                                        </Col>
                                        {/*<Col span={6}>*/}
                                            {/*<FormItem {...formItemLayout} label={ChineseEnglishSize.InventoryAlarmAccordingToConsuloc ? ChineseEnglishSize.InventoryAlarmAccordingToConsuloc.descripts:'抗菌药物级别'}>*/}
                                                {/*{getFieldDecorator('stkCat',{*/}
                                                    {/*initialValue: "",*/}
                                                    {/*rules:[{ required : ChineseEnglishSize.InventoryAlarmAccordingToConsuloc ? ChineseEnglishSize.InventoryAlarmAccordingToConsuloc.required =='Y'? true:false: false, message: ChineseEnglishSize.InventoryAlarmAccordingToConsuloc ? ChineseEnglishSize.InventoryAlarmAccordingToConsuloc.message:'抗菌药物级别不能为空'}]*/}
                                                {/*})(*/}
                                                    {/*<Select allowClear>*/}
                                                        {/*{stkCatSelect}*/}
                                                    {/*</Select>*/}
                                                {/*) }*/}
                                            {/*</FormItem>*/}
                                        {/*</Col>*/}
                                        <Col span={8}>
                                            <FormItem {...formItemLayout} label={ChineseEnglishSize.InventoryAlarmAccordingToConsuloc ? ChineseEnglishSize.InventoryAlarmAccordingToConsuloc.descripts:'处方总数'}>
                                                {getFieldDecorator('total',{
                                                    initialValue: "",
                                                    rules:[{ required : ChineseEnglishSize.InventoryAlarmAccordingToConsuloc ? ChineseEnglishSize.InventoryAlarmAccordingToConsuloc.required =='Y'? true:false: false, message: ChineseEnglishSize.InventoryAlarmAccordingToConsuloc ? ChineseEnglishSize.InventoryAlarmAccordingToConsuloc.message:'处方总数不能为空'}]
                                                })(
                                                    <Input disabled />
                                                ) }
                                            </FormItem>
                                        </Col>
                                    </Row>
                                    <Row >
                                        <Col span={8}>
                                            <FormItem {...formItemLayout} label={ChineseEnglishSize.InventoryAlarmAccordingToConsuloc ? ChineseEnglishSize.InventoryAlarmAccordingToConsuloc.descripts:'患者年龄'}>
                                                {getFieldDecorator('maxAge',{
                                                    initialValue:undefined,
                                                })(
                                                  <Input/>
                                                ) }
                                            </FormItem>
                                        </Col>
                                        <Col span={8}>
                                            <FormItem {...formItemLayout} label={ChineseEnglishSize.InventoryAlarmAccordingToConsuloc ? ChineseEnglishSize.InventoryAlarmAccordingToConsuloc.descripts:'医生科室'}>
                                                {getFieldDecorator('Outpatient',{
                                                    initialValue: "",
                                                    rules:[{ required : ChineseEnglishSize.InventoryAlarmAccordingToConsuloc ? ChineseEnglishSize.InventoryAlarmAccordingToConsuloc.required =='Y'? true:false: false, message: ChineseEnglishSize.InventoryAlarmAccordingToConsuloc ? ChineseEnglishSize.InventoryAlarmAccordingToConsuloc.message:'医生科室不能为空'}]
                                                })(
                                                    <Select allowClear showSearch optionFilterProp="seatchprop">
                                                        {OutpatientLoc}
                                                    </Select>
                                                ) }
                                            </FormItem>
                                        </Col>
                                        <Col span={8}>
                                            <FormItem {...formItemLayout} label={ChineseEnglishSize.InventoryAlarmAccordingToConsuloc ? ChineseEnglishSize.InventoryAlarmAccordingToConsuloc.descripts:'类型'}>
                                                {getFieldDecorator('stkCat',{
                                                    initialValue: "",
                                                    rules:[{ required : ChineseEnglishSize.InventoryAlarmAccordingToConsuloc ? ChineseEnglishSize.InventoryAlarmAccordingToConsuloc.required =='Y'? true:false: false, message: ChineseEnglishSize.InventoryAlarmAccordingToConsuloc ? ChineseEnglishSize.InventoryAlarmAccordingToConsuloc.message:'类型不能为空'}]
                                                })(
                                                    <Select allowClear>
                                                        {stkCatSelect}
                                                    </Select>
                                                ) }
                                            </FormItem>
                                        </Col>
                                    </Row>
                                </Form>
                            </Col>
                            <Col span={4} style={{textAlign:'center'}}>
                                <Row style={{marginBottom: '18px'}} className="button">
                                    <Button  onClick={this.getAdultSpecialData}>{ChineseEnglishSize.InventoryAlarmAccordingToConsusearch ? ChineseEnglishSize.InventoryAlarmAccordingToConsusearch.descripts:'查询'}</Button>
                                </Row>
                            </Col>
                        </Card>
                    </Row>
                    <Row>
                        <Card
                            size="small"
                            title={<div className="card-title-left-icon"><div></div>{ChineseEnglishSize.InventoryAlarmAccordingToConsuaccToConsumption ? ChineseEnglishSize.InventoryAlarmAccordingToConsuaccToConsumption.descripts:'生成点评单'}</div>}
                        >
                            <Col span={14}>
                                <Row >
                                    <Col span={8}>
                                        <FormItem {...formItemLayout} label={ChineseEnglishSize.InventoryAlarmAccordingToConsuloc ? ChineseEnglishSize.InventoryAlarmAccordingToConsuloc.descripts:'点评单号'}>
                                            {getFieldDecorator('prescNo',{
                                                initialValue: "",
                                                rules:[{ required : ChineseEnglishSize.InventoryAlarmAccordingToConsuloc ? ChineseEnglishSize.InventoryAlarmAccordingToConsuloc.required =='Y'? true:false: false, message: ChineseEnglishSize.InventoryAlarmAccordingToConsuloc ? ChineseEnglishSize.InventoryAlarmAccordingToConsuloc.message:'点评单号不能为空'}]
                                            })(
                                                <Input style={{ width: '100%' }} disabled />
                                            ) }
                                        </FormItem>
                                    </Col>
                                    <Col span={8}>
                                        <FormItem {...formItemLayout} label={ChineseEnglishSize.InventoryAlarmAccordingToConsuloc ? ChineseEnglishSize.InventoryAlarmAccordingToConsuloc.descripts:'随机数'}>
                                            {getFieldDecorator('random',{
                                                initialValue: "",
                                                rules:[{ required : ChineseEnglishSize.InventoryAlarmAccordingToConsuloc ? ChineseEnglishSize.InventoryAlarmAccordingToConsuloc.required =='Y'? true:false: false, message: ChineseEnglishSize.InventoryAlarmAccordingToConsuloc ? ChineseEnglishSize.InventoryAlarmAccordingToConsuloc.message:'随机数不能为空'}]
                                            })(
                                                <Input style={{ width: '100%' }} />
                                            ) }
                                        </FormItem>
                                    </Col>
                                </Row>
                                <Row style={{margin: '20px 0 0 100px'}} className="button">
                                    <Button disabled={this.state.total > 0 ? false : true} onClick={this.getExtractionData} >{ChineseEnglishSize.InventoryAlarmAccordingToConsusearch ? ChineseEnglishSize.InventoryAlarmAccordingToConsusearch.descripts:'抽取处方样本'}</Button>
                                </Row>
                            </Col>
                        </Card>
                    </Row>
                </div>
            )
        }
    }
);
export default AdultSpecial;