/*
* 设置表单
* */
let timeoutCommon;
import React, { Component } from 'react';
import { Switch, Form, Input, Row, Col, Button, message, DatePicker, Select } from 'antd';
import moment from 'moment';
import { $http } from '../../containers/config/https';
import { Util } from '../../tools';
import SetFormOrderTable from './SetFormOrderTable';
import PublicModalTable from './PublicModalTable';
// import PropTypes from 'prop-types';
const Option = Select.Option;
const { TextArea } = Input;
const formModalData = Form.create()(
    class extends Component {
        constructor(props) {
            super(props);
            this.state = {
                editField: [],
                fetching: false,
                data: [],
                value: "",
                selectData: {},
                detailInfo: {}, //双击药品获取的数据
                rowId: "",
                ColNum: 6,
                className: "",
                operateAuth: "",
                ModalRowData: {},  //双击带过来的行数据
                userInfo: {}, //点击右边表格行数据
                modalData: [], // 弹框列表数据
                unitData: [],
                rowKey: '',
                fieldDesc: '',
                parameter: '', //录入顺序的数据参数
                inputFocus: true,  //默认光标
                typeID: '',
                language: JSON.parse(window.sessionStorage.userData),
                languageSize: {}, //录入翻译
                columnsData: [], //公共表头
                modalColumns: [],
                modalColumnsWidth: '',
                wardSelectData: [],
                wardID: undefined,
            };
            this.modalColumns = [
                {
                    key: 1,
                    title: '库存项代码',
                    dataIndex: 'stockCode',
                    align: "center",
                    width: '22%'
                },
                {
                    key: 2,
                    title: '库存项描述',
                    dataIndex: 'stockDesc',
                    align: "center",
                    width: '24%',
                },
                {
                    key: 5,
                    title: '库存分类',
                    dataIndex: 'stkSubCatDesc',
                    align: "center",
                    width: '16%',
                },
                {
                    key: 3,
                    title: '包装规格',
                    dataIndex: 'stockSpec',
                    align: "center",
                    width: '12%',
                },
                {
                    key: 6,
                    title: '基本单位',
                    dataIndex: 'baseUnitDesc',
                    align: "center",
                    width: '12%',
                },
                {
                    key: 7,
                    title: '入库单位',
                    dataIndex: 'purUnitDesc',
                    align: "center",
                }
            ];
        }

        componentDidMount() {
            this.props.onRef(this);
            this.getEditField();
            this.getDrugTableColumns();
        }
        componentWillReceiveProps(props) {
            this.setState({ userInfo: props.userInfo, rowKey: props.rowKey, unitData: props.unitData, SelectData: props.SelectData, parameter: props.parameter })
        }

        componentDidUpdate(prevProps, prevState) {
            if (this.state.editField.length > 0 && !this.props.form.getFieldValue(this.state.editField[0].code) && this.state.inputFocus) {
                this.input.focus();
            }
        }

        //获取药品下拉列表
        getDrugTableColumns = () => {
            let { language } = this.state;
            let data = {
                params: [{
                    compontName: 'DrugNameList',
                    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>{language.language == 'EN' ? item.enDescripts : item.title}</div>
                            }
                        }) : '';
                        let filterArr = arr.filter(function (item) { return item.display === 'Y' });
                        this.setState({ modalColumns: filterArr, modalColumnsWidth: res.totalWidth })
                    }
                }
            })
        };

        onRefStockDesc = (ref) => {
            this.childStock = ref;
        };
        //获取表单的模板数据
        getEditField = () => {
            let { language } = this.state;
            let data = {
                params: [
                    { compontName: this.props.parameter ? this.props.parameter : 'purchasePlan', }
                ]
            };
            $http.post('urlS', this, {
                code: "02020206",
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        this.setState({
                            editField: language.language == 'EN' ? res.result[0].ENRows : res.result[0].CNRows,
                            ColNum: res.result[0].columns,
                            typeID: res.result[0].typeID,
                            columnsData: res.result[0].componet.C,
                            languageSize: language.language == 'EN' ? res.result[0].componet.language.EN : res.result[0].componet.language.CN
                        });
                        // this.props.handelThis.testData(res.result[0].rows)
                    }
                }
            })
        };
        // 获取描述列表数据
        getModalListData(alias) {
            var v = {
                stockAlias: alias, // 库存项描述别名
            }

            if (!Util.isEmpty(this.props.parameData)) {
                Object.assign(v, this.props.parameData);
            }
            let data = {
                params: [v]
            };
            $http.post('urlS', this, {
                code: this.props.stockCode ? this.props.stockCode : "02020042",
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        for (var i = 0; i < res.result.length; i++) {
                            res.result[i].key = i + 1
                        }
                        this.setState({ modalData: res.result, rowId: res.result[0].key })
                    } else {
                        this.setState({ modalData: [] })
                    }
                }
            })
        };
        // 操作弹框
        onClickRowPublic = (record) => {
            return {
                // 单击行选中
                onClick: () => {
                    if (this.state.rowId === '') {
                        // 保存行数据以及ID
                        this.setState({ rowId: record.key })
                    } else {
                        if (this.state.rowId !== record.key) {
                            this.setState({ rowId: record.key })
                        }
                    }
                },
                onDoubleClick: () => {
                    this.confirmSelection(record);
                }
            }
        };

        // 双击选中行数据的回调
        confirmSelection = (record) => {
            this.resetFields();
            this.setState({ ModalRowData: record }, () => {
                if (this.state.parameter == 'RequestVouching') {
                    this.props.handelThis.operationShow();
                }
                // 关闭弹窗
                this.childStock.handleCancel();
                // 获取单位下拉框数据
                this.getDrugData(record.stockID);
                this.props.form.setFieldsValue({ stockDesc: record.stockDesc });
            })
        };
        // 双击获取药品详细信息
        getDrugData(id) {
            let data = {
                params: [
                    {
                        stockID: id, // 库存项描述别名
                        inOperLocID: this.props.inOperLocID ? this.props.inOperLocID : undefined,
                        frLocID: this.props.frLocDr ? this.props.frLocDr : undefined,
                        toLocID: this.props.toLocID ? this.props.toLocID : undefined,
                    }
                ]
            };
            $http.post('urlS', this, {
                code: this.props.APICode ? this.props.APICode : "02020105",
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        // for(var i = 0; i < res.result.length; i++) {
                        //     res.result[i].key = i
                        // }
                        this.setState({ detailInfo: res.result }, () => {
                            if (this.state.parameter == 'RequestVouching') {
                                this.props.handelThis.operationShow();
                            }
                            let fieldArr = JSON.parse(JSON.stringify(this.state.editField));
                            let fieldArrNewData = fieldArr.filter((g) => { return g.readOnly == 'N' });
                            let fieldArrNew = fieldArrNewData.filter((v) => { return v.enterJump == 'Y' });
                            for (var i = 0; i < fieldArrNew.length; i++) {
                                if (this.state.fieldDesc === fieldArrNew[i].code) {
                                    if (fieldArrNew[i + 1]) {
                                        var fieldObj = this.props.form.getFieldInstance(fieldArrNew[i + 1].code);
                                        setTimeout(() => { fieldObj.focus() }, 300)

                                    }
                                }
                            }
                            //计算售价金额和进价金额
                            setTimeout(() => {
                                let qtyMoney = this.props.form.getFieldValue('qty') ? this.props.form.getFieldValue('qty') : 0;
                                let RPMoney = this.props.form.getFieldValue('rp') ? this.props.form.getFieldValue('rp') : 0;
                                let SPMoney = this.props.form.getFieldValue('sp') ? this.props.form.getFieldValue('sp') : 0;
                                this.props.form.setFieldsValue({ rpAmt: (RPMoney * qtyMoney).toFixed(2), spAmt: (SPMoney * qtyMoney).toFixed(2) });
                            }, 300)
                        });
                    } else {
                        this.setState({ detailInfo: [] })
                    }
                }
            })
        }
        // 药品名称表格行的类名
        setRowClassNamePublic = (record) => {
            return record.key === this.state.rowId ? 'clickRowStyle' : '';
        };
        //录入弹窗数据上下选中
        handleOnKeydown = (e) => {
            var e = window.event || e;
            let scroll_height = 50;
            let id = '';
            let oneArr = this.state.modalData && this.state.modalData.length > 0 ? this.state.modalData : [];
            switch (e.keyCode) {
                case 13:
                    if (this.state.rowId) {
                        let obj = {}
                        for (var i = 0; i < oneArr.length; i++) {
                            if (oneArr[i].key === this.state.rowId) {
                                obj = i > 0 ? oneArr[i] : oneArr[0];
                                break;
                            }
                        }
                        this.confirmSelection(obj);
                    } else {
                        message.info("请选择一条需要操作的数据")
                    }
                    break;
                case 38: //上
                    if (this.state.rowId) {
                        for (var i = 0; i < oneArr.length; i++) {
                            if (oneArr[i].key === this.state.rowId) {
                                id = i > 0 ? oneArr[i - 1].key : oneArr[0].key;
                                break;
                            }
                        }
                        this.setState({ rowId: id })
                        setTimeout(() => {
                            var gundong = document.getElementById("gundong");
                            gundong.scrollTop = gundong.scrollTop - scroll_height;
                        }, 300)
                    } else {
                        this.setState({ rowId: oneArr[0].key })
                    }
                    break;
                case 40: //下
                    if (this.state.rowId) {
                        for (let i = 0; i < oneArr.length; i++) {
                            if (oneArr[i].key === this.state.rowId) {
                                id = i + 1 >= oneArr.length ? oneArr[oneArr.length - 1].key : oneArr[i + 1].key;
                                break;
                            }
                        }
                        this.setState({ rowId: id })
                        setTimeout(() => {
                            var gundong = document.getElementById("gundong");
                            gundong.scrollTop = gundong.scrollTop + scroll_height;
                        }, 300)
                    } else {
                        this.setState({ rowId: oneArr[0].key })
                    }
                    break;
            }
        };
        //字段跳转方法和回车显示药品名称弹窗
        FieldOnKeyDown = (e, field, type, dateString) => {
            if (e.keyCode === 13 || type == 'Select' || type == 'DatePicker') {
                if (field == 'stockDesc') {
                    let inOpLocDr = this.props.frLocDr ? this.props.frLocDr : this.props.frLocID;
                    if (!inOpLocDr && this.state.parameter == 'RequestVouching') { message.error('请选择供给科室'); return }
                    if (this.props.form.getFieldValue('stockDesc')) {
                        let top = document.getElementById('stock-desc').getBoundingClientRect().top + 40 + 'px';
                        let left = document.getElementById('stock-desc').getBoundingClientRect().left + 100 + 'px';
                        this.setState({
                            top: top,
                            left: left,
                            fieldDesc: field,
                            modalData: [],
                        });
                        this.getModalListData(e.target.value);
                        setTimeout(() => {
                            var gundong = document.getElementById("gundong");
                            gundong.scrollTop = 0;
                        }, 300)
                        this.childStock.showModal();
                        // this.FieldOnKeyDown(e,field, type)
                    } else {
                        message.info("请输入药品名称");
                    }
                } else {
                    let fieldArr = JSON.parse(JSON.stringify(this.state.editField));
                    let fieldArrNewData = fieldArr.filter((g) => { return g.readOnly == 'N' });
                    let fieldArrNew = fieldArrNewData.filter((v) => { return v.enterJump == 'Y' });
                    for (var i = 0; i < fieldArrNew.length; i++) {
                        if (field === fieldArrNew[i].code) {
                            if (fieldArrNew[i].enterSave == 'Y' && field !== 'DatePicker') {
                                this.handelSave(dateString);
                            } else if (fieldArrNew[i + 1]) {
                                if (this.props.form.getFieldValue(fieldArrNew[i].code) || fieldArrNew[i].required == '' || fieldArrNew[i].required == 'N') {
                                    var fieldObj = this.props.form.getFieldInstance(fieldArrNew[i + 1].code);
                                    setTimeout(() => { fieldObj.focus(); }, 100)
                                } else if (type == 'Select') {
                                    return ''
                                } else {
                                    message.error(fieldArrNew[i].desc + '不能为空！')
                                }
                            }
                        }
                    }
                }
            }
        }
        //时间回车时间
        TimeOnKeyDown = (e, field, type, dateString) => {
            let fieldArr = JSON.parse(JSON.stringify(this.state.editField));
            let fieldArrNewData = fieldArr.filter((g) => { return g.readOnly == 'N' });
            let fieldArrNew = fieldArrNewData.filter((v) => { return v.enterJump == 'Y' });
            for (var i = 0; i < fieldArrNew.length; i++) {
                if (field === fieldArrNew[i].code) {
                    if (fieldArrNew[i].enterSave == 'Y') {
                        this.handelSave(dateString);
                    } else if (fieldArrNew[i + 1]) {
                        if (this.props.form.getFieldValue(fieldArrNew[i].code) || fieldArrNew[i].required == '' || fieldArrNew[i].required == 'N') {
                            var fieldObj = this.props.form.getFieldInstance(fieldArrNew[i + 1].code);
                            setTimeout(() => { fieldObj.focus(); }, 100)
                        } else if (type == 'Select') {
                            return ''
                        } else {
                            message.error(fieldArrNew[i].desc + '不能为空！')
                        }
                    }
                }
            }
        }
        // 当描述失去焦点的时候
        stastockDescOnBlure = (e) => {
            this.setState({ inputFocus: false }); //失去默认焦点
        };
        //表单有变化时
        clearData = (val, field) => {
            //药品名称为空时清除表单数据
            if (field == 'stockDesc') {
                if (!val.target.value) {
                    this.setState({ userInfo: {}, detailInfo: {}, ModalRowData: {} });
                    this.resetFields();
                    if (this.state.parameter == 'RequestVouching') {
                        this.props.handelThis.operationHide();
                    }
                }
            }
            //计算售价金额和进价金额
            setTimeout(() => {
                let qtyMoney = this.props.form.getFieldValue('qty') ? this.props.form.getFieldValue('qty') : 0;
                let RPMoney = this.props.form.getFieldValue('rp') ? this.props.form.getFieldValue('rp') : 0;
                let SPMoney = this.props.form.getFieldValue('sp') ? this.props.form.getFieldValue('sp') : 0;
                this.props.form.setFieldsValue({ rpAmt: (RPMoney * qtyMoney).toFixed(2), spAmt: (SPMoney * qtyMoney).toFixed(2) });
            }, 300)
        };

        GetCom = (fieldItem, key) => {

            let { languageSize } = this.state;
            const selectData = this.props.SelectData;
            const { getFieldDecorator } = this.props.form;
            let detailInfo = this.state.detailInfo ? this.state.detailInfo : {};
            let userInfo = this.state.userInfo ? this.state.userInfo : {};
            var code = detailInfo[fieldItem.code] ? detailInfo[fieldItem.code] : userInfo[fieldItem.code] ? userInfo[fieldItem.code] : '';
            var type = fieldItem.componentType;
            var ReadOnlyFlag = fieldItem.readOnly;
            var disabled = false;
            if (ReadOnlyFlag === "Y") disabled = true;
            if (type === "Input" || type == 'InputNumber') {
                return (
                    {
                        ...getFieldDecorator(fieldItem.code, {
                            initialValue: code ? code : '',
                            rules: [{ required: fieldItem.required == "Y" ? true : false, message: languageSize.EnterSequenceinputTips ? (languageSize.EnterSequenceinputTips.descripts + ' ' + fieldItem.desc) : ('请输入' + fieldItem.desc) }],
                        })(<Input
                            type={type == 'InputNumber' ? "number" : "text"}
                            allowClear={!disabled}
                            // stkRecSpEdit为入库制单售价是否可编辑的判断
                            disabled={selectData && selectData.stkRecSpEdit && fieldItem && fieldItem.code === 'sp' && (+selectData.stkRecSpEdit === 1) ? false : ((fieldItem && fieldItem.code === 'sp' && selectData && +selectData.stkRecSpEdit === 0) ? true : disabled)}
                            ref={key == 0 ? (input) => this.input = input : ''}
                            style={{ width: '100%' }}
                            placeholder={disabled ? '' : languageSize.EnterSequenceinputTips ? (languageSize.EnterSequenceinputTips.descripts + ' ' + fieldItem.desc) : ('请输入' + fieldItem.desc)}
                            onKeyDown={(e) => {
                                if (!disabled) {
                                    this.FieldOnKeyDown(e, fieldItem.code)
                                }
                            }}
                            onBlur={this.stastockDescOnBlure}
                            onChange={(e) => this.clearData(e, fieldItem.code)}
                        />)
                    }
                )
            } else if (type === "Radio") {
                return (
                    {
                        ...getFieldDecorator(fieldItem.code, {
                            initialValue: code === "Y" ? true : false,
                            valuePropName: 'checked',
                            rules: [{ required: fieldItem.required == "Y" ? true : false }],
                            normalize: (value, prevValue) => {
                                return value
                            }
                        })(<Switch disabled={disabled} checkedChildren="是" unCheckedChildren="否" />)
                    }
                )
            } else if (type === "DatePicker") {
                var date = ""
                if (fieldItem.code === "StartDate") {
                    date = code ? moment(code, 'YYYY-MM-DD') : moment(new Date(), 'YYYY-MM-DD')
                } else {
                    date = code ? moment(code, 'YYYY-MM-DD') : null
                }
                return (
                    {
                        ...getFieldDecorator(fieldItem.code, {
                            initialValue: date,
                            rules: [{ required: fieldItem.required == "Y" ? true : false, message: languageSize.EnterSequencepleaseChoose ? (languageSize.EnterSequencepleaseChoose.descripts + ' ' + fieldItem.desc) : ('请选择' + fieldItem.desc) }],
                        })(<DatePicker
                            style={{ width: '100%' }}
                            disabled={disabled}
                            format="YYYY-MM-DD"
                            placeholder={disabled ? "" : languageSize.EnterSequencepleaseChoose ? (languageSize.EnterSequencepleaseChoose.descripts + ' ' + fieldItem.desc) : ('请选择' + fieldItem.desc)}
                            onChange={(e, dateString) => {
                                if (dateString && this.props.form.getFieldValue('stockDesc')) {
                                    this.TimeOnKeyDown(e, fieldItem.code, type, dateString)
                                }
                            }}
                        />)
                    }
                )
            } else if (type === "Select") {
                if (this.props.parameter == 'WarehouseVoucher' && fieldItem.code == 'manf') {
                    return this.GetSelectManf(fieldItem, detailInfo, type);
                } else {
                    return this.GetSelectOther(fieldItem, detailInfo, type);
                }

            } else if (type === "Text") {
                return (
                    {
                        ...getFieldDecorator(fieldItem.code, {
                            initialValue: code,
                            rules: [{ required: fieldItem.required == "Y" ? true : false, message: languageSize.EnterSequenceinputTips ? (languageSize.EnterSequenceinputTips.descripts + ' ' + fieldItem.desc) : ('请输入' + fieldItem.desc) }],
                        })(<TextArea rows={1} style={{ width: '100%' }} placeholder={languageSize.EnterSequenceinputTips ? (languageSize.EnterSequenceinputTips.descripts + ' ' + fieldItem.desc) : ('请输入' + fieldItem.desc)} />)
                    }
                )
            } else {
                return (
                    {
                        ...getFieldDecorator(fieldItem.code, {
                            initialValue: code,
                            rules: [{ required: fieldItem.required == "Y" ? true : false, message: languageSize.EnterSequenceinputTips ? (languageSize.EnterSequenceinputTips.descripts + ' ' + fieldItem.desc) : ('请输入' + fieldItem.desc) }],
                        })(<Input type={type == 'InputNumber' ? "number" : false}
                            disabled={disabled}
                            placeholder={languageSize.EnterSequenceinputTips ? (languageSize.EnterSequenceinputTips.descripts + ' ' + fieldItem.desc) : ('请输入' + fieldItem.desc)}
                        />)
                    }
                )
            }
        }
        GetSelectOther = (fieldItem, detailInfo, type) => {
            let { languageSize } = this.state;
            const selectData = this.props.SelectData;
            const { getFieldDecorator } = this.props.form;
            let userInfo = this.state.userInfo ? this.state.userInfo : {};
            var code = detailInfo[fieldItem.code + 'ID'] ? fieldItem.code == 'unit' ? (detailInfo ? detailInfo[fieldItem.code + 'ID'].toString() : '') : detailInfo[fieldItem.code + 'ID'] : userInfo[fieldItem.code + 'ID'] ? userInfo[fieldItem.code + 'ID'].toString() : '';
            var ReadOnlyFlag = fieldItem.readOnly;
            var disabled = false;
            if (ReadOnlyFlag === "Y") disabled = true;
            return (
                {
                    ...getFieldDecorator(fieldItem.code, {
                        initialValue: code ? code : '',
                        rules: [{ required: fieldItem.required == "Y" ? true : false, message: languageSize.EnterSequencepleaseChoose ? (languageSize.EnterSequencepleaseChoose.descripts + ' ' + fieldItem.desc) : ('请选择' + fieldItem.desc) }],
                        normalize: (value, prevValue) => {
                            if (+value === 0) {
                                value = ""
                            }
                            return value
                        }
                    })(

                        <Select
                            allowClear
                            showSearch
                            optionFilterProp="seatchprop"
                            disabled={disabled}
                            filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
                            style={{ width: '100%' }}
                            placeholder={disabled ? '' : languageSize.EnterSequencepleaseChoose ? (languageSize.EnterSequencepleaseChoose.descripts + ' ' + fieldItem.desc) : ('请选择' + fieldItem.desc)}
                            onChange={this.changeUnit}
                        >
                            {fieldItem.code == 'unit' ? detailInfo.unit ?
                                detailInfo.unit && detailInfo.unit.length > 0 && detailInfo.unit.map((g) => {
                                    return <Option onClick={(e) => this.FieldOnKeyDown(e, fieldItem.code, type)} key={g.id} value={g.id}>{g.descripts}</Option>
                                })
                                :
                                userInfo.unit ? userInfo.unit.length > 0 && userInfo.unit.map((v) => {
                                    return <Option onClick={(e) => this.FieldOnKeyDown(e, fieldItem.code, type)} key={v.id} value={v.id}>{v.descripts}</Option>
                                }) :
                                    this.state.unitData.length > 0 && this.state.unitData.map((g) => {
                                        return <Option onClick={(e) => this.FieldOnKeyDown(e, fieldItem.code, type)} key={g.id} value={g.id}>{g.descripts}</Option>
                                    })
                                :
                                selectData[fieldItem.code] && selectData[fieldItem.code].length && selectData[fieldItem.code].map(d => { return <Option onClick={(e) => this.FieldOnKeyDown(e, fieldItem.code, type)} key={d.id} value={d.id} seatchprop={d.descriptsSPCode + d.descripts}>{d.descripts}</Option> })
                            }
                        </Select>
                    )
                }
            );
        };
        GetSelectManf = (fieldItem, detailInfo, type) => {
            let { languageSize } = this.state;
            const selectData = this.props.SelectData;
            const { getFieldDecorator } = this.props.form;
            let userInfo = this.state.userInfo ? this.state.userInfo : {};
            var code = detailInfo[fieldItem.code + 'Desc'] || userInfo[fieldItem.code + 'Desc'];
            var ReadOnlyFlag = fieldItem.readOnly;
            var disabled = false;
            if (ReadOnlyFlag === "Y") disabled = true;
            return (
                {
                    ...getFieldDecorator(fieldItem.code, {
                        initialValue: code ? code : this.state.wardID,
                        rules: [{ required: fieldItem.required == "Y" ? true : false, message: languageSize.EnterSequencepleaseChoose ? (languageSize.EnterSequencepleaseChoose.descripts + ' ' + fieldItem.desc) : ('请选择' + fieldItem.desc) }],
                        normalize: (value, prevValue) => {
                            if (+value === 0) {
                                value = ""
                            }
                            return value
                        }
                    })(

                        <Select
                            allowClear
                            showSearch
                            disabled={disabled}
                            defaultActiveFirstOption={false}
                            showArrow={false}
                            filterOption={false}
                            notFoundContent={null}
                            style={{ width: '100%' }}
                            placeholder={disabled ? '' : languageSize.EnterSequencepleaseChoose ? (languageSize.EnterSequencepleaseChoose.descripts + ' ' + fieldItem.desc) : ('请选择' + fieldItem.desc)}
                            onSearch={this.handleWardSelectData}
                            onChange={this.handleWardOnChange}
                        // value={this.state.wardID}
                        >
                            {
                                this.state.wardSelectData && this.state.wardSelectData.map((item, index) => {
                                    return (<Option onClick={(e) => this.FieldOnKeyDown(e, fieldItem.code, type)} key={index} value={item.descripts} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
                                })
                            }
                        </Select>
                    )
                }
            );
        };

        handleWardSelectData = (value) => {
            if (timeoutCommon) {
                clearTimeout(timeoutCommon);
                timeoutCommon = null;
            }
            timeoutCommon = setTimeout(() => {
                if (value) {
                    let data = {
                        params: [{
                            desc: value
                        }]
                    }
                    $http.post('urlS', this, {
                        code: "02020352",
                        data: data,
                        success: function (res) {
                            if (+res.errorCode === 0) {
                                this.setState({ wardSelectData: res.manf })
                            }
                        }
                    })
                }
            }, 300)
        };
        handleWardOnChange = e => {
            this.setState({ wardID: e }, () => {
                // this.getWardTableData()
            })
        }
        shouldComponentUpdate(nextProps, nextState) {
            if (nextState === this.state) {
                //return false
            }
            return true
        }

        // 重置表单
        resetFields = () => {
            this.setState({
                rowId: "",
                detailInfo: {},
                userInfo: {},
                ModalRowData: {},
                inputFocus: true,
                wardID: ''
            });
            this.props.form.resetFields(); //清空所有
            // this.props.handelThis.resetFields();
            if (this.state.parameter == 'RequestVouching') {
                this.props.handelThis.operationHide();
            }

        }

        //保存
        handelSave = (time) => {
            let qtyMoney = this.props.form.getFieldValue('qty') ? this.props.form.getFieldValue('qty') : 0;
            let RPMoney = this.props.form.getFieldValue('rp') ? this.props.form.getFieldValue('rp') : 0;
            let SPMoney = this.props.form.getFieldValue('sp') ? this.props.form.getFieldValue('sp') : 0;
            this.props.form.setFieldsValue({ rpAmt: (RPMoney * qtyMoney).toFixed(2), spAmt: (SPMoney * qtyMoney).toFixed(2) });
            const { form: { validateFields } } = this.props;
            validateFields((errors, values) => {
                if (errors === null) {
                    let obj = JSON.parse(JSON.stringify(values));
                    console.log("保存degrees：", obj)
                    // 将开关的值转化
                    obj.preDate = obj.preDate ? moment(obj.preDate).format('YYYY-MM-DD') : time ? moment(time).format('YYYY-MM-DD') : '' // 到货日期
                    if (obj.expDate) {
                        obj.expDate = moment(obj.expDate).format('YYYY-MM-DD');
                    }
                    if (obj.produceDate) {
                        obj.produceDate = moment(obj.produceDate).format('YYYY-MM-DD');
                    }
                    if (obj.invDate) {
                        obj.invDate = moment(obj.invDate).format('YYYY-MM-DD');
                    }
                    if (this.props.SelectData) {
                        if (this.props.SelectData.manf) {
                            for (var i = 0; i < this.props.SelectData.manf.length; i++) {
                                if (this.props.SelectData.manf[i].id === obj.manf) {
                                    obj.manfDesc = this.props.SelectData.manf[i].descripts;
                                    obj.manfID = this.props.SelectData.manf[i].id;
                                }
                            }
                        }
                        if (this.props.SelectData.vendor) {
                            for (var i = 0; i < this.props.SelectData.vendor.length; i++) {
                                if (this.props.SelectData.vendor[i].id === obj.vendor) {
                                    obj.vendorID = this.props.SelectData.vendor[i].id;
                                    obj.vendorDesc = this.props.SelectData.vendor[i].descripts;
                                }
                            }
                        }
                        if (this.props.SelectData.purchase) {
                            for (var va = 0; va < this.props.SelectData.purchase.length; va++) {
                                if (this.props.SelectData.purchase[va].id === obj.purchase) {
                                    obj.purchaseID = this.props.SelectData.purchase[va].id;
                                    obj.purchaseDesc = this.props.SelectData.purchase[va].descripts;
                                }
                            }
                        }
                        // 晶体度数
                        if (this.props.SelectData.degrees) {
                            for (var va = 0; va < this.props.SelectData.degrees.length; va++) {
                                if (this.props.SelectData.degrees[va].id === obj.degrees) {
                                    obj.degreesID = this.props.SelectData.degrees[va].id;
                                    obj.degreesDesc = this.props.SelectData.degrees[va].descripts;
                                }
                            }
                        }
                        // 柱镜度数
                        if (this.props.SelectData.clyDegrees) {
                            for (var i = 0; i < this.props.SelectData.clyDegrees.length; i++) {
                                if (this.props.SelectData.clyDegrees[i].id === obj.clyDegrees) {
                                    obj.clyDegreesID = this.props.SelectData.clyDegrees[i].id;
                                    obj.clyDegreesDesc = this.props.SelectData.clyDegrees[i].descripts;
                                }
                            }
                        }
                    }
                    if (this.state.detailInfo && this.state.detailInfo.unit) {
                        for (var i = 0; i < this.state.detailInfo.unit.length; i++) {
                            if (this.state.detailInfo.unit[i].id === obj.unit) {
                                obj.unitDesc = this.state.detailInfo.unit[i].descripts;
                                obj.unitID = this.state.detailInfo.unit[i].id;
                                obj.unit = this.state.detailInfo.unit;
                            }
                        }
                    } else {
                        if (this.state.unitData) {
                            for (var i = 0; i < this.state.unitData.length; i++) {
                                if (this.state.unitData[i].descripts === obj.unit) {
                                    obj.unitDesc = this.state.unitData[i].descripts;
                                    obj.unitID = this.state.unitData[i].id;
                                    obj.unit = this.state.unitData;
                                } else if (this.state.unitData[i].id === obj.unit) {
                                    obj.unitDesc = this.state.unitData[i].descripts;
                                    obj.unitID = this.state.unitData[i].id;
                                    obj.unit = this.state.unitData;
                                }
                            }
                        }
                    }
                    let p = this.state.ModalRowData ? this.state.ModalRowData : undefined;
                    if (this.state.rowKey) {
                        obj.stockID = p.stockID ? p.stockID : this.state.userInfo ? (/^[0-9]*$/g.test(this.state.userInfo.StockItemDr) ? this.state.userInfo.StockItemDr : this.state.userInfo.stockID) : '';
                        obj.inOpDetailID = this.state.userInfo.inOpDetailID;
                        obj.inOperDetailID = this.state.userInfo.inOperDetailID;
                        obj.key = this.state.rowKey;
                        obj.stockDesc = this.state.userInfo.stockDesc;
                        obj.PPDetailID = this.state.userInfo.PPDetailID;
                        obj.stkReqDetailID = this.state.userInfo.stkReqDetailID;
                        obj.PODetailID = this.state.userInfo.PODetailID;
                    } else {
                        obj.stockID = p.stockID;
                        obj.spAmt = obj.spAmt + '';
                        obj.rpAmt = obj.rpAmt + '';
                        obj.stockDesc = p.stockDesc;
                    }
                    if (this.props.parameter == 'WarehouseVoucher' && this.state.wardSelectData && this.state.wardSelectData.length > 0) {
                        for (var i = 0; i < this.state.wardSelectData.length; i++) {
                            if (this.state.wardSelectData[i].descripts === obj.manf) {
                                obj.manfDesc = this.state.wardSelectData[i].descripts;
                                obj.manfID = this.state.wardSelectData[i].id;
                            }
                        }
                    } else if (this.props.parameter == 'WarehouseVoucher' && this.state.wardSelectData && this.state.wardSelectData.length == 0) {
                        obj.manfDesc = this.state.detailInfo.manfDesc || this.state.userInfo.manfDesc;
                        obj.manfID = this.state.detailInfo.manfID || this.state.userInfo.manfID;
                    }
                    obj.tradeName = this.state.detailInfo.tradeName;
                    values.preDate = values.preDate ? moment(values.preDate).format('YYYY-MM-DD') : undefined;
                    this.props.handelThis.addHandle(obj, values);
                    console.log("obj", obj)
                    // this.setState({inputFocus: true})
                }
            })
        };
        onRef = (ref) => {
            this.child = ref;
        };
        //选择单位后改变进价和售价
        changeUnit = (e, event) => {
            if (this.state.detailInfo && this.state.detailInfo.unit) {
                let g = this.state.detailInfo.unit.filter((v) => v.id == e);
                if (g.length > 0) {
                    this.props.form.setFieldsValue({ rp: g[0].rp });
                    this.props.form.setFieldsValue({ sp: g[0].sp });
                }
            } else if (this.state.userInfo && this.state.userInfo.unit) {
                let arr = this.state.userInfo.unit.filter((v) => v.id == e);
                if (arr.length > 0) {
                    this.props.form.setFieldsValue({ rp: arr[0].rp });
                    this.props.form.setFieldsValue({ sp: arr[0].sp });
                }
            }
            this.clearData();
        };
        render() {
            let { modalColumns, modalColumnsWidth } = this.state;
            let ColWidth = Math.ceil(24 / this.state.ColNum);
            const formItemInput = {
                labelCol: {
                    span: 8
                },
                wrapperCol: {
                    span: 16
                },
            };
            let param = {
                width: parseInt(modalColumnsWidth) > 1000 ? 1000 + 'px' : modalColumnsWidth,
                top: this.state.top,
                left: this.state.left,
                columns: modalColumns.length > 0 ? modalColumns : this.modalColumns,
                data: this.state.modalData,
                isOnRow: true,
                TableClassName: 'tab-placeholder',
                rowClassName: true
            };
            let { languageSize } = this.state;
            return (
                <div>
                    <Form onSubmit={this.handleSubmit} layout="vertical" className="FormTitle">
                        <Row gutter={24} className="RowTitle" >
                            {
                                this.state.editField.length > 0 ? this.state.editField.map((value, key) => {
                                    return (
                                        <Col span={ColWidth} key={key} style={{ paddingRight: '0', paddingLeft: '0' }} className={value.display == "N" ? 'ColTitle display' : 'ColTitle'} id={value.code == 'stockDesc' ? 'stock-desc' : ''}>
                                            <Form.Item key={key} label={value.desc + '： '} style={{ minHeight: '40px' }}  {...formItemInput} >
                                                {this.GetCom(value, key)}
                                            </Form.Item>
                                        </Col>
                                    )
                                }) : ""
                            }
                        </Row>
                        <Row style={{ textAlign: 'right' }}>
                            <Col span={6} >
                                <Button onClick={this.handelSave} type="primary">{languageSize.EnterSequencesave ? languageSize.EnterSequencesave.descripts : '保存'}</Button>
                            </Col>
                            <Col span={6} >
                                <Button type="primary" onClick={this.resetFields}>{languageSize.EnterSequencereset ? languageSize.EnterSequencereset.descripts : '重置'}</Button>
                            </Col>
                            <Col span={6} >
                                <Button type="primary" onClick={() => { this.child.showModal(this.state.columnsData); }} >{languageSize.EnterSequenceentry ? languageSize.EnterSequenceentry.descripts : '录入顺序'}</Button>
                            </Col>
                        </Row>
                    </Form>
                    <SetFormOrderTable columnsData={this.state.columnsData} languageSize={this.state.languageSize} editField={this.state.editField} typeID={this.state.typeID} parameter={this.state.parameter} onRef={this.onRef} handleThis={this} />
                    <div
                        tabIndex={1}
                        onKeyDown={this.handleOnKeydown}
                        style={{ outline: 'none' }}
                    >
                        <PublicModalTable
                            onClickRowPublic={this.onClickRowPublic}
                            setRowClassNamePublic={this.setRowClassNamePublic}
                            param={param}
                            onRef={this.onRefStockDesc}
                            id="gundong"
                        />
                    </div>
                </div>
            );
        }
    })

export default formModalData;
