<template>
  <el-checkbox-group class="ps-checkbox" v-model="inputValue" :disabled="disabled" @change="operaChange">
    <el-checkbox :label="defalutProps ? item[defalutProps.id] : item.id" v-for="(item, index) in dataSource"
      :key="index">{{ defalutProps ? item[defalutProps.desc] : item.desc }}</el-checkbox>
  </el-checkbox-group>
</template>

<script>
export default {
  name: "PsCheckbox",
  props: {
    value: null,
    dataSource: {
      type: Array,
      default: () => []
    },
    defalutProps: {
      type: Object,
      default: () => undefined
    },
    
    disabled: {
      type: Boolean,
      default: false
    },

    id: { type: String, default: "" }
  },
  //处理v-model语法糖的emit事件
  model: {
    prop: 'value',
    event: 'handler'
  },
  watch: {
    value: {
      handler(val) {
        this.inputValue = val || []
      },
      immediate: true
    }
  },
  data() {
    return {
      inputValue: [],
    };
  },
  created() {

  },
  mounted() {
  },
  methods: {
    operaChange(e) {
      this.$emit('handler', e)
      this.$emit("change", e);
    },
  },
};
</script>

<style></style>
