//抗菌药专项点评
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:9 },
    wrapperCol: { span: 15 },
};

const AntibacterialDrugs = Form.create()(
    class extends React.Component {
        constructor() {
            super();
            this.state = {
                userInfo: JSON.parse(window.sessionStorage.userData),
                data: [],
                queryCondition: {},
                inOpLocDr:'',
                vendor: '',
                WaListData: [], //库存单数据
                pageSize: 20,
                page: 1,
                total:0,
                modalData: [],
                stockID: '',
                ModalRowData: {}, // 弹框双击选中行数据
                columns: [],
                ChineseEnglishSize: [],
                detailWidthTotal: '',
                auditDate: '',
            }
        }

        componentDidMount() {
            // 初始化数据
            // this.getTacitlyApproveData();
            this.getDetailTableColumns();
            let listData = document.querySelectorAll('.AccordingHeight  .ant-table-body');
            if(listData.length>0){
                listData[0].style.height = (store.getState().tableHeight.y)/2 +160 + 'px';
            }
        }

        componentWillUnmount() {
            // 组件销毁前将静止让setState修改state的状态，防止内存泄漏
            this.setState = (state,callback)=>{ return; }
        }

        // 获取明系列表头数据
        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})
                    }
                }
            });
        };

        //清空表格内容
        handleReset = () => {
            this.setState({WaListData: [],total: 0, auditDate: ''});
            this.props.form.resetFields();
        };

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

        // 抗菌药转向点评处方总数
        getAntibacterilData=()=>{
            let {ChineseEnglishSize} = this.state;
            this.props.form.validateFields((error, value)=>{
                let obj = JSON.parse(JSON.stringify(value));
                if(error == null){
                    let data = {
                        params: [{
                            docPer: obj. docPer ? obj. docPer : '',
                            startDate: obj.StartDate ? Moment(obj.StartDate).format( 'YYYY-MM-DD') : '',
                            endDate: obj.EndData ? Moment(obj.EndData).format('YYYY-MM-DD') : '',
                            orderPer: obj.orderPer ? obj.orderPer : "",
                        }]
                    };
                    $http.post('urlS', this, {
                        code: "02020310",
                        data: data,
                        success: function (res) {
                            if(res.errorCode == 0){
                                this.setState({ total: res.total,});
                                this.props.form.setFieldsValue({total: res.total});
                                if (userInfo.language == 'EN'){
                                    message.success(res.errorEnMessage)
                                } else {
                                    message.success(res.errorMessage)
                                }
                            }
                        }
                    });
                }
            })

        };
        // 抽取处方样本
        getExtractionData=()=>{
            let {ChineseEnglishSize,userInfo} = this.state;
            // let random = this.props.form.getFieldValue('random');
            let data = {
                params: [{
                    total: this.state.total
                }]
            };
            $http.post('urlS', this, {
                code: "02020311",
                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;
            return (
                <div className="AntibacterialDrugs">
                    <Row>
                        <Card
                            size="small"
                            title={<div className="card-title-left-icon"><div></div>{ChineseEnglishSize.InventoryAlarmAccordingToConsuaccToConsumption ? ChineseEnglishSize.InventoryAlarmAccordingToConsuaccToConsumption1.descripts:'抗菌药专项点评'}</div>}
                        >
                            <Col span={20}>
                                <Form>
                                    <Row >
                                        <Col span={8}>
                                            <FormItem {...formItemLayout} label={ChineseEnglishSize.InventoryAlarmAccordingToConsuStartDate ? ChineseEnglishSize.InventoryAlarmAccordingToConsuStartDate.descripts:'起初日期'}>
                                                {getFieldDecorator('StartDate',{
                                                    initialValue: 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: Moment(),
                                                    rules: [{required: true, message: '截止日期不能为空',}],
                                                })(
                                                    <DatePicker  format="YYYY-MM-DD" style={{width:'100%'}}/>
                                                ) }
                                            </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('docPer',{
                                                    initialValue: undefined,
                                                })(
                                                  <Input/>
                                                ) }
                                            </FormItem>
                                        </Col>
                                        <Col span={8}>
                                            <FormItem {...formItemLayout} label={ChineseEnglishSize.InventoryAlarmAccordingToConsuloc ? ChineseEnglishSize.InventoryAlarmAccordingToConsuloc.descripts:'处方张数(每位医生)'}>
                                                {getFieldDecorator('orderPer',{
                                                    initialValue: undefined,
                                                })(
                                                 <Input/>
                                                ) }
                                            </FormItem>
                                        </Col>
                                    </Row>
                                </Form>
                            </Col>
                            <Col span={4} style={{textAlign:'center'}}>
                                <Row style={{marginBottom: '18px'}} className="button">
                                    <Button  onClick={this.getAntibacterilData}>{ChineseEnglishSize.InventoryAlarmAccordingToConsusearch ? ChineseEnglishSize.InventoryAlarmAccordingToConsusearch.descripts:'查询'}</Button>
                                </Row>
                                {/*<Row style={{marginBottom: '18px'}} className="button">*/}
                                {/*<Button type="primary" onClick={this.handleReset}>{ChineseEnglishSize.InventoryAlarmAccordingToConsuclean ? ChineseEnglishSize.InventoryAlarmAccordingToConsuclean.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={20}>
                                <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>
                                </Row>
                                <Row style={{margin: '20px 0 0 194px'}} 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 AntibacterialDrugs;