import React from 'react'
import * as mobx from 'mobx'
import {
    inject,
    observer,
} from 'mobx-react'
import {
    WeaTop,
    WeaDropdown,
    WeaRightMenu,
    WeaLeftRightLayout,
} from 'ecCom'
import {
    Row,
    Col,
    Spin,
    Modal,
    Button,
    message,
} from 'antd'
import {
    i18n
} from '../../public/i18n';
import '../../style/area.css'
const toJS = mobx.toJS;
const confirm = Modal.confirm;
const {
    ButtonSelect
} = WeaDropdown;

import LeftTree from './LeftTree'
import NewAndEditDialog from './NewAndEditDialog'
import AreaTable from './AreaTable'
import TabInfo from './TabInfo'
import BriefInfo from './BriefInfo'

import Import from '../importRelatedComponet/index';
import {
    HrmImportCommon
} from '../../stores/importCommon';
const hrmImportCommon = new HrmImportCommon();

@inject('hrmImportCommon')
@inject('hrmAdAreaSet')
@observer
export default class Main extends React.Component {
    constructor(props) {
        super(props);
    }

    componentWillMount() {
        let bool = window.location.href.indexOf('/spa/hrm/engine.html') > -1;
        if (bool) {
            document.title = i18n.module.areaSet();
        }
    }

    componentDidMount() {
        this.init();
    }

    componentWillReceiveProps(nextProps) {
        const {
            hrmAdAreaSet
        } = this.props;

        if (this.props.location.key !== nextProps.location.key) {
            hrmAdAreaSet.orgTreeShValueReset();
            hrmAdAreaSet.setOrgTreeStatus();
            hrmAdAreaSet.formTwoReset();
            hrmAdAreaSet.countrynameReset();
            hrmAdAreaSet.dpIconStatusReset();
            this.handleTreeNodeClick('all', 'tag'); //第二个参数没有实际意义，只是为了不让左侧树刷新
        }
    }

    componentWillUnmount() {
        const {
            hrmAdAreaSet
        } = this.props;

        hrmAdAreaSet.orgTreeShValueReset();
        hrmAdAreaSet.setOrgTreeStatus();
        hrmAdAreaSet.formTwoReset();
        hrmAdAreaSet.countrynameReset();
        hrmAdAreaSet.dpIconStatusReset();
        this.handleTreeNodeClick('all', 'tag'); //第二个参数没有实际意义，只是为了不让左侧树刷新
    }


    init() {
        const {
            hrmAdAreaSet
        } = this.props;

        hrmAdAreaSet.setOperation('getTable'); //设置接下来操作的类型
        hrmAdAreaSet.setFuncName('getCountryList');
        hrmAdAreaSet.getTable();
    }

    //列表中的编辑按钮
    getEditForm(id) {
        const {
            hrmAdAreaSet
        } = this.props, {
            type
        } = hrmAdAreaSet;

        hrmAdAreaSet.setFormType('edit');
        hrmAdAreaSet.setVisible(true);

        if (type == 'all') {
            hrmAdAreaSet.setDialogTitle(i18n.label.editCountry());
            hrmAdAreaSet.setCountryId(id);
            hrmAdAreaSet.setOperation('edit');
            hrmAdAreaSet.setFuncName('getCountryForm');
            hrmAdAreaSet.getForm();
        }
        if (type == 'country') {
            hrmAdAreaSet.setDialogTitle(i18n.label.editProvince());
            hrmAdAreaSet.setProvinceId(id);
            hrmAdAreaSet.setOperation('edit');
            hrmAdAreaSet.setFuncName('getProvinceForm');
            hrmAdAreaSet.getForm();
        }
        if (type == 'province') {
            hrmAdAreaSet.setDialogTitle(i18n.label.editCity());
            hrmAdAreaSet.setCityId(id);
            hrmAdAreaSet.setOperation('edit');
            hrmAdAreaSet.setFuncName('getCityForm');
            hrmAdAreaSet.getForm();
        }
        if (type == 'city') {
            hrmAdAreaSet.setDialogTitle(i18n.label.editCityTwo());
            hrmAdAreaSet.setCountyId(id);
            hrmAdAreaSet.setOperation('edit');
            hrmAdAreaSet.setFuncName('getCityTwoForm');
            hrmAdAreaSet.getForm();
        }
    }

