import React from 'react';
import List from '../../public/list/components/ListComponent';
import BaseSet from '../../public/baseSet/components/BaseSetComponent';
import LdapFilter from './LdapFilter';
import InputSelect from './InputSelect';

import {inject, observer} from 'mobx-react';
import {toJS} from 'mobx';
import {Button, message, Row,Modal} from "antd";
import {WeaDialog, WeaLocaleProvider, WeaRightMenu, WeaNewScroll, WeaTab, WeaTable, WeaSearchGroup, WeaHelpfulTip} from "ecCom";

const getLabel = WeaLocaleProvider.getLabel;

@inject('ldapStore')
@observer
export default class Ldap extends React.Component {
    constructor(props) {
        super(props);
        const {ldapStore} = this.props;
        ldapStore.setState({
            baseApiUrl: '/api/integration/ldap/base',
            listApiUrl: '/api/integration/ldap/list',
            showBase: false,
            initList: false,
            baseDatas: {},
            key: Math.random().toString(36).substr(2, 6),
            baseKey: Math.random().toString(36).substr(2, 6)
        });
    }

    componentDidMount() {
      this.props.ldapStore.setState({
        selectedKey: "base"
      })
    }

    /**
     * 列表菜单点击
     * @param type
     * @param datas
     */
    onListMenuClick = (type, datas) => {
        const {ldapStore} = this.props;
		const { status, listStore } = ldapStore;
        const { selectedKey } = toJS(status);
        const { rowSelectIds } = toJS(listStore.status);
		if (selectedKey === 'base') {
			if (type == 'BTN_ADD') {//新建
				ldapStore.setState({
					showBase: true,
					dialogType: "base",
					baseApiUrl: '/api/integration/ldap/base',
					baseDatas: {}
				});
            }
            
            if (type == 'BTN_BatchDelete') {// 批量删除
				this.batchDelete({
                    ldapId: rowSelectIds,
                    type: "base"
                });
			}
		}
		if (selectedKey === 'custominterface') {
			if (type == 'BTN_ADD') {//新建
				ldapStore.setState({
					showBase: true,
					dialogType: "custominterface",
					baseApiUrl: '/api/integration/ldap/custominterfacebase',
                    baseDatas: {}
				});
			}
			if (type == 'BTN_BatchDelete') {// 批量删除
				var ids = toJS(ldapStore.listStore.status.rowSelectIds);
				this.batchDelete({
                    formartid: ids,
                    type: "custominterface"
                });
			}
        }
        if(selectedKey === 'useraccount') {
          if(type === 'BTN_DESIGN_DEPARTMENT') {
            ldapStore.setState({
              showBase: true,
              dialogType: "userdesigndepartment",
              baseTabKey: "base",
              baseApiUrl: '/api/integration/ldap/userdesigndepartment',
              baseDatas: {
                ldapId: rowSelectIds,
              }
            });
          }else if (type === "BTN_MERGE_USER") {
            ldapStore.setState({
              showBase: true,
              dialogType: "useraccountmatchbase",
              baseTabKey: "base",
              baseApiUrl: '/api/integration/ldap/useraccountmatchbase',
              baseDatas: {
                ldapId: rowSelectIds,
              }
            });
          }
        }
    }

    /**
     * 列表行点击
     * @param record
     * @param index
     * @param operate
     * @param flag
     */
    onListRowClick = (record, index, operate, flag) => {
		const { ldapStore } = this.props;
		const { status } = ldapStore;
        const { selectedKey } = toJS(status);
		if (selectedKey === 'base') {
			if (operate && operate.type) {
				const {ldapStore} = this.props;

				// 测试
				if(operate.type == 'BTN_TEST') {
                    ldapStore.baseTableEdit = [];
					ldapStore.setState({
						showTestVersion: true,
						dialogType: "test",
						baseTabKey: "base",
						testInitDatas: {},
						errorMessage: '',
						baseApiUrl: '/api/integration/ldap/test',
						baseDatas: {
							ldapId: record.ldapid,
							ldapType: record.ldaptype
						}
					});
					ldapStore.getTestFields();
					ldapStore.getTestMenu();
					ldapStore.getBase('base');
				} else if (operate.type == "BTN_EDIT") {
					ldapStore.setState({
						showBase: true,
						dialogType: "base",
						baseTabKey: "",
						baseApiUrl: '/api/integration/ldap/base',
						baseDatas: {
							ldapId: record.ldapid
						}
					});
				} else if (operate.type == "BTN_DEL") {
					this.deleteLdap({ldapId: record.ldapid});

				} else if (operate.type == "BTN_PULL") {
					ldapStore.baseTableEdit = [];
					ldapStore.setState({
						showBase: true,
						dialogType: "pull",
						baseTabKey: "base",
						baseApiUrl: '/api/integration/ldap/pull',
						baseDatas: {
							ldapId: record.ldapid,
							ldapType: record.ldaptype
						}
					});
				} else if (operate.type == "BTN_PUSH") {
					ldapStore.baseTableEdit = [];
					ldapStore.setState({
						showBase: true,
						dialogType: "push",
						baseTabKey: "base",
						baseApiUrl: '/api/integration/ldap/push',
						baseDatas: {
							ldapId: record.ldapid,
							ldapType: record.ldaptype
						}
					});
				} else if (operate.type == "BTN_SYNC_LOG") {
					ldapStore.setState({
                        showBase: true,
                        showLogDetail: false,
                        dialogType: "synclog",
                        baseApiUrl: '/api/integration/ldap/synclog',
                        baseDatas: {
							ldapId: record.ldapid
						}
                    });
				}else if (operate.type == "BTN_DEL_LOG") {
					this.deleteLdap({
                        logId: record.logId,
                        ldapId: record.ldapId
                    });

				}else if (operate.type == "BTN_LOG") {
					ldapStore.setState({
						logDatas: {
							show: true,
							targetId: record.ldapid
						}
					});
				}
			}
		}else{
			if (operate && operate.type) {
				if (operate.type == "BTN_DEL") {
					this.deleteLdap({formartid: record.formartid});
				}else if (operate.type == "BTN_EDIT" || operate.type == "BTN_DETAIL") {
					ldapStore.baseSetStore.setButtonShowStatus(record.formartlevel);
					ldapStore.baseSetStore.setInputModifyType(operate.type);
					ldapStore.setState({
						showBase: true,
						dialogType: "custominterface",
						baseTabKey: "",
						baseApiUrl: '/api/integration/ldap/custominterfacebase',
						baseDatas: {
							formartid: record.formartid
						}
					});
				}else if(operate.type === "BTN_DESIGN_DEPARTMENT") {
                  ldapStore.setState({
                    showBase: true,
                    dialogType: "userdesigndepartment",
                    baseTabKey: "base",
                    baseApiUrl: '/api/integration/ldap/userdesigndepartment',
                    baseDatas: {
                      ldapId: [record.randomFieldId],
                    }
                  });
                }else if(operate.type === "BTN_DESIGN_MERGE_USER") {
                  ldapStore.setState({
                    showBase: true,
                    dialogType: "usermerge",
                    baseTabKey: "base",
                    baseApiUrl: '/api/integration/ldap/usermerge',
                    baseDatas: {
                      ldapId: record["ID"],
                      loginid: record["LOGINID"],
                      ldapType: record.ldaptype
                    }
                  });
                }
			}
		}
    }

