<!--
 * @Descripttion:
 * @Version: 1.0
 * @Author: +C
 * @Date: 2022-02-15 08:47:06
 * @LastEditors: wufz
 * @LastEditTime: 2022-02-25 11:49:27
-->
<script>
import formComponents from "./formComponents"
export default {
  name: `DxxAutoComplete`,
  //继承表单父组件
  extends: formComponents,
  /* 这里的v-model的值将会传入这个名为 value的prop。同时当组件触发一个 change事件并附带一个新的值的时候，这个 value的 property将会被更新。 */
  model: {
    prop: 'value',
    event: 'change'
  },
  // functional: true, //函数式组件
  props: {
    value: { // v-model绑定的值
      type: String,
      required: false
    }
  },
  methods: {
    /**
     * @description: 让下拉框相对定位到表单组件而不是body
     * @author: wufz
     * @return {*}
     */
    getPopupContainer() {
      return this.$parent.$el
    }
  },
  //建立虚拟 DOM
  render: function (createElement) {
    // let _this = Object.entries(this)

    //详细：dom输出值
    let drawText = createElement(`span`, {}, [this._props.value])
    this.$attrs.getPopupContainer = this.getPopupContainer

    //编辑：dom表单元素
    let drawFromComponents = createElement(
      // 标签名称
      `a-auto-complete`,
      // 传递数据
      {
        attrs: {
          ...this.$attrs
        },
        props: {
          ...this._props
        },
        on: {
          ...this.$listeners
        },
        scopedSlots: {
          ...this.$scopedSlots
        }
        /* ...context.data,
        props: {
          ...context.props
        },
        class: (context.data.staticClass || "") + " dxx-select", //自定义class
        style: {
          ...context.data.staticStyle
        } */
      },
      // 子节点数组，createElement...
      [
        this.$slots.default
      ]
    );

    return this.isDetail ? drawText : drawFromComponents;
  }
};
</script>

<style scoped>
</style>