"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _comp = require("../../ui/src/comp");
var _xeUtils = _interopRequireDefault(require("xe-utils"));
var _ui = require("../../ui");
var _dom = require("../../ui/src/dom");
var _utils = require("../../ui/src/utils");
var _log = require("../../ui/src/log");
var _vn = require("../../ui/src/vn");
var _input = _interopRequireDefault(require("../../input"));
var _button = _interopRequireDefault(require("../../button"));
var _tree = _interopRequireDefault(require("../../tree"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var _createComponentLog = (0, _log.createComponentLog)('tree-select'),
  warnLog = _createComponentLog.warnLog,
  errLog = _createComponentLog.errLog;
function getOptUniqueId() {
  return _xeUtils.default.uniqueId('node_');
}
function createReactData() {
  return {
    initialized: false,
    searchValue: '',
    searchLoading: false,
    panelIndex: 0,
    panelStyle: {},
    panelPlacement: null,
    triggerFocusPanel: false,
    visiblePanel: false,
    isAniVisible: false,
    isActivated: false,
    fullOptFlag: 1,
    lazyOptFlag: 1
  };
}
function createInternalData() {
  return {
    // hpTimeout: undefined,
    fullOptionList: [],
    fullNodeMaps: {},
    lazyNodeMaps: {}
  };
}
var _default2 = exports.default = /* define-vxe-component start */(0, _comp.defineVxeComponent)({
  name: 'VxeTreeSelect',
  mixins: [_ui.globalMixins.sizeMixin],
  model: {
    prop: 'value',
    event: 'modelValue'
  },
  props: {
    value: [String, Number, Array],
    clearable: {
      type: Boolean,
      default: function _default() {
        return (0, _ui.getConfig)().treeSelect.clearable;
      }
    },
    placeholder: {
      type: String,
      default: function _default() {
        return _xeUtils.default.eqNull((0, _ui.getConfig)().treeSelect.placeholder) ? (0, _ui.getI18n)('vxe.base.pleaseSelect') : (0, _ui.getConfig)().treeSelect.placeholder;
      }
    },
    readonly: {
      type: Boolean,
      default: null
    },
    loading: Boolean,
    disabled: {
      type: Boolean,
      default: null
    },
    showFullLabel: {
      type: Boolean,
      default: function _default() {
        return (0, _ui.getConfig)().treeSelect.showFullLabel;
      }
    },
    separator: {
      type: String,
      default: function _default() {
        return (0, _ui.getConfig)().treeSelect.separator;
      }
    },
    filterable: Boolean,
    filterConfig: Object,
    multiple: Boolean,
    className: [String, Function],
    /**
     * 已废弃，请使用 popupConfig.className
     * @deprecated
     */
    popupClassName: [String, Function],
    prefixIcon: String,
    placement: String,
    lazyOptions: Array,
    options: Array,
    optionProps: Object,
    /**
     * 已废弃，请使用 popupConfig.zIndex
     * @deprecated
     */
    zIndex: Number,
    size: {
      type: String,
      default: function _default() {
        return (0, _ui.getConfig)().treeSelect.size || (0, _ui.getConfig)().size;
      }
    },
    remote: Boolean,
    remoteConfig: Function,
    showRadio: {
      type: Boolean,
      default: function _default() {
        return (0, _ui.getConfig)().treeSelect.showRadio;
      }
    },
    radioConfig: Object,
    showCheckbox: {
      type: Boolean,
      default: function _default() {
        return (0, _ui.getConfig)().treeSelect.showCheckbox;
      }
    },
    checkboxConfig: Object,
    popupConfig: Object,
    treeConfig: Object,
    menuConfig: Object,
    virtualYConfig: Object,
    /**
     * 已废弃，被 checked-closable, clear-closable 替换
     * @deprecated
     */
    autoClose: {
      type: Boolean,
      default: function _default() {
        return (0, _ui.getConfig)().treeSelect.autoClose;
      }
    },
    checkedClosable: {
      type: Boolean,
      default: function _default() {
        return (0, _ui.getConfig)().treeSelect.checkedClosable;
      }
    },
    clearClosable: {
      type: Boolean,
      default: function _default() {
        return (0, _ui.getConfig)().treeSelect.clearClosable;
      }
    },
    showCloseButton: {
      type: Boolean,
      default: function _default() {
        return (0, _ui.getConfig)().treeSelect.showCloseButton;
      }
    },
    showTotalButton: {
      type: Boolean,
      default: function _default() {
        return (0, _ui.getConfig)().treeSelect.showTotalButton;
      }
    },
    showCheckedButton: {
      type: Boolean,
      default: function _default() {
        return (0, _ui.getConfig)().treeSelect.showCheckedButton;
      }
    },
    showClearButton: {
      type: Boolean,
      default: function _default() {
        return (0, _ui.getConfig)().treeSelect.showClearButton;
      }
    },
    showExpandButton: {
      type: Boolean,
      default: function _default() {
        return (0, _ui.getConfig)().treeSelect.showExpandButton;
      }
    },
    transfer: {
      type: Boolean,
      default: null
    },
    /**
     * 已废弃，被 remote-config.queryMethod 替换
     * @deprecated
     */
    remoteMethod: Function
  },
  inject: {
    $xeModal: {
      default: null
    },
    $xeDrawer: {
      default: null
    },
    $xeTable: {
      default: null
    },
    $xeForm: {
      default: null
    },
    formItemInfo: {
      from: 'xeFormItemInfo',
      default: null
    }
  },
  provide: function provide() {
    var $xeTreeSelect = this;
    return {
      $xeTreeSelect: $xeTreeSelect
    };
  },
  data: function data() {
    var xID = _xeUtils.default.uniqueId();
    var reactData = createReactData();
    return Object.assign(Object.assign({}, {}), {
      xID: xID,
      reactData: reactData
    });
  },
  computed: Object.assign(Object.assign({}, {}), {
    computeFormReadonly: function computeFormReadonly() {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      var $xeForm = $xeTreeSelect.$xeForm;
      var readonly = props.readonly;
      if (readonly === null) {
        if ($xeForm) {
          return $xeForm.readonly;
        }
        return false;
      }
      return readonly;
    },
    computeIsDisabled: function computeIsDisabled() {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      var $xeForm = $xeTreeSelect.$xeForm;
      var disabled = props.disabled;
      if (disabled === null) {
        if ($xeForm) {
          return $xeForm.disabled;
        }
        return false;
      }
      return disabled;
    },
    computeBtnTransfer: function computeBtnTransfer() {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      var $xeTable = $xeTreeSelect.$xeTable;
      var $xeModal = $xeTreeSelect.$xeModal;
      var $xeDrawer = $xeTreeSelect.$xeDrawer;
      var $xeForm = $xeTreeSelect.$xeForm;
      var popupOpts = $xeTreeSelect.computePopupOpts;
      var transfer = popupOpts.transfer;
      if (_xeUtils.default.isBoolean(transfer)) {
        return transfer;
      }
      if (props.transfer === null) {
        var globalTransfer = (0, _ui.getConfig)().treeSelect.transfer;
        if (_xeUtils.default.isBoolean(globalTransfer)) {
          return globalTransfer;
        }
        if ($xeTable || $xeModal || $xeDrawer || $xeForm) {
          return true;
        }
      }
      return props.transfer;
    },
    computePopupOpts: function computePopupOpts() {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      return Object.assign({}, (0, _ui.getConfig)().treeSelect.popupConfig, props.popupConfig);
    },
    computeTreeOpts: function computeTreeOpts() {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      return Object.assign({}, (0, _ui.getConfig)().treeSelect.treeConfig, props.treeConfig);
    },
    computeMenuOpts: function computeMenuOpts() {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      return Object.assign({}, (0, _ui.getConfig)().treeSelect.menuConfig, props.menuConfig);
    },
    computeTreeNodeOpts: function computeTreeNodeOpts() {
      var $xeTreeSelect = this;
      var treeOpts = $xeTreeSelect.computeTreeOpts;
      return Object.assign({
        isHover: true
      }, treeOpts.nodeConfig);
    },
    computeTreeCheckboxOpts: function computeTreeCheckboxOpts() {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      var showCheckbox = props.showCheckbox,
        checkboxConfig = props.checkboxConfig;
      var treeOpts = $xeTreeSelect.computeTreeOpts;
      return Object.assign({
        showIcon: _xeUtils.default.isBoolean(showCheckbox) ? showCheckbox : !!treeOpts.showCheckbox
      }, treeOpts.checkboxConfig, checkboxConfig, {
        trigger: 'node'
      });
    },
    computeTreeRadioOpts: function computeTreeRadioOpts() {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      var showRadio = props.showRadio,
        radioConfig = props.radioConfig;
      var treeOpts = $xeTreeSelect.computeTreeOpts;
      return Object.assign({
        showIcon: _xeUtils.default.isBoolean(showRadio) ? showRadio : !!treeOpts.showRadio
      }, treeOpts.radioConfig, radioConfig, {
        trigger: 'node'
      });
    },
    computePropsOpts: function computePropsOpts() {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      return Object.assign({}, (0, _ui.getConfig)().treeSelect.optionProps, props.optionProps);
    },
    computeNodeKeyField: function computeNodeKeyField() {
      var $xeTreeSelect = this;
      var treeOpts = $xeTreeSelect.computeTreeOpts;
      return treeOpts.keyField || 'id';
    },
    computeLabelField: function computeLabelField() {
      var $xeTreeSelect = this;
      var propsOpts = $xeTreeSelect.computePropsOpts;
      return propsOpts.label || 'label';
    },
    computeValueField: function computeValueField() {
      var $xeTreeSelect = this;
      var propsOpts = $xeTreeSelect.computePropsOpts;
      return propsOpts.value || 'value';
    },
    computeChildrenField: function computeChildrenField() {
      var $xeTreeSelect = this;
      var propsOpts = $xeTreeSelect.computePropsOpts;
      return propsOpts.children || 'children';
    },
    computeNodeParentField: function computeNodeParentField() {
      var $xeTreeSelect = this;
      var propsOpts = $xeTreeSelect.computePropsOpts;
      var treeOpts = $xeTreeSelect.computeTreeOpts;
      return propsOpts.parent || treeOpts.parentField || 'parentId';
    },
    computeHasChildField: function computeHasChildField() {
      var $xeTreeSelect = this;
      var propsOpts = $xeTreeSelect.computePropsOpts;
      return propsOpts.hasChild || 'hasChild';
    },
    computeVirtualYOpts: function computeVirtualYOpts() {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      return Object.assign({}, (0, _ui.getConfig)().treeSelect.virtualYConfig, props.virtualYConfig);
    },
    computeRemoteOpts: function computeRemoteOpts() {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      return Object.assign({}, (0, _ui.getConfig)().treeSelect.remoteConfig, props.remoteConfig);
    },
    computeFilterOpts: function computeFilterOpts() {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      var treeOpts = $xeTreeSelect.computeTreeOpts;
      return Object.assign({}, treeOpts.filterConfig, props.filterConfig);
    },
    computeSelectVals: function computeSelectVals() {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      var modelValue = props.value;
      return _xeUtils.default.eqNull(modelValue) ? [] : _xeUtils.default.isArray(modelValue) ? modelValue : [modelValue];
    },
    computeSelectLabel: function computeSelectLabel() {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      var reactData = $xeTreeSelect.reactData;
      var internalData = $xeTreeSelect.internalData;
      var showFullLabel = props.showFullLabel;
      var fullOptFlag = reactData.fullOptFlag,
        lazyOptFlag = reactData.lazyOptFlag;
      var fullNodeMaps = internalData.fullNodeMaps,
        lazyNodeMaps = internalData.lazyNodeMaps;
      var labelField = $xeTreeSelect.computeLabelField;
      var selectVals = $xeTreeSelect.computeSelectVals;
      return selectVals.map(function (val) {
        var cacheItem = fullNodeMaps[val];
        if (fullOptFlag && cacheItem) {
          return showFullLabel ? cacheItem.fullLabel : cacheItem.item[labelField];
        }
        if (lazyOptFlag) {
          var lazyCacheItem = lazyNodeMaps[val];
          if (lazyCacheItem) {
            return showFullLabel ? lazyCacheItem.fullLabel : lazyCacheItem.item[labelField];
          }
        }
        return val;
      }).join(', ');
    },
    computePopupWrapperStyle: function computePopupWrapperStyle() {
      var $xeTreeSelect = this;
      var popupOpts = $xeTreeSelect.computePopupOpts;
      var height = popupOpts.height,
        width = popupOpts.width;
      var stys = {};
      if (width) {
        stys.width = (0, _dom.toCssUnit)(width);
      }
      if (height) {
        stys.height = (0, _dom.toCssUnit)(height);
        stys.maxHeight = (0, _dom.toCssUnit)(height);
      }
      return stys;
    }
  }),
  methods: {
    //
    // Method
    //
    dispatchEvent: function dispatchEvent(type, params, evnt) {
      var $xeTreeSelect = this;
      $xeTreeSelect.$emit(type, (0, _ui.createEvent)(evnt, {
        $treeSelect: $xeTreeSelect
      }, params));
    },
    emitModel: function emitModel(value) {
      var $xeTreeSelect = this;
      var _events = $xeTreeSelect._events;
      if (_events && _events.modelValue) {
        $xeTreeSelect.$emit('modelValue', value);
      } else {
        $xeTreeSelect.$emit('model-value', value);
      }
    },
    callSlot: function callSlot(slotFunc, params, h) {
      var $xeTreeSelect = this;
      var slots = $xeTreeSelect.$scopedSlots;
      if (slotFunc) {
        if (_xeUtils.default.isString(slotFunc)) {
          slotFunc = slots[slotFunc] || null;
        }
        if (_xeUtils.default.isFunction(slotFunc)) {
          return (0, _vn.getSlotVNs)(slotFunc.call($xeTreeSelect, params, h));
        }
      }
      return [];
    },
    getNodeid: function getNodeid(option) {
      var $xeTreeSelect = this;
      var nodeKeyField = $xeTreeSelect.computeNodeKeyField;
      var nodeid = option[nodeKeyField];
      return nodeid ? encodeURIComponent(nodeid) : '';
    },
    handleCacheMap: function handleCacheMap(optList) {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      var separator = props.separator;
      var treeOpts = $xeTreeSelect.computeTreeOpts;
      var nodeKeyField = $xeTreeSelect.computeNodeKeyField;
      var nodeParentField = $xeTreeSelect.computeNodeParentField;
      var childrenField = $xeTreeSelect.computeChildrenField;
      var valueField = $xeTreeSelect.computeValueField;
      var labelField = $xeTreeSelect.computeLabelField;
      var transform = treeOpts.transform;
      var nodeMaps = {};
      var keyMaps = {};
      var handleOptNode = function handleOptNode(item, index, items, path, parentItem, nodes) {
        var nodeid = $xeTreeSelect.getNodeid(item);
        if (!nodeid) {
          nodeid = getOptUniqueId();
        }
        if (keyMaps[nodeid]) {
          errLog('vxe.error.repeatKey', [nodeKeyField, nodeid]);
        }
        keyMaps[nodeid] = true;
        var value = item[valueField];
        if (nodeMaps[value]) {
          errLog('vxe.error.repeatKey', [valueField, value]);
        }
        nodeMaps[value] = {
          item: item,
          index: index,
          items: items,
          parent: parentItem,
          nodes: nodes,
          fullLabel: nodes.map(function (item) {
            return item[labelField];
          }).join(separator || ' / ')
        };
      };
      if (optList) {
        if (transform) {
          // if (showFullLabel) {
          var treeList = _xeUtils.default.toArrayTree(optList, {
            key: nodeKeyField,
            parentKey: nodeParentField,
            mapChildren: childrenField,
            rootParentValue: treeOpts.rootParentValue,
            rootValues: treeOpts.rootValues
          });
          _xeUtils.default.eachTree(treeList, handleOptNode, {
            children: childrenField
          });
          // } else {
          //   optList.forEach((item, index, items) => {
          //     handleOptNode(item, index, items, [], null, [])
          //   })
          // }
        } else {
          _xeUtils.default.eachTree(optList, handleOptNode, {
            children: childrenField
          });
        }
      }
      return nodeMaps;
    },
    cacheDataMap: function cacheDataMap() {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      var reactData = $xeTreeSelect.reactData;
      var internalData = $xeTreeSelect.internalData;
      var options = props.options;
      internalData.fullNodeMaps = $xeTreeSelect.handleCacheMap(options || []);
      internalData.fullOptionList = options || [];
      reactData.fullOptFlag++;
    },
    cacheLazyDataMap: function cacheLazyDataMap() {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      var reactData = $xeTreeSelect.reactData;
      var internalData = $xeTreeSelect.internalData;
      var lazyOptions = props.lazyOptions;
      internalData.lazyNodeMaps = $xeTreeSelect.handleCacheMap(lazyOptions || []);
      reactData.lazyOptFlag++;
    },
    updateZindex: function updateZindex() {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      var reactData = $xeTreeSelect.reactData;
      var popupOpts = $xeTreeSelect.computePopupOpts;
      var customZIndex = popupOpts.zIndex || props.zIndex;
      if (customZIndex) {
        reactData.panelIndex = _xeUtils.default.toNumber(customZIndex);
      } else if (reactData.panelIndex < (0, _utils.getLastZIndex)()) {
        reactData.panelIndex = (0, _utils.nextZIndex)();
      }
    },
    updatePlacement: function updatePlacement() {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      var reactData = $xeTreeSelect.reactData;
      var placement = props.placement;
      var panelIndex = reactData.panelIndex;
      var targetElem = $xeTreeSelect.$refs.refElem;
      var panelElem = $xeTreeSelect.$refs.refOptionPanel;
      var btnTransfer = $xeTreeSelect.computeBtnTransfer;
      var popupOpts = $xeTreeSelect.computePopupOpts;
      var handleStyle = function handleStyle() {
        var ppObj = (0, _dom.updatePanelPlacement)(targetElem, panelElem, {
          placement: popupOpts.placement || placement,
          defaultPlacement: popupOpts.defaultPlacement,
          teleportTo: btnTransfer
        });
        var panelStyle = Object.assign(ppObj.style, {
          zIndex: panelIndex
        });
        reactData.panelStyle = panelStyle;
        reactData.panelPlacement = ppObj.placement;
      };
      handleStyle();
      return $xeTreeSelect.$nextTick().then(handleStyle);
    },
    showOptionPanel: function showOptionPanel(evnt) {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      var reactData = $xeTreeSelect.reactData;
      var internalData = $xeTreeSelect.internalData;
      var loading = props.loading,
        remote = props.remote,
        filterable = props.filterable;
      var fullOptionList = internalData.fullOptionList;
      var isDisabled = $xeTreeSelect.computeIsDisabled;
      var remoteOpts = $xeTreeSelect.computeRemoteOpts;
      if (!loading && !isDisabled) {
        if (internalData.hpTimeout) {
          clearTimeout(internalData.hpTimeout);
        }
        if (!reactData.initialized) {
          reactData.initialized = true;
          var btnTransfer = $xeTreeSelect.computeBtnTransfer;
          var panelElem = $xeTreeSelect.$refs.refOptionPanel;
          if (btnTransfer) {
            if (panelElem) {
              document.body.appendChild(panelElem);
            }
          }
        }
        reactData.isActivated = true;
        reactData.isAniVisible = true;
        if (filterable) {
          if (remote && remoteOpts.enabled && remoteOpts.autoLoad && !fullOptionList.length) {
            $xeTreeSelect.handleSearchEvent();
          }
        }
        setTimeout(function () {
          reactData.visiblePanel = true;
          $xeTreeSelect.handleFocusSearch();
          $xeTreeSelect.updatePlacement();
        }, 10);
        $xeTreeSelect.updateZindex();
        $xeTreeSelect.updatePlacement();
        $xeTreeSelect.dispatchEvent('visible-change', {
          visible: true
        }, evnt || null);
      }
    },
    hideOptionPanel: function hideOptionPanel(evnt) {
      var $xeTreeSelect = this;
      var reactData = $xeTreeSelect.reactData;
      var internalData = $xeTreeSelect.internalData;
      reactData.visiblePanel = false;
      internalData.hpTimeout = setTimeout(function () {
        reactData.isAniVisible = false;
      }, 350);
      $xeTreeSelect.dispatchEvent('visible-change', {
        visible: false
      }, evnt || null);
    },
    changeEvent: function changeEvent(evnt, selectValue, node) {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      var $xeForm = $xeTreeSelect.$xeForm;
      var formItemInfo = $xeTreeSelect.formItemInfo;
      var value = _xeUtils.default.isArray(selectValue) ? selectValue.map(_utils.deModelValue) : (0, _utils.deModelValue)(selectValue);
      $xeTreeSelect.emitModel(value);
      if (value !== props.value) {
        $xeTreeSelect.dispatchEvent('change', {
          value: value,
          node: node,
          option: node
        }, evnt);
        // 自动更新校验状态
        if ($xeForm && formItemInfo) {
          $xeForm.triggerItemEvent(evnt, formItemInfo.itemConfig.field, value);
        }
      }
    },
    clearValueEvent: function clearValueEvent(evnt, selectValue) {
      var $xeTreeSelect = this;
      $xeTreeSelect.changeEvent(evnt, selectValue, null);
      $xeTreeSelect.dispatchEvent('clear', {
        value: selectValue
      }, evnt);
    },
    clearEvent: function clearEvent(params) {
      var $xeTreeSelect = this;
      var $event = params.$event;
      $xeTreeSelect.clearValueEvent($event, null);
      $xeTreeSelect.hideOptionPanel($event);
    },
    allCheckedPanelEvent: function allCheckedPanelEvent(params) {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      var $event = params.$event;
      var multiple = props.multiple,
        autoClose = props.autoClose,
        checkedClosable = props.checkedClosable;
      var $tree = $xeTreeSelect.$refs.refTree;
      if (multiple) {
        if ($tree) {
          $tree.setAllCheckboxNode(true).then(function (_ref) {
            var checkNodeKeys = _ref.checkNodeKeys,
              checkNodes = _ref.checkNodes;
            $xeTreeSelect.changeEvent($event, checkNodeKeys, checkNodes[0]);
            $xeTreeSelect.dispatchEvent('all-change', {
              value: checkNodeKeys
            }, $event);
            if (_xeUtils.default.isBoolean(checkedClosable) ? checkedClosable : autoClose) {
              $xeTreeSelect.hideOptionPanel($event);
            }
          });
        }
      }
    },
    clearCheckedPanelEvent: function clearCheckedPanelEvent(params) {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      var $event = params.$event;
      var multiple = props.multiple,
        autoClose = props.autoClose,
        clearClosable = props.clearClosable;
      var $tree = $xeTreeSelect.$refs.refTree;
      if ($tree) {
        var value = multiple ? [] : null;
        $tree.clearCheckboxNode().then(function () {
          if (_xeUtils.default.isBoolean(clearClosable) ? clearClosable : autoClose) {
            $xeTreeSelect.hideOptionPanel($event);
          }
        });
        $xeTreeSelect.changeEvent($event, value, null);
        $xeTreeSelect.dispatchEvent('clear', {
          value: value
        }, $event);
      }
    },
    closePanelEvent: function closePanelEvent(params) {
      var $xeTreeSelect = this;
      var $event = params.$event;
      $xeTreeSelect.hideOptionPanel($event);
    },
    allExpandPanelEvent: function allExpandPanelEvent() {
      var $xeTreeSelect = this;
      var $tree = $xeTreeSelect.$refs.refTree;
      if ($tree) {
        $tree.setAllExpandNode(true);
      }
    },
    clearExpandPanelEvent: function clearExpandPanelEvent() {
      var $xeTreeSelect = this;
      var $tree = $xeTreeSelect.$refs.refTree;
      if ($tree) {
        $tree.clearAllExpandNode();
      }
    },
    handleGlobalMousewheelEvent: function handleGlobalMousewheelEvent(evnt) {
      var $xeTreeSelect = this;
      var reactData = $xeTreeSelect.reactData;
      var visiblePanel = reactData.visiblePanel;
      var isDisabled = $xeTreeSelect.computeIsDisabled;
      if (!isDisabled) {
        if (visiblePanel) {
          var panelElem = $xeTreeSelect.$refs.refOptionPanel;
          if ((0, _dom.getEventTargetNode)(evnt, panelElem).flag) {
            $xeTreeSelect.updatePlacement();
          } else {
            $xeTreeSelect.hideOptionPanel(evnt);
          }
        }
      }
    },
    handleGlobalMousedownEvent: function handleGlobalMousedownEvent(evnt) {
      var $xeTreeSelect = this;
      var reactData = $xeTreeSelect.reactData;
      var visiblePanel = reactData.visiblePanel;
      var isDisabled = $xeTreeSelect.computeIsDisabled;
      if (!isDisabled) {
        var el = $xeTreeSelect.$refs.refElem;
        var panelElem = $xeTreeSelect.$refs.refOptionPanel;
        reactData.isActivated = (0, _dom.getEventTargetNode)(evnt, el).flag || (0, _dom.getEventTargetNode)(evnt, panelElem).flag;
        if (visiblePanel && !reactData.isActivated) {
          $xeTreeSelect.hideOptionPanel(evnt);
        }
      }
    },
    handleGlobalBlurEvent: function handleGlobalBlurEvent(evnt) {
      var $xeTreeSelect = this;
      var reactData = $xeTreeSelect.reactData;
      var visiblePanel = reactData.visiblePanel,
        isActivated = reactData.isActivated;
      if (visiblePanel) {
        $xeTreeSelect.hideOptionPanel(evnt);
      }
      if (isActivated) {
        reactData.isActivated = false;
      }
      if (visiblePanel || isActivated) {
        var $input = $xeTreeSelect.$refs.refInput;
        if ($input) {
          $input.blur();
        }
      }
    },
    handleGlobalResizeEvent: function handleGlobalResizeEvent() {
      var $xeTreeSelect = this;
      var reactData = $xeTreeSelect.reactData;
      var visiblePanel = reactData.visiblePanel;
      if (visiblePanel) {
        $xeTreeSelect.updatePlacement();
      }
    },
    handleFocusSearch: function handleFocusSearch() {
      var $xeSelect = this;
      var props = $xeSelect;
      if (props.filterable) {
        $xeSelect.$nextTick(function () {
          var inpSearch = $xeSelect.$refs.refInpSearch;
          if (inpSearch) {
            inpSearch.focus();
          }
        });
      }
    },
    focusEvent: function focusEvent(evnt) {
      var $xeTreeSelect = this;
      var reactData = $xeTreeSelect.reactData;
      var isDisabled = $xeTreeSelect.computeIsDisabled;
      if (!isDisabled) {
        if (!reactData.visiblePanel) {
          reactData.triggerFocusPanel = true;
          $xeTreeSelect.showOptionPanel(evnt);
          setTimeout(function () {
            reactData.triggerFocusPanel = false;
          }, 150);
        }
      }
      $xeTreeSelect.dispatchEvent('focus', {}, evnt);
    },
    clickEvent: function clickEvent(evnt) {
      var $xeTreeSelect = this;
      $xeTreeSelect.togglePanelEvent(evnt);
      $xeTreeSelect.dispatchEvent('click', {}, evnt);
    },
    blurEvent: function blurEvent(evnt) {
      var $xeTreeSelect = this;
      var reactData = $xeTreeSelect.reactData;
      reactData.isActivated = false;
      $xeTreeSelect.dispatchEvent('blur', {}, evnt);
    },
    modelSearchEvent: function modelSearchEvent(value) {
      var $xeTreeSelect = this;
      var reactData = $xeTreeSelect.reactData;
      reactData.searchValue = value;
    },
    handleSearchEvent: function handleSearchEvent() {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      var reactData = $xeTreeSelect.reactData;
      var modelValue = props.value,
        remote = props.remote,
        remoteMethod = props.remoteMethod;
      var searchValue = reactData.searchValue;
      var remoteOpts = $xeTreeSelect.computeRemoteOpts;
      var queryMethod = remoteOpts.queryMethod || remoteMethod;
      if (remote && queryMethod && remoteOpts.enabled) {
        reactData.searchLoading = true;
        Promise.resolve(queryMethod({
          $treeSelect: $xeTreeSelect,
          searchValue: searchValue,
          value: modelValue
        })).then(function () {
          return $xeTreeSelect.$nextTick();
        }).catch(function () {
          return $xeTreeSelect.$nextTick();
        }).finally(function () {
          reactData.searchLoading = false;
        });
      }
    },
    togglePanelEvent: function togglePanelEvent(params) {
      var $xeTreeSelect = this;
      var reactData = $xeTreeSelect.reactData;
      var $event = params.$event;
      $event.preventDefault();
      if (reactData.triggerFocusPanel) {
        reactData.triggerFocusPanel = false;
      } else {
        if (reactData.visiblePanel) {
          $xeTreeSelect.hideOptionPanel($event);
        } else {
          $xeTreeSelect.showOptionPanel($event);
        }
      }
    },
    nodeExpandEvent: function nodeExpandEvent() {
      var $xeTreeSelect = this;
      $xeTreeSelect.updatePlacement();
    },
    nodeClickEvent: function nodeClickEvent(params) {
      var $xeTreeSelect = this;
      var $event = params.$event;
      $xeTreeSelect.dispatchEvent('node-click', params, $event);
    },
    radioChangeEvent: function radioChangeEvent(params) {
      var $xeTreeSelect = this;
      var value = params.value,
        $event = params.$event,
        node = params.node;
      $xeTreeSelect.changeEvent($event, value, node);
      $xeTreeSelect.hideOptionPanel($event);
    },
    checkboxChangeEvent: function checkboxChangeEvent(params) {
      var $xeTreeSelect = this;
      var value = params.value,
        $event = params.$event,
        node = params.node;
      $xeTreeSelect.changeEvent($event, value, node);
    },
    loadSuccessEvent: function loadSuccessEvent() {
      var $xeTreeSelect = this;
      $xeTreeSelect.cacheDataMap();
    },
    //
    // Render
    //
    renderVN: function renderVN(h) {
      var $xeTreeSelect = this;
      var props = $xeTreeSelect;
      var slots = $xeTreeSelect.$scopedSlots;
      var reactData = $xeTreeSelect.reactData;
      var className = props.className,
        modelValue = props.value,
        multiple = props.multiple,
        options = props.options,
        loading = props.loading,
        menuConfig = props.menuConfig,
        filterable = props.filterable,
        showTotalButton = props.showTotalButton,
        showCheckedButton = props.showCheckedButton,
        showClearButton = props.showClearButton,
        showExpandButton = props.showExpandButton,
        showCloseButton = props.showCloseButton;
      var initialized = reactData.initialized,
        isActivated = reactData.isActivated,
        isAniVisible = reactData.isAniVisible,
        visiblePanel = reactData.visiblePanel,
        searchValue = reactData.searchValue;
      var vSize = $xeTreeSelect.computeSize;
      var isDisabled = $xeTreeSelect.computeIsDisabled;
      var selectLabel = $xeTreeSelect.computeSelectLabel;
      var btnTransfer = $xeTreeSelect.computeBtnTransfer;
      var formReadonly = $xeTreeSelect.computeFormReadonly;
      var popupWrapperStyle = $xeTreeSelect.computePopupWrapperStyle;
      var headerSlot = slots.header;
      var footerSlot = slots.footer;
      var prefixSlot = slots.prefix;
      var popupOpts = $xeTreeSelect.computePopupOpts;
      var ppClassName = popupOpts.className || props.popupClassName;
      if (formReadonly) {
        return h('div', {
          ref: 'refElem',
          class: ['vxe-tree-select--readonly', className]
        }, [h('span', {
          class: 'vxe-tree-select-label'
        }, selectLabel)]);
      }
      var treeOpts = $xeTreeSelect.computeTreeOpts;
      var menuOpts = $xeTreeSelect.computeMenuOpts;
      var treeNodeOpts = $xeTreeSelect.computeTreeNodeOpts;
      var treeCheckboxOpts = $xeTreeSelect.computeTreeCheckboxOpts;
      var treeRadioOpts = $xeTreeSelect.computeTreeRadioOpts;
      var nodeKeyField = $xeTreeSelect.computeNodeKeyField;
      var labelField = $xeTreeSelect.computeLabelField;
      var valueField = $xeTreeSelect.computeValueField;
      var childrenField = $xeTreeSelect.computeChildrenField;
      var nodeParentField = $xeTreeSelect.computeNodeParentField;
      var hasChildField = $xeTreeSelect.computeHasChildField;
      var virtualYOpts = $xeTreeSelect.computeVirtualYOpts;
      var filterOpts = $xeTreeSelect.computeFilterOpts;
      var treeSlots = treeOpts.slots;
      var selectVals = _xeUtils.default.eqNull(modelValue) ? [] : _xeUtils.default.isArray(modelValue) ? modelValue : [modelValue];
      var treeScopedSlots = {};
      if (treeSlots) {
        var treeIconSlot = treeSlots.icon,
          treeTitleSlot = treeSlots.title,
          treeExtraSlot = treeSlots.extra;
        if (treeIconSlot) {
          treeScopedSlots.icon = function (slotParams) {
            return $xeTreeSelect.callSlot(treeIconSlot, slotParams, h);
          };
        }
        if (treeTitleSlot) {
          treeScopedSlots.title = function (slotParams) {
            return $xeTreeSelect.callSlot(treeTitleSlot, slotParams, h);
          };
        }
        if (treeExtraSlot) {
          treeScopedSlots.extra = function (slotParams) {
            return $xeTreeSelect.callSlot(treeExtraSlot, slotParams, h);
          };
        }
      }
      return h('div', {
        ref: 'refElem',
        class: ['vxe-tree-select', className ? _xeUtils.default.isFunction(className) ? className({
          $treeSelect: $xeTreeSelect
        }) : className : '', _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "size--".concat(vSize), vSize), 'is--filterable', filterable), 'is--visible', visiblePanel), 'is--disabled', isDisabled), 'is--loading', loading), 'is--active', isActivated)]
      }, [h(_input.default, {
        ref: 'refInput',
        props: {
          clearable: props.clearable,
          placeholder: props.placeholder,
          editable: false,
          disabled: isDisabled,
          type: 'text',
          prefixIcon: props.prefixIcon,
          suffixIcon: loading ? (0, _ui.getIcon)().TREE_SELECT_LOADED : visiblePanel ? (0, _ui.getIcon)().TREE_SELECT_OPEN : (0, _ui.getIcon)().TREE_SELECT_CLOSE,
          value: loading ? (0, _ui.getI18n)('vxe.select.loadingText') : selectLabel,
          title: selectLabel
        },
        on: {
          clear: $xeTreeSelect.clearEvent,
          click: $xeTreeSelect.clickEvent,
          focus: $xeTreeSelect.focusEvent,
          blur: $xeTreeSelect.blurEvent,
          'suffix-click': $xeTreeSelect.togglePanelEvent
        },
        scopedSlots: prefixSlot ? {
          prefix: function prefix() {
            return prefixSlot({});
          }
        } : {}
      }), h('div', {
        ref: 'refOptionPanel',
        class: ['vxe-table--ignore-clear vxe-tree-select--panel', ppClassName ? _xeUtils.default.isFunction(ppClassName) ? ppClassName({
          $treeSelect: $xeTreeSelect
        }) : ppClassName : '', _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "size--".concat(vSize), vSize), 'is--transfer', btnTransfer), 'ani--leave', !loading && isAniVisible), 'ani--enter', !loading && visiblePanel)],
        attrs: {
          placement: reactData.panelPlacement
        },
        style: reactData.panelStyle
      }, initialized ? [h('div', {
        class: 'vxe-tree-select--panel-wrapper'
      }, [filterable ? h('div', {
        class: 'vxe-tree-select--panel-search'
      }, [h(_input.default, {
        ref: 'refInpSearch',
        class: 'vxe-tree-select-search--input',
        props: {
          value: searchValue,
          title: selectLabel,
          clearable: true,
          disabled: false,
          readonly: false,
          placeholder: (0, _ui.getI18n)('vxe.treeSelect.search'),
          prefixIcon: (0, _ui.getIcon)().INPUT_SEARCH
        },
        on: {
          'model-value': $xeTreeSelect.modelSearchEvent
        }
      })]) : (0, _ui.renderEmptyElement)($xeTreeSelect), showCheckedButton && multiple || showClearButton || showExpandButton || headerSlot ? h('div', {
        class: 'vxe-tree-select--panel-header'
      }, headerSlot ? headerSlot({}) : [h('div', {
        class: 'vxe-tree-select--header-button'
      }, [showCheckedButton && multiple || showClearButton ? h('div', {
        class: 'vxe-tree-select--selected-btns'
      }, [showCheckedButton && multiple ? h(_button.default, {
        props: {
          content: (0, _ui.getI18n)('vxe.treeSelect.allChecked'),
          mode: 'text'
        },
        on: {
          click: $xeTreeSelect.allCheckedPanelEvent
        }
      }) : (0, _ui.renderEmptyElement)($xeTreeSelect), showClearButton ? h(_button.default, {
        props: {
          content: (0, _ui.getI18n)('vxe.treeSelect.clearChecked'),
          mode: 'text'
        },
        on: {
          click: $xeTreeSelect.clearCheckedPanelEvent
        }
      }) : (0, _ui.renderEmptyElement)($xeTreeSelect)]) : (0, _ui.renderEmptyElement)($xeTreeSelect), showExpandButton ? h('div', {
        class: 'vxe-tree-select--expand-btns'
      }, [h(_button.default, {
        props: {
          content: (0, _ui.getI18n)('vxe.treeSelect.allExpand'),
          mode: 'text'
        },
        on: {
          click: $xeTreeSelect.allExpandPanelEvent
        }
      }), h(_button.default, {
        props: {
          content: (0, _ui.getI18n)('vxe.treeSelect.clearExpand'),
          mode: 'text'
        },
        on: {
          click: $xeTreeSelect.clearExpandPanelEvent
        }
      })]) : (0, _ui.renderEmptyElement)($xeTreeSelect)])]) : (0, _ui.renderEmptyElement)($xeTreeSelect), h('div', {
        class: 'vxe-tree-select--panel-body'
      }, [h('div', {
        ref: 'refTreeWrapper',
        class: 'vxe-tree-select-tree--wrapper',
        style: popupWrapperStyle
      }, [h(_tree.default, {
        ref: 'refTree',
        class: 'vxe-tree-select--tree',
        props: {
          data: options,
          height: popupOpts.height ? '100%' : treeOpts.height,
          minHeight: treeOpts.minHeight,
          maxHeight: popupOpts.height ? '' : treeOpts.maxHeight,
          autoResize: true,
          indent: treeOpts.indent,
          showRadio: !multiple,
          radioConfig: treeRadioOpts,
          checkNodeKey: multiple ? null : modelValue,
          showCheckbox: !!multiple,
          checkNodeKeys: multiple ? modelValue : null,
          checkboxConfig: treeCheckboxOpts,
          titleField: labelField,
          valueField: valueField,
          keyField: nodeKeyField,
          childrenField: treeOpts.childrenField || childrenField,
          parentField: nodeParentField,
          hasChildField: treeOpts.hasChildField || hasChildField,
          accordion: treeOpts.accordion,
          expandAll: treeOpts.expandAll,
          expandNodeKeys: treeOpts.expandNodeKeys,
          nodeConfig: treeNodeOpts,
          lazy: treeOpts.lazy,
          loadMethod: treeOpts.loadMethod,
          toggleMethod: treeOpts.toggleMethod,
          transform: treeOpts.transform,
          rootParentValue: treeOpts.rootParentValue,
          rootValues: treeOpts.rootValues,
          trigger: treeOpts.trigger,
          showIcon: treeOpts.showIcon,
          showLine: treeOpts.showLine,
          iconOpen: treeOpts.iconOpen,
          iconLoaded: treeOpts.iconLoaded,
          iconClose: treeOpts.iconClose,
          filterValue: searchValue,
          filterConfig: filterOpts,
          menuConfig: menuConfig ? menuOpts : undefined,
          virtualYConfig: virtualYOpts
        },
        on: {
          'node-expand': $xeTreeSelect.nodeExpandEvent,
          'node-click': $xeTreeSelect.nodeClickEvent,
          'radio-change': $xeTreeSelect.radioChangeEvent,
          'checkbox-change': $xeTreeSelect.checkboxChangeEvent,
          'load-success': $xeTreeSelect.loadSuccessEvent
        },
        scopedSlots: treeScopedSlots
      })])]), footerSlot || showTotalButton || showCloseButton ? h('div', {
        class: 'vxe-tree-select--panel-footer'
      }, footerSlot ? footerSlot({}) : [h('div', {
        class: 'vxe-tree-select--footer-button'
      }, [showTotalButton ? h('div', {
        class: 'vxe-tree-select--total-btns'
      }, (0, _ui.getI18n)('vxe.treeSelect.total', [selectVals.length])) : (0, _ui.renderEmptyElement)($xeTreeSelect), showCloseButton ? h('div', {
        class: 'vxe-tree-select--oper-btns'
      }, [h(_button.default, {
        props: {
          content: (0, _ui.getI18n)('vxe.select.close'),
          mode: 'text'
        },
        on: {
          click: $xeTreeSelect.closePanelEvent
        }
      })]) : (0, _ui.renderEmptyElement)($xeTreeSelect)])]) : (0, _ui.renderEmptyElement)($xeTreeSelect)])] : [])]);
    }
  },
  watch: {
    options: function options() {
      var $xeTreeSelect = this;
      $xeTreeSelect.cacheDataMap();
    },
    lazyOptions: function lazyOptions() {
      var $xeTreeSelect = this;
      $xeTreeSelect.cacheLazyDataMap();
    }
  },
  created: function created() {
    var $xeTreeSelect = this;
    $xeTreeSelect.internalData = createInternalData();
    $xeTreeSelect.cacheDataMap();
    $xeTreeSelect.cacheLazyDataMap();
  },
  mounted: function mounted() {
    var $xeTreeSelect = this;
    var props = $xeTreeSelect;
    if (_xeUtils.default.isBoolean(props.autoClose)) {
      warnLog('vxe.error.delProp', ['auto-close', 'checked-closable | clear-closable']);
    }
    _ui.globalEvents.on($xeTreeSelect, 'mousewheel', $xeTreeSelect.handleGlobalMousewheelEvent);
    _ui.globalEvents.on($xeTreeSelect, 'mousedown', $xeTreeSelect.handleGlobalMousedownEvent);
    _ui.globalEvents.on($xeTreeSelect, 'blur', $xeTreeSelect.handleGlobalBlurEvent);
    _ui.globalEvents.on($xeTreeSelect, 'resize', $xeTreeSelect.handleGlobalResizeEvent);
  },
  beforeDestroy: function beforeDestroy() {
    var $xeTreeSelect = this;
    var reactData = $xeTreeSelect.reactData;
    var internalData = $xeTreeSelect.internalData;
    var panelElem = $xeTreeSelect.$refs.refOptionPanel;
    if (panelElem && panelElem.parentNode) {
      panelElem.parentNode.removeChild(panelElem);
    }
    _ui.globalEvents.off($xeTreeSelect, 'mousewheel');
    _ui.globalEvents.off($xeTreeSelect, 'mousedown');
    _ui.globalEvents.off($xeTreeSelect, 'blur');
    _ui.globalEvents.off($xeTreeSelect, 'resize');
    _xeUtils.default.assign(reactData, createReactData());
    _xeUtils.default.assign(internalData, createInternalData());
  },
  render: function render(h) {
    return this.renderVN(h);
  }
});
/* define-vxe-component end */