MultiCheckBox.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <div class="multiCheckbox" >
  3. <div class="linkMulti_list" ref="mycheckMul">
  4. <div class="title">{{title}}</div>
  5. <ul class="linkMulti_list_one">
  6. <li class="checkAll"><a-checkbox :indeterminate="indeterminate" :checked="checkAll" @change="onCheckAllChange"> 全选</a-checkbox> </li>
  7. <li @click="listItemClick(item)" v-for="(item,index) in listArr" :key='index' >
  8. <a-checkbox @change='checkItemChange' >{{item.name}}</a-checkbox>
  9. <span class="more" v-show="item.children"><a-icon type="right" /></span>
  10. </li>
  11. </ul>
  12. </div>
  13. <MultiCheckBox class="childClass" :title='currentItem.name' :listArr='currentItem.children' v-if="currentItem" :curLayerNum='currentLayerNum' />
  14. </div>
  15. </template>
  16. <script>
  17. const plainOptions = ['Apple', 'Pear', 'Orange'];
  18. export default {
  19. name:'MultiCheckBox',
  20. props:['title','listArr','curLayerNum'],
  21. data() {
  22. return {
  23. checkedList: [],
  24. indeterminate: false,
  25. checkAll: false,
  26. plainOptions,
  27. layersNum:0,//控制层级
  28. currentLayerNum:0,//当前层级是多少层,
  29. currentItem:null,
  30. }
  31. },
  32. methods: {
  33. onChange(checkedList) {
  34. this.indeterminate = !!checkedList.length && checkedList.length < plainOptions.length;
  35. this.checkAll = checkedList.length === plainOptions.length;
  36. },
  37. onCheckAllChange(e) {
  38. Object.assign(this, {
  39. checkedList: e.target.checked ? plainOptions : [],
  40. indeterminate: false,
  41. checkAll: e.target.checked,
  42. });
  43. },
  44. listItemClick(item){
  45. console.log(item);
  46. if(item.children){
  47. this.currentLayerNum++;
  48. this.currentItem=item;
  49. this.$refs.mycheckMul.style='width:50%;border-right:1px solid #ccc';
  50. }
  51. },
  52. checkItemChange(e){
  53. console.log(e.target.checked);
  54. // if(e.target.checked){
  55. // }
  56. },
  57. //判断传入的数组的children层数
  58. getLayersNum(arr){
  59. arr.map((item,index)=>{
  60. if(item.children){
  61. }
  62. })
  63. }
  64. },
  65. mounted() {
  66. this.currentLayerNum=this.curLayerNum;
  67. console.log(this.curLayerNum)
  68. },
  69. }
  70. </script>
  71. <style lang="scss" scoped>
  72. .multiCheckbox{
  73. // width:100%;
  74. // overflow: auto;
  75. height: 100%;
  76. display: flex;
  77. overflow: scorll;
  78. ul,li{
  79. margin: 0;
  80. padding: 0;
  81. list-style: none;
  82. }
  83. .linkMulti_list{
  84. // padding: 5px 0px;
  85. display: inline-block;
  86. width: 100%;
  87. height: 300px;
  88. box-sizing: border-box;
  89. overflow: hidden;
  90. .title{
  91. height: 36px;
  92. line-height: 36px;
  93. font-size: 14px;
  94. font-weight: 600;
  95. border-radius: 5px 5px 0 0;
  96. background-color: rgb(248,249,250);
  97. padding: 0 15px;
  98. border-bottom: 1px solid #ccc;
  99. }
  100. ul{
  101. height: 264px;
  102. overflow: auto;
  103. }
  104. .checkAll{
  105. }
  106. li{
  107. height: 30px;
  108. line-height: 30px;
  109. cursor: pointer;
  110. padding: 0 15px;
  111. position: relative;
  112. .more{
  113. position:absolute;
  114. top: 2px;
  115. right: 10px;
  116. }
  117. }
  118. li:hover{
  119. background-color: rgb(240,240,240);
  120. }
  121. }
  122. .ant-checkbox-group{
  123. width: 100%;
  124. }
  125. }
  126. ul,li{
  127. margin: 0;
  128. padding: 0;
  129. list-style: none;
  130. }
  131. .linkMulti_list{
  132. // padding: 5px 0px;
  133. display: inline-block;
  134. width: 100%;
  135. min-width: 200px;
  136. height: 300px;
  137. box-sizing: border-box;
  138. overflow: auto;
  139. .title{
  140. height: 36px;
  141. line-height: 36px;
  142. font-size: 14px;
  143. font-weight: 600;
  144. border-radius: 5px 5px 0 0;
  145. background-color: rgb(248,249,250);
  146. padding: 0 15px;
  147. border-bottom: 1px solid #ccc;
  148. }
  149. ul{
  150. height: 264px;
  151. overflow: auto;
  152. }
  153. .checkAll{
  154. }
  155. li{
  156. height: 30px;
  157. line-height: 30px;
  158. cursor: pointer;
  159. padding: 0 15px;
  160. position: relative;
  161. .more{
  162. position:absolute;
  163. top: 2px;
  164. right: 10px;
  165. }
  166. }
  167. li:hover{
  168. background-color: rgb(240,240,240);
  169. }
  170. }
  171. .addborder{
  172. border-right: 1px solid #ccc;
  173. }
  174. </style>