    //封存
    seal(id) {
        const {
            hrmAdAreaSet
        } = this.props, {
            type,
            selectedKey,
            selectedRows,
            isDisplayBlock
        } = hrmAdAreaSet;

        hrmAdAreaSet.setCancelFlag(0);

        if (id) {
            type == 'all' && hrmAdAreaSet.setCountryId(id);
            type == 'country' && hrmAdAreaSet.setProvinceId(id);
            type == 'province' && hrmAdAreaSet.setCityId(id);
            type == 'city' && hrmAdAreaSet.setCountyId(id);
        } else {
            if (!selectedRows && (type == 'all' || selectedKey == '1')) {
                this.getSealOrUnsealTip();
                return;
            }
        }
        this.showConfirm('seal', id);
    }

    //解封
    unseal(id) {
        const {
            hrmAdAreaSet
        } = this.props, {
            type,
            selectedKey,
            selectedRows
        } = hrmAdAreaSet;

        if (id) {
            type == 'all' && hrmAdAreaSet.setCountryId(id);
            type == 'country' && hrmAdAreaSet.setProvinceId(id);
            type == 'province' && hrmAdAreaSet.setCityId(id);
            type == 'city' && hrmAdAreaSet.setCountyId(id);
        } else {
            if (!selectedRows && (type == 'all' || selectedKey == '1')) {
                this.getSealOrUnsealTip();
                return;
            }
        }

        hrmAdAreaSet.setCancelFlag(1);
        hrmAdAreaSet.setOperation('sealOrUnseal');
        hrmAdAreaSet.sealOrUnseal();
    }

    getSealOrUnsealTip() {
        const {
            hrmAdAreaSet
        } = this.props, {
            type,
            selectedKey,
            isBatchSeal
        } = hrmAdAreaSet;

        if (type == 'all') {
            isBatchSeal ? message.warning('请选择要封存的国家！') : message.warning('请选择要解封的国家！');
        }
        if (type == 'country' && selectedKey == '1') {
            isBatchSeal ? message.warning('请选择要封存的省份！') : message.warning('请选择要解封的省份！');
        }
        if ((type == 'province' && selectedKey == '1')) {
            isBatchSeal ? message.warning('请选择要封存的城市！') : message.warning('请选择要解封的城市！');
        }
        if ((type == 'city' && selectedKey == '1')) {
            isBatchSeal ? message.warning('请选择要封存的区县！') : message.warning('请选择要解封的区县！');
        }
    }
    //删除表格的一行或者多行数据
    deleteRows(id) {
        const {
            hrmAdAreaSet
        } = this.props, {
            type,
            selectedRows,
            selectedKey
        } = hrmAdAreaSet;

        //删除单行（删除多行的ids，通过setSelectedRow()方法设置）
        if (id) {
            type == 'all' && hrmAdAreaSet.setCountryId(id);
            type == 'country' && hrmAdAreaSet.setProvinceId(id);
            type == 'province' && hrmAdAreaSet.setCityId(id);
            type == 'city' && hrmAdAreaSet.setCountyId(id);
            hrmAdAreaSet.setOperation('delete');
        } else {
            if (selectedKey == '0') {
                if (type !== 'all') {
                    hrmAdAreaSet.setOperation('delete');
                } else {
                    if (!selectedRows) {
                        this.getDeleteTip();
                        return;
                    } else {
                        hrmAdAreaSet.setOperation('batch_delete');
                    }
                }
            } else {
                if (!selectedRows) {
                    this.getDeleteTip();
                    return;
                } else {
                    hrmAdAreaSet.setOperation('batch_delete');
                }
            }
        }
        let v = id ? 'del' : 'batchDel';
        this.showConfirm(v);
    }

    getDeleteTip() {
        const {
            hrmAdAreaSet
        } = this.props, {
            type,
            countryId,
            provinceId,
            cityId,
            countyId
        } = hrmAdAreaSet;

        type == 'all' && message.warning('请选择要删除的国家！');
        type == 'country' && message.warning('请选择要删除的省份！');
        type == 'province' && message.warning('请选择要删除的城市！');
        type == 'city' && message.warning('请选择要删除的区县！');
    }

    //删除确认框
    showConfirm(type, id) {
        let _this = this;
        let obj = {
            title: i18n.confirm.defaultTitle(),
            okText: i18n.button.ok(),
            cancelText: i18n.button.cancel(),
            onOk() {
                _this.onOk(type, id);
            },
            onCancel() {
                return false;
            },
        }
        let func = (type == 'del') ? 'delete' : (type == 'batchDel') ? 'batchDeleteConfirm' : 'cancelSelected';
        obj.content = i18n.confirm[func]();
        confirm(obj);
    }

