import * as Api from '../apis/recruitPlan'; //TODO
import {
    observable,
    action,
    computed,
} from 'mobx';
import {
    WeaForm,
    WeaTableNew,
    WeaSwitch,
} from 'comsMobx';
import {
    WeaLocaleProvider,
    WeaFormItem,
    WeaSearchGroup,
    WeaMoreButton,
    WeaTools,
    WeaBrowser,
    WeaButtonIcon,
} from 'ecCom';
import {
    message,
    Button,
    Row,
    Col,
    Modal,
} from 'antd';
const {
    TableStore
} = WeaTableNew;
const getLabel = WeaLocaleProvider.getLabel;
const confirm = Modal.confirm;

export class HrmRecruitPlan {
    //*************************index********************************
    @observable main = {
        authorized: false,
        loading: true,
        isSingle: false,
        ref: '',
    }

    @action
    getAuth = () => {
        Api.getAuth().then(cb => {
            const {
                status,
                hasRight
            } = cb;

            if (status == '1') {
                hasRight && this.grantAuth();
                this.stoploading();
            } else {
                message.error();
            }
        }).catch(error => {
            message.error();
        });
    }

    @action
    grantAuth = () => {
        this.main.authorized = true;
    }

    @action
    stoploading = () => {
        this.main.loading = false;
    }

    @action
    refresh = () => {
        this.resetSearch();
        this.getTableInfo();
    }

    @action
    setPropsFromParent = (id) => {
        this.main.isSingle = true;
        this.main.id = id;
    }

    @action
    setChildRef = (ref) => {
        this.main.ref = ref;
    }

    //*************************Top*******************************
    @observable top = {
        title: getLabel('6132', "招聘计划"), //TODO
        menu: [],
    }

    @action
    getMenus = () => {
        Api.getButtonsMenu().then(cb => {
            const {
                api_status,
                btnMenu
            } = cb;

            if (api_status) {
                this.top.menu = btnMenu;
            } else {
                message.error();
            }
        }).catch(error => {
            message.error();
        });
    }

