// 盘点单完成与汇总
import React from 'react';
import { Card, Row, Col, Form, DatePicker, Select, Button, Modal, Table, Switch, message, Pagination, Input, Checkbox, Icon } from 'antd';
import { $http } from 'containers/config/https';
import CommonPagination from 'components/pagination/index';
import Moment from 'moment';
import store from 'store';
import AddInvoices from './component/AddInvoices';
import {printStkTakeData} from '../commonPrint/stkPrint';
import ColumnAuthoritysModel from 'pages/columnAuthority/ColumnAuthoritysModel';
import './style/index.less';
var standingNumber = 0; //盘点单序列号

const { Option } = Select;
const FormItem = Form.Item;
const formItemLayout = {    // label 和input宽度
    labelCol: { span:7 },
    wrapperCol: { span: 17 },
};
var bilData = [];
var newArr = [];
const TakeStockCreateBill = Form.create()(
    class extends React.Component {
        constructor() {
            super();
            this.state = {
                userInfo: JSON.parse(window.sessionStorage.userData),
                data: [],
                queryCondition: {},
                SelectData: {},
                inOpLocDr:'',
                vendor: '',
                detailsId: '',//盘点单ID
                detailsListData:[], //盘点单明细数据
                WaListData: [], //盘点单数据
                pageSize: 20,
                page: 1,
                pageSize2: 20,
                page2: 1,
                total:0,
                detailTotal: 0,
                show: false,
                stateID: '',
                modalColumns: [], //表头数据
                detailWidthTotal: '',
                detailWidthTotal2: '',
                columns: [],
                takeStockListCode: '', // 表头弹窗识别code
                saveState: false,
                ChineseEnglishSize: {}, // 中英翻译
            };

            // 药品的数据表头
            this.columns = [
                {
                    key: 1,
                    title: '盘点单号',
                    dataIndex: 'stkTakeNO',
                    align: "center",
                    width: '25%'
                },
                {
                    key: 2,
                    title: '状态',
                    dataIndex: 'stateDesc',
                    align: "center",
                    width: '16%'
                },
                {
                    key: 3,
                    title: '调整库存',
                    dataIndex: 'stockDesc',
                    align: "center",
                    width: '13%'
                },
                {
                    key: 4,
                    title: '冻结时间',
                    dataIndex: 'freezeTime',
                    align: "center",
                    width: '23%'
                },
                {
                    key: 5,
                    title: '盘点时间',
                    dataIndex: 'takeTime',
                    align: "center",
                    width: '23%'
                }

            ];
            // 盘点单详细表头
            this.modalColumns = [
                {
                    key: 9,
                    title: '药品代码',
                    dataIndex: 'stockCode',
                    align: "center",
                    width: '10%',
                    sorter: (a, b) => a.stockCode - b.stockCode,
                },
                {
                    key: 1,
                    title: '药品名称',
                    dataIndex: 'stockDesc',
                    align: "center",
                    width: '13%'
                },
                {
                    key: 2,
                    title: '货位号',
                    dataIndex: 'stockBin',
                    align: "center",
                    width: '10%',
                    sorter: (a, b) => a.stockBin - b.stockBin,
                },
                {
                    key: 5,
                    title: '包装规格',
                    dataIndex: 'stockSpec',
                    align: "center",
                    width: '10%',
                },
                {
                    key: 6,
                    title: '冰结数量(库存单位)',
                    dataIndex: 'purQtyDesc',
                    align: "center",
                    width: '11%',
                },
                {
                    key: 7,
                    title: '冰结数量(基本单位)',
                    dataIndex: 'baseQtyDesc',
                    align: "center",
                    width: '11%',
                },
                {
                    key: 3,
                    title: '盘点数量(库存单位)',
                    dataIndex: 'takeStockNumIn',
                    align: "center",
                    width: '11%',
                    render: (text, record) => {
                        return(  <span><Input disabled={this.state.stateID == 20 ? false : true} min={0} type="number" value={record.purQty} style={{  float: 'left', marginLeft: '10px', width: '57%'}} onChange={(g)=>{this.handleFieldChange( g,'purQty',record.ID)} }/><span  style={{verticalAlign: '-webkit-baseline-middle'}}>{record.purUnitDesc}</span></span>)
                    },
                },
                {
                    key: 10,
                    title: '盘点数量(基本单位)',
                    dataIndex: 'takeStockNumBa',
                    align: "center",
                    width: '11%',
                    render: (text, record) => {
                        return(  <span><Input disabled={this.state.stateID == 20 ? false : true} min={0} type="number" value={record.baseQty} style={{ float: 'left', marginLeft: '10px', width: '57%'}} onChange={(g)=> {this.handleFieldChange(g,'baseQty' ,record.ID)}} /><span  style={{verticalAlign: '-webkit-baseline-middle'}}>{record.baseUnitDesc}</span></span>)
                    },
                },
                {
                    key: 8,
                    title: '生产厂家',
                    dataIndex: 'manfDesc',
                    align: "center",
                    width: '13%',
                }
            ]
        }

        componentDidMount() {
            // 初始化数据
            this.getInitialData();
            this.getDetailTableColumns();
            this.getDetailTableColumns2();
            let leftList = document.querySelectorAll('.takeHeight  .ant-table-body');
            if(leftList.length>0){
                leftList[0].style.height = store.getState().tableHeight.y +40 + 'px';
            }
            let listData = document.querySelectorAll('.accomplishHeight  .ant-table-body');
            if(listData.length>0){
                listData[0].style.height = store.getState().tableHeight.y +1 +'px';
            }
        }

        // 获取明系列表头数据
        getDetailTableColumns = () => {
            let {userInfo} = this.state;
            let data = {
                params: [{
                    reactCode: ['DrugInventoryFormCompletionAnd'],
                    compontName: 'takeStockAccomplishDetail',
                    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.setState({takeStockListCode: 'takeStockAccomplishDetail'},()=>{
                                    this.columnRef.onOpenModel();
                                })}}>{userInfo.language== 'EN' ? item.enDescripts : item.title}</div>,
                                sorter:  (a, b) => {
                                    if(item.code == 'stockBin' ){
                                        return a.stockBin - b.stockBin
                                    }else if( item.code == 'stockCode'){
                                        return a.stockCode - b.stockCode
                                    }else {
                                        return false
                                    }
                                },
                                render: (text, record) => {
                                    if(item.code == 'takeStockNumIn'){
                                        return(  <span><Input disabled={this.state.stateID == 20 ? false : true} min={0} type="number" value={record.purQty} style={{  float: 'left', marginLeft: '10px', width: '57%'}} onChange={(g)=>{this.handleFieldChange( g,'purQty',record.ID)} }/><span  style={{verticalAlign: '-webkit-baseline-middle'}}>{record.purUnitDesc}</span></span>)
                                    }else if(item.code == 'takeStockNumBa'){
                                        return(  <span><Input disabled={this.state.stateID == 20 ? false : true} min={0} type="number" value={record.baseQty} style={{ float: 'left', marginLeft: '10px', width: '57%'}} onChange={(g)=> {this.handleFieldChange(g,'baseQty' ,record.ID)}} /><span  style={{verticalAlign: '-webkit-baseline-middle'}}>{record.baseUnitDesc}</span></span>)
                                    }else {
                                        return (<span>{text}</span>)
                                    }
                                },
                            }
                        }) : '';
                        let filterArr = arr.filter(function(item){ return item.display === 'Y'});
                        this.setState({modalColumns: filterArr, detailWidthTotal: res.totalWidth,ChineseEnglishSize:userInfo.language=='EN' ? res.result.language.EN : res.result.language.CN})
                    }
                }
            });
        };
        getDetailTableColumns2 = () => {
            let {userInfo} = this.state;
            let data = {
                params: [{
                    compontName: 'DrugInventoryFormCompletionAnd',
                    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.setState({takeStockListCode: 'DrugInventoryFormCompletionAnd'},()=>{
                                    this.columnRef.onOpenModel();
                                }) }}>{userInfo.language== 'EN' ? item.enDescripts : item.title}</div>
                            }
                        }) : '';
                        let filterArr = arr.filter(function(item){ return item.display === 'Y'});
                        //   let obj =  {
                        //       title: '操作',
                        //       key: 13,
                        //       fixed: 'right',
                        //       align: "center",
                        //       width: '100px',
                        //       render: (text, record) => (
                        //           <span>
                        //   <Popconfirm title="删除不可恢复，你确定要删除吗?" onCancel={this.handlePopconfirm} onConfirm={(e) => this.handleDelete(record, e)} onClick={this.handlePopconfirm} >
                        //       <span className='span' style={{color: 'rgba(240,65,52,1)'}}>删除</span>
                        //   </Popconfirm>
                        // </span>
                        //       ),
                        //   };
                        //   filterArr.push(obj);
                        this.setState({columns: filterArr, detailWidthTotal2: res.totalWidth})
                    }
                }
            });
        };
        //获取操作行数据对象
        getRowByKey(key, newData) {
            const { detailsListData } = this.state;
            return (newData || detailsListData).filter(item => item.ID === key)[0];
        }

        //文本框数据修改
        handleFieldChange=(e, fieldName, key)=>{
            const { detailsListData} = this.state;
            const newData = detailsListData.map(item => ({ ...item }));
            const target = this.getRowByKey(key, newData);
            if (target) {
                target[fieldName] = e.target.value;
                this.setState({detailsListData: newData});
            }
        };


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

        // 获取界面默认值
        getInitialData() {
            let data = {
                params: []
            };
            // 获取下拉数据
            $http.post('urlS', this, {
                code: "02020155",
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        this.setState({SelectData: res},()=>{
                            this.searchInformation();
                        })
                    }
                }
            })
        }
        searchInformation=()=>{
            this.setState({page: 1,saveState: false},()=>{
                this.getInvoicesList()
            })
        };
        // 获取盘点单据列表数据
        getInvoicesList=()=>{
            let {ChineseEnglishSize} = this.state;
            this.setState({loading: true})
            let qLocDr = this.props.form.getFieldValue('loc');
            let state = this.props.form.getFieldValue('state');
            let EndData = this.props.form.getFieldValue('EndData');
            let StartDate = this.props.form.getFieldValue('StartDate');
            let data = {
                params: [{
                    begin: StartDate ?  Moment(StartDate).format('YYYY-MM-DD') : undefined,
                    end: EndData ? Moment(EndData).format('YYYY-MM-DD') : undefined,
                    locID: qLocDr ? qLocDr : undefined,
                    stateID: state ? state : undefined
                }],
                pagination: [
                    {
                        pageSize:this.state.pageSize,
                        currentPage:this.state.page,
                        sort:"ID",
                        dir:"asc",
                    }
                ],
            };
            $http.post('urlS', this, {
                code: "02020164",
                data: data,
                success: function (res) {
                    if(res.rows.length > 0){
                        for(var i = 0; i < res.rows.length; i++){
                            res.rows[i].key = i;
                            res.rows[i].freezeTime =  res.rows[i].createDate+'  ' + res.rows[i].createTime;
                            res.rows[i].takeTime =  res.rows[i].sumDate +'  '+ res.rows[i].sumTime;
                        }
                        if(!this.state.saveState){
                            this.setState({ WaListData: res.rows,total: res.total, detailsId: res.rows[0].stkTakeID, stateID: res.rows[0].stateID, loading: false});
                            // standingNumber = 0;
                            this.getTakeStockDetails(res.rows[0].stkTakeID)
                        }else {
                            this.setState({ WaListData: res.rows,total: res.total, loading: false});
                            // standingNumber = 0;
                            this.getTakeStockDetails()
                        }

                    }else {
                        this.setState({WaListData: [], detailsListData: []});
                        message.error(ChineseEnglishSize.DrugInventoryFormCompletionAndnoData ? ChineseEnglishSize.DrugInventoryFormCompletionAndnoData.descripts:"没数据")
                    }
                },
                error: function (err) {
                    message.error(err.errorMessage)
                }
            });
        };
        // 获取单据详情列表
        getTakeStockDetails(id) {
            this.setState({detailsLoading: true})
            let data = {
                params: [{
                    stkTakeID: this.state.detailsId ? this.state.detailsId : id ? id : undefined,

                }],
                pagination: [
                    {
                        pageSize:this.state.pageSize2,
                        currentPage: this.state.page2 ,
                        sort:"ID",
                        dir:"asc",
                    }
                ]
            };
            $http.post('urlS', this, {
                code: "02020236",
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        for(let i = 0; i < res.rows.length; i++){
                            res.rows[i].key = i;
                            res.rows[i].purQtyDesc = res.rows[i].accPurQty + '  '+ res.rows[i].purUnitDesc;
                            res.rows[i].baseQtyDesc = res.rows[i].accBaseQty + '  '+ res.rows[i].baseUnitDesc;
                        }
                        bilData = JSON.parse(JSON.stringify(res.rows)); //深拷贝
                        this.setState({detailsListData:res.rows, detailTotal: res.total, detailsLoading: false,stateID:res.main.stateID,  });
                    }
                }
            })
        }



        // 获取到盘点部门的值
        getInOpLocDr() {
            let inOpLocDr = this.props.form.getFieldValue('locDr');
            this.setState({inOpLocDr: inOpLocDr});
            return inOpLocDr
        }

        //点击行，渲染当前行样式
        setRowClassName = (record) => {
            standingNumber = standingNumber + 1;
            if(record){
                if(this.state.detailsId == record.stkTakeID) return 'clickRowStyle';
                else return '';
            }else {
                return '';
            }
        };

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

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

        // 页码改变的回调，参数是改变后的页码及每页条数 盘点单详情
        onChange2 = (page, pageSize) => {
            this.setState({page2: page, pageSize2: this.state.pageSize2}, () => {
                // 重新调用查询方法
                this.getTakeStockDetails(this.state.detailsId);
            });
        };

        onShowSizeChange2 = (current, size) => {
            this.setState({page2: current, pageSize2: size}, () => {
                // 重新调用查询方法
                this.onChange2(current,size);
            })
        };

        // 收起明细录入
        packUpHandle = () => {
            this.setState({show: !this.state.show, span: 24})
        };

        onRef = (ref) => {
            this.childModal = ref;
        };

        // addPaymentReceipt=()=>{
        //     this.childModal.showModal();
        // };

        //获取盘点数量（库存单位）
        takeStockNumIn=(e, resect)=> {
            for(var i=0; i<this.state.detailsListData.length; i++){
                if(this.state.detailsListData[i].ID == resect.ID){
                    this.state.detailsListData[i].purQty = e.target.value
                }
            }
        };
        //获取盘点数量（基本单位）
        takeStockNumBa=(e , resect)=> {
            for(var i=0; i<this.state.detailsListData.length; i++){
                if(this.state.detailsListData[i].ID == resect.ID){
                    this.state.detailsListData[i].baseQty = e.target.value
                }
            }
        };


        //主页面保存
        saveHostData=()=>{
            let {ChineseEnglishSize} = this.state;
            if(this.state.detailsListData == bilData){
                message.error(ChineseEnglishSize.DrugInventoryFormCompletionAndnoSaveData ? ChineseEnglishSize.DrugInventoryFormCompletionAndnoSaveData.descripts:'没有保存的数据');
                return
            }
            let data = {
                params: [{
                    stkTakeID: this.state.detailsId ? this.state.detailsId : undefined,
                    detail: this.state.detailsListData ? this.state.detailsListData : undefined

                }]
            };
            $http.post('urlS', this, {
                code: "02020159",
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        message.success(res.errorMessage);
                        this.setState({detailsListData: []},()=> {
                            this.getTakeStockDetails();
                        });

                    }
                }
            })
        };

        //调整库存
        adjustIn=() => {
            let data = {
                params: [{
                    stkTakeID: this.state.detailsId ? this.state.detailsId : undefined,

                }]
            };
            $http.post('urlS', this, {
                code: "02020163",
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        message.success(res.errorMessage);
                        this.setState({detailsListData: []},()=> {
                            this.getInvoicesList();
                        });

                    }
                }
            })
        };

        //汇总
        collect=() => {
            let data = {
                params: [{
                    stkTakeID: this.state.detailsId ? this.state.detailsId : undefined,

                }]
            };
            $http.post('urlS', this, {
                code: "02020160",
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        message.success(res.errorMessage);
                        this.setState({detailsListData: [],saveState: true},()=> {
                            this.getInvoicesList();
                        });

                    }
                }
            })
        };
        //取消汇总
        cancel=()=>{
            let data = {
                params: [{
                    stkTakeID: this.state.detailsId ? this.state.detailsId : undefined,

                }]
            };
            $http.post('urlS', this, {
                code: "02020334",
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        message.success(res.errorMessage);
                        this.getInvoicesList();
                    }
                }
            })
        };
        //完成
        accomplish=() => {
            let data = {
                params: [{
                    stkTakeID: this.state.detailsId ? this.state.detailsId : undefined,

                }]
            };
            $http.post('urlS', this, {
                code: "02020161",
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        message.success(res.errorMessage);
                        this.setState({detailsListData: [],saveState: true},()=> {
                            this.getInvoicesList();
                        });

                    }
                }
            })
        };

        // 取消完成
        offAccomplish=() => {
            let data = {
                params: [{
                    stkTakeID: this.state.detailsId ? this.state.detailsId : undefined,

                }]
            };
            $http.post('urlS', this, {
                code: "02020174",
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        message.success(res.errorMessage);
                        this.setState({detailsListData: [],saveState: true},()=> {
                            this.getInvoicesList();
                        });

                    }
                }
            })
        };

        //删除
        delete=() => {
            let data = {
                params: [{
                    stkTakeID: this.state.detailsId ? this.state.detailsId : undefined,

                }]
            };
            $http.post('urlS', this, {
                code: "02020162",
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        message.success(res.errorMessage);
                        this.setState({detailsListData: []},()=> {
                            this.searchInformation();
                        });

                    }
                }
            })
        };
        //组件权限编辑器
        onColumnRef = (ref) => {
            this.columnRef = ref;
        };
        // 显示分页总条数
        showTotal(total) {
            return `共 ${total ? total : 0} 条`;
        }
        //导出数据
        ExportData =()=>{
            let data ={
                params:[{
                    stkTakeID:this.state.detailsId ? this.state.detailsId : ''
                }]}
            $http.post('urlS', this, {
                code: "02020330",
                data: data,
                success: function (res) {
                    if(res.result.filePath){
                        document.getElementById("ifile").src= res.result.filePath;
                        message.success(ChineseEnglishSize.FamilyDoctorSigningStatisticsdownloading1 ? ChineseEnglishSize.FamilyDoctorSigningStatisticsdownloading.descripts:'正在导出...')
                    }else {
                        message.error(ChineseEnglishSize.FamilyDoctorSigningStatisticsnoDownloadYet1 ? ChineseEnglishSize.FamilyDoctorSigningStatisticsnoDownloadYet.descripts:'导出失败')
                    }
                }
            });
        };
        render() {
            const { getFieldDecorator } = this.props.form;
            let { detailWidthTotal,modalColumns,columns, detailWidthTotal2,ChineseEnglishSize} = this.state;
            //盘点下拉列表
            let loc = [];
            let state = [];
            this.state.SelectData.loc && this.state.SelectData.loc.map((item, i) => {
                loc.push(<Option value={item.id} key={i}>{item.descripts}</Option>)
            });
            this.state.SelectData.state && this.state.SelectData.state.map((item, i) => {
                state.push(<Option value={item.id} key={i}>{item.descripts}</Option>)
            });

            return (
                <div className="takeStockCreateBill">
                    <Row>
                        <Card
                            size="small"
                            title={<div className="card-title-left-icon"><div></div>{ChineseEnglishSize.DrugInventoryFormCompletionAndinventory ? ChineseEnglishSize.DrugInventoryFormCompletionAndinventory.descripts:'盘点'}</div>}
                        >
                            <Col span={13}>
                                <Form>
                                    <Row >
                                        <Col span={6}>
                                            <FormItem {...formItemLayout} label={ChineseEnglishSize.DrugInventoryFormCompletionAndloc ? ChineseEnglishSize.DrugInventoryFormCompletionAndloc.descripts:'科室'}>
                                                {getFieldDecorator('loc',{
                                                    initialValue: this.state.userInfo.locID ? this.state.userInfo.locID : undefined,
                                                    rules:[{ required : false, message: '科室不能为空'}]
                                                })(
                                                    <Select allowClear={true}>
                                                        {loc}
                                                    </Select>
                                                ) }
                                            </FormItem>
                                        </Col>
                                        <Col span={6}>
                                            <FormItem {...formItemLayout} label={ChineseEnglishSize.DrugInventoryFormCompletionAndstate ? ChineseEnglishSize.DrugInventoryFormCompletionAndstate.descripts:'状态'}>
                                                {getFieldDecorator('state',{
                                                    initialValue: undefined,
                                                    rules:[{required: false,message: '状态不能为空'}]
                                                })(
                                                    <Select allowClear={true}>
                                                        {state}
                                                    </Select>
                                                ) }
                                            </FormItem>
                                        </Col>
                                        <Col span={4} className="queryTime" style={{marginLeft: '30px'}}>
                                            <FormItem>
                                                {getFieldDecorator('StartDate',{
                                                    initialValue: this.state.SelectData.params ? Moment(this.state.SelectData.params.startDate, 'YYYY-MM-DD') : Moment(Moment().format('L'), 'YYYY-MM-DD'),
                                                    rules:[{ required : ChineseEnglishSize.DrugInventoryFormCompletionAndStartDate ? ChineseEnglishSize.DrugInventoryFormCompletionAndStartDate.required =='Y'? true:false: false, message: ChineseEnglishSize.DrugInventoryFormCompletionAndStartDate ? ChineseEnglishSize.DrugInventoryFormCompletionAndStartDate.message:'起始日期不能为空'}]
                                                })(
                                                    <DatePicker style={{width: '100%'}} />
                                                ) }
                                            </FormItem>
                                        </Col>
                                        <Col span={1} style={{    textAlign: 'center', lineHeight: '37px'}}>
                                            <span>{ChineseEnglishSize.DrugInventoryFormCompletionAndto ? ChineseEnglishSize.DrugInventoryFormCompletionAndto.descripts:'到'}</span>
                                        </Col>
                                        <Col span={4}  className="queryTime">
                                            <FormItem>
                                                {getFieldDecorator('EndData',{
                                                    initialValue: this.state.SelectData.params ? Moment(this.state.SelectData.params.endDate, 'YYYY-MM-DD') : Moment(Moment().format('L'), 'YYYY-MM-DD'),
                                                    rules:[{ required : ChineseEnglishSize.DrugInventoryFormCompletionAnddeadline ? ChineseEnglishSize.DrugInventoryFormCompletionAnddeadline.required =='Y'? true:false: false, message: ChineseEnglishSize.DrugInventoryFormCompletionAnddeadline ? ChineseEnglishSize.DrugInventoryFormCompletionAnddeadline.message:'截止日期不能为空'}]
                                                })(
                                                    <DatePicker style={{width: '100%'}} />
                                                ) }
                                            </FormItem>
                                        </Col>
                                    </Row>
                                </Form>
                            </Col>
                            <Col span={2}  style={{marginLeft: '-50px'}}>
                                <Row style={{marginTop: '4px'}} className="buttonLeft">
                                    <Button onClick={this.getInvoicesList}>{ChineseEnglishSize.DrugInventoryFormCompletionAndsearch ? ChineseEnglishSize.DrugInventoryFormCompletionAndsearch.descripts:'查询'}</Button>
                                </Row>
                            </Col>
                            <Col span={9} style={{textAlign: 'right'}}>
                                <iframe id="ifile" style={{display:'none'}}></iframe>
                                <Row style={{marginTop: '4px'}} className="buttonRight">
                                    <Button style={{margin: '0 10px'}} onClick={this.adjustIn} disabled={this.state.stateID == 30 ? false : true}>{ChineseEnglishSize.DrugInventoryFormCompletionAndadjustInventory ? ChineseEnglishSize.DrugInventoryFormCompletionAndadjustInventory.descripts:'调整库存'}</Button>
                                    {this.state.stateID == 30 ?
                                        <Button style={{margin: '0 10px'}} onClick={this.offAccomplish} disabled={this.state.stateID == 30 ? false : true}>{ChineseEnglishSize.DrugInventoryFormCompletionAndcancelComplete ? ChineseEnglishSize.DrugInventoryFormCompletionAndcancelComplete.descripts:'取消完成'}</Button>
                                        :
                                        <Button style={{margin: '0 10px'}} onClick={this.accomplish} disabled={this.state.stateID == 20 ? false : true}>{ChineseEnglishSize.DrugInventoryFormCompletionAndaccomplish ? ChineseEnglishSize.DrugInventoryFormCompletionAndaccomplish.descripts:'完成'}</Button>
                                    }
                                    <Button style={{margin: '0 10px'}} onClick={this.collect} disabled={this.state.stateID == 10 ? false : true}>{ChineseEnglishSize.DrugInventoryFormCompletionAndGather ? ChineseEnglishSize.DrugInventoryFormCompletionAndGather.descripts:'汇总'}</Button>
                                    <Button style={{margin: '0 10px'}} onClick={this.cancel} disabled={this.state.stateID == 20 ? false : true}>{ChineseEnglishSize.DrugInventoryFormCompletionAndcancleSummery ? ChineseEnglishSize.DrugInventoryFormCompletionAndcancleSummery.descripts:'取消汇总'}</Button>
                                    <Button style={{margin: '0 10px'}} onClick={this.delete} disabled={this.state.stateID == 20 ||  this.state.stateID == 40 ?  true : false}>{ChineseEnglishSize.DrugInventoryFormCompletionAnddelete ? ChineseEnglishSize.DrugInventoryFormCompletionAnddelete.descripts:'删除'}</Button>
                                    <Button type="dashed"style={{margin: '0 10px'}}  onClick={this.ExportData}> {ChineseEnglishSize.DrugInventoryFormCompletionAndprint1 ? ChineseEnglishSize.DrugInventoryFormCompletionAndprint.descripts:'导出'}</Button>
                                    <Button type="dashed" style={{margin: '0 10px'}}  onClick={printStkTakeData.bind(this,this.state.detailsId)}> {ChineseEnglishSize.DrugInventoryFormCompletionAndprint ? ChineseEnglishSize.DrugInventoryFormCompletionAndprint.descripts:'打印'}</Button>
                                    {/*<Button onClick={this.addPaymentReceipt}>新增</Button>*/}
                                </Row>
                            </Col>
                        </Card>
                    </Row>
                    <Row>
                        <Col span={6} style={{display: this.state.show ? 'none' : ''}} className={!this.state.show ? "animate-wrap active down-in" : "animate-wrap"}>
                            <Card
                                size="small"
                                title={<div className="card-title-left-icon"><div></div>{ChineseEnglishSize.DrugInventoryFormCompletionAndinventoryDoc ? ChineseEnglishSize.DrugInventoryFormCompletionAndinventoryDoc.descripts:'盘点单据'}</div>}
                                extra={<span style={{color: '#666'}} className='span' onClick={() => {this.setState({takeStockListCode: 'DrugInventoryFormCompletionAnd'},()=>{
                                    this.columnRef.onOpenModel();
                                }) }}><Icon type="setting" title={ChineseEnglishSize.DrugInventoryFormCompletionAndcolumnSettings ? ChineseEnglishSize.DrugInventoryFormCompletionAndcolumnSettings.descripts:'列权限设置'} /></span>}
                            >
                                <div className="drugList " style={{height: store.getState().tableHeight.y +85 + 'px'}}>
                                    <Table
                                        columns={columns.length>0 ? columns : this.columns}
                                        dataSource={this.state.WaListData}
                                        pagination={false}
                                        bordered
                                        scroll={{ x:detailWidthTotal2 ? detailWidthTotal2 : 600, y: store.getState().tableHeight.y + 3}}
                                        rowClassName={this.setRowClassName}
                                        rowKey={record => record.key}
                                        className='takeHeight'
                                        onRow={(record) => {
                                            return {
                                                onClick: () => {
                                                    if (this.state.detailsId === '') {
                                                        // 保存行数据以及ID
                                                        this.setState({detailsId: record.stkTakeID, stateID: record.stateID, page2: 1 },()=> {
                                                            this.getTakeStockDetails();
                                                        });
                                                    } else {
                                                        if (this.state.detailsId !== record.stkTakeID ) {
                                                            this.setState({detailsId: record.stkTakeID, stateID: record.stateID, page2: 1 },()=> {
                                                                this.getTakeStockDetails();
                                                            });
                                                        }else {
                                                            this.setState({detailsId: '',detailsListData: [],stateID: '' })
                                                        }
                                                    }
                                                },
                                            };
                                        }}
                                    />
                                    {/*<CommonPagination size='small' current={this.state.page} total={this.state.total} search= 'search'*/}
                                    {/*onShowSizeChange={this.onShowSizeChange.bind(this)} complete={true} dataSource={this.state.WaListData}*/}
                                    {/*loading={this.state.loading} onChange={this.onChange.bind(this)} />*/}
                                    <Pagination
                                        showTotal={() => this.showTotal(this.state.total)}
                                        size="small"
                                        showQuickJumper
                                        showSizeChanger
                                        defaultCurrent={1}
                                        total={this.state.total ? this.state.total : 0}
                                        onChange={this.onChange.bind(this)}
                                        onShowSizeChange={this.onShowSizeChange.bind(this)}
                                        style={{textAlign: "right", margin: '8px 0'}}
                                        defaultPageSize={20}
                                    />
                                </div>
                            </Card>
                        </Col>
                        <Col span={this.state.show ? 24 : 18} className="centerSelect">
                            <Card
                                size="small"
                                title={<span><Icon onClick={this.packUpHandle} type={this.state.show ? 'double-right' : 'double-left'} />{ChineseEnglishSize.DrugInventoryFormCompletionAndinventoryFormDetail ? ChineseEnglishSize.DrugInventoryFormCompletionAndinventoryFormDetail.descripts:'盘点单明细'}</span>}
                                extra={<span style={{color: '#666'}} className='span'  onClick={() => {this.setState({takeStockListCode: 'takeStockAccomplishDetail'},()=>{
                                    this.columnRef.onOpenModel();
                                }) }}>
                                    <span className='color'>
                                        <span><span className='color-B'></span>盘盈<span className='color-R'></span>盘亏</span>
                                    </span>
                                    <Icon type="setting" title={ChineseEnglishSize.DrugInventoryFormCompletionAndcolumnSettings ? ChineseEnglishSize.DrugInventoryFormCompletionAndcolumnSettings.descripts:'列权限设置'} /></span>}
                            >
                                <div >
                                    <Table
                                        columns={modalColumns.length>0 ? modalColumns : this.modalColumns}
                                        dataSource={this.state.detailsListData}
                                        pagination={false}
                                        bordered
                                        scroll={{x:detailWidthTotal ? detailWidthTotal : 1350, y: store.getState().tableHeight.y  }}
                                        rowKey={record => record.key}
                                        className='accomplishHeight'
                                        rowClassName={(record,index)=>{let ret='';if (record.dif>0){ret='blue'}else if(record.dif<0){ret='red'}return ret;}}
                                    />
                                    <CommonPagination size='small' current={this.state.page2} total={this.state.detailTotal} search= 'search'
                                                      onShowSizeChange={this.onShowSizeChange2.bind(this)} complete={true} dataSource={this.state.detailsListData}
                                                      loading={this.state.detailsLoading} onChange={this.onChange2.bind(this)} pageSize={true} />
                                </div>
                            </Card>
                        </Col>
                    </Row>
                    {/*<AddInvoices onRef={this.onRef}  handleThis={this} SelectData={this.state.SelectData} />*/}
                    <ColumnAuthoritysModel
                        clientWidth='800px'
                        compontName={ this.state.takeStockListCode}
                        configType="C"
                        onRef={this.onColumnRef}
                        reloadData={() => {
                            if (this.state.takeStockListCode == 'takeStockAccomplishDetail') {
                                this.getDetailTableColumns()
                            }else if(this.state.takeStockListCode == 'DrugInventoryFormCompletionAnd'){
                                this.getDetailTableColumns2()
                            }
                        }
                        }
                    />
                </div>
            )
        }
    }
);
export default TakeStockCreateBill;