    onOk(_type, id) {
        const {
            hrmAdAreaSet
        } = this.props, {
            type,
            selectedKey,
            isDisplayBlock
        } = hrmAdAreaSet;

        if (_type == 'del' || _type == 'batchDel') {
            if (type == 'all' || (type == 'country' && selectedKey == '0')) {
                hrmAdAreaSet.setFuncName('deleteCountry');
                hrmAdAreaSet.delete();
                type == 'country' && this.handleTreeNodeClick('all');
            }
            if ((type == 'country' && selectedKey == '1') || (type == 'province' && selectedKey == '0')) {
                hrmAdAreaSet.setFuncName('deleteProvince');
                hrmAdAreaSet.delete();
                type == 'province' && this.handleTreeNodeClick('country');
            }
            if ((type == 'province' && selectedKey == '1') || (type == 'city' && selectedKey == '0')) {
                hrmAdAreaSet.setFuncName('deleteCity');
                hrmAdAreaSet.delete();
                type == 'city' && this.handleTreeNodeClick('province');
            }
            if ((type == 'city' && selectedKey == '1') || type == 'citytwo') {
                hrmAdAreaSet.setFuncName('deleteCityTwo');
                hrmAdAreaSet.delete();
                type == 'citytwo' && this.handleTreeNodeClick('city');
            }

        }
        if (_type == 'seal') {
            hrmAdAreaSet.setOperation('sealOrUnseal');
            hrmAdAreaSet.sealOrUnseal();
            !id && selectedKey == '0' && isDisplayBlock == '0' && this.handleTreeNodeClick('all');
        }
    }

    //"高级搜索"中的搜索按钮、显示封存和不显示封存数据按钮
    search(arg) {
        const {
            hrmAdAreaSet
        } = this.props, {
            type,
            isPanelShow
        } = hrmAdAreaSet;

        if (arg == 'dpIcon') {
            hrmAdAreaSet.setDisplayBlockStatus();
            hrmAdAreaSet.setTableLinkToTreeStatus(true);
            hrmAdAreaSet.setDpIconNeedResetStatus(false);
            this.handleTreeNodeClick('all'); //封存后跳转到初始页面
        }

        hrmAdAreaSet.setOperation('getTable'); //设置操作的类型
        this.getTable();

        isPanelShow && hrmAdAreaSet.setPanelStatus(false);

        type == 'citytwo' && hrmAdAreaSet.setTreeRefresh();
    }

    onSearchChange(val) {
        const {
            hrmAdAreaSet
        } = this.props, {
            type,
            form2
        } = hrmAdAreaSet;

        (type == 'all' || type == 'country') && !this.isEmptyObject(form2.getFormParams()) && hrmAdAreaSet.updateFields(val);
        type == 'all' && hrmAdAreaSet.setCountryName(val);
        type == 'country' && hrmAdAreaSet.setProvinceName(val);
        type == 'province' && hrmAdAreaSet.setCityName(val);
        type == 'city' && hrmAdAreaSet.setCityTwoName(val);
    }

    isEmptyObject(obj) {
        for (let key in obj) {
            if (!obj[key]) return true;
            return false;
        }
        return true;
    }


    //获取到表格中选中行id值的集合
    setSelectedRow() {
        const {
            hrmAdAreaSet
        } = this.props, {
            tableStore,
            type
        } = hrmAdAreaSet;

        let keys = toJS(tableStore.selectedRowKeys).toString();
        hrmAdAreaSet.setSelectRows(keys);
    }
    //处理左侧树点击事件
    handleTreeNodeClick(type, id) {
        const {
            hrmAdAreaSet
        } = this.props, {
            countryId,
            provinceId,
            cityId,
            countyId,
            isDpIconNeedReset
        } = hrmAdAreaSet;

        isDpIconNeedReset && hrmAdAreaSet.dpIconStatusReset(); //是否需要重置封存、解封图标状态
        hrmAdAreaSet.setType(type); //设置当前点击节点的类型
        hrmAdAreaSet.selectedKeyReset(); //重置tab页签
        hrmAdAreaSet.batchKeyReset(); //重置batchKey
        hrmAdAreaSet.setPanelStatus(false); //关闭高级搜索下拉面板
        hrmAdAreaSet.formTwoReset();
        hrmAdAreaSet.countrynameReset();

        //设置对应的ID
        type == 'all' && this.init();
        type == 'country' && id && hrmAdAreaSet.setCountryId(id);
        type == 'province' && id && hrmAdAreaSet.setProvinceId(id);
        type == 'city' && id && hrmAdAreaSet.setCityId(id);
        type == 'citytwo' && id && hrmAdAreaSet.setCountyId(id);

        //获取左侧树节点的基本信息 
        if (type !== 'all') {
            hrmAdAreaSet.setOperation('getBriefInfo');
            hrmAdAreaSet.getBriefInfo();
        }
        //点击面包屑时，刷新左侧树
        !id && hrmAdAreaSet.setTreeRefresh();
    }