    /**
     * 列表列点击
     * @param record
     * @param type
     */
    onColumClick = (record, type) => {
        const {ldapStore} = this.props;
        const { status } = ldapStore;
        const { selectedKey } = toJS(status);
        
        if (selectedKey === 'base') {
            if (type && type == "BTN_EDIT") {
                ldapStore.setState({
                    showBase: true,
                    dialogType: "base",
                    baseApiUrl: '/api/integration/ldap/base',
                    baseDatas: {
                        ldapId: record.ldapid
                    }
                });
            }else if(type && type == "BTN_DETAIL_LOG"){
                ldapStore.setState({
                    showLogDetail: true,
                    dialogType: "synclogdetail",
                    baseApiUrl: '/api/integration/ldap/getLogDetial',
                    baseDatas: {
                        logId: record.logId
                    }
                });
            }
        }else{
            if (type && type == "BTN_EDIT") {
                ldapStore.baseSetStore.setButtonShowStatus(record.formartlevel);
                ldapStore.setState({
                    showBase: true,
                    dialogType: "custominterface",
                    baseTabKey: "",
                    baseApiUrl: '/api/integration/ldap/custominterfacebase',
                    baseDatas: {
                        formartid: record.formartid
                    }
                });
            }
        }
    }

    /**
     * 弹框按钮点击
     * @param type
     * @param form
     * @param tableDatas
     * @param refs
     */
    onBaseMenuClick = (type, form, tableDatas, refs) => {
        const {ldapStore} = this.props;
        const {status} = ldapStore;
        const {dialogType, baseTabKey, baseDatas} = toJS(status);
        if (type && type == "BTN_SAVE") {  
            if ("base" == dialogType) {
                //基础信息保存
                ldapStore.saveBase(form);
            } else if ("pull" == dialogType) {
                if (!baseTabKey || "" == baseTabKey || "base" == baseTabKey) {
                    //正向同步，同步节点保存
                    this.configPullSync(tableDatas, refs);
                } else if ("mapping" == baseTabKey) {
                    //正向同步，字段映射保存
                    this.configPullMapping(tableDatas, refs);
                } else if ("sync" == baseTabKey) {
                    //正向同步，手动同步
                    this.runSync("run", form);
                } else if("schedule" == baseTabKey) {
                    ldapStore.configSchedule(form);
                }
            } else if ("push" == dialogType) {
                if (!baseTabKey || "" == baseTabKey || "base" == baseTabKey) {
                    //反向同步，同步节点保存
                    this.configPushSync(tableDatas, refs);
                } else if ("mapping" == baseTabKey) {
                    //反向同步，字段映射保存
                    this.configPushMapping(tableDatas, refs);
                } else if ("sync" == baseTabKey) {
                    //反向同步，手动同步
                    this.runSync("oarun", form);
                } else if("schedule" == baseTabKey) {
                    ldapStore.configSchedule(form);
                }
            }else if("custominterface" == dialogType){
				// 自定义接口基础信息保存
                ldapStore.saveCustomInterfaceBase(form);
			}
        } else if (type && type == "BTN_DEL") {
            const {ldapStore} = this.props;
            const {status} = ldapStore;
            const {baseDatas} = toJS(status);

            if (baseDatas && baseDatas.ldapId) {
                this.deleteLdap({ldapId: baseDatas.ldapId});
            }
        } else if (type && type == "BTN_BatchDelete_Log") {
            const {ldapStore} = this.props;
            var ids = toJS(ldapStore.baseSetStore.status.rowSelectIds);
			this.batchDelete({
                logId: ids,
                type: "synclog"
            });
        } else if(type && type === "BTN_CONFIRM") {
           if(dialogType === "userdesigndepartment") {
             let params = form.getFormParams();
             form.validateForm().then(f => {
               if(f.isValid) {
                 ldapStore.updateUserInfo({...params, userIds: baseDatas.ldapId, subcompanyId: ldapStore.baseSetStore.status.subcompanyId});
               }else {
                 f.showErrors();
               }
             })
           } else if(dialogType === 'usermerge') {
             let params = form.getFormParams();
             form.validateForm().then(f => {
               if(f.isValid) {
                 ldapStore.mergeUserInfo({targetId: params.userId , modifyId: baseDatas.ldapId, loginid: baseDatas.loginid});
               }else {
                 f.showErrors();
               }
             })
           }
        } else if(type && type === "BTN_CANCLE") {
          if(dialogType === "userdesigndepartment" || dialogType === "usermerge") {
            ldapStore.setState({
             showBase: false
            })
          }
        } else if(type && type === "BTN_MATCH_TEST") {
          let params = form.getFormParams();
          form.validateForm().then(f => {
            if(f.isValid) {
              ldapStore.getTestMatchData(params);
            }else {
              f.showErrors();
            }
          })
        } else if(type && type === "BTN_BATCH_MERGE") {
          let params = form.getFormParams();
          form.validateForm().then(f => {
            if(f.isValid) {
              ldapStore.batchMergeUserInfo(params);
            }else {
              f.showErrors();
            }
          })
        }
    }

    /**
     * 手动同步
     * @param form
     */
    runSync = (type, form) => {
        
        const {ldapStore} = this.props;
        form && form.isFormInit && form.validateForm().then(f => {
            if (f.isValid) {
                if (form.getFormDatas().isSync && form.getFormDatas().isSync.value == "1") {
                    message.error(getLabel(131202, '该同步正在运行中，不可重复运行，您可以查看运行详情'));
                    return;
                } else {
                    form.updateFields({
                        isSync: "1",
                        syncLogShow: getLabel(131322, '同步程序正在初始化……') + "\n\r"
                    });
                }

                ldapStore.runSync(type, form);

            } else {
                f.showErrors();
            }
        });
    }

