Component({
  options: { multipleSlots: true },
  /**
   * 组件的属性列表
   */
  properties: {
    mode: { type: String, value: "single" },
    title: { type: String, value: "请选择" },
    options: { type: Array, value: [] },
    value: { type: null, value: [] },
  },
  observers: {
    "value,mode": function (v, m) {
      if (m == "multiple") {
        this.setData({ val: Array.isArray(v) ? [...v] : [] });
      } else {
        this.setData({ val: v });
      }
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    visible: false,
    val: [] as any[] | string | number,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    click() {
      this.setData({ visible: true });
    },
    close() {
      this.setData({ visible: false });
    },
    radioChange(e: any) {
      this.triggerEvent("change", { value: e.detail.value });
      this.setData({ val: e.detail.value, visible: false });
    },
    checkboxChange(e: any) {
      this.setData({ val: e.detail.value });
    },
    ok() {
      this.setData({ visible: false });
      this.triggerEvent("change", { value: this.data.val });
    },
  },
});

