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

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

export default {
  name: "ZxGpaccountSelect",
  model: {
    prop: "value",
    event: "change",
  },
  props: {
    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;
      gpAccountSelectList({
      }).then((res) => {
        var newList = []
        for (var i = 0; i < res.result.data.length; i++) {
          res.result.data[i]['value'] = res.result.data[i]['value'] + ''
          newList.push(res.result.data[i])
        }
        this.list = newList
        this.$emit("list", this.list);
        if (this.addAllOption == "true") {
          this.list.unshift({
            lable: "全部",
            value: "",
          });
        }
      });
    },
    handleChange(value) {
      this.$emit("change", value);
    },
  },
};
</script>