    /**
     * 配置反向同步字段映射
     * @param tableDatas
     * @param refs
     */
    configPushMapping = (tableDatas, refs) => {
        //反向同步字段映射保存

        const {ldapStore} = this.props;
        const {template, baseTableEdit} = ldapStore;

        //未配置有效的同步节点
        if (!baseTableEdit || !baseTableEdit || baseTableEdit.length <= 0) {
            message.error(this.stringFormart(getLabel(131534, '请至%s设置%s'), [getLabel(21952, '同步设置'), getLabel(125555, '同步节点')]));
            return;
        }

        if (!refs) {
            return;
        }

        let submitDatas = [];
        for (let tableKey of baseTableEdit) {
            if (!refs[tableKey] || !refs[tableKey].doValidate().pass) {
                return;
            }

            let lable = '';
            let templateKey = '';
            if ("pushSubcompanySet" == tableKey) {
                lable = getLabel(82267, '分部同步字段对应设置');
                templateKey = "oasubcompany";
            } else if ("pushDepartmentSet" == tableKey) {
                lable = getLabel(82268, '部门同步字段对应设置');
                templateKey = "oadepartment";
            } else if ("pushUserSet" == tableKey) {
                lable = getLabel(32239, ' 人员同步对应关系设置 ');
                templateKey = "oauser";
            }

            //至少配置一个
            if (!tableDatas || !tableDatas[tableKey] || !tableDatas[tableKey].length || tableDatas[tableKey].length <= 0) {
                message.error(getLabel(131183, '至少设置一个') + lable);
                return;
            }


            let allConfig = '';
            
            for (let elem of tableDatas[tableKey].values()) {
                //同步域重名检测
                let showName = elem.attributeName;
                if (template && template[templateKey] && template[templateKey].options) {
                    for (let t of template[templateKey].options.values()) {
                        if (showName == t.key) {
                            showName = t.showname;
                        }
                    }
                }
               
                if(allConfig.indexOf(`(#@#)${showName}(#@#)`) < 0) {
                    allConfig += `(#@#)${showName}(#@#)`;
                }else {
                    message.error(`${lable}(${showName}) ${getLabel(18082, '重复')}`);
                    return
                }
            }

            if("pushSubcompanySet" === tableKey){
                var flag = this.judgeAttributeName("name",tableDatas[tableKey]);
                lable = getLabel(82267, '分部同步字段对应设置');
                // if(flag == false){
                //     message.error(`${lable}-${getLabel(390997,'请添加LDAP分部名称')}(name)`);
                //     return;
                // }
                var oper = this.judgeOperation("name",tableDatas[tableKey]);
                var ldapLable = getLabel(391339,'LDAP分部名称');
                if("1" === oper){
                    message.error(`${ldapLable}(name)${getLabel(391335,'操作类别为仅添加，则其他对应字段操作类别需设置为仅添加')}`);
                    return;
                }
                if("2" === oper){
                    message.error(`${ldapLable}(name)${getLabel(391336,'操作类别为仅修改，则其他对应字段操作类别需设置为仅修改')}`);
                    return;
                }

            }
            else if("pushDepartmentSet" === tableKey){
                var flag = this.judgeAttributeName("name",tableDatas[tableKey]);
                lable = getLabel(82268, '部门同步字段对应设置');
                // if(flag == false){
                //     message.error(`${lable}-${getLabel(391000,'请添加LDAP部门名称')}(name)`);
                //     return;
                // }
                var oper = this.judgeOperation("name",tableDatas[tableKey]);
                var ldapLable = getLabel(391340,'LDAP部门名称');
                if("1" === oper){
                    message.error(`${ldapLable}(name)${getLabel(391335,'操作类别为仅添加，则其他对应字段操作类别需设置为仅添加')}`);
                    return;
                }
                if("2" === oper){
                    message.error(`${ldapLable}(name)${getLabel(391336,'操作类别为仅修改，则其他对应字段操作类别需设置为仅修改')}`);
                    return;
                }
            }
            else if("pushUserSet" === tableKey){
                var flag = this.judgeAttributeName("sAMAccountName",tableDatas[tableKey]);
                lable = getLabel(32239, ' 人员同步对应关系设置 ');
                //if(flag == false){
                //    message.error(`${lable}-${getLabel(390999,'请添加LDAP用户帐号')}(sAMAccountName)`);
                //    return;
                //}
                var oper = this.judgeOperation("sAMAccountName",tableDatas[tableKey]);
                var ldapLable = getLabel(391341,'LDAP用户帐号');
                if("1" === oper){
                    message.error(`${ldapLable}(name)${getLabel(391335,'操作类别为仅添加，则其他对应字段操作类别需设置为仅添加')}`);
                    return;
                }
                if("2" === oper){
                    message.error(`${ldapLable}(name)${getLabel(391336,'操作类别为仅修改，则其他对应字段操作类别需设置为仅修改')}`);
                    return;
                }
            }
            submitDatas.push(...tableDatas[tableKey]);
        }
        ldapStore.configMapping("push", {mapping: JSON.stringify(submitDatas)});
    }

    /**
     * 配置正向同步字段映射
     * @param tableDatas
     * @param refs
     */
    configPullMapping = (tableDatas, refs) => {
        //正向同步字段映射保存
        const {ldapStore} = this.props;
        const {status, template, baseTableEdit} = ldapStore;
        const {baseDatas} = toJS(status);

        //未配置有效的同步节点
        if (!baseTableEdit || !baseTableEdit || baseTableEdit.length <= 0) {
            message.error(this.stringFormart(getLabel(131534, '请至%s设置%s'), [getLabel(21952, '同步设置'), getLabel(125555, '同步节点')]));
            ldapStore.baseTableEdit = [];
            ldapStore.setState({
                showBase: true,
                dialogType: "pull",
                baseTabKey: "base",
                baseApiUrl: '/api/integration/ldap/pull',
                baseDatas: baseDatas
            });
            return;
        }

        if (!refs) {
            return;
        }

        let submitDatas = [];
        for (let tableKey of baseTableEdit) {
            if (!refs[tableKey] || !refs[tableKey].doValidate().pass) {
                return;
            }

            let lable = '';
            let templateKey = '';
            if ("subcompanySet" == tableKey) {
                lable = getLabel(82267, '分部同步字段对应设置');
                templateKey = "subcompany";
            } else if ("departmentSet" == tableKey) {
                lable = getLabel(82268, '部门同步字段对应设置');
                templateKey = "department";
            } else if ("userSet" == tableKey) {
                lable = getLabel(32239, ' 人员同步对应关系设置 ');
                templateKey = "user";
            }

            //至少配置一个
            if (!tableDatas || !tableDatas[tableKey] || !tableDatas[tableKey].length || tableDatas[tableKey].length <= 0) {
                message.error(getLabel(131183, '至少设置一个') + lable);
                return;
            }


            let allConfig = '';
            for (let elem of tableDatas[tableKey].values()) {
                let showName = elem.attributeName;

                if (template && template[templateKey] && template[templateKey].options) {
                    for (let t of template[templateKey].options.values()) {
                        if (showName == t.key) {
                            showName = t.showname;
                        }
                    }
                }
                //同步域重名检测
                if (allConfig.indexOf(`(#@#)${showName}(#@#)`) < 0) {
                    allConfig += `(#@#)${showName}(#@#)`;
                } else {
                    message.error(`${lable}(${showName}) ${getLabel(18082, '重复')}`);
                    return
                }
            }

            if("subcompanySet" === tableKey){
                var flag = this.judgeAttributeName("subcompanyname",tableDatas[tableKey]);
                lable = getLabel(82267, '分部同步字段对应设置');
                if(flag == false){
                    message.error(`${lable}-${getLabel(390994,'请添加OA分部名称')}(subcompanyname)`);
                    return;
                }
                var oper = this.judgeOperation("subcompanyname",tableDatas[tableKey]);
				var oaLable = getLabel(391338,'OA分部名称');
                if("1" === oper){
                    message.error(`${oaLable}(subcompanyname)${getLabel(391335,'操作类别为仅添加，则其他对应字段操作类别需设置为仅添加')}`);
                    return;
                }
                if("2" === oper){
                    message.error(`${oaLable}(subcompanyname)${getLabel(391336,'操作类别为仅修改，则其他对应字段操作类别需设置为仅修改')}`);
                    return;
                }

            }
            else if("departmentSet" === tableKey){
                var flag = this.judgeAttributeName("departmentmark",tableDatas[tableKey]);
                lable = getLabel(82268, '部门同步字段对应设置');
                if(flag == false){
                    message.error(`${lable}-${getLabel(390995,'请添加OA部门标识')}(departmentmark)`);
                    return;
                }
                var oper = this.judgeOperation("departmentmark",tableDatas[tableKey]);
				var oaLable = getLabel(391337,'OA部门标识');
                if("1" === oper){
                    message.error(`${oaLable}(departmentmark)${getLabel(391335,'操作类别为仅添加，则其他对应字段操作类别需设置为仅添加')}`);
                    return;
                }
                if("2" === oper){
                    message.error(`${oaLable}(departmentmark)${getLabel(391336,'操作类别为仅修改，则其他对应字段操作类别需设置为仅修改')}`);
                    return;
                }
            }
            else if("userSet" === tableKey){
                var flag = this.judgeAttributeName("loginid",tableDatas[tableKey]);
                lable = getLabel(32239, ' 人员同步对应关系设置 ');
                if(flag == false){
                    message.error(`${lable}-${getLabel(390996,'请添加OA用户标识')}(loginid)`);
                    return;
                }
                var oper = this.judgeOperation("loginid",tableDatas[tableKey]);
				var oaLable = getLabel(391334,'OA用户账号');
                if("1" === oper){
                    message.error(`${oaLable}(loginid)${getLabel(391335,'操作类别为仅添加，则其他对应字段操作类别需设置为仅添加')}`);
                    return;
                }
                if("2" === oper){
                    message.error(`${oaLable}(loginid)${getLabel(391336,'操作类别为仅修改，则其他对应字段操作类别需设置为仅修改')}`);
                    return;
                }
            }
            submitDatas.push(...tableDatas[tableKey]);
        }

        ldapStore.configMapping("pull", {mapping: JSON.stringify(submitDatas)});
    }

