<template>
  <el-cascader
    size="small"
    style="width: 240px"
    v-model="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: String,
  },
  data() {
    return {
      tenantOptions: [],
      tenant_id: undefined,
    };
  },
  watch: {
    value(newVal, oldVal) {
      if (newVal == "") {
        this.tenant_id = undefined;
      } else {
        this.tenant_id = newVal;
      }
    },
    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>