row.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view class="row">
  3. <view class="content-wrap" @click="rowClick">
  4. <view class="left">
  5. <view>
  6. <image class="left-icon"
  7. :style="{width: hasChildren ? '25rpx' : '20rpx'}"
  8. :src="`../../static/${leftIcon}.png`"></image>
  9. </view>
  10. <text>{{ option.label }}</text>
  11. </view>
  12. <view v-if="parentCheckble||option.parentId !== 0" class="right" @click="checkedHandle">
  13. <image :src="`../../static/${rightIcon}.png`"></image>
  14. </view>
  15. </view>
  16. <view class="children-wrap" v-if="open">
  17. <tm-trees-row v-for="(item,index) in option.children"
  18. :option="item"
  19. :openKeys="openKeys"
  20. :checkedKeys="checkedKeys"
  21. v-on:open-keys="openKeysHandle"
  22. v-on:checked-keys="checkedKeysHandle"
  23. :key="index"/>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import {_stopPropagation} from "../../utils/compatible.js";
  29. import {arrFilter} from "../../utils/arrFilter.js";
  30. export default {
  31. data() {
  32. return {
  33. }
  34. },
  35. props: ['option', 'openKeys', 'checkedKeys','parentCheck'],
  36. computed: {
  37. hasChildren: function() {
  38. return this.option.children && this.option.children.length > 0;
  39. },
  40. open: function() {
  41. return this.hasChildren && this.openKeys.includes(this.option.key);
  42. },
  43. checked: function() {
  44. return this.checkedKeys.includes(this.option.key);
  45. },
  46. parentCheckble(){
  47. //父级节点是否可选
  48. return this.parentCheck;
  49. },
  50. leftIcon: function() {
  51. let iconName = 'parent-open';
  52. if(this.hasChildren) {
  53. if(this.open) {
  54. iconName = 'parent-close';
  55. }
  56. } else {
  57. iconName = 'child'
  58. }
  59. return iconName;
  60. },
  61. rightIcon: function() {
  62. return this.checked ? 'check-checkbox' : 'check-no';
  63. }
  64. },
  65. mounted() {
  66. // console.log('this.props',this.parentCheckble);
  67. },
  68. methods: {
  69. rowClick: function() {
  70. if(!this.hasChildren) return;
  71. this.openKeysHandle(arrFilter(this.option.key, this.openKeys));
  72. },
  73. checkedHandle: function(e) {
  74. _stopPropagation(e);
  75. let checkedKeys = this.checkedKeys;
  76. if(this.option.children&&this.option.children.length>0){
  77. //勾选的是父级
  78. const keys = this.option.children.map(item=>item.key);
  79. [...keys,this.option.key].forEach(item=>{
  80. const index = checkedKeys.findIndex(key => key == item);
  81. if(index != -1){
  82. checkedKeys.splice(index,1);
  83. }else{
  84. checkedKeys.push(item);
  85. }
  86. });
  87. this.checkedKeysHandle(checkedKeys,this.option);
  88. }else{
  89. this.checkedKeysHandle(arrFilter(this.option.key, this.checkedKeys),this.option);
  90. }
  91. },
  92. openKeysHandle: function(arr) {
  93. this.$emit('open-keys', arr);
  94. },
  95. checkedKeysHandle: function(arr,items) {
  96. this.$emit('checked-keys',arr,items);
  97. }
  98. }
  99. }
  100. </script>
  101. <style lang="less">
  102. .row {
  103. display: flex;
  104. flex-direction: column;
  105. align-items: center;
  106. padding-left: 25rpx;
  107. width: 100%;
  108. background-color: #fff;
  109. .content-wrap {
  110. display: flex;
  111. flex-direction: row;
  112. justify-content: space-between;
  113. align-items: center;
  114. border-bottom: 0.62rpx solid #DADEE6;
  115. width: 100%;
  116. height: 87.5rpx;
  117. font-size: 22.5rpx;
  118. line-height: 33.75rpx;
  119. color: #292C33;
  120. .left {
  121. display: flex;
  122. flex-direction: row;
  123. align-items: center;
  124. view {
  125. margin-right: 20rpx;
  126. height: 28rpx;
  127. image {
  128. width: 25rpx;
  129. height: 22.5rpx;
  130. }
  131. }
  132. }
  133. .right {
  134. display: flex;
  135. flex-direction: row;
  136. justify-content: center;
  137. align-items: center;
  138. width: 87.5rpx;
  139. height: 87.5rpx;
  140. image {
  141. width: 25rpx;
  142. height: 25rpx;
  143. }
  144. }
  145. }
  146. .children-wrap {
  147. width: 100%;
  148. padding-left: 77.5rpx;
  149. }
  150. }
  151. </style>