//生产企业维护单
import React from 'react';
import { Card, Row,Radio, Col, Form, DatePicker, Select, Button, Checkbox, Table, Switch, message,TimePicker, Pagination, Input } from 'antd';
import { $http } from 'containers/config/https';
import CommonPagination from 'components/pagination/index';
import Reports from '../../raqSoft/reportsEmbed';
import './style/index.less';
import { BrowserRouter as Router,Route} from 'react-router-dom';
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 InventoryLossReportingStatistics = Form.create()(
    class extends React.Component {
        constructor() {
            super();
            this.state = {
                selectLocList:[], //科室列表数据
                selectScrapList:[],//原因列表数据
                selectGroupClassList:[],//组类列表数据
                userInfo: {}, //表单数据详情
                language: JSON.parse(window.sessionStorage.userData),
                ChineseEnglishSize: [],
                params:{},
                reportName:"inventoryLossReportingStatistics"

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

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

        //清空表格内容
        resetFields = () => {
            this.props.form.resetFields();
            this.setState({userInfo: {}, rowKey: '', rowData: ''});
        };
        handleReset=()=> {
            this.resetFields();
            
        }

        //获取初始化页面的下拉列表数据
        getSelectListData=()=>{
            $http.post('urlS', this, {
                code: "02020131",
                data: {params:[],
                        pagination:[]},
                success: function (res) {
                    let id=this.state.language.locID;
                    let descripts=this.state.language.locDesc;
                    
                    this.setState({ selectLocList: res.loc,
                            selectScrapList:res.reason,
                            selectGroupClassList:res.stkCat,
                            userInfo:{id:id,descripts:descripts},
                        });
                        
                       
                        // userInfo:this.state.concat({ID:ID,LocDr:LocDr})
                   
                  
                   
                }
            });
        }
        // 根据表单获取列表数据
        searchInformation=()=>{
            let locID = this.props.form.getFieldValue('Loc');
            let startDate = this.props.form.getFieldValue('startDate');
            let endDate = this.props.form.getFieldValue('endDate');
      
            let reason = this.props.form.getFieldValue('reason');
            let groupClass = this.props.form.getFieldValue('groupClass');


            let params = {
                                locID : locID ? locID :undefined,
                                reasonID : reason ? reason :undefined,
                                groupClassID : groupClass ? groupClass :undefined,
                                startDate : startDate ? Moment(startDate).format("YYYY-MM-DD") :undefined,
                                endDate : endDate ? Moment(endDate).format("YYYY-MM-DD") :undefined,
                                tableName: "库存报损统计"
                    };
            this.setState({params:params})
           
 
        };


       

      

        // 页码改变的回调，参数是改变后的页码及每页条数
        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: ['InventoryLossReportingStatistics'],
                    compontName: 'InventoryLossReportingStatistics',
                    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="InventoryLossReportingStatistics">
                    <Row>
                    <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"
                                >
                                    <section className="ant-form-list">
                                    <div style={{height: store.getState().tableHeight.y +50 + 'px'}}>                           
                                    <Col >              
                                        <Row>
                                            <Col >
                                                <FormItem label="科室" {...formItemItem}>
                                                    {getFieldDecorator('Loc', {
                                                         initialValue: userInfo.id ? userInfo.id : "",
                                                        rules: [
                                                            {
                                                              type: 'text',
                                                            },
                                                            {
                                                              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.descripts}>{item.descripts}</Option>
                                                    })}
                                                </Select>
                                                    )}
                                                </FormItem>
                                            </Col>
                                        </Row>
                                        <Row>
                                        <Col >
                                            <FormItem label="开始日期" {...formItemItem}>
                                                {getFieldDecorator('startDate', {
                                                     initialValue: Moment(new Date()),
                                                    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('endDate', {
                                                     initialValue: Moment(new Date()),
                                                  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('reason', {
                                                     rules: [
                                                        {
                                                          required: false,
                                                          message: 'Please input your supplier',
                                                        },
                                                      ],
                                                })(
                                                    <Select  showSearch optionFilterProp="seatchprop" allowClear style={{width: '100%'}}>
                                                    {this.state.selectScrapList.length>0 && this.state.selectScrapList.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>
                                        
                                       
                                        
                                        
                                      
                                   
                                    </Col>
                                    
                                    </div>
                                    </section>
                                </Card>
                            </Form>
                            
                        </Col>
                        </Row>
                    </Col>
                    <Col  span={18}>
                            
                                
                    <div  style={{height: store.getState().tableHeight.y +200 + 'px'}}>
                                <Reports raqName={this.state.reportName} params={this.state.params} />
                                </div>
                            
                    </Col >
                    </Row>
                    
                </div>
            )
        }
    }
);
export default InventoryLossReportingStatistics;