    get menus() {
        const top = this.top.menu.filter(item => item.isTop == '1'),
            right = this.top.menu;

        const {
            tableStore
        } = this.mainTable;

        let buttons = [],
            dropMenuDatas = [];

        top.map(item => {
            if (item.menuFun !== 'batchDelete') {
                buttons.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@5fsd9v`} type='primary' disabled={tableStore.loading} onClick={() => this.handleTopBtnsClick(item)}>{item.menuName}</Button>);
            } else {
                buttons.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@rslopo`} type='primary' disabled={tableStore.selectedRowKeys.length == 0} onClick={() => this.handleTopBtnsClick(item)}>{item.menuName}</Button>);
            }
        });

        right.map((item, index) => {
            let obj = {
                key: item.menuFun,
                icon: <i className={`${item.menuIcon}`}/>,
                content: item.menuName,
                onClick: () => this[item.menuFun](item.menuFun)
            }
            if (item.menuFun == 'collection' || item.menuFun == 'help' || item.menuFun == 'pageAddress') {
                obj.disabled = true;
            }
            if (item.menuFun == 'batchDelete') { //TODO
                obj.disabled = tableStore.selectedRowKeys.length == 0;
            }
            dropMenuDatas.push(obj);
        })

        return {
            buttons,
            dropMenuDatas
        };
    }

    @action
    handleTopBtnsClick = (item) => {
        const {
            isPanelShow
        } = this.mainTab;

        isPanelShow && this.changePanelStatus(false);
        this[item.menuFun] && this[item.menuFun](item.menuFun)
    }

    log = () => {
        window.setLogViewProps({
            logSmallType: '3045',
        });
    }

    @action
    new = (funcName) => {
        this.openDialog(funcName);
    }

    batchDelete = () => {
        this.showConfirm('batch');
    }

    @action
    custom = () => {
        const {
            tableStore
        } = this.mainTable;

        tableStore.setColSetVisible(true);
        tableStore.tableColSet(true);

    }

    //*************************MainTab*******************************
    @observable mainTab = {
        curKey: '1',
        isPanelShow: false,
        conditionCount: 3, //TODO
        form: new WeaForm(),
        conditions: [],
    }

    get mainTabDatas() {
        const datas = [{
            key: '0',
            title: getLabel(82857, '全部'),
        }, {
            key: '1',
            title: getLabel(24324, '未结束'),
        }, {
            key: '2',
            title: getLabel(383417, '已结束'),
        }]

        return datas;
    }

    get buttonsAd() {
        const form = !this.mainDialog.visible ? this.mainTab.form : this.subTab.form;

        const buttonsAd = [
            (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@5p18nw`} type="primary" onClick={() => this.handleSearch()}>{getLabel(82529, '搜索')}</Button>),
            (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@g7a2px`} onClick={() => form.reset()}>{getLabel(27088, '重置')}</Button>),
            (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@u8umww`} onClick={() => this.changePanelStatus(false)}>{getLabel(32694, '取消')}</Button>),
        ];

        return buttonsAd;
    }

    get searchsAd() {
        let form;
        let conditions;
        let isFormInit;

        if (!this.mainDialog.visible) {
            form = this.mainTab.form;
            conditions = this.mainTab.conditions;
        } else {
            form = this.subTab.form;
            conditions = this.subTab.conditions;
        }

        isFormInit = form.isFormInit;

        let arr = [];
        isFormInit && conditions.map(c => {
            c.items.map((field, index) => {
                arr.push(<Col ecId={`${this && this.props && this.props.ecId || ''}_Col@qwz1li@${index}`} span={10} offset={1}>
                              <div style={{marginTop: 20}}>
                                  <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@pq61dn@${index}`}
                                      label={`${field.label}`}
                                      labelCol={{span: 6}}
                                      wrapperCol={{span: 18}}>
                                          {<WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@tilz7t@${index}`} fieldConfig={field} form={form} formParams={form.getFormParams()} />}
                                  </WeaFormItem>
                              </div>
                         </Col>)
            })
        })

        return <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@dy262u`}
            onKeyDown={(e) =>( e.keyCode == 13 && e.target.tagName === "INPUT")  && this.handleSearch()}
        >{arr}</Row>
    }

    @action
    clickTab = (key) => {
        const {
            visible
        } = this.mainDialog, {
            loading
        } = this.tableEdit;

        if (!visible) {
            this.mainTab.curKey = key;
            this.resetSearch();
            this.getTableInfo();
        } else {
            this.subTab.curKey = key;
            this.subTab.selectedRowKeys = '';

            if (!loading) {
                this.resetTableEditDatas();
            }

            if (['1', '3'].includes(key)) {
                this.getTableEditDatas();
            }
        }

    }

    @action
    changePanelStatus = (bool) => {
        if (!this.mainDialog.visible) {
            this.mainTab.isPanelShow = bool;
        } else {
            this.subTab.isPanelShow = bool;
        }
    }

    @action
    handleSearch = () => {
        const isPanelShow = !this.mainDialog.visible ? this.mainTab.isPanelShow : this.subTab.isPanelShow;

        isPanelShow && this.changePanelStatus(false);

        if (!this.mainDialog.visible) {
            this.getTableInfo();
        } else {
            this.main.ref.getTableInfo({ ...this.subTab.form.getFormParams(),
                qname: this.subTab.baseValue
            })
        }
    }

    @action
    getSearchCondition = () => {
        const func = !this.mainDialog.visible ? 'getSearchCondition' : 'getSearchConditionSub';

        Api[func]().then(rs => {
            const {
                api_status,
                conditions
            } = rs;

            if (api_status) {
                if (!this.mainDialog.visible) {
                    this.mainTab.conditions = conditions;
                    this.mainTab.form.initFormFields(conditions);
                } else {
                    this.subTab.conditions = conditions;
                    this.subTab.form.initFormFields(conditions);
                }
            } else {
                message.error();
            }
        }).catch(error => {
            message.error();
        });
    }

    @action
    resetSearch = () => {
        this.mainTab.isPanelShow = false;
        this.mainTab.form.reset();
    }

    @action
    setSearchsBaseValue = (val) => {
        this.subTab.baseValue = val;
    }

    @action
    handleTabUnmount = () => {
        this.mainTab.isPanelShow = false;
        this.mainTab.conditions = [];
        this.mainTab.form = new WeaForm();
    }

    //*************************MainTable*******************************
    @observable mainTable = {
        tableStore: new TableStore(),
        index: '',
    }

    @action
    getTableInfo = () => {
        const {
            form,
        } = this.mainTab, {
            visible
        } = this.mainDialog;

        Api.getTableInfo({
            status: this.mainTab.curKey,
            ...form.getFormParams()
        }).then(cb => {
            const {
                api_status,
                sessionkey,
            } = cb;

            if (api_status) {
                this.mainTable.tableStore = new TableStore();
                this.mainTable.tableStore.getDatas(sessionkey, 1);
            } else {
                message.error();
            }
        }).catch(error => {
            message.error();
        });
    }

    onOperatesClick = (record, rowIndex, operate) => {
        const {
            index
        } = operate, {
            randomFieldId,
            startdatespan,
        } = record;

        if (!this.mainDialog.visible) {
            if (index == '0' || index == '3') {
                this.openDialog(index, randomFieldId);
            }
            if (index == '1') {
                this.mainTable.id = randomFieldId;
                this.showConfirm('del');
            }
            if (index == '2') {
                window.setLogViewProps({
                    logSmallType: '3045',
                    targetId: randomFieldId,
                });
            }
            if (index == '4') {
                this.mainTable.id = randomFieldId;
                this.showConfirm('inform');
            }

            this.mainTable.startdate = startdatespan;
        } else {
            this.openDialog(index, randomFieldId);
        }
    }

    showConfirm = (type) => {
        let _this = this;
        confirm({
            title: getLabel(131329, '信息确认'),
            content: (type == 'batch') ? getLabel(385625, '确定要删除选择的记录吗？') : (type == 'del') ? getLabel(83877, '确定要删除吗？') : getLabel(15782, '确定要通知吗？'),
            okText: getLabel(33703, '确定'),
            cancelText: getLabel(32694, '取消'),
            onOk() {
                _this.onOk(type)
            },
            onCancel() {
                return false
            },
        });
    }

    onOk = (type) => {
        if (type == 'inform') {
            this.inform();
        } else {
            this.del(type)
        }
    }

    del = (type) => {
        const {
            tableStore,
            id,
        } = this.mainTable;

        const params = {
            careerPlanIds: (type == 'batch') ? tableStore.selectedRowKeys.toString() : id, //TODO
        };

        Api.deleteTableInfo(params).then(rs => {
            const {
                api_status,
                sign
            } = rs;

            if (api_status) {
                if (sign == '1') {
                    message.success(rs.message);
                    this.getTableInfo();
                } else {
                    message.warning(rs.message)
                }
            }
        }).catch(error => {
            message.error();
        });
    }

    inform = () => {
        const params = {
            careerPlanId: this.mainTable.id
        };
        Api.inform(params).then(rs => {
            const {
                api_status,
                sign
            } = rs;

            if (api_status) {
                if (sign == '1') {
                    message.success(rs.message);
                } else {
                    message.warning(rs.message)
                }
            }
        }).catch(error => {
            message.error();
        });
    }

    //*************************MainDialog*******************************
    @observable mainDialog = {
        visible: false,
        title: '',
        value: '',
        hasSaveBtn: true,
    }

    get buttons() {
        const {
            index,
        } = this.mainTable, {
            curKey
        } = this.subTab, {
            loading
        } = this.formInfo, {
            table
        } = this.tableEdit;

        let datas = [];
        if (table.length > 0) {
            datas = table[0].datas;
        }
        let buttons = [];
        if (!this.subDialog.visible) {
            if (index == 'new' || index == '3' || (index == '0' && curKey != '2')) {
                const disabled = (['1', '3'].includes(curKey)) ? this.tableEdit.loading : loading,

                    func = (['1', '3'].includes(curKey)) ? 'saveTableEditDatas' : 'save';

                this.mainDialog.hasSaveBtn && buttons.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@tbnt60`} type="primary" disabled={disabled} onClick={this[func]}>{getLabel('30986',"保存")}</Button>);
            }
            if (index == 'new') { //TODO
                buttons.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@0j07bh`} type="primary" disabled={loading} onClick={() => this.save('saveAndSet')}>{getLabel(32159, '保存并进入详细设置')}</Button>);
            }
        } else {
            const buttons = <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@5ubb7u`} type="primary" onClick={this.sendEmail} disabled={loading}>{getLabel('1226',"邮件发送")}</Button>;
        }

        buttons.push(<WeaMoreButton ecId={`${this && this.props && this.props.ecId || ''}_WeaMoreButton@6thfg9`} datas={this.dropMenuDatas} />);

        return buttons;
    }

    get style() {
        return {
            width: 800,
            height: 500
        }
    }

    get dropMenuDatas() {
        const {
            index
        } = this.mainTable, {
            curKey
        } = this.subTab, {
            loading
        } = this.formInfo, {
            hasSaveBtn
        } = this.mainDialog;

        let datas = [];
        if (!this.subDialog.visible) {
            if (index == 'new' || index == '3' || (index == '0' && ['0', '1', '3'].includes(curKey))) {
                const func = (['1', '3'].includes(curKey)) ? 'saveTableEditDatas' : 'save';

                if (!hasSaveBtn) {
                    return
                }

                datas.push({
                    key: '3',
                    icon: <i className='icon-coms-Preservation' />,
                    content: getLabel('30986', "保存"),
                    disabled: (['1', '3'].includes(curKey)) ? this.tableEdit.loading : loading,
                    onClick: this[func],
                })
            }

            if (index == 'new') {
                datas.push({
                    key: '4',
                    icon: <i className='icon-coms-Preservation' />,
                    content: getLabel(32159, '保存并进入详细设置'),
                    disabled: loading,
                    onClick: () => this.save('saveAndSet'),
                })
            }
        } else {
            datas.push({
                key: '1',
                disabled: loading,
                icon: <i className='icon-coms-email' />,
                content: getLabel('1226', "邮件发送"),
                onClick: () => this.sendMail(),
            })
        }

        return datas;
    }

    @action
    openDialog = (index, id, startdate) => {
        if (!this.mainDialog.visible) {
            this.mainTable.index = index;
            this.mainTable.id = id;
            this.mainDialog.visible = true;
            if (startdate) {
                this.mainTable.startdate = startdate
            }

            let title;
            if (index == 'new') {
                title = getLabel('386996', "新建招聘计划");
            }
            if (index == '0') {
                title = getLabel('386997', "编辑招聘计划");
            }
            if (index == '3') {
                title = getLabel('386998', "结束招聘计划")
            }
            this.mainDialog.title = title;
        } else {
            this.subTable.index = index;
            this.subTable.id = id;
            this.subDialog.visible = true;
            this.subDialog.title = getLabel('15691', "邮件通知");
        }
    }

    @action
    closeDialog = () => {
        if (this.subDialog.visible) {
            this.subDialog.visible = false;
        } else {
            this.mainDialog.visible = false;
        }
    }

    save = (arg) => {
        const {
            form
        } = this.formInfo;

        form.validateForm().then(f => {
            if (f.isValid) {
                const {
                    index,
                    id
                } = this.mainTable, {
                    curKey
                } = this.subTab;

                let func;
                const params = form.getFormParams();

                if (index == 'new') {
                    func = 'add';
                }
                if (index == '0' && curKey == '0') { //TODO
                    func = 'edit';
                }
                if (index == '3') {
                    func = 'finish';
                }
                if (id) {
                    Object.assign(params, {
                        careerPlanId: id //TODO
                    })
                }

                this.formInfo.loading = true;

                Api[func](params).then(rs => {
                    const {
                        api_status,
                        sign,
                        careerPlanId, //TODO
                    } = rs;

                    if (api_status) {
                        this.formInfo.loading = false;
                        if (sign == '1') {
                            message.success(rs.message);
                            this.closeDialog();
                            this.getTableInfo();
                            if (arg == 'saveAndSet') this.openDialog('0', careerPlanId); //TODO
                        } else {
                            message.warning(rs.message)
                        }
                    }
                }).catch(error => {
                    message.error(error);
                });
            } else {　　　　　　
                f.showErrors();
                this.setDate(new Date());
            }
        })
    }　　
    @action
    setDate = (date) => {
        this.formInfo.date = date;
    }

    addInviteInfo = (ids) => {
        const params = {
            careerPlanId: this.mainTable.id,
            inviteInfoIds: ids,
        };
        Api.addInviteInfo(params).then(rs => {
            const {
                api_status,
                sign,
            } = rs;

            if (api_status) {
                if (sign == '1') {
                    this.main.ref.getTableInfo();
                    message.success(rs.message);
                } else {
                    message.warning(rs.message)
                }
            }
        }).catch(error => {
            message.error(error);
        });
    }

    sendEmail = () => {
        const params = {
            applyInfoId: this.subTable.id,
        };
        this.formInfo.form.validateForm().then(f => {
            if (f.isValid) {
                Api.sendEmail(params).then(cb => {
                    const {
                        api_status,
                        sign,
                    } = cb;

                    if (api_status) {
                        if (sign == '1') {
                            message.success(cb.message);
                            this.closeDialog();
                            this.getTableInfo();
                        } else {
                            message.warning(cb.message);
                        }
                    } else {
                        message.error();
                    }
                }).catch(error => {
                    message.error();
                });
            } else {　　　　　　
                f.showErrors();
                this.setDate(new Date());
            }
        })
    }

    //*************************SubDialog*******************************
    @observable subDialog = {
        visible: false,
        title: '',
    }
    //*************************SubTab*******************************
    @observable subTab = {
        curKey: '0',
        isPanelShow: false,
        conditionCount: 1,
        baseValue: '',
        conditions: [],
        form: new WeaForm(),
        searchParams: {},
        selectedRowKeys: '',
    }

    get subTabDatas() {
        const datas = [{
            key: '0',
            title: getLabel(1361, '基本信息'),
        }, {
            key: '1',
            title: getLabel('15745', "招聘步骤"),
        }, {
            key: '2',
            title: getLabel('366', "招聘信息"),
        }, {
            key: '3',
            title: getLabel('386999', "应聘情况"),
        }]

        return datas;
    }

    @action
    resetSubTab = () => {
        this.subTab.curKey = '0';
        this.subTab.isPanelShow = false;
        this.subTab.conditions = [];
        this.subTab.form = new WeaForm();
        ['baseValue', 'selectedRowKeys'].map(v => {
            this.subTab[v] = '';
        });
    }

    get buttonsTab() {
        const {
            curKey
        } = this.subTab, {
            ref
        } = this.main;

        const hasRight = ref ? ref.main.authorized : false;

        const buttonsTab = [
            <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@je6u2r`}
                    type={307}
                    customized
                    inputStyle={{width: 200}}
                    icon='icon-coms-hrm'
                    iconBgcolor='#217346'
                    isSingle={false}
                    title={getLabel('366', "招聘信息")}
                    onChange={(ids, names, datas)=> this.addInviteInfo(ids)}
                >
                    <WeaButtonIcon ecId={`${this && this.props && this.props.ecId || ''}_WeaButtonIcon@zwi6y3`} buttonType='batchAdd' type="primary"/>
                </WeaBrowser>,
            <WeaButtonIcon ecId={`${this && this.props && this.props.ecId || ''}_WeaButtonIcon@22xwu7`} 
                buttonType='add' 
                type="primary" 
                onClick={() => (curKey == '2') ? this.main.ref.new('new') : this.tableEdit.ref.doAdd()}
            />,
            <WeaButtonIcon ecId={`${this && this.props && this.props.ecId || ''}_WeaButtonIcon@g43vgm`} 
                buttonType='del' 
                type="primary" 
                disabled={!this.subTab.selectedRowKeys ? true : false}
                onClick={() => (curKey == '2') ? this.main.ref.showConfirm('batch') : this.tableEdit.ref.doDelete()}
            />,
        ]

        return hasRight ? buttonsTab : [];
    }

    @action
    setSelectedRowKeys = (keys) => {
        this.subTab.selectedRowKeys = keys.toString();
    }

    //*************************FormInfo*******************************
    @observable formInfo = {
        form: new WeaForm(),
        conditions: [],
        loading: true,
        date: new Date(),
    }

    @action
    getFormConditions = () => {
        const {
            index,
            id
        } = this.mainTable, {
            form
        } = this.formInfo;

        form.isFormInit && this.resetFormInfo();

        const params = {};
        let func;

        if (index == '3') {
            func = 'getFinishForm';
        } else {
            func = 'getFormConditions';
        }
        if (id) {
            Object.assign(params, {
                careerPlanId: id
            });
        }

        Api[func](params).then(rs => {
            const {
                api_status,
                conditions,
                hasSaveBtn = true,
            } = rs;
            if (api_status) {
                this.formInfo.conditions = conditions;
                this.formInfo.form.initFormFields(conditions);
                this.formInfo.loading = false;
                this.mainDialog.hasSaveBtn = hasSaveBtn;
            } else {
                message.error();
            }
        }).catch(error => {
            message.error();
        });
    }

    @action
    resetFormInfo = () => {
        this.formInfo.conditions = [];
        this.formInfo.form = new WeaForm();
        this.formInfo.loading = true;
    }

    handleChange = (cb) => {}


    //*************************TableEdit*******************************
    @observable tableEdit = {
        table: [],
        loading: true,
    }

    get validator() {
        return {
            rules: {
                stepname: 'required',
                stepstartdate: 'required',
                stependdate: 'required',
            },
            errorMessage: {
                required: getLabel(385869, '此项必填'),
            }
        }
    }

    exportDatas = (datas, index) => {
        this.tableEdit.table[index].datas = datas;
    }

    getTableEditDatas = () => {
        const {
            curKey
        } = this.subTab;

        const func = (curKey == '1') ? 'getTableEditDatas' : 'getApplyInfoListByPlanId';

        Api[func]({
            careerPlanId: this.mainTable.id,
        }).then(rs => {
            const {
                api_status,
                table,
                hasSaveBtn = true,
            } = rs;
            if (api_status) {
                this.tableEdit.table = table;
                this.tableEdit.loading = false;
                this.mainDialog.hasSaveBtn = hasSaveBtn;
            } else {
                message.error();
            }
        }).catch(error => {
            message.error();
        });
    }

    saveTableEditDatas = () => {
        const {
            table
        } = this.tableEdit, {
            curKey
        } = this.subTab;

        if (curKey == '1' && !this.tableEdit.ref.doValidate().pass) {
            return
        }

        if (curKey == '1' && !this.compareTime(table)) {
            return
        }

        const params = {
            careerPlanId: this.mainTable.id
        };

        table.map(t => {
            Object.assign(params, this.jsonTranslation(t.datas));
            Object.assign(params, {
                [t.rownumName]: t.datas.length
            });
        })

        this.tableEdit.loading = true;

        const func = (curKey == '1') ? 'saveTableEditDatas' : 'updateApplyInfoIsInform';

        Api[func](params).then(rs => {
            const {
                api_status,
                sign,
            } = rs;

            if (api_status) {
                this.tableEdit.loading = false;
                if (sign == '1') {
                    message.success(rs.message);
                } else {
                    message.warning(rs.message)
                }
            }
        }).catch(error => {
            message.error(error);
        });
    }

    compareTime = (table) => {
        const {
            startdate
        } = this.mainTable;

        for (let i = 0; i < table.length; i++) {
            const tb = table[i];
            for (let j = 0; j < tb.datas.length; j++) {
                const data = tb.datas[j];
                const {
                    stepstartdate,
                    stependdate
                } = data;

                if (startdate && !this.isLater(startdate, stepstartdate)) {
                    message.warning(getLabel('388155', "开始日期需大于计划开始日期"));
                    return
                }

                if (stepstartdate && stependdate && !this.isLater(stepstartdate, stependdate)) {
                    message.warning(`${getLabel('15323',"第")} ${j + 1} ${getLabel('27592',"行")}${getLabel(387072, '结束时间需要大于开始时间！')}`);
                    return false
                }
            }
        }
        return true
    }

    jsonTranslation = (datas) => {
        const obj = {};
        datas.map((data, index) => {
            Object.keys(data).map(key => {
                obj[`${key}_${index}`] = data[key]
            })
        });
        return obj
    }

    isLater = (startTime, endTime) => {
        let arr = [];
        ['startTime', 'endTime'].map(v => {
            arr.push(Date.parse(eval(v).replace(/-/g, "/")));
        })

        const [st, et] = arr;

        if (st > et) {
            return false
        }
        return true

    }

    @action
    resetTableEditDatas = () => {
        this.tableEdit.table = [];
        this.tableEdit.loading = true;
    }

    @action
    setRef = (com) => {
        this.tableEdit.ref = com;
    }

}