    judgeAttributeName = (attrname,arr) => {
        var flag = false;
        for(let elem of arr.values()){
            if(attrname === elem.attributeName){
                flag = true;
            }
        }
        return flag;
    }

    judgeOperation = (attrname,arr) =>{
        let compareOper;
        let addOper = [];
        let editOper = [];
        for(let elem of arr.values()){
            if(attrname === elem.attributeName){
                compareOper = elem.attributeOperation;
                continue;
            }
            if("1" === elem.attributeOperation){
                addOper.push(elem.attributeOperation);
            }
            if("2" === elem.attributeOperation){
                editOper.push(elem.attributeOperation);
            }
			if("0" === elem.attributeOperation){
				addOper.push(elem.attributeOperation);
				editOper.push(elem.attributeOperation);
			}
        }
		if("1" === compareOper){
			if(editOper.length>0){
				return "1";
			}
		}
		if("2" === compareOper){
			if(addOper.length>0){
				return "2";
			}
		}
    }

    stringFormart = function (str, val) {
        for (let i = 0; i < val.length; i++) {
            str = str.replace("%s", val[i]);
        }
        return str;
    }


    /**
     * 配置正向同步同步节点
     * @param tableDatas
     * @param refs
     */
    configPullSync = (tableDatas, refs) => {
        //正向同步同步节点保存
        //同步节点 必填校验
        if (!refs || !refs.syncSet || !refs.syncSet.doValidate().pass) {
            return;
        }

        //OU组织类型设置 必填校验
        if (!refs || !refs.attributeSet || !refs.attributeSet.doValidate().pass) {
            return;
        }

        //至少配置一个同步节点
        if (!tableDatas || !tableDatas.syncSet || !tableDatas.syncSet.length || tableDatas.syncSet.length <= 0) {
            message.error(`${getLabel(131183, '至少设置一个')}${getLabel(125555, '同步节点')}`);
            return;
        }

        let isMustOrg = false;
        if (!tableDatas || !tableDatas.attributeSet || !tableDatas.attributeSet.length || tableDatas.attributeSet.length <= 0) {
            isMustOrg = true;
        }

        let check = true;
        let allConfig = '';
        for (let elem of tableDatas.syncSet.values()) {

            //同步域重名检测
            let data = elem.baseDomain.replace(/^(\s*)|(\s*)$/g, '');
            if (allConfig.indexOf(`(#@#)${data}(#@#)`) < 0) {
                allConfig += `(#@#)${data}(#@#)`;
            } else {
                message.error(getLabel(32287, '同步域') + data + getLabel(18082, '重复'));
                return
            }

            //未设置OU组织类型时，同步节点必须指定部门
            if (isMustOrg && elem.syncOrg == "1" && (!elem.departmentId || elem.departmentId == "" || elem.departmentId == "0")) {
                //请设置OU组织类型或为所有的组织结构指定部门
                message.error(`${getLabel(131185, '请设置OU组织类型或为所有的组织结构指定部门!')}`);
                return;
            }

            if (check && (elem.syncOrg == "1" || elem.syncUser == "1")) {
                check = false;
            }
        }

        // if (check) {
        //     //同步节点中至少开启一个同步组织结构或用户
        //     message.error(`${getLabel(131533, '至少开启一个同步组织结构或用户')}`);
        //     return;
        // }

        let ouConfig = '';
        for(let elem of tableDatas.attributeSet.values()) {
            // OU组织类型设置
            let attributeName = elem.attributeName.replace(/^(\s*)|(\s*)$/g, '');
            let attributeValue = elem.attributeValue.replace(/^(\s*)|(\s*)$/g, '');
            if(ouConfig.indexOf(`(#@#)${attributeName}+${attributeValue}(#@#)`) < 0) {
                ouConfig += `(#@#)${attributeName}+${attributeValue}(#@#)`;
            }else {
                message.error(getLabel(82372, 'OU类型的标识属性') + attributeName + ',' + getLabel(129025, '属性值') + attributeValue + getLabel(18082, '重复'));
                return
            }
        }

        //let params = [...tableDatas.syncSet, ...tableDatas.attributeSet];
        let params = {
            sync:JSON.stringify(tableDatas.syncSet),
            auttibute:JSON.stringify(tableDatas.attributeSet)
        };
        const {ldapStore} = this.props;
        ldapStore.configSync("pull", params);
    }

    /**
     * 配置反向同步同步节点
     * @param tableDatas
     * @param refs
     */
    configPushSync = (tableDatas, refs) => {
        //反向同步同步节点保存
        //同步节点 必填校验
        if (!refs || !refs.pushSyncSet || !refs.pushSyncSet.doValidate().pass) {
            return;
        }

        //OU组织类型设置 必填校验
        if (!refs || !refs.pushAttributeSet || !refs.pushAttributeSet.doValidate().pass) {
            return;
        }

        //至少配置一个同步节点
        if (!tableDatas || !tableDatas.pushSyncSet || !tableDatas.pushSyncSet.length || tableDatas.pushSyncSet.length <= 0) {
            message.error(`${getLabel(131183, '至少设置一个')}${getLabel(125555, '同步节点')}`);
            return;
        }

        let check = true;
        let allOrgConfig = '';
        let allUserConfig = '';
        for (let elem of tableDatas.pushSyncSet.values()) {
            if(elem.syncOrg != '0' || elem.syncUser != '0') {
                let tempOrgVal = `(#@#)${elem.subcompanyId}(||)${elem.departmentId}(||)${elem.syncOrg}(#@#)`;
                let tempUserVal = `(#@#)${elem.subcompanyId}(||)${elem.departmentId}(||)${elem.syncUser}(#@#)`;
                //同步域重名检测
                if (allOrgConfig.indexOf(tempOrgVal) < 0 && allUserConfig.indexOf(tempUserVal) < 0) {
                    allOrgConfig += tempOrgVal;
                    allUserConfig += tempUserVal;
                } else {
                    message.error(getLabel(125555, '同步节点') + " ( " + elem.subcompanyIdspan + " ) " + getLabel(18082, '重复'));
                    return
                }
            
                if (check && (elem.syncOrg == "1" || elem.syncUser == "1")) {
                    check = false;
                }
            }
        }

        if (check) {
            //同步节点中至少开启一个同步组织结构或用户
            message.error(`${getLabel(131533, '至少开启一个同步组织结构或用户')}`);
            return;
        }

        // ou组织类型设置的数据添加showOrder
        tableDatas.pushAttributeSet && tableDatas.pushAttributeSet.map((data, index) => {
          let attributeName = data.attributeName;
          data.showOrder = attributeName === 'subkey' ? '1' : attributeName === 'subValue' ? '2' : attributeName === 'subClass' ? '3' 
            : attributeName === 'depkey' ? '4' : attributeName === 'depValue' ? '5' : attributeName === 'depClass' ? '6' 
            : attributeName === 'userkey' ? '7' : attributeName === 'userValue' ? '8' : attributeName === 'userClass' ? '9' : '';
        })

        let params = {
            sync:JSON.stringify(tableDatas.pushSyncSet),
            auttibute:JSON.stringify(tableDatas.pushAttributeSet)
        };
        //[...tableDatas.pushSyncSet, ...tableDatas.pushAttributeSet];
        const {ldapStore} = this.props;
        ldapStore.configSync("push", params);
    }