    //新建国家
    newCountry() {
        const {
            hrmAdAreaSet
        } = this.props;

        hrmAdAreaSet.setDialogTitle(i18n.label.newCountry());
        hrmAdAreaSet.setFormType('new'); //设置保存的类型：新建
        hrmAdAreaSet.setNewType('country'); //设置新建的种类：国家
        hrmAdAreaSet.setOperation('new'); //设置这次操作的类型：新建。
        hrmAdAreaSet.setFuncName('getCountryForm');
        hrmAdAreaSet.getForm();
        hrmAdAreaSet.setVisible(true);
    }
    //新建省份
    newProvince() {
        const {
            hrmAdAreaSet
        } = this.props;

        hrmAdAreaSet.setDialogTitle(i18n.label.newProvince());
        hrmAdAreaSet.setFormType('new');
        hrmAdAreaSet.setNewType('province');
        hrmAdAreaSet.setOperation('new');
        hrmAdAreaSet.setFuncName('getProvinceForm');
        hrmAdAreaSet.getForm();
        hrmAdAreaSet.setVisible(true);
    }
    //新建城市
    newCity() {
        const {
            hrmAdAreaSet
        } = this.props;

        hrmAdAreaSet.setDialogTitle(i18n.label.newCity());
        hrmAdAreaSet.setFormType('new');
        hrmAdAreaSet.setNewType('city');
        hrmAdAreaSet.setOperation('new');
        hrmAdAreaSet.setFuncName('getCityForm');
        hrmAdAreaSet.getForm();
        hrmAdAreaSet.setVisible(true);
    }
    //新建区县
    newCounty() {
        const {
            hrmAdAreaSet
        } = this.props;

        hrmAdAreaSet.setDialogTitle(i18n.label.newCityTwo());
        hrmAdAreaSet.setFormType('new');
        hrmAdAreaSet.setNewType('citytwo');
        hrmAdAreaSet.setOperation('new');
        hrmAdAreaSet.setFuncName('getCityTwoForm');
        hrmAdAreaSet.getForm();
        hrmAdAreaSet.setVisible(true);
    }
    //"编辑"按钮
    edit() {
        const {
            hrmAdAreaSet
        } = this.props, {
            type
        } = hrmAdAreaSet;

        hrmAdAreaSet.setFormType('edit');
        hrmAdAreaSet.setOperation('edit');

        let dialogTitle;
        if (type == 'country') {
            dialogTitle=i18n.label.editCountry();
            hrmAdAreaSet.setFuncName('getCountryForm');
            hrmAdAreaSet.getForm();
        }
        if (type == 'province') {
             dialogTitle=i18n.label.editProvince();
            hrmAdAreaSet.setFuncName('getProvinceForm');
            hrmAdAreaSet.getForm();
        }
        if (type == 'city') {
            dialogTitle=i18n.label.editCity();
            hrmAdAreaSet.setFuncName('getCityForm');
            hrmAdAreaSet.getForm();
        }
        if (type == 'citytwo') {
            dialogTitle=i18n.label.editCityTwo();
            hrmAdAreaSet.setFuncName('getCityTwoForm');
            hrmAdAreaSet.getForm();
        }
        hrmAdAreaSet.setDialogTitle(dialogTitle);
         hrmAdAreaSet.setVisible(true);


    }

