<template>
  <el-cascader
    :size="size"
    :style="{ width: limitWidth ? '240px' : '100%' }"
    v-model="value.tenant_id"
    clearable
    separator="-"
    placeholder="请选择，支持搜索"
    :options="tenantOptions"
    filterable
    :props="{ emitPath: false, value: 'id', label: 'name' }"
  ></el-cascader>
</template>
<script>
import { tenantSelect } from "@/api/subPlatform/tenant";
export default {
  props: {
    value: Object,
    size: {
      type: String,
      default: "small",
    },
    limitWidth: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      tenantOptions: [],
    };
  },
  // watch: {
  //   value: {
  //     handler(newVal, oldVal) {
  //       if (newVal == "" || newVal == null) {
  //         this.tenant_id = undefined;
  //       } else {
  //         this.tenant_id = newVal;
  //       }
  //     },
  //     immediate: true,
  //   },
  //   tenant_id(newVal, oldVal) {
  //     this.$emit("handleChange", newVal);
  //   },
  // },
  created() {
    tenantSelect().then((res) => {
      for (const key in res.data) {
        if (Object.hasOwnProperty.call(res.data, key)) {
          const item = res.data[key];
          this.tenantOptions.push(item);
        }
      }
    });
  },
};
</script>