//处方点评-过敏记录
import React from 'react';
import { Card, Row, Col, Form, DatePicker, Select, Button, Tabs, Table, Input, message, Pagination  } from 'antd';
import { $http } from 'containers/config/https';
import store from 'store';
import CommonPagination from 'components/pagination/index';
import ColumnAuthoritysModel from 'pages/columnAuthority/ColumnAuthoritysModel';
const { Option } = Select;
const FormItem = Form.Item;
const AllergyRecords = Form.create()(
    class extends React.Component {
        constructor() {
            super();
            this.state = {
                userInfo: JSON.parse(window.sessionStorage.userData),
                TableDataEditField:[], //统计单明细数据
                pageSize2: 20,
                page2: 1,
                detailTotal: 0,
            };
            // 统计单详细表头
            this.modalColumns = [

                {
                    key: 1,
                    title: '代码 ',
                    dataIndex: 'stockCode',
                    align: "center",
                    width: '6%'
                },
                {
                    key: 2,
                    title: '名称',
                    dataIndex: 'stockDesc',
                    align: "center",
                    width: '10%'
                },
                {
                    key: 3,
                    title: '货位',
                    dataIndex: 'unitDesc',
                    align: "center",
                    width: '6%'
                },
                {
                    key: 4,
                    title: '批号',
                    dataIndex: 'batNo',
                    align: "center",
                    width: '6%'
                },
                {
                    key: 5,
                    title: '有效期',
                    dataIndex: 'expDate',
                    align: "center",
                    width: '6%'
                },
                {
                    key: 6,
                    title: '库存(包装单位)',
                    dataIndex: 'purQty',
                    align: "center",
                    width: '6%'
                },
                {
                    key: 7,
                    title: '包装单位',
                    dataIndex: 'purUnitDesc',
                    align: "center",
                    width: '6%'
                },
                {
                    key: 8,
                    title: '库存(基本单位)',
                    dataIndex: 'baseQty',
                    align: "center",
                    width: '6%'
                },
                {
                    key: 9,
                    title: '基本单位',
                    dataIndex: 'baseUnitDesc',
                    align: "center",
                    width: '6%'
                },
                {
                    key: 10,
                    title: '零售价',
                    dataIndex: 'sp',
                    align: "center",
                    width: '6%'
                },
                {
                    key: 11,
                    title: '最新进价',
                    dataIndex: 'rp',
                    align: "center",
                    width: '6%'
                },
                {
                    key: 12,
                    title: '售价金额',
                    dataIndex: 'spAmt',
                    align: "center",
                    width: '6%'
                },
                {
                    key: 13,
                    title: '进价金额',
                    dataIndex: 'rpAmt',
                    align: "center",
                    width: '6%'
                },
                {
                    key: 14,
                    title: '规格',
                    dataIndex: 'stockSpec',
                    align: "center",
                    width: '6%'
                },
                {
                    key: 15,
                    title: '生产厂家',
                    dataIndex: 'manfDesc',
                    align: "center",
                    width: '6%'
                },
                {
                    key: 16,
                    title: '批次供应商',
                    dataIndex: 'vendorDesc',
                    align: "center",
                    width: '6%'
                }
            ]
        }

        componentDidMount(){
            this.props.onRef(this);
            // this.getDetailTableColumns();
            let leftList = document.querySelectorAll('.tableDataHeight .ant-table-body');
            if(leftList.length>0){
                leftList[0].style.height = store.getState().tableHeight.y + 'px';
            }
        }

        // 获取明细列表头数据
        getDetailTableColumns = () => {
            let {userInfo} = this.state;
            let data = {
                params: [{
                    compontName: 'TableDataFormList',
                    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({modalColumns: filterArr, modalColumnsWidth: res.totalWidth})
                    }
                }
            });
        };

        componentWillReceiveProps(props){
            if(props.TableDataEditField){
                this.setState({
                    TableDataEditField: props.TableDataEditField.rows,
                    detailTotal: props.TableDataEditField.total
                })
            }

        }
        componentWillUnmount() {
            this.setState({  page: 1,});
            // 组件销毁前将静止让setState修改state的状态，防止内存泄漏
            this.setState = (state,callback)=>{ return; }
        }
        //清空表格内容
        handleReset = () => {
            this.setState({stockID: ''})  ;
        };
        // 页码改变的回调，参数是改变后的页码及每页条数 统计单详情
        onChange2 = (page, pageSize) => {
            this.setState({page2: page, pageSize2: this.state.pageSize2}, () => {
                // 重新调用查询方法
                // this.props.handelThis.callbackCheck(2,this.state.page2, this.state.pageSize2);
            });
        };

        onShowSizeChange2 = (current, size) => {
            this.setState({page2: current, pageSize2: size}, () => {
                // 重新调用查询方法
                this.onChange2(current,size);
            })
        };
        //组件权限编辑器
        onColumnRef = (ref) => {
            this.columnRef = ref;
        };
        // 表格行的类名
        setRowClassName = (record) => {
            return record.stockCode === this.state.stockID ? 'clickRowStyle' : '';
        };
        render() {
            const { getFieldDecorator } = this.props.form;
            let {modalColumns, modalColumnsWidth} = this.state;
            return (
                <div className="AllergyRecords">

                    <Row>
                        <Card
                            size="small"
                            title={<div className="card-title-left-icon"><div></div>过敏记录</div>}
                        >
                            <Col>
                                <div>
                                    <Table
                                        columns={this.modalColumns}
                                        dataSource={this.state.TableDataEditField}
                                        pagination={false}
                                        bordered
                                        scroll={{x:1500, y: store.getState().tableHeight.y + 'px' }}
                                        style={{height:  store.getState().tableHeight.y + 'px'}}
                                        rowKey={record => record.key}
                                        className='tableDataHeight'

                                    />
                                    <CommonPagination size='small' current={this.state.page2} total={this.state.detailTotal} search= 'search'
                                                      onShowSizeChange={this.onShowSizeChange2.bind(this)} complete={true} dataSource={this.state.TableDataEditField}
                                                      loading={this.state.loading} onChange={this.onChange2.bind(this)}  pageSize={true} />
                                </div>
                            </Col>
                        </Card>
                    </Row>
                    <ColumnAuthoritysModel
                        clientWidth='800px'
                        compontName='TableDataFormList'
                        configType="C"
                        onRef={this.onColumnRef}
                        reloadData={this.getDetailTableColumns}
                    />
                </div>
            )
        }
    }
);
export default AllergyRecords;
