UiCheckbox.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <el-row class="form-group">
  3. <el-col :span="3" style="min-height:50px;padding-top:10px;">
  4. <label style="margin-left:10px;vertical-align: middle;" class="control-label">{{label ? label : 'CheckBox'}}</label>
  5. </el-col>
  6. <el-col :span="14">
  7. <div class=".layui-input-block-my">
  8. <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
  9. <div style="margin: 15px 0;"></div>
  10. <br>
  11. <el-checkbox-group
  12. v-model="checkedbox"
  13. :size="params.group.size ? 'large' : 'small'"
  14. :fill="params.group.fill ? params.group.fill : '#20a0ff'"
  15. :text-color="params.group.textColor ? params.group.textColor : '#ffffff'"
  16. :min="params.group.min ? params.group.min : 0"
  17. :max="params.group.max ? params.group.max : 100"
  18. @change="handleCheckedCitiesChange">
  19. <el-checkbox
  20. v-for="item in params.attr.checkboxs"
  21. :key="item.value"
  22. :name="params.attr.name ? params.attr.name : 'checkbox[]'"
  23. :disable="item.disable ? true : false"
  24. :checked="item.checked ? true : false"
  25. :label="item.value" border>{{item.label}}
  26. </el-checkbox>
  27. &ensp;&ensp;&ensp;&ensp;
  28. </el-checkbox-group>
  29. </div>
  30. </el-col>
  31. <el-col :span="7">
  32. <div class="classJs">
  33. <div v-if="tips">
  34. <span class="red">*</span>&ensp;{{tips}}
  35. </div>
  36. </div>
  37. </el-col>
  38. </el-row>
  39. </template>
  40. <script>
  41. export default {
  42. props: ['label','params','tips'],
  43. data() {
  44. return {
  45. checkAll: false,
  46. isIndeterminate: false,
  47. checkedbox: []
  48. }
  49. },
  50. mounted() {
  51. //> 判断当前是否是全选
  52. //> this.checkAll = true;
  53. },
  54. methods: {
  55. handleCheckAllChange(event) {
  56. console.log(event.target.checked);
  57. this.checkedbox = event.target.checked ? this.dataAll() : [];
  58. this.isIndeterminate = false;
  59. },
  60. handleCheckedCitiesChange(value) {
  61. let checkedCount = value.length;
  62. let paramLength = this.params.attr.checkboxs.length;
  63. this.checkAll = checkedCount === paramLength;
  64. this.isIndeterminate = checkedCount > 0 && checkedCount < paramLength;
  65. },
  66. dataAll(){
  67. var _data = [];
  68. var _th = this.params.attr.checkboxs;
  69. var length = _th.length;
  70. for (var i = 0; i < length; ++i) {
  71. if(!_th[i].disabled){
  72. _data.push(_th[i].value);
  73. }
  74. }
  75. console.log(_data);
  76. return _data;
  77. }
  78. }
  79. }
  80. </script>
  81. <style scoped>
  82. .el-checkbox__original {
  83. display: none;
  84. }
  85. .layui-input-block-my {
  86. margin-left:0;
  87. min-height: 42px;
  88. }
  89. .classJs {
  90. margin-left: 10px;
  91. vertical-align: middle;
  92. height:42px;
  93. line-height:42px;
  94. }
  95. .red{
  96. color: red;
  97. }
  98. </style>