    //保存
    save() {
        const {
            hrmAdAreaSet
        } = this.props, {
            type,
            formType,
            newType,
            selectedKey
        } = hrmAdAreaSet;

        formType == 'new' && hrmAdAreaSet.setOperation('save_new'); //新建保存
        formType == 'edit' && hrmAdAreaSet.setOperation('save_edit'); //编辑保存
        if (type == 'all') {
            if (formType == 'new') {
                hrmAdAreaSet.setFuncName('addCountry');
                hrmAdAreaSet.add();
            } else {
                hrmAdAreaSet.setFuncName('editCountry');
                hrmAdAreaSet.edit();
            }
        }
        if (type == 'country') {
            if (selectedKey == '0') {
                if (formType == 'new' && newType == 'country') {
                    hrmAdAreaSet.setFuncName('addCountry');
                    hrmAdAreaSet.add();
                }
                if (formType == 'new' && newType == 'province') {
                    hrmAdAreaSet.setFuncName('addProvince');
                    hrmAdAreaSet.add();
                }
                if (formType == 'edit') {
                    hrmAdAreaSet.setFuncName('editCountry');
                    hrmAdAreaSet.edit();
                }
            } else {
                if (formType == 'new') {
                    hrmAdAreaSet.setFuncName('addProvince');
                    hrmAdAreaSet.add();
                } else {
                    hrmAdAreaSet.setFuncName('editProvince');
                    hrmAdAreaSet.edit();
                }
            }
        }
        if (type == 'province') {
            if (selectedKey == '0') {
                if (formType == 'new' && newType == 'province') {
                    hrmAdAreaSet.setFuncName('addProvince');
                    hrmAdAreaSet.add();
                }
                if (formType == 'new' && newType == 'city') {
                    hrmAdAreaSet.setFuncName('addCity');
                    hrmAdAreaSet.add();
                }
                if (formType == 'edit') {
                    hrmAdAreaSet.setFuncName('editProvince');
                    hrmAdAreaSet.edit();
                }
            } else {
                if (formType == 'new') {
                    hrmAdAreaSet.setFuncName('addCity');
                    hrmAdAreaSet.add();
                } else {
                    hrmAdAreaSet.setFuncName('editCity');
                    hrmAdAreaSet.edit();
                }
            }
        }
        if (type == 'city') {
            if (selectedKey == '0') {
                if (formType == 'new' && newType == 'city') {
                    hrmAdAreaSet.setFuncName('addCity');
                    hrmAdAreaSet.add();
                }
                if (formType == 'new' && newType == 'citytwo') {
                    hrmAdAreaSet.setFuncName('addCityTwo');
                    hrmAdAreaSet.add();
                }
                if (formType == 'edit') {
                    hrmAdAreaSet.setFuncName('editCity');
                    hrmAdAreaSet.edit();
                }
            } else {
                if (formType == 'new') {
                    hrmAdAreaSet.setFuncName('addCityTwo');
                    hrmAdAreaSet.add();
                } else {
                    hrmAdAreaSet.setFuncName('editCityTwo');
                    hrmAdAreaSet.edit();
                }
            }
        }
        if (type == 'citytwo') {
            if (formType == 'new') {
                hrmAdAreaSet.setFuncName('addCityTwo');
                hrmAdAreaSet.add();
            } else {
                hrmAdAreaSet.setFuncName('editCityTwo');
                hrmAdAreaSet.edit();
            }
        }
    }

    //导入
    import () {
        const {
            hrmImportCommon,
        } = this.props, {
            setTempletName,
            setImportDialogTitle,
            setImportType,
            setImportDialogVisible,
            setImportPage,
        } = hrmImportCommon;

        setTempletName(i18n.label.importTemplate());
        setImportDialogTitle(i18n.button.areaInfoImport());
        setImportType('area');
        setImportDialogVisible(true);
        //设置标识，标识当前是那个页面在导入
        setImportPage(this.props.location.pathname.split('/').pop());
    }