    /**
     * 删除LDAP
     * @param params
     */
    deleteLdap = (params) => {
        const {ldapStore} = this.props;
		const { status } = ldapStore;
		const { selectedKey, dialogType } = toJS(status);
        Modal.confirm({
            title: `${getLabel(386786, '信息确认')}`,
            content: `${getLabel(15097, '确定要删除吗？')}`,
            okText: `${getLabel(16631, '确定')}`,
            cancelText: `${getLabel(31129, '取消')}`,
            onOk: () => {
				if(selectedKey == 'base'){
                    if(dialogType == 'synclog' || dialogType == 'synclogdetail'){
                        ldapStore.deleteLdapSyncLog(params);
                    }else{
                        ldapStore.deleteLdap(params);
                    }
				}else{
					ldapStore.deleteCustomInterface(params);
				}
                
            },
        });
    }

	/**
	 * 批量删除
	 *
	 */
	batchDelete = (params) => {
		const {ldapStore} = this.props;
		Modal.confirm({
            title: `${getLabel(386786, '信息确认')}`,
            content: `${getLabel(385625, '确定要删除选择的记录吗？')}`,
            okText: `${getLabel(16631, '确定')}`,
            cancelText: `${getLabel(31129, '取消')}`,
            onOk: () => {
                if(params.type == 'custominterface'){
                    ldapStore.deleteCustomInterface(params);
                }else if(params.type == 'synclog'){
                    ldapStore.deleteLdapSyncLog(params);
                }else if(params.type == 'base') {
                    delete params.type;
                    ldapStore.deleteLdap(params);
                }
            }
        });
	};
	  
    /**
     * 弹框Tab点击
     * @param tabKey
     */
    onBaseTabChange = (tabKey) => {
        const {ldapStore} = this.props;
        const {status, getBase} = ldapStore;
        const {dialogType, baseDatas} = toJS(status);

        ldapStore.template = [];
        ldapStore.baseTableEdit = [];
        if ("pull" == dialogType) {
            if (tabKey && tabKey == "base") {
                ldapStore.setState({
                    baseTabKey: tabKey,
                    baseApiUrl: '/api/integration/ldap/pull',
                });
            } else if (tabKey && tabKey == "mapping") {
                ldapStore.initFormart("ldap");
                ldapStore.setState({
                    baseTabKey: tabKey,
                    baseApiUrl: '/api/integration/ldap/pullMapping',
                });
            } else if (tabKey && tabKey == "sync") {
                ldapStore.setState({
                    baseTabKey: tabKey,
                    baseApiUrl: '/api/integration/ldap/pullSync',
                });
            } else if (tabKey && tabKey == "schedule") {
                Object.assign(baseDatas, {syncType:dialogType});

                ldapStore.setState({
                    baseDatas: baseDatas,
                    baseTabKey: tabKey,
                    baseApiUrl: '/api/integration/ldap/schedule',
                });
            }
        } else if ("push" == dialogType) {
            if (tabKey && tabKey == "base") {
                ldapStore.setState({
                    baseTabKey: tabKey,
                    baseApiUrl: '/api/integration/ldap/push',
                });
            } else if (tabKey && tabKey == "mapping") {
                ldapStore.initFormart("oa");
                ldapStore.setState({
                    baseTabKey: tabKey,
                    baseApiUrl: '/api/integration/ldap/pushMapping',
                });
            } else if (tabKey && tabKey == "sync") {
                ldapStore.setState({
                    baseTabKey: tabKey,
                    baseApiUrl: '/api/integration/ldap/pushSync',
                });
            } else if (tabKey && tabKey == "schedule") {
                Object.assign(baseDatas, {syncType:dialogType});

                ldapStore.setState({
                    baseDatas: baseDatas,
                    baseTabKey: tabKey,
                    baseApiUrl: '/api/integration/ldap/schedule',
                });
            }
        } else if("test" == dialogType) {
            if(tabKey && tabKey == 'base') {
                getBase('base');
            }else if(tabKey && tabKey == 'pull'){
                getBase('pull');
            }else if(tabKey && tabKey == 'push') {
                getBase('push');
            }
        }
    }
	
	/**
     * 列表Tab点击
     * @param tabKey
     */
    onTabListChange = (tabKey) => {
        const {ldapStore} = this.props;
        const {status, getBase} = ldapStore;

        if ("base" == tabKey) {
			ldapStore.setState({
				selectedKey: tabKey,
				listApiUrl: '/api/integration/ldap/list',
            });
        } else if ("custominterface" == tabKey) {
            ldapStore.setState({
				selectedKey: tabKey,
				listApiUrl: '/api/integration/ldap/custominterface',
            });
        } else if("useraccount" == tabKey) {
          ldapStore.setState({
            selectedKey: tabKey,
            listApiUrl: '/api/integration/ldap/useraccount',
          }); 
        }
    }

    willEdit = ( editType, rowKey, datas, result) =>{
        const {
            baseTabKey,
        } = this.props.ldapStore.status;
        const {key,record} = result;
        let ret = new Object();
        if(key=="subcompanyId"){
            ret["datas"] = datas.map(data => {
                if(data[rowKey] === record[rowKey]) {
                    ret["cells"] = [{
                        [rowKey]: record[rowKey],
                        departmentId: {
                            com: [{
                                viewAttr: 2,
                                editType: 1,
                                label: "",
                                type: "BROWSER",
                                browserConditionParam: {
                                    type: "4",
                                    title: getLabel(27511,"部门"),
                                    icon: "icon-coms-hrm",
                                    iconBgcolor: "#217346",
                                    hasAddBtn: false,
                                    hasAdvanceSerach: true,
                                    hasBorder: false,
                                    hideVirtualOrg: false,
                                    idSeparator: ",",
                                    isAutoComplete: 1,
                                    isDetail: 0,
                                    isMultCheckbox: false,
                                    isSingle: true,
                                    linkUrl: (window.ecologyContentPath || "") + "/spa/hrm/engine.html#/hrmengine/organization?showTree=false&type=department&id=",
                                    showCheckStrictly: true,
                                    dataParams:{
                                        subcompanyid1:data.subcompanyId == '' ? '-1' : data.subcompanyId
                                    },
                                    tabs: [{
                                        isSearch: false,
                                        key: "2",
                                        name: getLabel(25332,"组织结构"),
                                        selected: false,
                                        showOrder: 0
                                    },{
                                        dataParams: {
                                            list: "1"
                                        },
                                        isSearch: true,
                                        key: "1",
                                        name: getLabel(130619,"按列表"),
                                        selected: false,
                                        showOrder: 0
                                    }]
                                },
                                key: "departmentId"
                            }]
                        }
                    }];
                    //return data;
                    return {
                        ...data,
                        departmentId: "",
                        departmentIdspan: ""
                    }
                }
                return data;
            });
            return ret;
        }
        if(key=="attributeType"){
            ret["datas"] = datas.map(data => {
                let attributeObj = {};
                if(["mapping"].includes(baseTabKey)) {
                    attributeObj = {attributeValue: ""};
                }
                if(data[rowKey]===record[rowKey]){
                    if(data.attributeType=="1" || data.attributeType=="2") {
                        data.attributeOperation = "1";
                        
                    } 
                    return {
                        ...data,
                        ...attributeObj,
                    }
                }
                return {
                    ...data,
                };
            });
            return ret;
        }
        ret["datas"] = datas;
        return ret;
    }

