<template>
  <div class="QdmCheckbox" :class="inline ? 'inline' : ''">
    <span :style="'width:' + colSpan + 'px;text-align:' + align + ';'"><i v-if="must">*</i>{{ name }}</span>
    <el-checkbox-group v-model="checkList" @change="checkboxChange"  :disabled="disabled">
      <el-checkbox v-for="(item, index) in list" :key="index" :label="item.id">{{ item.name }}</el-checkbox>
    </el-checkbox-group>
  </div>
</template>
<script>
export default {
  name: "QdmCheckbox",
  props: {
    name: {
      type: String,
      default: ''
    },
    value: {
      type: Array,
      default: () => {
        return []
      }
    },
    list: {
      type: Array,
      default: () => {
        return []
      }
    },
    colSpan: {
      type: Number,
      default: 60
    },
    align: {
    	type: String,
      default: 'right'
    },
    inline: {
      type: Boolean,
      default: false
    },
    must: {
      type: Boolean,
      default: false
    },
    disabled: {
    	type: Boolean,
      default: false
    }
  },
  data() {
    return {
      checkList: []
    }
  },
  created() {
    this.checkList = this.value
  },
  methods: {
    checkboxChange() {
      this.$emit('checkboxReturn', this.checkList)
    }
  },
  watch: {
  	value(val) {
  		this.checkList = val
  	}
  }
}
</script>
<style lang="less">
.QdmCheckbox {
  margin-right: 10px;
  margin-bottom: 8px;
  height: 30px;
  >span {
    display: block;
    height: 30px;
    float: left;
    line-height: 30px;
    padding-right: 8px;
    font-size: 12px;
    >i {
      color: #F5222D;
      margin-right: 5px;
      padding-left: 3px;
    }
  }
  .el-checkbox-group {
    float: left;
    >label {
      line-height: 30px;
    }
    .el-checkbox__label {
    	font-size: 12px;
    }
  }
  &.inline {
    float: left;
  }
}
</style>