"use strict";

var _interopRequireDefault = require("E:/OPU/\u524D\u7AEF\u5F00\u53D1\u9879\u76EE/opu-components-vue/node_modules/@babel/runtime/helpers/interopRequireDefault.js").default;

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

require("core-js/modules/es.array.concat.js");

require("core-js/modules/es.object.to-string.js");

require("core-js/modules/es.regexp.to-string.js");

var _toConsumableArray2 = _interopRequireDefault(require("E:/OPU/\u524D\u7AEF\u5F00\u53D1\u9879\u76EE/opu-components-vue/node_modules/@babel/runtime/helpers/esm/toConsumableArray.js"));

var _objectSpread2 = _interopRequireDefault(require("E:/OPU/\u524D\u7AEF\u5F00\u53D1\u9879\u76EE/opu-components-vue/node_modules/@babel/runtime/helpers/esm/objectSpread2.js"));

var _interface = require("ant-design-vue/lib/tree-select/interface");

var _utils = _interopRequireDefault(require("../../utils"));

var _default2 = {
  name: "optionsComponent",
  components: {},
  props: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _interface.TreeSelectProps)()), {}, {
    searchFields: {
      type: Array,
      default: function _default() {
        return [];
      }
    }
  }),
  model: {
    prop: "value",
    event: "update"
  },
  data: function data() {
    return {
      optionsData: []
    };
  },
  watch: {
    treeData: function treeData(val) {
      this.setOptionsData(val);
    }
  },
  computed: {
    componentProps: function componentProps() {
      var _this = this;

      var $listeners = this.$listeners,
          $options = this.$options,
          optionsData = this.optionsData,
          replaceFields = this.replaceFields,
          searchFields = this.searchFields;
      var propsData = $options.propsData;
      var ons = {};

      _utils.default.each($listeners, function (cb, type) {
        ons[type] = function () {
          for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
            args[_key] = arguments[_key];
          }

          _this.$emit.apply(_this, [type].concat(args));
        };
      });

      var props = {
        props: (0, _objectSpread2.default)({}, propsData),
        on: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ons), {}, {
          change: this.updateValue
        })
      };

      if (props.props.showSearch && !props.props.filterTreeNode) {
        props.props.filterTreeNode = function (value, treeNode) {
          var obj = treeNode.componentOptions.propsData.dataRef;
          var is = false;
          var searchFieldList = [replaceFields.key, replaceFields.title].concat((0, _toConsumableArray2.default)(searchFields));

          for (var i = 0; i < searchFieldList.length; i++) {
            var key = searchFieldList[i];

            if (obj[key]) {
              if (obj[key].toString().toLowerCase().indexOf(value.toLowerCase()) >= 0) {
                is = true;
                break;
              }
            }
          }

          return is;
        };
      }

      props.props.treeData = optionsData;
      return props;
    }
  },
  created: function created() {
    this.optionsData = this.treeData;
  },
  methods: {
    updateValue: function updateValue(value) {
      this.$emit("update", value);
      this.$emit("change", value);
    },
    setOptionsData: function setOptionsData(data) {
      this.optionsData = data;
      return data;
    },
    getOptionsData: function getOptionsData() {
      return this.optionsData;
    },
    focus: function focus() {
      var input = this.$refs.inputComponent;
      input.focus();
    },
    blur: function blur() {
      var input = this.$refs.inputComponent;
      input.blur();
      input.$refs.vcTreeSelect.onDropdownVisibleChange(false);
    }
  },
  render: function render(h) {
    var componentProps = this.componentProps;
    return h("a-tree-select", {
      ref: "inputComponent",
      props: (0, _objectSpread2.default)({}, componentProps.props),
      on: (0, _objectSpread2.default)({}, componentProps.on)
    }, []);
  }
};
exports.default = _default2;