    /**
     * 初始化TableEdit
     * @param editType
     */
    initBaseTableEdit = (editType) => {
        const {ldapStore} = this.props;
        const {baseSetStore} = ldapStore;

        ldapStore.baseTableEdit.push(editType);
        let p = [];
        let isRun = true;
        if ("subcompanySet" == editType || "pushSubcompanySet" == editType) {
            let p1 = ldapStore.getTemplate("subcompany");
            let p2 = ldapStore.getTemplate("oasubcompany");
            p.push(p1, p2);
        } else if ("departmentSet" == editType || "pushDepartmentSet" == editType) {

            let p1 = ldapStore.getTemplate("department");
            let p2 = ldapStore.getTemplate("oadepartment");
            p.push(p1, p2);

        } else if ("userSet" == editType || "pushUserSet" == editType) {

            let p1 = ldapStore.getTemplate("user");
            let p2 = "";
            if("userSet" == editType) {
                p2 = ldapStore.getTemplate("ldapToOauser");
            } else if("pushUserSet" == editType) {
                p2 = ldapStore.getTemplate("oauser");
            }
            p.push(p1, p2);
        } else if ("pushAttributeSet" == editType) {

            let p1 = ldapStore.getTemplate("oaou");
            let p2 = ldapStore.getTemplate("subcompany");
            let p3 = ldapStore.getTemplate("department");
            let p4 = ldapStore.getTemplate("user");
            p.push(p1, p2, p3, p4);

        } else {
            isRun = false;
        }
        Promise.all(p).finally((result) => {
            baseSetStore.tableInit(editType);
        });
    }

    /**
     * 初始化同步节点自定义组件
     * @param editType
     * @param com
     * @returns {{key, type: {label: string, type: string, viewAttr: string, key: string, width: number}[], render: function(*, *, *, *): *}}
     */
    initBaseTableEditColumn = (editType, com) => {

        const {ldapStore} = this.props;
        const {status} = ldapStore;
        const {baseDatas} = toJS(status);
        if (editType && com && com.key) {
            if (editType == "syncSet") {
                return this.getLdapFilter(com);
            } else if (editType == "subcompanySet") {
                if (com.key == "attributeName") {
                    return this.getInputSelect("subcompany", com);
                } else if (com.key == "attributeValue") {
                    return this.getInputSelect("oasubcompany", com);
                }
            } else if (editType == "departmentSet") {
                if (com.key == "attributeName") {
                    return this.getInputSelect("department", com);
                } else if (com.key == "attributeValue") {
                    return this.getInputSelect("oadepartment", com);
                }
            } else if (editType == "userSet") {
                if (com.key == "attributeName") {
                    return this.getInputSelect("user", com);
                } else if (com.key == "attributeValue") {
                    return this.getInputSelect("ldapToOauser", com);
                }
            } else if (editType == "pushAttributeSet") {
                return this.getInputSelectOfPush("oaou", com);

            } else if (editType == "pushSubcompanySet") {
                if (com.key == "attributeName") {
                    return this.getInputSelect("oasubcompany", com);
                } else if (com.key == "attributeValue") {
                    return this.getInputSelect("subcompany", com);
                }
            } else if (editType == "pushDepartmentSet") {
                if (com.key == "attributeName") {
                    return this.getInputSelect("oadepartment", com);
                } else if (com.key == "attributeValue") {
                    return this.getInputSelect("department", com);
                }
            } else if (editType == "pushUserSet") {
                if (com.key == "attributeName") {
                    return this.getInputSelect("oauser", com);
                } else if (com.key == "attributeValue") {
                    return this.getInputSelect("user", com);
                }
            }
        }
    }

    /**
     *
     * 获取LDAP过虑配置组件
     *
     * @param com
     * @returns {{key, type: {label: string, type: string, viewAttr: string, key: string, width: number}[], render: function(*, *=, *, *): *}}
     */
    getLdapFilter = (com) => {
        const {ldapStore} = this.props;
        const {status} = ldapStore;
        const {baseDatas} = toJS(status);

        if (com.key == "syncOrg") {
            let defFilter = '(|(objectClass=organization)(objectClass=organizationalUnit))';
            if ("AD" == baseDatas.ldapType) {
                defFilter = "(|(objectClass=organization)(objectClass=organizationalUnit))";
            }
            return {
                key: com.key,
                type: com.type,
                render: (text, record, index, onEdit) => (
                    <LdapFilter ecId={`${this && this.props && this.props.ecId || ''}_LdapFilter@hdh7qu`} checkValue={record.syncOrg} checkKey={'syncOrg'} filterKey={'orgFilter'}
                                filterValue={record.orgFilter && record.orgFilter != '' ? record.orgFilter : defFilter}
                                type={'org'}
                                title={getLabel(25332, '组织架构') + getLabel(32299, '同步条件')}
                                onChange={(values, key, value) => {
                                    Object.assign(record, values);
                                    onEdit({record, index, key, value});
                                }}
                    ></LdapFilter>
                )
            }
        } else if (com.key == "syncUser") {
            let defFilter = '(|(objectClass=user)(objectClass=person))';
            if ("AD" == baseDatas.ldapType) {
                defFilter = "(|(objectClass=user)(objectClass=person))";
            }
            return {
                key: com.key,
                type: com.type,
                render: (text, record, index, onEdit) => (
                    <LdapFilter ecId={`${this && this.props && this.props.ecId || ''}_LdapFilter@istabg`} checkValue={record.syncUser} checkKey={'syncUser'} filterKey={'userFilter'}
                                filterValue={record.userFilter && record.userFilter != '' ? record.userFilter : defFilter}
                                type={'user'}
                                title={getLabel(24533, '用户') + getLabel(32299, '同步条件')}
                                onChange={(values, key, value) => {
                                    Object.assign(record, values);
                                    onEdit({record, index, key, value});
                                }}
                    ></LdapFilter>
                )
            }
        }
    }

