import React from 'react';
import { connect } from 'dva';
import { Button, Row, Col, Form, Input, Select, Upload, Icon, Modal, Spin, message } from 'antd';
import {
  extend,
  extendRule,
  initFilter,
  initQueryFilter,
  getOnlyPropertyData,
  extendInclude, guid, setDataFieldValue
} from "../../../utils/common";
import DropDownPagination from '../../common/DropDownPaginationEx';
import EditComponent from "../../Lib/EditComponent";
import FormPage from '../../FormPage';
import config from "../../../config";
import moment from 'moment';

const FormItem = Form.Item;
const Option = Select.Option;
const { TextArea } = Input;
class SEditPage extends EditComponent {
    constructor(props) {
        super(props);
        this.state = {
            data: {

            },
        };
    };

    onBeforeEdit(params) {
        super.onBeforeEdit(params);
        const { isNew, isCopy, copySrcData } = params ? params : {};
        const data = { ...this.state.data };

        if (isNew) {
            setDataFieldValue(data, 'USER_ID', this.props.login.user.ID);
            setDataFieldValue(data, 'Nav_User', {
                ID: this.props.login.user.ID,
                NAME: this.props.login.user.NAME,
            });
            setDataFieldValue(data, 'DEPARTMENT_ID', this.props.login.user.DEPARTMENT_ID);
            setDataFieldValue(data, 'Nav_Department', this.props.login.user.Nav_Department);
            setDataFieldValue(data, 'TIME', new Date());
            if (this.props.data.record){
                setDataFieldValue(data, 'Nav_System', {
                    ID: this.props.data.record.ID,
                    CODE: this.props.data.record.CODE,
                    NAME: this.props.data.record.NAME,
                    TYPE: this.props.data.record.TYPE,
                    ORG_ID: this.props.data.record.ORG_ID,
                });
                setDataFieldValue(data, 'SYSTEM_ID',this.props.data.record.ID);
            }
            this.setState({
                data
            })
        } 
        this.setFieldLabel('REASON',this.props.data.IS_ANNUL ? '废除原因' : '修订原因');
        this.setFieldLabel('EDIT_TIME',this.props.data.IS_ANNUL ? '废除时间' : '修订时间');
        this.setFieldVisible('SUMMARY',this.props.data.IS_ANNUL ? false : true);
        this.setFieldVisible('REQUIRE',this.props.data.IS_ANNUL ? false : true);
        setDataFieldValue(data, 'IS_ANNUL', this.props.data.IS_ANNUL ? true : false);
        this.setFieldEditable('TIME',false);
        this.setFieldRequire('Nav_Files.Nav_File.NAME',this.props.data.IS_ANNUL ? false : true); 
    } 

    onBeforeSaveHandleRecord(params){
        super.onBeforeSaveHandleRecord(params);
        const {editCode,record,srcRecord}=params?params:{};
        if(['SC002Edit','SC003Edit','SC004Edit'].indexOf(editCode) == -1)
            return;
        record.Nav_System = srcRecord.Nav_System;
    }
}


export default connect(({ login, loading, custom, app }) => ({ login, loading, custom, app }))(Form.create()(SEditPage));