    //导入文件提交
    submit() {
        const {
            hrmAdAreaSet
        } = this.props;

        hrmAdAreaSet.setOperation('import_submit');
        hrmAdAreaSet.importInfoSubmit();
    }
    //获取WeaTop组件的按钮
    getTopMenuBtns() {
        const {
            hrmAdAreaSet
        } = this.props, {
            topMenu
        } = hrmAdAreaSet;

        let btns = [];
        topMenu.map((item, i) => {
            btns.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@9jr4qh@${i}`} type='primary' onClick={() => this.handleClick(item)}>{item.menuName}</Button>);
        });

        return btns;
    }

    handleClick(item) {
        const {
            hrmAdAreaSet
        } = this.props, {
            isPanelShow
        } = hrmAdAreaSet;

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

    handleBtnSelectClick(key) {
        const {
            hrmAdAreaSet
        } = this.props, {
            isPanelShow
        } = hrmAdAreaSet;

        isPanelShow && hrmAdAreaSet.setPanelStatus(false);
        if (key == '0') {
            hrmAdAreaSet.setIsBatchSealStatus(true);
            this.setSelectedRow();
            this.seal('');
        }
        if (key == '1') {
            hrmAdAreaSet.setIsBatchSealStatus(false);
            this.setSelectedRow();
            this.unseal('');
        }
        if (key == '2') {
            this.setSelectedRow();
            this.deleteRows();
        }
    }

    getSearchsBaseValue() {
        const {
            hrmAdAreaSet
        } = this.props, {
            type,
            form2,
            countryname,
            provincename
        } = hrmAdAreaSet;

        let val;
        if (type == 'all') {
            if (this.isEmptyObject(form2.getFormParams())) {
                val = countryname;
            } else {
                val = form2.getFormParams().countryname;
            }
        }
        if (type == 'country') {
            if (this.isEmptyObject(form2.getFormParams())) {
                val = provincename;
            } else {
                val = form2.getFormParams().provincename
            }
        }

        return val;
    }

    //点击表格中的td(效果和点击左侧树节点效果一样)
    //isTabSwitch参数控制跳转后的当前tab页
    tdClick(params) {
        const {
            hrmAdAreaSet
        } = this.props;
        let type = params.indexTo;
        let id = params.id;
        this.handleTreeNodeClick(type, id);
        params.isTabSwitch && hrmAdAreaSet.setSelectedKey('1');
    }

    //历史导入记录查询
    importHistoryQuery() {
        const {
            hrmAdAreaSet
        } = this.props;

        hrmAdAreaSet.setOperation('import_info_query');
        hrmAdAreaSet.getImportHistory();
    }

    getLeftCom() {
        const {
            hrmAdAreaSet
        } = this.props, {
            isDisplayBlock,
            treeRefresh,
            orgTreeShValue,
            isOrgTreeShow
        } = hrmAdAreaSet;

        return (
            <LeftTree ecId={`${this && this.props && this.props.ecId || ''}_LeftTree@ox9a03`}
                isDisplayBlock={isDisplayBlock}
                treeRefresh={treeRefresh}
                orgTreeShValue={orgTreeShValue}
                isOrgTreeShow={isOrgTreeShow}
                ltSearchChange={val => this.ltSearchChange(val)}
                treeNodeClick={(type, id) => this.handleTreeNodeClick(type, id)}
            />
        )
    }

    ltSearchChange(val) {
        const {
            hrmAdAreaSet
        } = this.props;

        hrmAdAreaSet.setOrgTreeShValue(val);
    }

    //获取WeaTop组件的Breadcrumb
    getBreadcrumb() {
        const {
            hrmAdAreaSet
        } = this.props, {
            type,
            curCountry,
            curProvince,
            curCity,
            curCounty
        } = hrmAdAreaSet;

        let breadcrumb;

        if (type == 'all') breadcrumb = [{
            name: i18n.module.areaSet()
        }];
        if (type == 'country') {
            breadcrumb = [{
                name: i18n.module.areaSet(),
                onClick: () => this.handleTreeNodeClick('all')
            }, {
                name: curCountry
            }];
        }
        if (type == 'province') {
            breadcrumb = [{
                name: curCountry,
                onClick: () => this.handleTreeNodeClick('country')
            }, {
                name: curProvince
            }];
        }
        if (type == 'city') {
            breadcrumb = [{
                name: curProvince,
                onClick: () => this.handleTreeNodeClick('province')
            }, {
                name: curCity
            }];
        }
        if (type == 'citytwo') {
            breadcrumb = [{
                name: curCity,
                onClick: () => this.handleTreeNodeClick('city')
            }, {
                name: curCounty
            }];
        }
        return breadcrumb;
    }

    getDropMenuDatas() {
        const {
            hrmAdAreaSet
        } = this.props, {
            rightMenu
        } = hrmAdAreaSet;

        let menus = [];
        toJS(rightMenu).map((item, index) => {
            if (item.menuFun === "batchDelete") return;
            let obj = {
                key: item.menuFun,
                icon: <i className={`${item.menuIcon}`}/>,
                content: item.menuName,
            }
            if (item.menuFun == 'collection' || item.menuFun == 'help' || item.menuFun == 'pageAddress') {
                obj.disabled = true;
            }
            menus.push(obj);
        })

        return menus;
    }

    log = () => {
        const {
            hrmAdAreaSet
        } = this.props, {
            type
        } = hrmAdAreaSet;

        window.setLogViewProps({
            logSmallType: (type == 'all') ? '3006' : (type == 'country') ? '3007' : (type == 'province') ? '3008' : '3009',
        });
    }

    custom = () => {
        const {
            hrmAdAreaSet
        } = this.props, {
            tableStore,
        } = hrmAdAreaSet;

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

    getButtonSelect() {
        const {
            hrmAdAreaSet
        } = this.props, {
            buttonSelect,
            tableStore,
            batchKey
        } = hrmAdAreaSet;

        if (buttonSelect.length > 0) {
            return (<ButtonSelect ecId={`${this && this.props && this.props.ecId || ''}_ButtonSelect@dcwtao`}
                        selectedKey={batchKey}
                        datas={buttonSelect}
                        btnProps={{disabled: tableStore.selectedRowKeys.length > 0 ? false : true}}
                        btnOnClick={key => this.handleBtnSelectClick(key)}
                        menuOnClick={key => this.handleMenuOnClick(key)}
                    />)
        } else {
            return []
        }

    }

    handleMenuOnClick(key) {
        const {
            hrmAdAreaSet
        } = this.props, {
            type,
            isPanelShow
        } = hrmAdAreaSet;

        isPanelShow && hrmAdAreaSet.setPanelStatus(false);
        hrmAdAreaSet.setBatchKey(key);
        hrmAdAreaSet.setOperation('getTable');

        this.getTable();
    }

    getTable() {
        const {
            hrmAdAreaSet
        } = this.props, {
            type
        } = hrmAdAreaSet;

        if (type == 'all') {
            hrmAdAreaSet.setFuncName('getCountryList');
            hrmAdAreaSet.getTable();
        }
        if (type == 'country') {
            hrmAdAreaSet.setFuncName('getProvinceList');
            hrmAdAreaSet.getTable();
        }
        if (type == 'province') {
            hrmAdAreaSet.setFuncName('getCityList');
            hrmAdAreaSet.getTable();
        }
        if (type == 'city') {
            hrmAdAreaSet.setFuncName('getCityTwoList');
            hrmAdAreaSet.getTable();
        }
    }

    getIconBtn() {
        const {
            hrmAdAreaSet
        } = this.props, {
            hasDpIcon,
            isDisplayBlock
        } = hrmAdAreaSet;

        if (hasDpIcon) {
            return (<div style={{paddingTop: 8}}>
                        <a onClick={() => this.search('dpIcon')} style={{fontSize: 23, textDecoration:'none'}} title={(isDisplayBlock == 1) ? i18n.label.hideCanceledOrg() : i18n.label.showCanceledOrg()}>{ (isDisplayBlock == 1) ? <i className='icon-coms-Department-number' style={{color: '#2DB7F5'}}/> : <i className='icon-coms-Department-number-hide' style={{color: '#8A8A8A'}}/>}</a>
                    </div>)
        } else {
            return [];
        }
    }

    //右键菜单点击事件
    handleMenuClick(key) {
        const {
            hrmAdAreaSet
        } = this.props, {
            isPanelShow
        } = hrmAdAreaSet;

        isPanelShow && hrmAdAreaSet.setPanelStatus(false);
        this[key] && this[key]();
    }

    //获取tab项的名称
    getTabName() {
        const {
            hrmAdAreaSet
        } = this.props, {
            type
        } = hrmAdAreaSet;

        let tabName;

        if (type == 'country') {
            tabName = [{
                key: '0',
                title: i18n.label.countryInfo()
            }, {
                key: '1',
                title: i18n.label.lowerProvince()
            }, ]
        }
        if (type == 'province') {
            tabName = [{
                key: '0',
                title: i18n.label.provinceInfo()
            }, {
                key: '1',
                title: i18n.label.lowerCity()
            }, ]
        }
        if (type == 'city') {
            tabName = [{
                key: '0',
                title: i18n.label.cityInfo()
            }, {
                key: '1',
                title: i18n.label.lowerCityTwo()
            }, ]
        }

        return tabName;
    }

    getSearchType() {
        const {
            hrmAdAreaSet
        } = this.props, {
            type,
            selectedKey
        } = hrmAdAreaSet;

        if (type == 'all' || (type == 'country' && selectedKey == '1')) {
            return ['base', 'advanced'];
        }
        if ((type == 'province' || type == 'city') && selectedKey == '1') {
            return ['base'];
        }
    }

    handleAdSearchClick(bool) {
        const {
            hrmAdAreaSet
        } = this.props;

        if (bool) {
            hrmAdAreaSet.setPanelStatus(true);
            hrmAdAreaSet.setOperation('search');
            hrmAdAreaSet.getSearchCondition();
        } else {
            hrmAdAreaSet.setPanelStatus(false);
        }
    }

    getWeaTopButtons() {
        return this.getTopMenuBtns().concat(this.getButtonSelect()).concat(this.getIconBtn())
    }

    jumpToImportResult(id) {
        const {
            hrmAdAreaSet
        } = this.props;

        hrmAdAreaSet.setPid(id);
        hrmAdAreaSet.setOperation('import_info');
        hrmAdAreaSet.getImportResult();
    }

    queryImportLog() {
        const {
            hrmAdAreaSet
        } = this.props;

        hrmAdAreaSet.setOperation('import_log');
        hrmAdAreaSet.getImportLogDetail();
        hrmAdAreaSet.setOperation('import_log_searchCondition');
        hrmAdAreaSet.getImportLogSearchCondition();
    }

    importLogSearch() {
        const {
            hrmAdAreaSet
        } = this.props;

        hrmAdAreaSet.setOperation('import_log');
        hrmAdAreaSet.getImportLogDetail();
    }

    batchDelete = () => {
        this.setSelectedRow();
        this.deleteRows();
    }

    render() {
        const {
            hrmAdAreaSet
        } = this.props;
        const {
            dialogTitle,
            visible,
            form,
            form2,
            condition,
            tableStore,
            type,
            isPanelShow,
            selectedKey,
            briefInfo,
            buttonSelect,
            newEditDialogLoading,
            searchConditionLoading,
            date,
            mpLoading,
            isDisplayBlock,
            treeRefresh,
            orgTreeShValue,
            isOrgTreeShow
        } = hrmAdAreaSet;

        const {
            hrmImportCommon
        } = this.props, {
            importDialog
        } = hrmImportCommon;

        const len = condition.length > 0 && condition[0].items.length;

        return (
            <div ref='page'>
                <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@6a3tgh`} 
                    datas={this.getDropMenuDatas()} 
                    onClick={ (key) => this.handleMenuClick(key)}
                    collectParams={{favname:i18n.module.areaSet(),favouritetype:5}}
                >
      		        <Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@s080w1`} spinning={mpLoading} size='large'>
                        <WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@tbameg`} 
                            breadcrumb={this.getBreadcrumb()}
                            icon={<i className='icon-coms-hrm' />}
                            iconBgcolor='#217346'
                            loading={true}
                            buttons={this.getWeaTopButtons()}
                            showDropIcon={true}
                            dropMenuDatas={this.getDropMenuDatas()}
                            onDropMenuClick={(key) => this.handleMenuClick(key)}
                        >
                        <WeaLeftRightLayout ecId={`${this && this.props && this.props.ecId || ''}_WeaLeftRightLayout@c66l5m`} 
                            isNew={true}
                            leftCom={<LeftTree ecId={`${this && this.props && this.props.ecId || ''}_LeftTree@owz2z5`} 
                                isDisplayBlock={isDisplayBlock}
                                treeRefresh={treeRefresh}
                                orgTreeShValue={orgTreeShValue}
                                isOrgTreeShow={isOrgTreeShow}
                                ltSearchChange={val => this.ltSearchChange(val)}
                                treeNodeClick={(type, id) => this.handleTreeNodeClick(type, id)}
                            />}
                        >
                        {  type !== 'citytwo' ?     <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@9gs11y`}>
                                                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@9u13n1`}>
                                                            <TabInfo ecId={`${this && this.props && this.props.ecId || ''}_TabInfo@dw9oc2`}
                                                                condition={toJS(condition)}
                                                                form={form2}
                                                                isFormInit={form2.isFormInit}
                                                                isPanelShow={isPanelShow}
                                                                loading={searchConditionLoading}
                                                                tabName={this.getTabName()}
                                                                searchType={this.getSearchType()}
                                                                searchsBaseValue={this.getSearchsBaseValue()}
                                                                selectedKey={selectedKey}
                                                                search={() => this.search()}
                                                                onSearchChange={(val) => this.onSearchChange(val)}
                                                                setPanelStatus={ b => this.handleAdSearchClick(b)}
                                                                setSelectedKey={(key) => hrmAdAreaSet.setSelectedKey(key)}
                                                            />
                                                        </Col>
                                                    </Row> : ''}
                        { type !== 'all' && selectedKey == '0' ? <BriefInfo ecId={`${this && this.props && this.props.ecId || ''}_BriefInfo@vo2a0m`} datas={toJS(briefInfo)} />   :   <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@vhr6pp`}>
                                                                                                                <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@96zf3w`}>
                                                                                                                    <AreaTable ecId={`${this && this.props && this.props.ecId || ''}_AreaTable@0c582p`} 
                                                                                                                        tableStore={tableStore}
                                                                                                                        type={type}
                                                                                                                        seal={ id => this.seal(id)}
                                                                                                                        unseal={ id => this.unseal(id)}
                                                                                                                        getEditForm={(id) => this.getEditForm(id)}
                                                                                                                        deleteRows={(id) => this.deleteRows(id)}
                                                                                                                        tdClick={ params => this.tdClick(params)}
                                                                                                                    />
                                                                                                                </Col>
                                                                                                            </Row>}
                    </WeaLeftRightLayout>
                </WeaTop>
                </Spin>
            </WeaRightMenu>
            <NewAndEditDialog ecId={`${this && this.props && this.props.ecId || ''}_NewAndEditDialog@zd1w01`} 
                title={dialogTitle}
                visible={visible}
                condition={toJS(condition)}
                form={form}
                isFormInit={form.isFormInit}
                loading={newEditDialogLoading}
                isEdit={true}
                date={date}
                height={ (len < 3) ? 140 : (len == 3) ? 180 : 215}
                conditionLen={1}
                save={() => this.save()}
                onCancel={() => hrmAdAreaSet.setVisible(false)}
            />
            {importDialog.visible && <Import ecId={`${this && this.props && this.props.ecId || ''}_Import@mawvx7`} />}
        </div>
        )
    }
}