    /**
     * 反向同步INPUT、Select切换控件
     * @param type
     * @param com
     * @returns {{key, type: {label: string, type: string, viewAttr: string, key: string, width: number}[], render: function(*, *, *, *)}}
     */
    getInputSelectOfPush = (type, com) => {
        const {ldapStore} = this.props;
        const {template, formart} = ldapStore;
        return {
            key: com.key,
            type: com.type,
            render: (text, record, index, onEdit) => {
                let options = [];
                let isMust = false;
                let showName = '';

                if (com.key == "attributeValue" && record.attributeType && record.attributeType == "0") {
                    let valueType;
                    if ("subValue" == record.attributeName) {
                        valueType = "subcompany";
                    } else if ("depValue" == record.attributeName) {
                        valueType = "department";
                    } else if ("userValue" == record.attributeName) {
                        valueType = "user";
                    }
                    options = template && template[valueType] && template[valueType].options ? template[valueType].options.slice() : [];

                } else if (com.key == "attributeName") {
                    if (template && template[type] && template[type].datas && template[type].datas[record.attributeName]) {
                        isMust = true;
                        showName = template[type].datas[record.attributeName].showName;
                    }
                }

                let inputType = 'input';
                let value;
                if (com.key == 'attributeName') {
                    value = record.attributeName;
                } else if (com.key == 'attributeValue') {
                    value = record.attributeValue;
                }
                if (!value || value == "" && options.length > 0) {
                    inputType = 'select';
                } else {
                    for (let v of options) {
                        if (v && v.key && v.key == value) {
                            inputType = 'select';
                        }
                    }
                }


                return (<InputSelect ecId={`${this && this.props && this.props.ecId || ''}_InputSelect@nu8ylo`} fieldsName={com.key}
                                     key={record.attributeType}
                                     isMust={isMust}
                                     inputType={inputType}
                                     showName={showName}
                                     isInput={com.key == "attributeValue" && record.attributeType && (record.attributeType == "1" || record.attributeType == "2")}
                                     value={record[com.key]}
                                     inputConfig={com.inputConfig}
                                     selectConfig={{
                                         ...com.selectConfig,
                                         options
                                     }}
                                     onChange={(value, key) => {
                                         onEdit({record, index, key, value});
                                     }}
                ></InputSelect>);
            }
        }
    }

    /**
     * 获取Input、Select切换组件
     * @param type
     * @param com
     * @returns {{key, type: {label: string, type: string, viewAttr: string, key: string, width: number}[], render: function(*, *=, *, *)}}
     */
    getInputSelect = (type, com) => {
        const {ldapStore} = this.props;
        const {template, formart} = ldapStore;

        return {
            key: com.key,
            type: com.type,
            render: (text, record, index, onEdit) => {
                let options = [];
                let isMust = false;
                let showName = '';

                if (com.key == "attributeValue") {
                    if (record.attributeType && record.attributeType == "2") {
                        options = formart ? formart.slice() : [];
                    } else {
                        options = template && template[type] && template[type].options ? template[type].options.slice() : [];
                    }
                } else if (com.key == "attributeName") {
                    if (template && template[type] && template[type].datas) {
                        if (template[type].datas[record.attributeName]
                            && template[type].datas[record.attributeName].isMust == "1") {
                            isMust = true;
                            showName = template[type].datas[record.attributeName].showName;
                        } else {
                            isMust = false;
                            let datas = template[type].datas;
                            for (let op in datas) {
                                if (datas[op].isMust != "1") {
                                    options.push({
                                        key: op,
                                        showname: datas[op].showName
                                    });
                                }
                            }
                        }
                    }
                }

                let inputType = 'input';
                let value;
                if (com.key == 'attributeName') {
                    value = record.attributeName;
                } else if (com.key == 'attributeValue') {
                    value = record.attributeValue;
                }


                for (let v of options) {
                    if (v && v.key && v.key == value) {
                        inputType = 'select';
                    }
                }

                if(!value || (value == '' && options.length > 0) || (value && options.length == 0)) {
                    inputType ='select';
                }

                // if (!value || value == "" && options.length > 0) {
                //     inputType = 'select';
                // } else {
                //     for (let v of options) {
                //         if (v && v.key && v.key == value) {
                //             inputType = 'select';
                //         }
                //     }
                // }
                /**
                 * 对应字段后面的 切换 按钮，是什么情况下都不会置灰的；
                 * 字段对应值那儿的 切换 按钮，在数据类型为 自定义接口 和 固定值 时，是置灰的
                 */
                return (<InputSelect ecId={`${this && this.props && this.props.ecId || ''}_InputSelect@uj4squ`} fieldsName={com.key}
                     key={record.attributeType}
                     isMust={isMust}
                     inputType={inputType}
                     showName={showName}
                     isInput={com.key == "attributeValue" && record.attributeType && record.attributeType == "1"}
                     customInterface={com.key != "attributeName" && record.attributeType == "2"}
                     value={record[com.key]}
                     inputConfig={com.inputConfig}
                     selectConfig={{
                         ...com.selectConfig,
                         options
                     }}
                     onChange={(value, key) => {
                         //如果是属性名，同时修改默认属性值类型、默认属性值
                         if (key == "attributeName" && template && template[type] && template[type].datas
                             && template[type].datas[value]) {

                             Object.assign(record, template[type].datas[value]);
                             if("1" === record.attributeType) {
                                 Object.assign(record,{attributeOperation:"1"});
                             } else{
                                 Object.assign(record,{attributeOperation:"0"});
                             }
                         }
                         onEdit({record, index, key, value});
                     }}
                ></InputSelect>);
            }
        }
    }

    /**
     * 禁用行
     * @param editType
     * @param rowSelection
     * @returns {{}}
     */
    getRowSelection = (editType, rowSelection) => {
        const sel = {...rowSelection};
        if (editType == "attributeSet" || editType == "subcompanySet" || editType == "departmentSet"
            || editType == "userSet" || editType == "pushSubcompanySet" || editType == "pushDepartmentSet"
            || editType == "pushUserSet") {

            sel.getCheckboxProps = record => {
                return {disabled: record.isMust == "1"};
            };
        } else if (editType == "pushAttributeSet") {
            return undefined;
        }

        return sel;
    }

    initTableData = (editType,rowKey,datas) =>{
        let ret = new Object();
        let cells = new Array();

        if(datas){
            for(let data of datas){
                if(data.subcompanyId){
                    cells.push({
                        [rowKey]: data[rowKey],
                        departmentId: {
                            com: [{
                                viewAttr: 2,
                                editType: 1,
                                label: "",
                                type: "BROWSER",
                                browserConditionParam: {
                                    type: "4",
                                    title: getLabel(27511,"部门"),
                                    icon: "icon-coms-hrm",
                                    iconBgcolor: "#217346",
                                    hasAddBtn: false,
                                    hasAdvanceSerach: true,
                                    hasBorder: false,
                                    hideVirtualOrg: false,
                                    idSeparator: ",",
                                    isAutoComplete: 1,
                                    isDetail: 0,
                                    isMultCheckbox: false,
                                    isSingle: true,
                                    linkUrl: (window.ecologyContentPath || "") + "/spa/hrm/engine.html#/hrmengine/organization?showTree=false&type=department&id=",
                                    showCheckStrictly: true,
                                    dataParams:{
                                        subcompanyid1:data.subcompanyId
                                    },
                                    tabs: [{
                                        isSearch: false,
                                        key: "2",
                                        name: getLabel(25332,"组织结构"),
                                        selected: false,
                                        showOrder: 0
                                    },{
                                        dataParams: {
                                            list: "1"
                                        },
                                        isSearch: true,
                                        key: "1",
                                        name: getLabel(130619,"按列表"),
                                        selected: false,
                                        showOrder: 0
                                    }]
                                },
                                key: "departmentId"
                            }]
                        }
                    });
                }
            }
        }
        ret.cells = cells;
        return ret;
    }

    getBase = () => {
        const {ldapStore} = this.props;
        const {getBase} = ldapStore; 

        getBase('base');
    }

