<template>
  <el-cascader
    v-model="value"
    :options="options"
    @change="handleChange"
    filterable
  ></el-cascader>
</template>

<script>
import { menuSelectApps } from "@/api/report";

export default {
  name: "ZxAppSelect",
  props: {
    menuCode: {
      type: String,
      default: "game.Overview",
    },
    platformId: {
      type: Number,
      default: 5,
    },
    all: {
      type: Boolean,
      default: false,
    },
    defaultValue: {
      type: [Array, String],
      default: () => ["", ""],
    },
  },
  data() {
    return {
      options: [],
      value: [],
    };
  },

  created() {
    this.APIMenuSelectApps(); // 获取应用
    this.$emit("input", this.defaultValue);
  },

  watch: {
    /* 保证数据双向绑定 */
    value(val) {
      this.$emit("input", val);
    },
  },
  methods: {
    APIMenuSelectApps() {
      let params = {
        platformId: this.platformId,
        menuCode: this.menuCode,
        belongGroup: true,
      };
      menuSelectApps(params).then((res) => {
        this.options = res.result.data;
        if (this.all) {
          this.options.unshift({
            label: "全部",
            value: "",
            children: [{ label: "全部", value: "" }],
          });
        }
        this.value = this.defaultValue;
      });
    },

    /* 将级联数据 发射出去 */
    handleChange() {
      this.$nextTick(() => {
        this.$emit("change", this.value);
      });
    },
  },
};
</script>

<style></style>
