"use strict";

var _interopRequireDefault = require("E:/T/git/\u5965\u666ETeam/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.number.constructor.js");

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

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

var _objectSpread2 = _interopRequireDefault(require("E:/T/git/\u5965\u666ETeam/opu-components-vue/node_modules/@babel/runtime/helpers/esm/objectSpread2.js"));

var _autoComplete = require("ant-design-vue/lib/auto-complete");

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

/**
 * 有下拉数据的输入组件
 */
var _default = {
  name: "optionsComponent",
  components: {},
  props: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _autoComplete.AutoCompleteProps), {}, {
    renderName: {
      type: String,
      default: "a-auto-complete"
    },
    value: [Number, String, Object, Array],
    options: Array,
    componentPropsData: Object
  }),
  model: {
    prop: "value",
    event: "update"
  },
  data: function data() {
    return {
      optionsData: []
    };
  },
  computed: {
    componentProps: function componentProps() {
      var _this = this;

      var $listeners = this.$listeners,
          optionsData = this.optionsData,
          componentPropsData = this.componentPropsData,
          value = this.value;
      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 currentValue = value;

      if (value && _utils.default.isNumber(value)) {
        currentValue = value + "";
      } else if (value && _utils.default.isArray(value)) {
        currentValue = value.map(function (p) {
          return p + "";
        });
      }

      var props = {
        props: (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, componentPropsData), {
          dataSource: optionsData
        }), {}, {
          value: currentValue
        }),
        on: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ons), {}, {
          change: this.updateValue
        })
      };
      props.props.options = optionsData;
      return props;
    }
  },
  created: function created() {
    this.init();
  },
  methods: {
    init: function init() {
      var options = this.options;

      if (options && options.length) {
        this.optionsData = options;
      }
    },
    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() {
      // const that = this;
      var input = this.$refs.inputComponent;
      input.focus(); // const el = input.$el;
      // // select获得输入焦点，弹出下拉面板
      // const box = el.getElementsByClassName("ant-select-selection__rendered");
      // if (box && box.length) {
      //   box[0].click();
      // }
    }
  },
  render: function render(h) {
    var renderName = this.renderName,
        componentProps = this.componentProps;
    return h(renderName, {
      ref: "inputComponent",
      props: (0, _objectSpread2.default)({}, componentProps.props),
      on: (0, _objectSpread2.default)({}, componentProps.on)
    }, []);
  }
};
exports.default = _default;