//出库汇总维护
import React from 'react';
import { Card, Row,Radio, Col, Form, DatePicker, Select, Button, Checkbox, Table, Switch, message, Pagination, Input  } from 'antd';
import { $http } from 'containers/config/https';
import CommonPagination from 'components/pagination/index';
import Moment from 'moment';
import store from 'store';

const { Option } = Select;
const FormItem = Form.Item;
const formItemLayout = {    // label 和input宽度
    labelCol: { span:8 },
    wrapperCol: { span: 16 },
};
const formItemItem  = {
    labelCol: {span: 10},
    wrapperCol: {span: 14}
};
const OutboundMaintenance = Form.create()(
    class extends React.Component {
        constructor() {
            super();
            this.state = {
                selectLocList:[], //出库科室列表数据
                selectStatisticalMethodList:[],//统计方式列表数据
                selectGroupClassList:[],//组类列表数据
                selectInventoryClassificationList:[],//库存分类数据列表
                selectControlClassificationList:[],//管制分类数据列表
                userInfo: {}, //表单数据详情
                outPutListData:[],//输出信息列表
                pageSize: 10,
                page: 1,
                total:0,
                language: JSON.parse(window.sessionStorage.userData),
                ChineseEnglishSize: [],
            }
        
            
        }

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

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

        //清空表格内容
        resetFields = () => {
            this.props.form.resetFields();
            this.setState({userInfo: {}, rowKey: '', rowData: ''});
        };
        handleReset=()=> {
            this.resetFields();
            
        }
        //导入数据
        importData=()=>{
            
        }
        searchInformation=()=>{
            this.setState({page: 1},()=>{
                this.getManufacturerList()
            })
        };
        //获取初始化页面的下拉列表数据
        getSelectListData=()=>{
            $http.post('urlS', this, {
                code: "02020294",
                data: {params:[],
                        pagination:[]},
                success: function (res) {
                        this.setState({ selectLocList: res.result.selectLocList.result.rows,
                            selectGroupClassList:res.result.selectGroupClassList,
                            selectInventoryClassificationList:res.result.selectInventoryClassificationList,
                            selectControlClassificationList:res.result.selectControlClassificationList,
                            selectStatisticalMethodList:res.result.selectStatisticalMethodList,
                        });
                        console.log(this.state.selectLocList,this.state.selectStatisticalMethodListthis.state.selectGroupClassList,this.state.selectInventoryClassificationList,this.state.selectControlClassificationList)
                }
            });
        }
        // 根据表单获取列表数据
        searchInformation=()=>{
            let Loc = this.props.form.getFieldValue('Loc');
            let startDate = this.props.form.getFieldValue('startDate');
            let endDate = this.props.form.getFieldValue('endDate');
            let startTime = this.props.form.getFieldValue('startTime');
            let endTime = this.props.form.getFieldValue('endTime');
            let groupClass = this.props.form.getFieldValue('groupClass');
            let inventoryClassification = this.props.form.getFieldValue('inventoryClassification');
            let controlClassification = this.props.form.getFieldValue('controlClassification');
            let drugName = this.props.form.getFieldValue('drugName');
            let otherDate = this.props.form.getFieldValue('otherDate');
            let reportType = this.props.form.getFieldValue('reportType');
            let statisticalmethod = this.props.form.getFieldValue('statisticalmethod');
            this.setState({loading: true})
                    let data = {
                        params: [
                            {
                                Loc : Loc ? Loc :undefined,
                                startDate : startDate ? startDate :undefined,
                                endDate : endDate ? endDate :undefined,
                                startTime : startTime ? startTime :undefined,
                                endTime : endTime ? endTime :undefined,
                                groupClass : groupClass ? groupClass :undefined,
                                inventoryClassification : inventoryClassification ? inventoryClassification :undefined,
                                controlClassification : controlClassification ? controlClassification :undefined,
                                drugName : drugName ? drugName :undefined,
                                otherDate : otherDate ? otherDate :undefined,
                                reportType : reportType ? reportType :undefined,
                                statisticalmethod : statisticalmethod ? statisticalmethod :undefined,

                            }
                        ],
                        pagination: [
                            {
                                pageSize:this.state.pageSize,
                                currentPage:this.state.page,
                                sort:"ID",
                                dir:"asc",
                            }
                        ],
                    };
                    $http.post('urlS', this, {
                        code: "02020264",
                        data: data,
                        success: function (res) {
                            if(res.errorCode==0 && res.result.rows.length > 0){
                                for(let i = 0; i < res.result.rows.length; i++){
                                    res.result.rows[i].key = i;
                                }
                                this.setState({ outPutListData: res.result.rows, total: res.result.total, loading: false});
                            }else {
                                this.setState({ outPutListData: [],total:0,loading: false});
                                if (language.language =='EN'){
                                    message.error("No related data was found");
                                }else{
                                    message.error("没数据");
                                }
                                this.props.form.resetFields();
                            }
                        }
                    });
        };


       

      

        // 页码改变的回调，参数是改变后的页码及每页条数
        onChange = (page, pageSize) => {
            this.setState({page: page, pageSize: this.state.pageSize}, () => {
                // 重新调用查询方法
                this.getManufacturerList();
            });
        };

        onShowSizeChange = (current, size) => {
            this.setState({page: current, pageSize: size}, () => {
                // 重新调用查询方法
                this.onChange(current,size);
            })
        };

        // 显示分页总条数
        showTotal(total) {
            return `共 ${total} 条`;
        }
        //页面中英文翻译
        getDetailTableColumns = () => {
            let {language} = this.state;
            let data = {
                params: [{
                    reactCode: ['OutboundMaintenance'],
                    compontName: 'OutboundMaintenance',
                    type: 'C',
                }]
            }
            $http.post('urlS', this, {
                code: '01040073',
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        this.setState({ChineseEnglishSize:  language.language=='EN' ? res.result.language.EN : res.result.language.CN})
                    }
                }
            })
        };
        render() {
            const { getFieldDecorator } = this.props.form;
            const {userInfo,ChineseEnglishSize } = this.state;
            return (
                <div className="OutboundMaintenance">
                    <Col span={6}>
                        <Row>
                            <Card
                                size="small"
                                title={<div className="card-title-left-icon"><div></div>按钮操作</div>}
                            >
                                <Col >
                                    <Row >

                                        <Col style={{textAlign: 'center'}} >
                                            <Button onClick={this.searchInformation}>查询</Button>
                                            <Button type="primary" onClick={this.handleReset} style={{marginLeft: '20px'}}>清屏</Button>
                                        </Col>
                                    </Row>
                                </Col>
                            </Card>
                        </Row>
                        <Row>
                        <Col >
                            
                            <Form>
                                <Card
                                    title={<div className="card-title-left-icon"><div></div>查询条件</div>}
                                    size="small"
                                >
                                    <div  style={{height: store.getState().tableHeight.y +450 + 'px'}}>
                                    <Col >
                                        <Row>
                                            <Col >
                                                <FormItem label="科室" {...formItemItem}>
                                                    {getFieldDecorator('Loc', {
                                                        rules: [
                                                            {
                                                              required: false,
                                                              message: 'Please input your Loc',
                                                            },
                                                          ],
                                                    })(
                                                       <Select  showSearch optionFilterProp="seatchprop" allowClear style={{width: '100%'}}>
                                                    {this.state.selectLocList.length>0 && this.state.selectLocList.map(item => {
                                                        return <Option value={item.ID} key={item.ID} title={item.descripts} seatchprop={item.LocDr}>{item.LocDr}</Option>
                                                    })}
                                                </Select>
                                                    )}
                                                </FormItem>
                                            </Col>
                                        </Row>
                                        <Row>
                                        <Col >
                                            <FormItem label="开始日期" {...formItemItem}>
                                                {getFieldDecorator('startDate', {
                                                    
                                                    rules:[{ required :false, message: 'Please select startDate!' }]
                                                })(
                                                    <DatePicker
                                                        format="YYYY-MM-DD"
                                                        style={{width:'100%'}}
                                                    >
                                                    </DatePicker>
                                                )}
                                            </FormItem>
                                          </Col>
                                    
                                        </Row>
                                        <Row> 
                                            <Col >
                                                <FormItem label="开始时间" {...formItemItem}>
                                                    {getFieldDecorator('startTime', {
                                                        rules: [
                                                            {
                                                              type: 'text',
                                                    
                                                            },
                                                            {
                                                              required: false,
                                                              message: 'Please input your startTime',
                                                            },
                                                          ],
                                                    })(
                                                        <Input style={{width: '100%'}} />
                                                    )}
                                                </FormItem>
                                            </Col>
                                     
                                        </Row>
                                        <Row>
                                        <Col >
                                            <FormItem label="结束日期" {...formItemItem}>
                                                {getFieldDecorator('endDate', {
                                                  rules:[{ required :false, message: 'Please select startDate!' }]
                                                })(
                                                    <DatePicker
                                                        format="YYYY-MM-DD"
                                                        style={{width:'100%'}}
                                                    >
                                                    </DatePicker>
                                                )}
                                            </FormItem>
                                          </Col>
                                        </Row>
                                        <Row>
                                        <Col >
                                                <FormItem label="结束时间" {...formItemItem}>
                                                    {getFieldDecorator('endTime', {
                                                         rules: [
                                                            {
                                                              type: 'text',
                                                    
                                                            },
                                                            {
                                                              required: false,
                                                              message: 'Please input your endTime',
                                                            },
                                                          ],
                                                    })(
                                                        <Input style={{width: '100%'}} />
                                                    )}
                                                </FormItem>
                                            </Col>
                                   
                                        </Row>
                                        <Row>
                                            <Col >
                                            <FormItem label="统计方式" {...formItemItem}>
                                                {getFieldDecorator('statisticalmethod', {
                                                     rules: [
                                                        {
                                                          type: 'text',
                                                
                                                        },
                                                        {
                                                          required: false,
                                                          message: 'Please input your statisticalmethod',
                                                        },
                                                      ],
                                                })(
                                                    <Select  showSearch optionFilterProp="seatchprop" allowClear style={{width: '100%'}}>
                                                    {this.state.selectStatisticalMethodList.length>0 && this.state.selectStatisticalMethodList.map(item => {
                                                        return <Option value={item.id} key={item.id} title={item.descripts} seatchprop={item.descripts+ '^'+item.descriptsSPCode}>{item.descripts}</Option>
                                                    })}
                                                    </Select>   
                                                )}
                                            </FormItem>
                                          </Col>
                                 
                                        </Row>
                                        <Row>
                                            <Col >
                                            <FormItem label="类组" {...formItemItem}>
                                                {getFieldDecorator('groupClass', {
                                                    rules: [
                                                        {
                                                          required: false,
                                                          message: 'Please input your groupClass',
                                                        },
                                                      ],
                                                })(
                                                    <Select  showSearch optionFilterProp="seatchprop" allowClear style={{width: '100%'}}>
                                                    {this.state.selectGroupClassList.length>0 && this.state.selectGroupClassList.map(item => {
                                                        return <Option value={item.id} key={item.id} title={item.descripts} seatchprop={item.descripts+ '^'+item.descriptsSPCode}>{item.descripts}</Option>
                                                    })}
                                                    </Select>   
                                                )}
                                            </FormItem>
                                          </Col>
                                 
                                        </Row>
                                        <Row>
                                            <Col >
                                            <FormItem label="库存分类" {...formItemItem}>
                                                {getFieldDecorator('inventoryClassification', {
                                                    initialValue: userInfo.mfProdEprsHygLic ? userInfo.mfProdEprsHygLic : undefined,
                                                })(
                                                    <Select  showSearch optionFilterProp="seatchprop" allowClear style={{width: '100%'}}>
                                                    {this.state.selectInventoryClassificationList.length>0 && this.state.selectInventoryClassificationList.map(item => {
                                                        return <Option value={item.id} key={item.id} title={item.descripts} seatchprop={item.descripts+ '^'+item.descriptsSPCode}>{item.descripts}</Option>
                                                    })}
                                                    </Select>  
                                                )}
                                            </FormItem>
                                          </Col>
                                       
                                        </Row>
                                        <Row>
                                            <Col >
                                            <FormItem label="管制分类" {...formItemItem}>
                                                {getFieldDecorator('controlClassification', {
                                                    initialValue: userInfo.mfSocialCreditCode ? userInfo.mfSocialCreditCode : undefined,
                                                })(
                                                    <Select  showSearch optionFilterProp="seatchprop" allowClear style={{width: '100%'}}>
                                                    {this.state.selectControlClassificationList.length>0 && this.state.selectControlClassificationList.map(item => {
                                                        return <Option value={item.id} key={item.id} title={item.descripts} seatchprop={item.descripts+ '^'+item.descriptsSPCode}>{item.descripts}</Option>
                                                    })}
                                                    </Select>  
                                                )}
                                            </FormItem>
                                          </Col>
                                   
                                        </Row>
                                        <Row>
                                            <Col >
                                            <FormItem label="药品名称" {...formItemItem}>
                                                {getFieldDecorator('drugName', {
                                                   rules: [
                                                    {
                                                      type: 'text',
                                            
                                                    },
                                                    {
                                                      required: false,
                                                      message: 'Please input your groupClass',
                                                    },
                                                  ],
                                                })(
                                                    <Input style={{width: '100%'}} />
                                                )}
                                            </FormItem>
                                          </Col>
                                        </Row>
                                
                                        <Row>
                                            <Col >
                                            <FormItem label="报表类型" {...formItemItem}>
                                                {getFieldDecorator('reportType', {
                                                    initialValue:  [""],
                                                   
                                                })(
                                                    <Radio.Group style={{ width: '100%' }}>
                                                        <Row>
                                                            <Col>
                                                            <Radio value="section/inventoryClassification">科室/库存分类</Radio>
                                                            </Col>
                                                        </Row>
                                                        <Row>   
                                                            <Col>
                                                            <Radio value="amountOfScientificResearch"> 科研金额</Radio>
                                                            </Col>
                                                        </Row>
                                                        <Row> 
                                                            <Col>
                                                            <Radio value="departmentAmount/researchGroup">科室金额/科研组</Radio>
                                                            </Col>
                                                        </Row>
                                                        <Row> 
                                                            <Col>
                                                            <Radio value="itemSummary">单品汇总</Radio>
                                                            </Col>
                                                        </Row>
                                                        <Row> 
                                                            <Col>
                                                            <Radio value="departmentItemsSummary ">  科室单品汇总</Radio>
                                                            </Col>
                                                        </Row>
                                                        <Row> 
                                                            <Col>
                                                            <Radio value="outboundDetails">出库明细</Radio>
                                                            </Col>
                                                        </Row>
                                                        <Row> 
                                                            <Col>
                                                            <Radio value="outboundOrderSummary">出库单汇总</Radio>
                                                            </Col>
                                                        </Row>
                                                        <Row> 
                                                            <Col>
                                                            <Radio value="inventoryClassification"> 库存分类</Radio>
                                                            </Col>
                                                        </Row>
                                                        </Radio.Group>,
                                                   
                                                )}
                                            </FormItem>
                                          </Col>
                                       
                                        </Row>
                                    </Col>
                                    </div>
                                </Card>
                            </Form>
                            
                        </Col>
                        </Row>
                    </Col>
                </div>
            )
        }
    }
);
export default OutboundMaintenance;