<template>
  <div style=" width:auto; display:inline-block !important; margin-top:8px;">
    <a-checkbox-group v-model="checked" name="checkboxgroup" :options="options" :disabled="disabled" @change="onChange" />
  </div>
</template>
<script>


export default {
  name: "paraCheck",
  data () {
    return {
      options: [],
      checked: [],
    };
  },
  props: {
    value: {
      type: Array,
      default: () => {
        return []
      }
    },
    typeId: {
      type: Number,
      default: () => {
        return null
      }
    },
    code: {
      type: String,
      default: () => {
        return null
      }
    },
    disabled: {
      type: Boolean,
      default: () => {
        return false;
      }
    }
  },
  created () {
    this.loadCheck()
  },
  methods: {
    loadCheck () {
      let pars = { typeId: this.typeId }
      this.$api.parameter.getParameterList(pars).then(({ data = { data } }) => {
        if (data) {
          this.options = []
          data.data.forEach(e => {
            this.options.push({ label: e.title, value: e.key })
          })
          if (!!this.value) {
            this.checked = this.value
          }
        }
      }).catch(() => { })
    },
    onChange (value) {
      this.$emit("input", value);
      this.$emit("change");
    }
  },
  watch: {
    value: {
      handler (value) {
        if (!!value)
          this.checked = this.value
      },
    },
  }
};
</script>
