<template>
  <div>
    <slot></slot>
    <el-select
      :value="value"
      filterable
      placeholder="请选择"
      @change="handleChange"
    >
      <el-option
        v-for="item in list"
        :key="item.id"
        :value="item.value"
        :label="item.label"
      />
    </el-select>
  </div>
</template>

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

export default {
  name: "ZxAppSelect1",
  model: {
    prop: "value",
    event: "change",
  },
  props: {
    platformId: {
      type: String,
      required: true,
    },
    menuCode: {
      type: String,
      required: true,
    },
    defaultValue: {
      type: String,
      required: false,
    },
    addAllOption: {
      type: [Boolean, String],
      required: false,
    },
    value: {
      type: [String, Number],
    },
  },
  data() {
    return {
      queryDate: [],
      selectValue: "",
      list: [],
    };
  },
  created() {
    this.init();
  },
  // 子组件监控日期组件的值发生变化的时候，通过emit传给父组件，父组件用v-model接收。这样就把子组件的v-model功能，传给了父组件
  watch: {
    value(val) {
      this.$emit("input", val);
    },
  },

  methods: {
    // 获取App名称配置列表
    init: function () {
      this.selectValue = this.defaultValue;
      menuSelectApps({
        platformId: this.platformId,
        menuCode: this.menuCode,
      }).then((res) => {
        this.list = res.result.data;
        var newList = []
        for (var i = 0; i < this.list.length; i++) {
          if (res.result.data[i].is_g_app == 1 && res.result.data[i].operate_type != null && res.result.data[i].operate_type != '') {
            if (res.result.data[i].status == 3 || res.result.data[i].status == 7 || res.result.data[i].status == 8) {
              newList.push(this.list[i])
            }
          }
        }
        this.list = newList
        this.$emit("list", this.list);
      });
    },
    handleChange(value) {
      this.$emit("change", value);
    },
  },
};
</script>