    getBtns = () => {
        const {ldapStore} = this.props;
        const {buttoninfo} = toJS(ldapStore.status);

        let btnArr = [];
        buttoninfo && buttoninfo.map(b => {
            btnArr.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@433gn3@integrationLdapButton${b.type}`} type={b.btnType} onClick={() => this.onRightMenuClick(b.type)}>
                    {b.btnName}
                </Button>
            );
        });
        return btnArr;
    }

    getMoreBtn = () => {
        const {ldapStore} = this.props;
        const {moreBtninfo} = toJS(ldapStore.status);
        let btnArr = [];
        moreBtninfo && moreBtninfo.map(m => {
            btnArr.push({
                key: m.key,
                icon: <i className={m.icon}/>,
                content: m.btnName,
                onClick: () => this.onRightMenuClick(m.type)
            });
        });
        return btnArr;
    }

    onRightMenuClick = () => {
        const {ldapStore} = this.props;
        const {topinfo} = toJS(ldapStore.status);

        ldapStore.getBase(topinfo.tab.selectedKey);
    }

    getRightMenu = () => {
        const {ldapStore} = this.props;
        const {menuinfo} = toJS(ldapStore.status);
        let btnArr = [];
        menuinfo && menuinfo.map(m => {
            btnArr.push({
                key: m.type,
                icon: <i className={m.menuIcon}/>,
                content: m.menuName,
                onClick: () => this.onRightMenuClick(m.type)
            });
        });
        return btnArr;
    }

    getTab = () => {
        const {ldapStore} = this.props;
        const {status} = ldapStore;
        const {topinfo} = toJS(status);

        if (topinfo && topinfo.tab) {
            return (<WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@7jl4tl`} {...topinfo.tab}
                            onChange={tabKey => {
                                var that = this;
                                setTimeout(function(){
                                    topinfo.tab.selectedKey = tabKey;
                                    ldapStore.setState({
                                        topinfo: topinfo,
                                        testInitDatas: {},
                                        errorMessage: '',
                                    });
                                    ldapStore.getBase(tabKey);
                                }, 300)
                            }}
            />);
        }
    }

    getColumns = (columns) => {
        let datas = [];

        columns && columns.map(column => {
            if(column['key'] == 'status') {
                datas.push({
                    dataIndex: column['dataIndex'],
                    key: column['key'],
                    sorter: column['sorter'],
                    title: column['title'],
                    render: (text, record) => {
                        if(text == '1') {
                            return <span style={{color: 'green'}}>√</span>
                        }else if(text == '0') {
                            return <nobr><span style={{color: 'red'}}>×</span>{record.details != undefined ? <WeaHelpfulTip ecId={`${this && this.props && this.props.ecId || ''}_WeaHelpfulTip@cx3op8`} style={{marginLeft: 10}} width={195} title={record.details}/> : ''}</nobr>
                        }else if(text == '2') {
                            return <nobr><span style={{color: '#FAA825'}}>!</span>{record.details != undefined ? <WeaHelpfulTip ecId={`${this && this.props && this.props.ecId || ''}_WeaHelpfulTip@4iv9mv`} style={{marginLeft: 10}} width={195} title={record.details}/> : ''}</nobr>
                        }
                    }
                })
            }else {
                datas.push({
                    dataIndex: column['dataIndex'],
                    key: column['key'],
                    sorter: column['sorter'],
                    title: column['title']
                })
            }
        })

        return datas;
    }

    getTest = () => {
        const {ldapStore} = this.props;
        const {status} = ldapStore;
        const {testColumns, testTitle, testInitDatas} = toJS(status);
        let group = [];

        for(let key in testInitDatas) {
            let items = [];
            items.push({
                com: (<Row ecId={`${this && this.props && this.props.ecId || ''}_Row@wlyk1a@integrationLdapTestForm${key}`}>
                    <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@j6a01w@integrationLdapTestForm${key}`}
                       columns={this.getColumns(testColumns)}
                       dataSource={testInitDatas[key]}
                       pagination={false}
                    /></Row>),
                colSpan: 1
            })
            group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@m4qr80@integrationLdapTestForm${key}`} col={1} needTigger={true} showGroup={true} title={testTitle[key]} items={items}/>);
       }

        return group;
    }

    getErrorMessage = () => {
        const {ldapStore} = this.props;
        const {status} = ldapStore;
        const {errorMessage} = toJS(status);

        return <h2 style={{color: 'red', textAlign: 'center'}}>{errorMessage}</h2>
    }

    render() {
        const {ldapStore} = this.props;
        const {status, listStore, baseSetStore} = ldapStore;
        const {listApiUrl, baseApiUrl, baseDatas, showBase, showLogDetail, key, baseKey, logDatas, testInitDatas, dialogType, showTestVersion, topinfo, collectinfo, errorMessage} = toJS(status);

        return <div>
            <List ecId={`${this && this.props && this.props.ecId || ''}_List@p6e6q0`} key={key}
                  apiUrl={listApiUrl}
                  listStore={listStore}
                  log={logDatas}
                  onLogClose={() => {
                      ldapStore.setState({
                          logDatas: {
                              show: false,
                              targetId: ''
                          }
                      });
                  }}
                  colums={
                      [
                        {
                            type: 'BTN_EDIT',
                            key: 'ldapid'
                        },
                        {
                          type: 'BTN_EDIT',
                          key: 'formartid'
                        }
                    ]
                  }
                  onMenuClick={this.onListMenuClick}
                  onRowClick={this.onListRowClick}
                  onColumClick={this.onColumClick}
				  onTabListChange={this.onTabListChange}
            />
            <BaseSet ecId={`${this && this.props && this.props.ecId || ''}_BaseSet@zeclvu`}
                ref={r => {
                    ldapStore.ldapRef = r
                }}
                key={baseKey}
                dialogType={dialogType}
                apiUrl={baseApiUrl}
                show={showBase}
                showLogDetail={showLogDetail}
                baseSetStore={baseSetStore}
                datas={baseDatas}
                initTableData={this.initTableData}
                onMenuClick={this.onBaseMenuClick}
                onTabChange={this.onBaseTabChange}
                initTableEdit={this.initBaseTableEdit}
                initCustomColum={this.initBaseTableEditColumn}
                getRowSelection={this.getRowSelection}
                willEdit={this.willEdit}
                onRowClick={this.onListRowClick}
                onColumClick={this.onColumClick}
                onCancel={() => {
                    ldapStore.setState({
                        showBase: false,
                        showLogDetail: false
                    });
                }}
                colums={
                    [
                      {
                          type: 'BTN_DETAIL_LOG',
                          key: 'ldapId'
                      },
                      {
                        type: 'BTN_DETAIL_LOG',
                        key: 'fileName'
                    }
                  ]
                }
            />

            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@kfq169`}
                visible={showTestVersion}
                onCancel={() => ldapStore.setState({showTestVersion: false})}
                hasScroll={true}
                title={topinfo.title}
                icon={topinfo.icon}
                iconBgcolor={topinfo.iconColor}
                style={{width: 800, height: 600}}
                buttons={this.getBtns()}
                moreBtn={this.getMoreBtn().length > 0 ? {
                    datas: this.getMoreBtn(),
                    collectParams: collectinfo
                } : []}
            >
                <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@cwz1xq`}
                    datas={this.getRightMenu()}
                    collectParams={collectinfo}
                >
                    {this.getTab()}
                    <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@406afk`} height={550}>
                        {errorMessage == '' ? this.getTest() : this.getErrorMessage()}
                    </WeaNewScroll>
                </WeaRightMenu>
            </WeaDialog>
        </div>
    }
}